use of com.perl5.lang.perl.psi.PsiPerlMethod in project Perl5-IDEA by Camelcade.
the class PerlFancyMethodCallInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new PerlVisitor() {
@Override
public void visitMethod(@NotNull PsiPerlMethod o) {
if (o.isObjectMethod() && o.getLastChild() instanceof PerlNamespaceElement) {
String packageName = o.getPackageName();
if (packageName == null) {
return;
}
PerlSubNameElement subNameElement = o.getSubNameElement();
if (subNameElement == null) {
return;
}
String properForm = String.format("%s->%s", packageName, subNameElement.getName());
holder.registerProblem(o, PerlBundle.message("perl.inspection.fancy.call", properForm), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new PerlFancyMethodQuickFix(properForm));
}
}
};
}
use of com.perl5.lang.perl.psi.PsiPerlMethod in project Perl5-IDEA by Camelcade.
the class PerlPackageSubCompletionProvider method addCompletions.
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
PsiElement method = parameters.getPosition().getParent();
assert method instanceof PsiPerlMethod : "Expected PsiPerlMethod, got " + method.getClass();
String explicitNamespace = ((PsiPerlMethod) method).getExplicitPackageName();
String currentPrefixMatcher = result.getPrefixMatcher().getPrefix();
String newPrefixMathcer = (explicitNamespace == null ? currentPrefixMatcher : (explicitNamespace + PerlPackageUtil.PACKAGE_SEPARATOR) + currentPrefixMatcher);
result = result.withPrefixMatcher(new PlainPrefixMatcher(newPrefixMathcer));
if (!((PsiPerlMethod) method).isObjectMethod()) {
PerlPackageCompletionUtil.fillWithAllPackageNamesWithAutocompletion(parameters.getPosition(), result);
} else {
if (!StringUtil.equals(PerlPackageUtil.SUPER_PACKAGE_FULL, newPrefixMathcer)) {
LookupElementBuilder newElement = PerlPackageCompletionUtil.getPackageLookupElementWithAutocomplete(method.getProject(), PerlPackageUtil.SUPER_PACKAGE_FULL, null);
newElement.putUserData(PerlCompletionWeighter.WEIGHT, -1);
result.addElement(newElement);
}
}
}
use of com.perl5.lang.perl.psi.PsiPerlMethod in project Perl5-IDEA by Camelcade.
the class PerlSubStaticCompletionProvider method addCompletions.
public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {
PsiElement method = parameters.getPosition().getParent();
assert method instanceof PsiPerlMethod;
String packageName = ((PsiPerlMethod) method).getPackageName();
if (packageName == null) {
return;
}
Project project = parameters.getPosition().getProject();
// defined subs
GlobalSearchScope searchScope = method.getResolveScope();
PerlSubUtil.processSubDefinitionsInPackage(project, packageName, searchScope, subDefinition -> {
if (subDefinition.isStatic()) {
resultSet.addElement(PerlSubCompletionUtil.getSubDefinitionLookupElement(subDefinition));
}
return true;
});
PerlSubUtil.processSubDeclarationsInPackage(project, packageName, searchScope, subDeclaration -> {
if (subDeclaration.isStatic()) {
resultSet.addElement(PerlSubCompletionUtil.getSubDeclarationLookupElement(subDeclaration));
}
return true;
});
// Globs
for (PerlGlobVariable globVariable : PerlGlobUtil.getGlobsDefinitions(project, "*" + packageName)) {
if (StringUtil.isNotEmpty(globVariable.getName())) {
resultSet.addElement(PerlSubCompletionUtil.getGlobLookupElement(globVariable));
}
}
}
use of com.perl5.lang.perl.psi.PsiPerlMethod in project Perl5-IDEA by Camelcade.
the class PerlRedundantNamespaceInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new PerlVisitor() {
@Override
public void visitMethod(@NotNull PsiPerlMethod o) {
PerlNamespaceElement namespaceElement = o.getNamespaceElement();
if (namespaceElement != null) {
String packageName = namespaceElement.getCanonicalName();
if (StringUtil.isNotEmpty(packageName)) {
String contextPackageName = PerlPackageUtil.getContextPackageName(o);
if (StringUtil.equals(packageName, contextPackageName)) {
if (!namespaceElement.getTextRange().isEmpty()) {
holder.registerProblem(namespaceElement, "Redundant namespace qualifier", ProblemHighlightType.LIKE_UNUSED_SYMBOL);
}
}
}
}
super.visitMethod(o);
}
};
}
use of com.perl5.lang.perl.psi.PsiPerlMethod in project Perl5-IDEA by Camelcade.
the class PerlImportedSubsCompletionProvider method addCompletions.
public void addCompletions(@NotNull final CompletionParameters parameters, ProcessingContext context, @NotNull final CompletionResultSet resultSet) {
PsiElement position = parameters.getPosition();
PsiPerlMethod method = (PsiPerlMethod) position.getParent();
if (method.isObjectMethod()) {
return;
}
Project project = method.getProject();
if (!method.hasExplicitNamespace()) {
PerlNamespaceDefinitionElement namespaceContainer = PerlPackageUtil.getNamespaceContainerForElement(position);
if (namespaceContainer != null) {
fillWithNamespaceImports(namespaceContainer, resultSet);
}
} else {
// not an object method, but has explicit namespace
PerlNamespaceElement namespaceElement = method.getNamespaceElement();
if (namespaceElement != null) {
String targetPackageName = namespaceElement.getCanonicalName();
if (targetPackageName != null) {
for (PerlNamespaceDefinitionElement namespaceDefinition : PerlPackageUtil.getNamespaceDefinitions(project, targetPackageName)) {
fillWithNamespaceImports(namespaceDefinition, resultSet);
}
}
}
}
}
Aggregations