Search in sources :

Example 6 with PerlUseStatement

use of com.perl5.lang.perl.psi.PerlUseStatement in project Perl5-IDEA by Camelcade.

the class PerlUseStrictInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    return new PerlVisitor() {

        @Override
        public void visitFile(PsiFile file) {
            if (file.getViewProvider() instanceof InjectedFileViewProvider || !file.isWritable() || !file.isPhysical() || file.getVirtualFile() instanceof LightVirtualFile) {
                return;
            }
            FileType fileType = file.getFileType();
            if (!(fileType instanceof PerlFileType) || !((PerlFileType) fileType).checkStrictPragma()) {
                return;
            }
            for (PerlUseStatement useStatement : PsiTreeUtil.findChildrenOfType(file, PerlUseStatement.class)) {
                if (useStatement.getPackageProcessor() instanceof PerlStrictProvider) {
                    return;
                }
            }
            holder.registerProblem(file, PerlBundle.message("perl.inspection.use.strict"), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new PerlUsePackageQuickFix("strict"));
        }
    };
}
Also used : InjectedFileViewProvider(com.intellij.psi.impl.source.tree.injected.InjectedFileViewProvider) PerlFileType(com.perl5.lang.perl.fileTypes.PerlFileType) PerlStrictProvider(com.perl5.lang.perl.extensions.packageprocessor.PerlStrictProvider) PerlUsePackageQuickFix(com.perl5.lang.perl.idea.quickfixes.PerlUsePackageQuickFix) FileType(com.intellij.openapi.fileTypes.FileType) PerlFileType(com.perl5.lang.perl.fileTypes.PerlFileType) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) PsiFile(com.intellij.psi.PsiFile) PerlVisitor(com.perl5.lang.perl.psi.PerlVisitor) PerlUseStatement(com.perl5.lang.perl.psi.PerlUseStatement) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with PerlUseStatement

use of com.perl5.lang.perl.psi.PerlUseStatement in project Perl5-IDEA by Camelcade.

the class packageProcessorsTest method testModernPerl.

public void testModernPerl() {
    initWithFileSmart("ModernPerl");
    PerlNamespaceDefinitionElement namespaceDefinition = getElementAtCaret(PerlNamespaceDefinitionElement.class);
    assertNotNull(namespaceDefinition);
    assertEquals(PerlMroType.C3, namespaceDefinition.getMroType());
    PerlUseStatement useStatement = getElementAtCaret(PerlUseStatement.class);
    assertNotNull(useStatement);
    PerlPackageProcessor packageProcessor = useStatement.getPackageProcessor();
    assertNotNull(packageProcessor);
    assertInstanceOf(packageProcessor, PerlStrictProvider.class);
    assertInstanceOf(packageProcessor, PerlMroProvider.class);
    assertInstanceOf(packageProcessor, PerlWarningsProvider.class);
    assertInstanceOf(packageProcessor, PerlPackageLoader.class);
}
Also used : PerlNamespaceDefinitionElement(com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement) PerlUseStatement(com.perl5.lang.perl.psi.PerlUseStatement)

Example 8 with PerlUseStatement

use of com.perl5.lang.perl.psi.PerlUseStatement 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)

Example 9 with PerlUseStatement

use of com.perl5.lang.perl.psi.PerlUseStatement in project Perl5-IDEA by Camelcade.

the class PerlUtil method processImportedEntities.

/**
 * Processing use statements in the namespace or file and processing all imports found
 *
 * @param namespace Root element to start searching from
 */
public static void processImportedEntities(@NotNull PerlNamespaceDefinitionElement namespace, @NotNull PerlNamespaceEntityProcessor<PerlExportDescriptor> processor) {
    for (PsiElement element : PerlPsiUtil.collectUseStatements(namespace)) {
        PerlUseStatement useStatement = (PerlUseStatement) element;
        String packageName = useStatement.getPackageName();
        if (packageName != null) {
            for (PerlExportDescriptor entry : useStatement.getPackageProcessor().getImports(useStatement)) {
                ProgressManager.checkCanceled();
                processor.process(packageName, entry);
            }
        }
    }
    PerlImportsProvider.processProviders(namespace, provider -> {
        for (PerlExportDescriptor descriptor : provider.getImports()) {
            if (!processor.process(namespace.getPackageName(), descriptor)) {
                return false;
            }
        }
        return true;
    });
}
Also used : PerlExportDescriptor(com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor) PerlUseStatement(com.perl5.lang.perl.psi.PerlUseStatement) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PerlUseStatement (com.perl5.lang.perl.psi.PerlUseStatement)7 PsiFile (com.intellij.psi.PsiFile)4 NotNull (org.jetbrains.annotations.NotNull)3 FileType (com.intellij.openapi.fileTypes.FileType)2 PsiElement (com.intellij.psi.PsiElement)2 InjectedFileViewProvider (com.intellij.psi.impl.source.tree.injected.InjectedFileViewProvider)2 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)2 PerlFileType (com.perl5.lang.perl.fileTypes.PerlFileType)2 PerlUsePackageQuickFix (com.perl5.lang.perl.idea.quickfixes.PerlUsePackageQuickFix)2 PerlNamespaceDefinitionElement (com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement)2 PerlVisitor (com.perl5.lang.perl.psi.PerlVisitor)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiComment (com.intellij.psi.PsiComment)1 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)1 PerlExportDescriptor (com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor)1 PerlLibProvider (com.perl5.lang.perl.extensions.packageprocessor.PerlLibProvider)1 PerlPackageProcessor (com.perl5.lang.perl.extensions.packageprocessor.PerlPackageProcessor)1 PerlStrictProvider (com.perl5.lang.perl.extensions.packageprocessor.PerlStrictProvider)1 PerlWarningsProvider (com.perl5.lang.perl.extensions.packageprocessor.PerlWarningsProvider)1 PsiPerlNamespaceContent (com.perl5.lang.perl.psi.PsiPerlNamespaceContent)1