Java Code Examples for fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent#isEnabledForIndex()

The following examples show how to use fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent#isEnabledForIndex() . 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: ContainerIdUsagesStubIndex.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, Integer, FileContent> getIndexer() {
    return inputData -> {
        Map<String, Integer> map = new HashMap<>();

        PsiFile psiFile = inputData.getPsiFile();
        if(!Symfony2ProjectComponent.isEnabledForIndex(psiFile.getProject())) {
            return map;
        }

        if(!ServicesDefinitionStubIndex.isValidForIndex(inputData, psiFile)) {
            return map;
        }

        if(psiFile instanceof YAMLFile) {
            map.putAll(getIdUsages((YAMLFile) psiFile));
        } else if(psiFile instanceof XmlFile) {
            map.putAll(getIdUsages((XmlFile) psiFile));
        }

        return map;
    };
}
 
Example 2
Source File: ServicesDefinitionStubIndex.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, ServiceSerializable, FileContent> getIndexer() {

    return inputData -> {

        Map<String, ServiceSerializable> map = new THashMap<>();

        PsiFile psiFile = inputData.getPsiFile();
        if(!Symfony2ProjectComponent.isEnabledForIndex(psiFile.getProject()) || !isValidForIndex(inputData, psiFile)) {
            return map;
        }

        for (ServiceSerializable service : ServiceContainerUtil.getServicesInFile(psiFile)) {
            map.put(service.getId().toLowerCase(), service);
        }

        return map;
    };
}
 
Example 3
Source File: ContainerBuilderStubIndex.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, ContainerBuilderCall, FileContent> getIndexer() {

    return inputData -> {

        Map<String, ContainerBuilderCall> map = new THashMap<>();

        PsiFile psiFile = inputData.getPsiFile();
        if(!(psiFile instanceof PhpFile) ||
            !Symfony2ProjectComponent.isEnabledForIndex(psiFile.getProject()) ||
            !isValidForIndex(inputData, psiFile)
            ){

            return map;
        }

        StreamEx.of(PhpPsiUtil.findAllClasses((PhpFile) psiFile))
            .flatMap(clazz -> StreamEx.of(clazz.getOwnMethods()))
            .forEach(method -> processMethod(method, map));
        return map;
    };
}
 
Example 4
Source File: TwigIncludeStubIndex.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, Void, FileContent> getIndexer() {
    return inputData -> {
        final Map<String, Void> map = new THashMap<>();

        PsiFile psiFile = inputData.getPsiFile();
        if(!Symfony2ProjectComponent.isEnabledForIndex(psiFile.getProject())) {
            return map;
        }

        if(!(psiFile instanceof TwigFile)) {
            return map;
        }

        TwigUtil.visitTemplateIncludes((TwigFile) psiFile, templateInclude ->
            map.put(TwigUtil.normalizeTemplateName(templateInclude.getTemplateName()), null)
        );

        return map;
    };

}
 
Example 5
Source File: EventAnnotationStubIndex.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, DispatcherEvent, FileContent> getIndexer() {
    return inputData -> {
        Map<String, DispatcherEvent> map = new HashMap<>();

        PsiFile psiFile = inputData.getPsiFile();
        if(!Symfony2ProjectComponent.isEnabledForIndex(psiFile.getProject())) {
            return map;
        }

        psiFile.accept(new MyPsiRecursiveElementWalkingVisitor(map));

        return map;
    };

}
 
Example 6
Source File: ContainerParameterStubIndex.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, String, FileContent> getIndexer() {
    return inputData -> {
        Map<String, String> map = new HashMap<>();

        PsiFile psiFile = inputData.getPsiFile();
        if(!Symfony2ProjectComponent.isEnabledForIndex(psiFile.getProject())) {
            return map;
        }

        if(!ServicesDefinitionStubIndex.isValidForIndex(inputData, psiFile)) {
            return map;
        }

        if(psiFile instanceof YAMLFile) {
            attachTHashMapNullable(YamlHelper.getLocalParameterMap(psiFile), map);
        } else if(psiFile instanceof XmlFile) {
            attachTHashMapNullable(XmlHelper.getFileParameterMap((XmlFile) psiFile), map);
        }

        return map;
    };
}
 
Example 7
Source File: TwigMacroFunctionStubIndex.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, TwigMacroTagIndex, FileContent> getIndexer() {
    return inputData -> {
        final Map<String, TwigMacroTagIndex> map = new THashMap<>();

        PsiFile psiFile = inputData.getPsiFile();
        if(!Symfony2ProjectComponent.isEnabledForIndex(psiFile.getProject())) {
            return map;
        }

        if(!(psiFile instanceof TwigFile)) {
            return map;
        }

        TwigUtil.visitMacros(psiFile, pair -> map.put(pair.getFirst().getName(), new TwigMacroTagIndex(pair.getFirst().getName(), pair.getFirst().getParameters())));

        return map;
    };

}
 
Example 8
Source File: FileResourcesIndex.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, FileResource, FileContent> getIndexer() {
    return inputData -> {
        PsiFile psiFile = inputData.getPsiFile();
        if(!Symfony2ProjectComponent.isEnabledForIndex(psiFile.getProject()) || !isValidForIndex(inputData, psiFile)) {
            return Collections.emptyMap();
        }

        final Map<String, FileResource> items = new THashMap<>();

        FileResourceVisitorUtil.visitFile(psiFile, consumer ->
            items.put(consumer.getResource(), consumer.createFileResource())
        );

        return items;
    };
}
 
Example 9
Source File: TwigExtendsStubIndex.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, Void, FileContent> getIndexer() {
    return inputData -> {
        Map<String, Void> map = new THashMap<>();

        PsiFile psiFile = inputData.getPsiFile();
        if(!Symfony2ProjectComponent.isEnabledForIndex(psiFile.getProject())) {
            return map;
        }

        if(!(psiFile instanceof TwigFile)) {
            return map;
        }

        TwigUtil.visitTemplateExtends((TwigFile) psiFile, pair ->
            map.put(TwigUtil.normalizeTemplateName(pair.getFirst()), null)
        );

        return map;
    };

}
 
Example 10
Source File: ConfigSchemaIndex.java    From idea-php-drupal-symfony2-bridge with MIT License 5 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, Set<String>, FileContent> getIndexer() {
    return inputData -> {
        Map<String, Set<String>> map = new THashMap<>();

        PsiFile psiFile = inputData.getPsiFile();
        if(!Symfony2ProjectComponent.isEnabledForIndex(psiFile.getProject())) {
            return map;
        }

        if(!(psiFile instanceof YAMLFile) || !isValidForIndex(psiFile)) {
            return map;
        }

        for(YAMLKeyValue yamlKeyValue: YamlHelper.getTopLevelKeyValues((YAMLFile) psiFile)) {
            String key = PsiElementUtils.trimQuote(yamlKeyValue.getKeyText());

            if(StringUtils.isBlank(key) || key.contains("*")) {
                continue;
            }

            Set<String> mappings = new HashSet<>();
            YAMLKeyValue mapping = YamlHelper.getYamlKeyValue(yamlKeyValue, "mapping");
            if(mapping == null) {
                continue;
            }

            Set<String> keySet = YamlHelper.getKeySet(mapping);
            if(keySet != null) {
                mappings.addAll(keySet);
            }

            map.put(key, mappings);
        }

        return map;
    };

}
 
Example 11
Source File: TwigControllerStubIndex.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, Void, FileContent> getIndexer() {
    return inputData -> {
        PsiFile psiFile = inputData.getPsiFile();
        if(!Symfony2ProjectComponent.isEnabledForIndex(psiFile.getProject()) || !(psiFile instanceof TwigFile)) {
            return Collections.emptyMap();
        }

        final Map<String, Void> map = new THashMap<>();
        TwigUtil.visitControllerFunctions(psiFile, pair -> map.put(pair.getFirst(), null));
        return map;
    };

}
 
Example 12
Source File: ServicesTagStubIndex.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, Set<String>, FileContent> getIndexer() {

    return inputData -> {

        Map<String, Set<String>> map = new THashMap<>();

        PsiFile psiFile = inputData.getPsiFile();
        if(!Symfony2ProjectComponent.isEnabledForIndex(psiFile.getProject())) {
            return map;
        }

        if (!ServicesDefinitionStubIndex.isValidForIndex(inputData, psiFile)) {
            return map;
        }

        if(psiFile instanceof YAMLFile) {
            map.putAll(FormUtil.getTags((YAMLFile) psiFile));
        }

        if(psiFile instanceof XmlFile) {
            map.putAll(FormUtil.getTags((XmlFile) psiFile));
        }

        return map;
    };
}
 
Example 13
Source File: PhpTwigTemplateUsageStubIndex.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, TemplateUsage, FileContent> getIndexer() {
    return inputData -> {
        PsiFile psiFile = inputData.getPsiFile();
        if(!Symfony2ProjectComponent.isEnabledForIndex(psiFile.getProject())) {
            return Collections.emptyMap();
        }

        if(!(inputData.getPsiFile() instanceof PhpFile) && isValidForIndex(inputData)) {
            return Collections.emptyMap();
        }

        Map<String, Set<String>> items = new HashMap<>();

        PhpMethodVariableResolveUtil.visitRenderTemplateFunctions(psiFile, triple -> {
            String templateName = triple.getFirst();

            if(!items.containsKey(templateName)) {
                items.put(templateName, new HashSet<>());
            }

            items.get(templateName).add(StringUtils.stripStart(triple.getSecond().getFQN(), "\\"));
        });

        Map<String, TemplateUsage> map = new HashMap<>();

        items.forEach(
            (key, value) -> map.put(key, new TemplateUsage(key, value))
        );

        return map;
    };
}