@Override protected void run(@NotNull Result result) throws Throwable { finalChildOfType.putKeyValue(next); }
/** * FOO: * - foobar * * FOO: [foobar] */ @NotNull static public Collection<YAMLSequenceItem> getSequenceItems(@NotNull YAMLKeyValue yamlKeyValue) { PsiElement yamlSequence = yamlKeyValue.getLastChild(); if(yamlSequence instanceof YAMLSequence) { return ((YAMLSequence) yamlSequence).getItems(); } return Collections.emptyList(); }
/** * [ROLE_USER, FEATURE_ALPHA, ROLE_ALLOWED_TO_SWITCH] */ @NotNull static public Collection<String> getYamlArrayValuesAsList(@NotNull YAMLSequence yamlArray) { Collection<String> keys = new ArrayList<>(); for (YAMLSequenceItem yamlSequenceItem : yamlArray.getItems()) { YAMLValue value = yamlSequenceItem.getValue(); if(!(value instanceof YAMLScalar)) { continue; } String textValue = ((YAMLScalar) value).getTextValue(); if(StringUtils.isNotBlank(textValue)) { keys.add(textValue); } } return keys; }
@Override public boolean accepts(@NotNull YAMLKeyValue yamlKeyValue, ProcessingContext processingContext) { return this.keyText.equals(yamlKeyValue.getKeyText()); } }
/** * 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[]{}); }
@Nullable public static String getStringValueOfKeyInProbablyMapping(@Nullable YAMLValue node, @NotNull String keyText) { YAMLKeyValue mapping = YAMLUtil.findKeyInProbablyMapping(node, keyText); if(mapping == null) { return null; } YAMLValue value = mapping.getValue(); if(value == null) { return null; } return value.getText(); }
@Override public PsiElement extractObjectForValidation(final PsiElement psiElement) { final Optional<PsiElement> thirdParent = Optional.ofNullable(psiElement.getParent()) .map(PsiElement::getParent) .map(PsiElement::getParent); if (thirdParent.isPresent() && thirdParent.get() instanceof YAMLSequenceItem) { return ((YAMLSequenceItem) thirdParent.get()).getValue(); } else if (thirdParent.isPresent() && thirdParent.get() instanceof YAMLKeyValue) { return ((YAMLKeyValue) thirdParent.get()).getKey(); } else { return psiElement.getParent(); } }
@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(); }
/** * Simplify getting of array psi elements in array or sequence context * * arguments: [@foo] * arguments: * - @foo * * TODO: can be handled nice know because on new yaml plugin */ @Nullable public static List<PsiElement> getYamlArrayOnSequenceOrArrayElements(@NotNull YAMLCompoundValue yamlCompoundValue) { if (yamlCompoundValue instanceof YAMLSequence) { return new ArrayList<>(((YAMLSequence) yamlCompoundValue).getItems()); } if (yamlCompoundValue instanceof YAMLMapping) { return new ArrayList<>(((YAMLMapping) yamlCompoundValue).getKeyValues()); } return null; }
@Nullable public static YAMLKeyValue getYamlKeyValue(@Nullable YAMLKeyValue yamlKeyValue, String keyName, boolean ignoreCase) { if(yamlKeyValue == null) { return null; } PsiElement yamlCompoundValue = yamlKeyValue.getValue(); if(!(yamlCompoundValue instanceof YAMLCompoundValue)) { return null; } return getYamlKeyValue(yamlCompoundValue, keyName, ignoreCase); }
private Optional<YAMLKeyValue> getAsYamlKeyValue(final PsiElement psiElement) { return Optional.ofNullable(psiElement) .map(PsiElement::getParent) .filter(el -> el instanceof YAMLKeyValue) .map(YAMLKeyValue.class::cast) .filter(value -> value.getKey() == psiElement); }
@Override public boolean accepts(@NotNull YAMLScalar yamlScalar, ProcessingContext processingContext) { return StringUtils.startsWith(yamlScalar.getTextValue(), value); } }
@Override public boolean accepts(@NotNull YAMLKeyValue yamlKeyValue, ProcessingContext context) { return "_defaults".equals(yamlKeyValue.getKeyText()); } }));
@Override public boolean isValue(final PsiElement psiElement) { return !(org.apache.commons.lang.StringUtils.isBlank(psiElement.getText()) || psiElement instanceof YAMLKeyValue) && Optional.ofNullable(psiElement.getParent()) .map(PsiElement::getParent) .filter(el -> el instanceof YAMLKeyValue) .map(YAMLKeyValue.class::cast) .filter(el -> el.getValue() == psiElement.getParent()) .isPresent(); }
@Override public boolean accepts(@NotNull YAMLKeyValue yamlKeyValue, ProcessingContext context) { return "bind".equals(yamlKeyValue.getKeyText()); } }).withParent(defaultsKey));
@Override public boolean value(PsiElement psiElement) { return psiElement instanceof YAMLKeyValue && ((YAMLKeyValue) psiElement).getKeyText().equals("name"); } }));
@Override public boolean value(PsiElement psiElement) { return psiElement instanceof YAMLKeyValue && ((YAMLKeyValue) psiElement).getKeyText().equals(this.key); } }
@Override public boolean value(YAMLKeyValue yamlKeyValue) { return key.equals(yamlKeyValue.getKeyText()); } }
@Override public boolean accepts(@NotNull YAMLKeyValue yamlKeyValue, ProcessingContext processingContext) { return yamlKeyValue.getKeyText().equals("foo"); } })));
@Override public boolean accepts(@NotNull YAMLKeyValue yamlKeyValue, ProcessingContext processingContext) { return yamlKeyValue.getKeyText().equals("Service\\YamlBar"); } })));