Java Code Examples for fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper#collectServiceTags()

The following examples show how to use fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper#collectServiceTags() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: YamlHelperLightTest.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * @see fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper#collectServiceTags
 */
public void testCollectServiceTagsForSymfony33TagsShortcut() {

    YAMLKeyValue fromText = YamlPsiElementFactory.createFromText(getProject(), YAMLKeyValue.class, "" +
        "foo:\n" +
        "  tags:\n" +
        "    - routing.loader_tags_1\n" +
        "    - routing.loader_tags_2\n"
    );

    assertNotNull(fromText);
    Set<String> collection = YamlHelper.collectServiceTags(fromText);

    assertContainsElements(collection, "routing.loader_tags_1");
    assertContainsElements(collection, "routing.loader_tags_2");
}
 
Example 2
Source File: TaggedExtendsInterfaceClassInspection.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Override
public void visitElement(PsiElement element) {

    if(YamlElementPatternHelper.getSingleLineScalarKey("class").accepts(element)) {

        // class: '\Foo'
        String text = PsiElementUtils.trimQuote(element.getText());
        if(StringUtils.isBlank(text)) {
            super.visitElement(element);
            return;
        }

        PsiElement yamlScalar = element.getParent();
        if(!(yamlScalar instanceof YAMLScalar)) {
            super.visitElement(element);
            return;
        }

        PsiElement classKey = yamlScalar.getParent();
        if(classKey instanceof YAMLKeyValue) {
            PsiElement yamlCompoundValue = classKey.getParent();
            if(yamlCompoundValue instanceof YAMLCompoundValue) {
                PsiElement serviceKeyValue = yamlCompoundValue.getParent();
                if(serviceKeyValue instanceof YAMLKeyValue) {
                    Set<String> tags = YamlHelper.collectServiceTags((YAMLKeyValue) serviceKeyValue);
                    if(tags.size() > 0) {
                        registerTaggedProblems(element, tags, text, holder, this.lazyServiceCollector);
                    }
                }
            }
        }
    }

    super.visitElement(element);
}
 
Example 3
Source File: FormUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * 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.size() > 0) {
            map.put(serviceName, serviceTagMap);
        }
    }

    return map;
}
 
Example 4
Source File: YamlServiceTagIntention.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
private static Pair<PhpClass, Set<String>> invoke(@NotNull Project project, @NotNull YAMLKeyValue serviceKeyValue) {

    String aClass = YamlHelper.getYamlKeyValueAsString(serviceKeyValue, "class");
    if(aClass == null || StringUtils.isBlank(aClass)) {
        PsiElement key = serviceKeyValue.getKey();
        if (key != null) {
            String text = key.getText();
            if (StringUtils.isNotBlank(text) && YamlHelper.isClassServiceId(text)) {
                aClass = text;
            }
        }
    }

    if(aClass == null) {
        return null;
    }

    PhpClass resolvedClassDefinition = ServiceUtil.getResolvedClassDefinition(project, aClass, new ContainerCollectionResolver.LazyServiceCollector(project));
    if(resolvedClassDefinition == null) {
        return null;
    }

    Set<String> phpClassServiceTags = ServiceUtil.getPhpClassServiceTags(resolvedClassDefinition);

    Set<String> strings = YamlHelper.collectServiceTags(serviceKeyValue);
    if(strings.size() > 0) {
        for (String s : strings) {
            if(phpClassServiceTags.contains(s)) {
                phpClassServiceTags.remove(s);
            }
        }
    }

    return Pair.create(resolvedClassDefinition, phpClassServiceTags);
}
 
Example 5
Source File: YamlHelperLightTest.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * @see fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper#collectServiceTags
 */
public void testCollectServiceTagsForSymfony33TagsShortcutInline() {
    YAMLKeyValue fromText = YamlPsiElementFactory.createFromText(getProject(), YAMLKeyValue.class, "" +
        "foo:\n" +
        "  tags: [routing.loader_tags_3, routing.loader_tags_4, 'routing.loader_tags_5']\n"
    );

    assertNotNull(fromText);
    Set<String> collection = YamlHelper.collectServiceTags(fromText);

    assertContainsElements(collection, "routing.loader_tags_3");
    assertContainsElements(collection, "routing.loader_tags_4");
    assertContainsElements(collection, "routing.loader_tags_5");
}
 
Example 6
Source File: YamlKeyValueAttributeValue.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public Collection<String> getTags() {
    return YamlHelper.collectServiceTags(yamlKeyValue);
}