Search in sources :

Example 6 with PerlVisitor

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

the class PerlNamespaceRecursiveInheritanceInspection 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;
            }
            if (hasRecursiveInheritance(o, new THashSet<>())) {
                registerError(holder, o.getContainingFile(), "Namespace " + packageName + " has recursive inheritance");
                registerError(holder, nameIdentifier, "Namespace " + packageName + " has recursive inheritance");
            }
        }
    };
}
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)

Example 7 with PerlVisitor

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

the class PerlUseWarningsInspection 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).checkWarningsPragma()) {
                return;
            }
            for (PerlUseStatement useStatement : PsiTreeUtil.findChildrenOfType(file, PerlUseStatement.class)) {
                if (useStatement.getPackageProcessor() instanceof PerlWarningsProvider) {
                    return;
                }
            }
            holder.registerProblem(file, PerlBundle.message("perl.inspection.use.warnings"), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new PerlUsePackageQuickFix("warnings FATAL => 'all'"), new PerlUsePackageQuickFix("warnings"));
        }
    };
}
Also used : InjectedFileViewProvider(com.intellij.psi.impl.source.tree.injected.InjectedFileViewProvider) PerlFileType(com.perl5.lang.perl.fileTypes.PerlFileType) 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) PerlWarningsProvider(com.perl5.lang.perl.extensions.packageprocessor.PerlWarningsProvider) PerlUseStatement(com.perl5.lang.perl.psi.PerlUseStatement) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with PerlVisitor

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

the class PerlUnresolvedSubInspection method buildVisitor.

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

        @Override
        public void visitStringContentElement(@NotNull PerlStringContentElementImpl o) {
            if (EXPORT_ASSIGNED_STRING_CONTENT.accepts(o)) {
                if (!isResolvable(o.getReference())) {
                    registerProblem(holder, o, PerlBundle.message("perl.inspection.no.exported.entity"));
                }
            }
        }

        @Override
        public void visitPerlMethod(@NotNull PerlMethod o) {
            PerlNamespaceElement namespaceElement = o.getNamespaceElement();
            PerlSubNameElement subNameElement = o.getSubNameElement();
            // fixme adjust built in checking to the file; Remove second condition after implementing annotations
            if (subNameElement == null || namespaceElement != null && namespaceElement.isBuiltin() || subNameElement.isBuiltIn()) {
                return;
            }
            for (PsiReference reference : subNameElement.getReferences()) {
                if (isResolvable(reference)) {
                    return;
                }
            }
            registerProblem(holder, subNameElement, PerlBundle.message("perl.inspection.no.sub.definition"));
        }
    };
}
Also used : PerlMethod(com.perl5.lang.perl.psi.PerlMethod) PerlSubNameElement(com.perl5.lang.perl.psi.PerlSubNameElement) PerlNamespaceElement(com.perl5.lang.perl.psi.PerlNamespaceElement) PsiReference(com.intellij.psi.PsiReference) PerlVisitor(com.perl5.lang.perl.psi.PerlVisitor) NotNull(org.jetbrains.annotations.NotNull) PerlStringContentElementImpl(com.perl5.lang.perl.psi.impl.PerlStringContentElementImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with PerlVisitor

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

the class PerlUseVarsInspection method buildVisitor.

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

        @Override
        public void visitUseStatement(@NotNull PsiPerlUseStatement 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 : PsiPerlUseStatement(com.perl5.lang.perl.psi.PsiPerlUseStatement) 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 10 with PerlVisitor

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

the class PerlUnresolvedVariableInspection method buildVisitor.

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

        @Override
        public void visitPerlVariable(@NotNull final PerlVariable variable) {
            PsiElement parent = variable.getParent();
            if (parent instanceof PerlVariableDeclarationElement || variable.isBuiltIn()) {
                return;
            }
            PerlVariableNameElement variableNameElement = variable.getVariableNameElement();
            if (variableNameElement != null) {
                for (PsiReference reference : variableNameElement.getReferences()) {
                    if (reference instanceof PsiPolyVariantReference && ((PsiPolyVariantReference) reference).multiResolve(false).length > 0 || reference.resolve() != null) {
                        return;
                    }
                }
                registerProblem(holder, variableNameElement, "Unable to find variable declaration.");
            }
        }
    };
}
Also used : PerlVariableDeclarationElement(com.perl5.lang.perl.psi.PerlVariableDeclarationElement) PerlVariableNameElement(com.perl5.lang.perl.psi.PerlVariableNameElement) PsiReference(com.intellij.psi.PsiReference) PerlVisitor(com.perl5.lang.perl.psi.PerlVisitor) PerlVariable(com.perl5.lang.perl.psi.PerlVariable) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) PsiPolyVariantReference(com.intellij.psi.PsiPolyVariantReference) 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