Java Code Examples for fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils#convertVirtualFilesToPsiFiles()

The following examples show how to use fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils#convertVirtualFilesToPsiFiles() . 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: TwigControllerUsageControllerRelatedGotoCollector.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public void collectGotoRelatedItems(ControllerActionGotoRelatedCollectorParameter parameter) {
    Method method = parameter.getMethod();
    PhpClass containingClass = method.getContainingClass();

    if (containingClass == null) {
        return;
    }

    String controllerAction = StringUtils.stripStart(containingClass.getPresentableFQN(), "\\") + "::" + method.getName();

    Collection<VirtualFile> targets = new HashSet<>();
    FileBasedIndex.getInstance().getFilesWithKey(TwigControllerStubIndex.KEY, new HashSet<>(Collections.singletonList(controllerAction)), virtualFile -> {
        targets.add(virtualFile);
        return true;
    }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(parameter.getProject()), TwigFileType.INSTANCE));

    for (PsiFile psiFile: PsiElementUtils.convertVirtualFilesToPsiFiles(parameter.getProject(), targets)) {
        TwigUtil.visitControllerFunctions(psiFile, pair -> {
            if (pair.getFirst().equalsIgnoreCase(controllerAction)) {
                parameter.add(new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(pair.getSecond()).withIcon(TwigIcons.TwigFileIcon, Symfony2Icons.TWIG_LINE_MARKER));
            }
        });
    }
}
 
Example 2
Source File: IndexTranslatorProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public Collection<PsiElement> getTranslationTargets(@NotNull Project project, @NotNull String translationKey, @NotNull String domain) {
    Collection<PsiElement> psiFoundElements = new ArrayList<>();

    Collection<VirtualFile> files = new HashSet<>();
    FileBasedIndex.getInstance().getFilesWithKey(TranslationStubIndex.KEY, new HashSet<>(Collections.singletonList(domain)), virtualFile -> {
        files.add(virtualFile);
        return true;
    }, GlobalSearchScope.allScope(project));

    for (PsiFile psiFile : PsiElementUtils.convertVirtualFilesToPsiFiles(project, files)) {
        psiFoundElements.addAll(TranslationUtil.getTranslationKeyTargetInsideFile(psiFile, domain, translationKey));
    }

    return psiFoundElements;
}
 
Example 3
Source File: ConfigAddPathTwigNamespaces.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
private static Collection<Pair<String, String>> getTwigPaths(@NotNull Project project) {
    Collection<Pair<String, String>> twigPathNamespace = new HashSet<>();

    // file config files a eg ".../app/..." or "../packages/..."
    Collection<PsiFile> psiFiles = PsiElementUtils.convertVirtualFilesToPsiFiles(
        project,
        ConfigUtil.getConfigurations(project, "twig")
    );

    for (PsiFile psiFile : psiFiles) {
        if (!(psiFile instanceof YAMLFile)) {
            continue;
        }

        for (Pair<String, String> stringStringPair : TwigUtil.getTwigPathFromYamlConfigResolved((YAMLFile) psiFile)) {
            // default path
            String first = stringStringPair.getFirst();
            if(first == null || first.equals("")) {
                first = TwigUtil.MAIN;
            }

            twigPathNamespace.add(Pair.create(stringStringPair.getSecond(), first));
        }
    }

    return twigPathNamespace;
}
 
Example 4
Source File: TranslationUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * Get targets for translation based on the domain path inside the compiled container
 *
 * TODO: completely remove this? support translation paths from service compiler
 */
public static Collection<PsiElement> getTranslationKeyFromCompiledContainerDomain(@NotNull Project project, @NotNull String domain, @NotNull String translationKey) {
    Collection<PsiElement> psiFoundElements = new ArrayList<>();

    // search for available domain files
    for(PsiFile psiFile : PsiElementUtils.convertVirtualFilesToPsiFiles(project, TranslationUtil.getDomainFilesFromCompiledContainer(project, domain))) {
        psiFoundElements.addAll(getTranslationKeyTargetInsideFile(psiFile, domain, translationKey));
    }

    return psiFoundElements;
}
 
Example 5
Source File: TranslationUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
public static List<PsiFile> getDomainPsiFiles(@NotNull Project project, @NotNull String domainName) {
    Set<VirtualFile> files = new HashSet<>();

    for (TranslatorProvider translationProvider : getTranslationProviders()) {
        files.addAll(translationProvider.getDomainPsiFiles(project, domainName));
    }

    return new ArrayList<>(PsiElementUtils.convertVirtualFilesToPsiFiles(project, files));
}
 
Example 6
Source File: TwigLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
protected Collection<? extends PsiElement> compute() {
    return PsiElementUtils.convertVirtualFilesToPsiFiles(project, TwigUtil.getTemplatesExtendingFile(project, virtualFile));
}