private boolean hasRootKey(final String keyName, final PsiFile psiFile) { return getRootChildrenOfType(psiFile, YAMLKeyValue.class) .stream() .anyMatch(yamlKeyValue -> keyName.equals(yamlKeyValue.getName())); }
public Optional<? extends PsiElement> getRootChildByName( final String keyName, final PsiFile psiFile) { return getRootChildrenOfType(psiFile, YAMLKeyValue.class) .stream() .filter(yamlKeyValue -> keyName.equals(yamlKeyValue.getName())) .findFirst(); }
@Override public List<PsiElement> getTags(final PsiFile psiFile) { return getRootChildrenOfType(psiFile, YAMLKeyValue.class) .stream() .filter(yamlKeyValue -> "tags".equals(yamlKeyValue.getName())) .map(YAMLKeyValue::getValue) .map(YAMLPsiElement::getYAMLElements) .flatMap(Collection::stream) .filter(el -> el instanceof YAMLSequenceItem) .map(YAMLSequenceItem.class::cast) .map(YAMLSequenceItem::getYAMLElements) .flatMap(Collection::stream) .filter(el -> el instanceof YAMLMapping) .map(YAMLMapping.class::cast) .map(yamlMapping -> yamlMapping.getKeyValueByKey("name")) .map(YAMLKeyValue::getValue) .filter(Objects::nonNull) .collect(Collectors.toList()); }
@Override public List<String> getSecurityScopesIfOAuth2(final PsiElement securityDefinitionItem) { final List<YAMLKeyValue> properties = getChildProperties(securityDefinitionItem); final boolean isOAuth2 = properties .stream() .anyMatch( prop -> { final Optional<String> value = Optional.ofNullable(prop.getValue()) .map(YAMLValue::getText) .map(StringUtils::removeAllQuotes); return "type".equals(prop.getName()) && Optional.of("oauth2").equals(value); }); if (isOAuth2) { return properties .stream() .filter(prop -> "scopes".equals(prop.getName())) .map(this::getChildProperties) .flatMap(Collection::stream) .map(YAMLKeyValue::getName) .collect(Collectors.toList()); } return ImmutableList.of(); }
/** * acme_demo.form.type.gender: * class: espend\Form\TypeBundle\Form\FooType * tags: * - { name: form.type, alias: foo_type_alias } * - { name: foo } */ @NotNull public static Map<String, Set<String>> getTags(@NotNull YAMLFile yamlFile) { Map<String, Set<String>> map = new HashMap<>(); for(YAMLKeyValue yamlServiceKeyValue : YamlHelper.getQualifiedKeyValuesInFile(yamlFile, "services")) { String serviceName = yamlServiceKeyValue.getName(); Set<String> serviceTagMap = YamlHelper.collectServiceTags(yamlServiceKeyValue); if(serviceTagMap != null && serviceTagMap.size() > 0) { map.put(serviceName, serviceTagMap); } } return map; }