Search in sources :

Example 1 with PerlLibProvider

use of com.perl5.lang.perl.extensions.packageprocessor.PerlLibProvider in project Perl5-IDEA by Camelcade.

the class PerlPackageUtil method getIncDirsForPsiElement.

/**
 * Returns List of lib directories including class roots, current directory and use lib ones
 *
 * @param psiElement to resolve for
 * @return list of lib dirs
 */
@NotNull
public static List<VirtualFile> getIncDirsForPsiElement(@NotNull PsiElement psiElement) {
    PsiFile psiFile = psiElement.getContainingFile().getOriginalFile();
    List<VirtualFile> result = new ArrayList<>();
    // libdirs providers fixme we need to use stubs or psi here
    for (PerlUseStatement useStatement : PsiTreeUtil.findChildrenOfType(psiFile, PerlUseStatement.class)) {
        PerlPackageProcessor packageProcessor = useStatement.getPackageProcessor();
        if (packageProcessor instanceof PerlLibProvider) {
            ((PerlLibProvider) packageProcessor).addLibDirs(useStatement, result);
        }
    }
    // classpath
    result.addAll(PerlProjectManager.getInstance(psiElement.getProject()).getAllLibraryRoots());
    // current dir
    if (PerlSharedSettings.getInstance(psiFile.getProject()).getTargetPerlVersion().lesserThan(PerlVersion.V5_26)) {
        VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile != null && virtualFile.getParent() != null) {
            result.add(virtualFile.getParent());
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PerlPackageProcessor(com.perl5.lang.perl.extensions.packageprocessor.PerlPackageProcessor) PerlLibProvider(com.perl5.lang.perl.extensions.packageprocessor.PerlLibProvider) PsiFile(com.intellij.psi.PsiFile) PerlUseStatement(com.perl5.lang.perl.psi.PerlUseStatement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 PerlLibProvider (com.perl5.lang.perl.extensions.packageprocessor.PerlLibProvider)1 PerlPackageProcessor (com.perl5.lang.perl.extensions.packageprocessor.PerlPackageProcessor)1 PerlUseStatement (com.perl5.lang.perl.psi.PerlUseStatement)1 NotNull (org.jetbrains.annotations.NotNull)1