Search in sources :

Example 11 with PerlVisitor

use of com.perl5.lang.perl.psi.PerlVisitor 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 12 with PerlVisitor

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

the class PerlRedundantNamespaceInspection method buildVisitor.

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

        @Override
        public void visitMethod(@NotNull PsiPerlMethod o) {
            PerlNamespaceElement namespaceElement = o.getNamespaceElement();
            if (namespaceElement != null) {
                String packageName = namespaceElement.getCanonicalName();
                if (StringUtil.isNotEmpty(packageName)) {
                    String contextPackageName = PerlPackageUtil.getContextPackageName(o);
                    if (StringUtil.equals(packageName, contextPackageName)) {
                        if (!namespaceElement.getTextRange().isEmpty()) {
                            holder.registerProblem(namespaceElement, "Redundant namespace qualifier", ProblemHighlightType.LIKE_UNUSED_SYMBOL);
                        }
                    }
                }
            }
            super.visitMethod(o);
        }
    };
}
Also used : PsiPerlMethod(com.perl5.lang.perl.psi.PsiPerlMethod) PerlNamespaceElement(com.perl5.lang.perl.psi.PerlNamespaceElement) PerlVisitor(com.perl5.lang.perl.psi.PerlVisitor) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with PerlVisitor

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

the class PerlClashedNamespacesInspection method buildVisitor.

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

        @Override
        public void visitPerlNamespaceDefinitionWithIdentifier(@NotNull PerlNamespaceDefinitionWithIdentifier o) {
            PsiElement nameIdentifier = o.getNameIdentifier();
            if (nameIdentifier == null) {
                return;
            }
            String packageName = o.getPackageName();
            if (PerlPackageUtil.MAIN_PACKAGE.equals(packageName)) {
                return;
            }
            // fixme we should check that this is not in SDK
            if (PerlPackageUtil.isBuiltIn(packageName)) {
                registerProblem(holder, nameIdentifier, "Namespace definition clashes with built-in namespace");
            }
        }
    };
}
Also used : PerlVisitor(com.perl5.lang.perl.psi.PerlVisitor) NotNull(org.jetbrains.annotations.NotNull) PerlNamespaceDefinitionWithIdentifier(com.perl5.lang.perl.psi.PerlNamespaceDefinitionWithIdentifier) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)13 PerlVisitor (com.perl5.lang.perl.psi.PerlVisitor)12 PsiElement (com.intellij.psi.PsiElement)4 Project (com.intellij.openapi.project.Project)3 PsiReference (com.intellij.psi.PsiReference)3 PerlNamespaceDefinitionWithIdentifier (com.perl5.lang.perl.psi.PerlNamespaceDefinitionWithIdentifier)3 PerlNamespaceElement (com.perl5.lang.perl.psi.PerlNamespaceElement)3 FileType (com.intellij.openapi.fileTypes.FileType)2 PsiFile (com.intellij.psi.PsiFile)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 PerlSubNameElement (com.perl5.lang.perl.psi.PerlSubNameElement)2 PerlUseStatement (com.perl5.lang.perl.psi.PerlUseStatement)2 PsiPerlMethod (com.perl5.lang.perl.psi.PsiPerlMethod)2 PsiPolyVariantReference (com.intellij.psi.PsiPolyVariantReference)1 IElementType (com.intellij.psi.tree.IElementType)1 PerlStrictProvider (com.perl5.lang.perl.extensions.packageprocessor.PerlStrictProvider)1 PerlWarningsProvider (com.perl5.lang.perl.extensions.packageprocessor.PerlWarningsProvider)1