Search in sources :

Example 11 with PerlUseStatementElement

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

the class ExceptionClassProcessor method computeLightElementsFromPsi.

@Override
@NotNull
public List<PerlDelegatingLightNamedElement<?>> computeLightElementsFromPsi(@NotNull PerlUseStatementElement useStatementElement) {
    PsiPerlExpr expr = useStatementElement.getExpr();
    if (expr == null) {
        return Collections.emptyList();
    }
    List<PerlDelegatingLightNamedElement<?>> result = new ArrayList<>();
    List<PsiElement> listElements = PerlArrayUtil.collectListElements(expr);
    for (int i = 0; i < listElements.size(); i++) {
        processExceptionElement(listElements, i, result, useStatementElement);
    }
    return result;
}
Also used : PerlDelegatingLightNamedElement(com.perl5.lang.perl.psi.light.PerlDelegatingLightNamedElement) PsiPerlExpr(com.perl5.lang.perl.psi.PsiPerlExpr) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with PerlUseStatementElement

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

the class packageProcessorsTest method testModernPerl.

@Test
public void testModernPerl() {
    initWithFileSmart("ModernPerl");
    PerlNamespaceDefinitionElement namespaceDefinition = getElementAtCaret(PerlNamespaceDefinitionElement.class);
    assertNotNull(namespaceDefinition);
    assertEquals(PerlMroType.C3, namespaceDefinition.getMroType());
    PerlUseStatementElement useStatement = getElementAtCaret(PerlUseStatementElement.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 : PerlUseStatementElement(com.perl5.lang.perl.psi.impl.PerlUseStatementElement) PerlNamespaceDefinitionElement(com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement) Test(org.junit.Test)

Example 13 with PerlUseStatementElement

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

the class PerlUseStrictInspection method buildVisitor.

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

        @Override
        public void visitFile(@NotNull PsiFile file) {
            if (!file.isWritable() || !file.isPhysical() || file.getVirtualFile() instanceof LightVirtualFile || InjectedLanguageManager.getInstance(file.getProject()).isInjectedFragment(file)) {
                return;
            }
            FileType fileType = file.getFileType();
            if (!(fileType instanceof PerlFileType) || !((PerlFileType) fileType).checkStrictPragma()) {
                return;
            }
            for (PerlUseStatementElement useStatement : PsiTreeUtil.findChildrenOfType(file, PerlUseStatementElement.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 : PerlFileType(com.perl5.lang.perl.fileTypes.PerlFileType) PerlStrictProvider(com.perl5.lang.perl.extensions.packageprocessor.PerlStrictProvider) PerlUsePackageQuickFix(com.perl5.lang.perl.idea.quickfixes.PerlUsePackageQuickFix) PerlUseStatementElement(com.perl5.lang.perl.psi.impl.PerlUseStatementElement) 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) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with PerlUseStatementElement

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

the class PerlUseVarsInspection method buildVisitor.

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

        @Override
        public void visitUseStatement(@NotNull PerlUseStatementElement o) {
            if (PACKAGE_VARS.equals(o.getPackageName())) {
                PerlUseVarsQuickFix quickFix = new PerlUseVarsQuickFix(o);
                holder.registerProblem(o, quickFix.isRemoval() ? PerlBundle.message("perl.redundant.code") : PerlBundle.message("perl.inspection.use.vars"), quickFix.isRemoval() ? ProblemHighlightType.LIKE_UNUSED_SYMBOL : ProblemHighlightType.GENERIC_ERROR_OR_WARNING, quickFix);
            }
        }
    };
}
Also used : PerlUseStatementElement(com.perl5.lang.perl.psi.impl.PerlUseStatementElement) PerlUseVarsQuickFix(com.perl5.lang.perl.idea.quickfixes.PerlUseVarsQuickFix) PerlVisitor(com.perl5.lang.perl.psi.PerlVisitor) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with PerlUseStatementElement

use of com.perl5.lang.perl.psi.impl.PerlUseStatementElement 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
 */
@VisibleForTesting
@NotNull
public static List<VirtualFile> getIncDirsForPsiElement(@NotNull PsiElement psiElement) {
    PsiFile psiFile = psiElement.getContainingFile().getOriginalFile();
    List<VirtualFile> result = new ArrayList<>();
    for (PerlUseStatementElement useStatement : PsiTreeUtil.findChildrenOfType(psiFile, PerlUseStatementElement.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) PerlUseStatementElement(com.perl5.lang.perl.psi.impl.PerlUseStatementElement) PerlLibProvider(com.perl5.lang.perl.extensions.packageprocessor.PerlLibProvider) PsiFile(com.intellij.psi.PsiFile)

Aggregations

PerlUseStatementElement (com.perl5.lang.perl.psi.impl.PerlUseStatementElement)9 NotNull (org.jetbrains.annotations.NotNull)8 PsiElement (com.intellij.psi.PsiElement)5 PerlVisitor (com.perl5.lang.perl.psi.PerlVisitor)4 PsiFile (com.intellij.psi.PsiFile)3 PerlPackageProcessor (com.perl5.lang.perl.extensions.packageprocessor.PerlPackageProcessor)3 PerlDelegatingLightNamedElement (com.perl5.lang.perl.psi.light.PerlDelegatingLightNamedElement)3 FileType (com.intellij.openapi.fileTypes.FileType)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 PsiPerlExpr (com.perl5.lang.perl.psi.PsiPerlExpr)2 ArrayList (java.util.ArrayList)2 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 AnnotationHolder (com.intellij.lang.annotation.AnnotationHolder)1 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)1 CodeInsightColors (com.intellij.openapi.editor.colors.CodeInsightColors)1 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)1 Project (com.intellij.openapi.project.Project)1