|
3 | 3 |
|
4 | 4 | import com.intellij.psi.PsiElement;
|
5 | 5 | import com.intellij.psi.util.PsiTreeUtil;
|
| 6 | +import fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper; |
6 | 7 | import org.apache.commons.lang.StringUtils;
|
| 8 | +import org.jetbrains.yaml.YAMLUtil; |
7 | 9 | import org.jetbrains.yaml.psi.*;
|
8 | 10 |
|
9 | 11 | import java.util.ArrayList;
|
|
13 | 15 | public class YamlTranslationVistor {
|
14 | 16 |
|
15 | 17 | public static void collectFileTranslations(YAMLFile yamlFile, YamlTranslationCollector translationCollector) {
|
16 |
| - List<YAMLDocument> documents = yamlFile.getDocuments(); |
17 |
| - |
18 |
| - if(documents.size() < 1) { |
19 |
| - return; |
20 |
| - } |
21 |
| - |
22 |
| - Collection<YAMLKeyValue> yamlKeyValues = PsiTreeUtil.getChildrenOfTypeAsList(documents.get(0), YAMLKeyValue.class); |
23 |
| - for(YAMLKeyValue yamlKeyValue: yamlKeyValues) { |
| 18 | + for(YAMLKeyValue yamlKeyValue: YamlHelper.getTopLevelKeyValues(yamlFile)) { |
24 | 19 | collectItems(yamlKeyValue, translationCollector);
|
25 | 20 | }
|
26 | 21 |
|
@@ -53,15 +48,16 @@ private static boolean collectItems(List<String> levels, YAMLKeyValue yamlKeyVal
|
53 | 48 | return true;
|
54 | 49 | }
|
55 | 50 |
|
| 51 | + // @TODO: use features of new yaml integration |
56 | 52 | // yaml key-value provide main psielement in last child element
|
57 | 53 | // depending of what we get here we have another key-value inside, multiline or string value
|
58 |
| - if(childElements.size() == 1) { |
| 54 | + if(childElements.size() == 1 && childElements.get(0) instanceof YAMLMapping) { |
59 | 55 |
|
60 | 56 |
|
61 | 57 | PsiElement lastChildElement = childElements.get(0);
|
62 | 58 |
|
63 | 59 | // catch next level keys
|
64 |
| - if(lastChildElement instanceof YAMLCompoundValue) { |
| 60 | + if(lastChildElement instanceof YAMLMapping) { |
65 | 61 |
|
66 | 62 | // use copy of current level and pipe to children call
|
67 | 63 | ArrayList<String> copyLevels = new ArrayList<String>(levels);
|
|
0 commit comments