use of com.perl5.lang.perl.adapters.CpanminusAdapter 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));
}
}
};
}
Aggregations