use of com.perl5.lang.perl.psi.impl.PerlUseStatementElement in project Perl5-IDEA by Camelcade.
the class ExceptionClassProcessor method computeLightElementsFromPsi.
@Override
@NotNull
public List<PerlDelegatingLightNamedElement<?>> computeLightElementsFromPsi(@NotNull PerlUseStatementElement useStatementElement) {
PsiPerlExpr expr = useStatementElement.getExpr();
if (expr == null) {
return Collections.emptyList();
}
List<PerlDelegatingLightNamedElement<?>> result = new ArrayList<>();
List<PsiElement> listElements = PerlArrayUtil.collectListElements(expr);
for (int i = 0; i < listElements.size(); i++) {
processExceptionElement(listElements, i, result, useStatementElement);
}
return result;
}
use of com.perl5.lang.perl.psi.impl.PerlUseStatementElement in project Perl5-IDEA by Camelcade.
the class packageProcessorsTest method testModernPerl.
@Test
public void testModernPerl() {
initWithFileSmart("ModernPerl");
PerlNamespaceDefinitionElement namespaceDefinition = getElementAtCaret(PerlNamespaceDefinitionElement.class);
assertNotNull(namespaceDefinition);
assertEquals(PerlMroType.C3, namespaceDefinition.getMroType());
PerlUseStatementElement useStatement = getElementAtCaret(PerlUseStatementElement.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.impl.PerlUseStatementElement in project Perl5-IDEA by Camelcade.
the class PerlUseStrictInspection method buildVisitor.
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new PerlVisitor() {
@Override
public void visitFile(@NotNull PsiFile file) {
if (!file.isWritable() || !file.isPhysical() || file.getVirtualFile() instanceof LightVirtualFile || InjectedLanguageManager.getInstance(file.getProject()).isInjectedFragment(file)) {
return;
}
FileType fileType = file.getFileType();
if (!(fileType instanceof PerlFileType) || !((PerlFileType) fileType).checkStrictPragma()) {
return;
}
for (PerlUseStatementElement useStatement : PsiTreeUtil.findChildrenOfType(file, PerlUseStatementElement.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.impl.PerlUseStatementElement in project Perl5-IDEA by Camelcade.
the class PerlUseVarsInspection method buildVisitor.
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
return new PerlVisitor() {
@Override
public void visitUseStatement(@NotNull PerlUseStatementElement 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);
}
}
};
}
use of com.perl5.lang.perl.psi.impl.PerlUseStatementElement 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
*/
@VisibleForTesting
@NotNull
public static List<VirtualFile> getIncDirsForPsiElement(@NotNull PsiElement psiElement) {
PsiFile psiFile = psiElement.getContainingFile().getOriginalFile();
List<VirtualFile> result = new ArrayList<>();
for (PerlUseStatementElement useStatement : PsiTreeUtil.findChildrenOfType(psiFile, PerlUseStatementElement.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;
}
Aggregations