use of com.perl5.lang.perl.psi.PerlUseStatement 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"));
}
};
}
use of com.perl5.lang.perl.psi.PerlUseStatement in project Perl5-IDEA by Camelcade.
the class packageProcessorsTest method testModernPerl.
public void testModernPerl() {
initWithFileSmart("ModernPerl");
PerlNamespaceDefinitionElement namespaceDefinition = getElementAtCaret(PerlNamespaceDefinitionElement.class);
assertNotNull(namespaceDefinition);
assertEquals(PerlMroType.C3, namespaceDefinition.getMroType());
PerlUseStatement useStatement = getElementAtCaret(PerlUseStatement.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);
}
use of com.perl5.lang.perl.psi.PerlUseStatement 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
*/
@NotNull
public static List<VirtualFile> getIncDirsForPsiElement(@NotNull PsiElement psiElement) {
PsiFile psiFile = psiElement.getContainingFile().getOriginalFile();
List<VirtualFile> result = new ArrayList<>();
// libdirs providers fixme we need to use stubs or psi here
for (PerlUseStatement useStatement : PsiTreeUtil.findChildrenOfType(psiFile, PerlUseStatement.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;
}
use of com.perl5.lang.perl.psi.PerlUseStatement in project Perl5-IDEA by Camelcade.
the class PerlUtil method processImportedEntities.
/**
* Processing use statements in the namespace or file and processing all imports found
*
* @param namespace Root element to start searching from
*/
public static void processImportedEntities(@NotNull PerlNamespaceDefinitionElement namespace, @NotNull PerlNamespaceEntityProcessor<PerlExportDescriptor> processor) {
for (PsiElement element : PerlPsiUtil.collectUseStatements(namespace)) {
PerlUseStatement useStatement = (PerlUseStatement) element;
String packageName = useStatement.getPackageName();
if (packageName != null) {
for (PerlExportDescriptor entry : useStatement.getPackageProcessor().getImports(useStatement)) {
ProgressManager.checkCanceled();
processor.process(packageName, entry);
}
}
}
PerlImportsProvider.processProviders(namespace, provider -> {
for (PerlExportDescriptor descriptor : provider.getImports()) {
if (!processor.process(namespace.getPackageName(), descriptor)) {
return false;
}
}
return true;
});
}
Aggregations