Search in sources :

Example 1 with CpanAdapter

use of com.perl5.lang.perl.adapters.CpanAdapter in project Perl5-IDEA by Camelcade.

the class PerlUnresolvedPackageFileInspection method buildVisitor.

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

        @Override
        public void visitUseStatement(@NotNull PerlUseStatementElement o) {
            if (o.getNamespaceElement() != null) {
                checkPackageFile(o.getNamespaceElement());
            }
        }

        @Override
        public void visitNoStatement(@NotNull PerlNoStatementElement o) {
            if (o.getNamespaceElement() != null) {
                checkPackageFile(o.getNamespaceElement());
            }
        }

        @Override
        public void visitRequireExpr(@NotNull PsiPerlRequireExpr o) {
            if (o.getNamespaceElement() != null) {
                checkPackageFile(o.getNamespaceElement());
            }
        }

        public void checkPackageFile(PerlNamespaceElement o) {
            List<PerlFileImpl> namespaceFiles = o.getNamespaceFiles();
            String packageName = o.getCanonicalName();
            if (namespaceFiles.isEmpty() && StringUtil.isNotEmpty(packageName)) {
                List<LocalQuickFix> fixes = new ArrayList<>();
                Project project = o.getProject();
                Sdk perlSdk = PerlProjectManager.getSdk(project);
                if (perlSdk != null) {
                    if (CpanminusAdapter.isAvailable(perlSdk)) {
                        fixes.add(new InstallPackageQuickfix(new CpanminusAdapter(perlSdk, project), packageName));
                    }
                    fixes.add(new InstallPackageQuickfix(new CpanAdapter(perlSdk, project), packageName));
                }
                registerProblem(holder, o, PerlBundle.message("perl.inspection.missing.package.file", packageName), fixes.toArray(LocalQuickFix.EMPTY_ARRAY));
            }
        }
    };
}
Also used : PerlUseStatementElement(com.perl5.lang.perl.psi.impl.PerlUseStatementElement) PerlFileImpl(com.perl5.lang.perl.psi.impl.PerlFileImpl) CpanAdapter(com.perl5.lang.perl.adapters.CpanAdapter) ArrayList(java.util.ArrayList) PerlNamespaceElement(com.perl5.lang.perl.psi.PerlNamespaceElement) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) PerlVisitor(com.perl5.lang.perl.psi.PerlVisitor) NotNull(org.jetbrains.annotations.NotNull) CpanminusAdapter(com.perl5.lang.perl.adapters.CpanminusAdapter) Project(com.intellij.openapi.project.Project) PsiPerlRequireExpr(com.perl5.lang.perl.psi.PsiPerlRequireExpr) PerlNoStatementElement(com.perl5.lang.perl.psi.impl.PerlNoStatementElement) Sdk(com.intellij.openapi.projectRoots.Sdk) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 Project (com.intellij.openapi.project.Project)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 CpanAdapter (com.perl5.lang.perl.adapters.CpanAdapter)1 CpanminusAdapter (com.perl5.lang.perl.adapters.CpanminusAdapter)1 PerlNamespaceElement (com.perl5.lang.perl.psi.PerlNamespaceElement)1 PerlVisitor (com.perl5.lang.perl.psi.PerlVisitor)1 PsiPerlRequireExpr (com.perl5.lang.perl.psi.PsiPerlRequireExpr)1 PerlFileImpl (com.perl5.lang.perl.psi.impl.PerlFileImpl)1 PerlNoStatementElement (com.perl5.lang.perl.psi.impl.PerlNoStatementElement)1 PerlUseStatementElement (com.perl5.lang.perl.psi.impl.PerlUseStatementElement)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1