Search in sources :

Example 1 with PsiPerlMethod

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));
            }
        }
    };
}
Also used : PerlSubNameElement(com.perl5.lang.perl.psi.PerlSubNameElement) PsiPerlMethod(com.perl5.lang.perl.psi.PsiPerlMethod) PerlFancyMethodQuickFix(com.perl5.lang.perl.idea.quickfixes.PerlFancyMethodQuickFix) PerlNamespaceElement(com.perl5.lang.perl.psi.PerlNamespaceElement) PerlVisitor(com.perl5.lang.perl.psi.PerlVisitor) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PsiPerlMethod

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);
        }
    }
}
Also used : PsiPerlMethod(com.perl5.lang.perl.psi.PsiPerlMethod) PlainPrefixMatcher(com.intellij.codeInsight.completion.PlainPrefixMatcher) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) PsiElement(com.intellij.psi.PsiElement)

Example 3 with PsiPerlMethod

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));
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiPerlMethod(com.perl5.lang.perl.psi.PsiPerlMethod) PerlGlobVariable(com.perl5.lang.perl.psi.PerlGlobVariable) PsiElement(com.intellij.psi.PsiElement)

Example 4 with PsiPerlMethod

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);
        }
    };
}
Also used : PsiPerlMethod(com.perl5.lang.perl.psi.PsiPerlMethod) PerlNamespaceElement(com.perl5.lang.perl.psi.PerlNamespaceElement) PerlVisitor(com.perl5.lang.perl.psi.PerlVisitor) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with PsiPerlMethod

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);
                }
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) PerlNamespaceDefinitionElement(com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement) PsiPerlMethod(com.perl5.lang.perl.psi.PsiPerlMethod) PerlNamespaceElement(com.perl5.lang.perl.psi.PerlNamespaceElement) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiPerlMethod (com.perl5.lang.perl.psi.PsiPerlMethod)5 PsiElement (com.intellij.psi.PsiElement)3 PerlNamespaceElement (com.perl5.lang.perl.psi.PerlNamespaceElement)3 Project (com.intellij.openapi.project.Project)2 PerlVisitor (com.perl5.lang.perl.psi.PerlVisitor)2 NotNull (org.jetbrains.annotations.NotNull)2 PlainPrefixMatcher (com.intellij.codeInsight.completion.PlainPrefixMatcher)1 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 PerlFancyMethodQuickFix (com.perl5.lang.perl.idea.quickfixes.PerlFancyMethodQuickFix)1 PerlGlobVariable (com.perl5.lang.perl.psi.PerlGlobVariable)1 PerlNamespaceDefinitionElement (com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement)1 PerlSubNameElement (com.perl5.lang.perl.psi.PerlSubNameElement)1