@NotNull public static Collection<YAMLKeyValue> getTopLevelKeyValues(@NotNull YAMLFile yamlFile) { YAMLDocument yamlDocument = PsiTreeUtil.getChildOfType(yamlFile, YAMLDocument.class); if(yamlDocument == null) { return Collections.emptyList(); } YAMLValue topLevelValue = yamlDocument.getTopLevelValue(); if(!(topLevelValue instanceof YAMLMapping)) { return Collections.emptyList(); } return ((YAMLMapping) topLevelValue).getKeyValues(); }
YAMLValue topLevelValue = yamlDocument.getTopLevelValue(); if(!(topLevelValue instanceof YAMLMapping)) { return null;
/** * Find last known KeyValue of key path, so that we can merge new incoming keys */ @NotNull private static Pair<YAMLKeyValue, String[]> findLastKnownKeyInFile(@NotNull YAMLFile file, @NotNull String... keys) { YAMLKeyValue last = null; YAMLMapping mapping = ObjectUtils.tryCast(file.getDocuments().get(0).getTopLevelValue(), YAMLMapping.class); for (int i = 0; i < keys.length; i++) { String s = keys[i]; if (mapping == null) { return Pair.create(last, Arrays.copyOfRange(keys, i, keys.length)); } YAMLKeyValue keyValue = mapping.getKeyValueByKey(s); if (keyValue == null) { return Pair.create(last, Arrays.copyOfRange(keys, i, keys.length)); } last = keyValue; mapping = ObjectUtils.tryCast(keyValue.getValue(), YAMLMapping.class); } return Pair.create(last, new String[]{}); }
@Override public void visitFile(PsiFile file) { // @TODO: detection of routing files in right way // routing.yml // comment.routing.yml // routing/foo.yml if(!YamlHelper.isRoutingFile(file)) { return; } YAMLDocument document = PsiTreeUtil.findChildOfType(file, YAMLDocument.class); if(document == null) { return; } YAMLValue topLevelValue = document.getTopLevelValue(); if(topLevelValue != null) { YamlHelper.attachDuplicateKeyInspection(topLevelValue, holder); } } }
YAMLDocument yamlDocument = PsiTreeUtil.getChildOfType(psiFile, YAMLDocument.class); if(yamlDocument != null) { YAMLValue topLevelValue = yamlDocument.getTopLevelValue(); if(topLevelValue instanceof YAMLMapping) { YAMLKeyValue firstChild = PsiTreeUtil.findChildOfType(topLevelValue, YAMLKeyValue.class);
YAMLValue topLevelValue = ((YAMLFile) psiFile).getDocuments().get(0).getTopLevelValue(); if(topLevelValue instanceof YAMLMapping) { Collection<YAMLKeyValue> keyValues = ((YAMLMapping) topLevelValue).getKeyValues();
/** * Try to find a valid indent value, which are spaces which we need to fill */ public static int getIndentSpaceForFile(@NotNull YAMLFile yamlFile) { List<YAMLDocument> documents = yamlFile.getDocuments(); YAMLMapping mapping = ObjectUtils.tryCast(documents.get(0).getTopLevelValue(), YAMLMapping.class); if(mapping != null) { // first first INDENT element in mapping PsiElementPattern.Capture<PsiElement> pattern = PlatformPatterns .psiElement(YAMLTokenTypes.INDENT) .with(new PsiElementPatternCondition()); for (YAMLPsiElement yamlPsiElement : mapping.getKeyValues()) { // get first value PsiElement firstChild = yamlPsiElement.getFirstChild(); if(firstChild == null) { continue; } // first valid INDENT PsiElement nextSiblingOfType = PsiElementUtils.getNextSiblingOfType(firstChild, pattern); if(nextSiblingOfType != null && nextSiblingOfType.getTextLength() > 0) { return nextSiblingOfType.getTextLength(); } } } // default value return 4; }
YAMLValue topLevelValue = yamlFile.getDocuments().get(0).getTopLevelValue(); if(topLevelValue instanceof YAMLMapping) { childOfType = (YAMLMapping) topLevelValue;