Search in sources :

Example 6 with PerlNamespaceElement

use of com.perl5.lang.perl.psi.PerlNamespaceElement in project Perl5-IDEA by Camelcade.

the class PerlUseStatementMixin method getPackageName.

@Override
public String getPackageName() {
    PerlUseStatementStub stub = getStub();
    if (stub != null) {
        return stub.getPackageName();
    }
    PerlNamespaceElement ns = getNamespaceElement();
    if (ns != null) {
        return ns.getCanonicalName();
    }
    return null;
}
Also used : PerlUseStatementStub(com.perl5.lang.perl.psi.stubs.imports.PerlUseStatementStub)

Example 7 with PerlNamespaceElement

use of com.perl5.lang.perl.psi.PerlNamespaceElement in project Perl5-IDEA by Camelcade.

the class PerlUseStatementMixin method getImportParameters.

@Override
@Nullable
public List<String> getImportParameters() {
    PerlUseStatementStub stub = getStub();
    if (stub != null) {
        return stub.getImportParameters();
    }
    if (getExpr() == null) {
        return null;
    }
    PerlNamespaceElement namespaceElement = getNamespaceElement();
    if (namespaceElement != null) {
        return PerlPsiUtil.collectStringContents(namespaceElement.getNextSibling());
    } else {
        return Collections.emptyList();
    }
}
Also used : PerlUseStatementStub(com.perl5.lang.perl.psi.stubs.imports.PerlUseStatementStub) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with PerlNamespaceElement

use of com.perl5.lang.perl.psi.PerlNamespaceElement in project Perl5-IDEA by Camelcade.

the class PerlFancyMethodQuickFix method applyFix.

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PsiElement method = descriptor.getPsiElement();
    assert method instanceof PerlMethod;
    PsiElement currentCallExpression = method.getParent();
    assert currentCallExpression instanceof PsiPerlSubCallExpr;
    // fixme ok, this is works, but we make syntax tree invalid, will be updated with next reparsing. Not sure it's a problem
    PerlNamespaceElement namespaceElement = ((PerlMethod) method).getNamespaceElement();
    assert namespaceElement != null;
    PerlSubNameElement subNameElement = ((PerlMethod) method).getSubNameElement();
    assert subNameElement != null;
    method.replace(PerlElementFactory.createMethodCall(project, namespaceElement.getCanonicalName(), subNameElement.getName()));
}
Also used : PerlMethod(com.perl5.lang.perl.psi.PerlMethod) PerlSubNameElement(com.perl5.lang.perl.psi.PerlSubNameElement) PsiPerlSubCallExpr(com.perl5.lang.perl.psi.PsiPerlSubCallExpr) PerlNamespaceElement(com.perl5.lang.perl.psi.PerlNamespaceElement) PsiElement(com.intellij.psi.PsiElement)

Example 9 with PerlNamespaceElement

use of com.perl5.lang.perl.psi.PerlNamespaceElement 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 10 with PerlNamespaceElement

use of com.perl5.lang.perl.psi.PerlNamespaceElement in project Perl5-IDEA by Camelcade.

the class PerlAnnotator method annotate.

@Override
public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) {
    IElementType elementType = PsiUtilCore.getElementType(element);
    if (elementType == NYI_STATEMENT) {
        holder.createInfoAnnotation(element, "Unimplemented statement").setTextAttributes(CodeInsightColors.TODO_DEFAULT_ATTRIBUTES);
    } else if (element instanceof PerlGlobVariable && ((PerlGlobVariable) element).isBuiltIn()) {
        holder.createInfoAnnotation(element, null).setTextAttributes(PERL_GLOB_BUILTIN);
    } else if (element instanceof PerlVariable && ((PerlVariable) element).isBuiltIn()) {
        holder.createInfoAnnotation(element, null).setTextAttributes(VARIABLE_KEYS_MAP.get(element.getClass()));
    } else if (elementType == LABEL_DECLARATION || elementType == LABEL_EXPR) {
        holder.createInfoAnnotation(element.getFirstChild(), null).setTextAttributes(PerlSyntaxHighlighter.PERL_LABEL);
    } else if (elementType == PACKAGE) {
        assert element instanceof PerlNamespaceElement;
        PerlNamespaceElement namespaceElement = (PerlNamespaceElement) element;
        PsiElement parent = namespaceElement.getParent();
        if (parent instanceof PerlNamespaceDefinitionWithIdentifier) {
            decorateElement(namespaceElement, holder, PerlSyntaxHighlighter.PERL_PACKAGE_DEFINITION, false);
        } else {
            if (namespaceElement.isPragma()) {
                decorateElement(namespaceElement, holder, PerlSyntaxHighlighter.PERL_PACKAGE_PRAGMA, false);
            } else if (namespaceElement.isBuiltin()) {
                decorateElement(namespaceElement, holder, PerlSyntaxHighlighter.PERL_PACKAGE_CORE, false);
            }
        }
    } else if (element instanceof PerlPolyNamedElement) {
        TextAttributesKey subAttribute = PerlSyntaxHighlighter.PERL_SUB_DEFINITION;
        if (elementType == PerlConstantsWrapperElementType.CONSTANT_WRAPPER) {
            // fixme some interface?
            subAttribute = PerlSyntaxHighlighter.PERL_CONSTANT;
        }
        for (PerlDelegatingLightNamedElement lightNamedElement : ((PerlPolyNamedElement) element).getLightElements()) {
            TextAttributesKey currentKey = lightNamedElement instanceof PerlSubDefinition ? subAttribute : PerlSyntaxHighlighter.PERL_PACKAGE_DEFINITION;
            PsiElement navigationElement = lightNamedElement.getNavigationElement();
            holder.createInfoAnnotation(ElementManipulators.getValueTextRange(navigationElement).shiftRight(lightNamedElement.getTextOffset()), null).setEnforcedTextAttributes(adjustTextAttributes(currentScheme.getAttributes(currentKey), false));
        }
    } else if (// instanceof PerlSubNameElement
    elementType == SUB_NAME) {
        PsiElement parent = element.getParent();
        if (parent instanceof PsiPerlSubDeclaration) {
            holder.createInfoAnnotation(element, null).setTextAttributes(PerlSyntaxHighlighter.PERL_SUB_DECLARATION);
        } else if (parent instanceof PerlSubDefinitionElement) {
            if ("AUTOLOAD".equals(((PerlSubNameElement) element).getName())) {
                holder.createInfoAnnotation(element, null).setTextAttributes(PerlSyntaxHighlighter.PERL_AUTOLOAD);
            } else {
                holder.createInfoAnnotation(element, null).setTextAttributes(PerlSyntaxHighlighter.PERL_SUB_DEFINITION);
            }
        } else if (parent instanceof PerlMethod) {
            // fixme don't we need to take multiple references here?
            PsiElement grandParent = parent.getParent();
            PerlNamespaceElement methodNamespace = ((PerlMethod) parent).getNamespaceElement();
            if (// / not ...->method fixme shouldn't we use isObjectMethod here?
            !(grandParent instanceof PsiPerlNestedCall) && // no explicit NS or it's core
            (methodNamespace == null || methodNamespace.isCORE()) && ((PerlSubNameElement) element).isBuiltIn()) {
                decorateElement(element, holder, PerlSyntaxHighlighter.PERL_SUB_BUILTIN);
            } else {
                PsiReference reference = element.getReference();
                if (reference instanceof PerlSubReference) {
                    ((PerlSubReference) reference).multiResolve(false);
                    if (((PerlSubReference) reference).isConstant()) {
                        holder.createInfoAnnotation(element, "Constant").setTextAttributes(PerlSyntaxHighlighter.PERL_CONSTANT);
                    } else if (((PerlSubReference) reference).isAutoloaded()) {
                        holder.createInfoAnnotation(element, "Auto-loaded sub").setTextAttributes(PerlSyntaxHighlighter.PERL_AUTOLOAD);
                    } else if (((PerlSubReference) reference).isXSub()) {
                        holder.createInfoAnnotation(element, "XSub").setTextAttributes(PerlSyntaxHighlighter.PERL_XSUB);
                    }
                }
            }
        }
    }
}
Also used : PerlSubReference(com.perl5.lang.perl.psi.references.PerlSubReference) PsiReference(com.intellij.psi.PsiReference) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) IElementType(com.intellij.psi.tree.IElementType) PerlDelegatingLightNamedElement(com.perl5.lang.perl.psi.light.PerlDelegatingLightNamedElement) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PerlNamespaceElement (com.perl5.lang.perl.psi.PerlNamespaceElement)7 PsiElement (com.intellij.psi.PsiElement)5 NotNull (org.jetbrains.annotations.NotNull)5 PerlSubNameElement (com.perl5.lang.perl.psi.PerlSubNameElement)4 PsiFile (com.intellij.psi.PsiFile)3 PsiReference (com.intellij.psi.PsiReference)3 PerlVisitor (com.perl5.lang.perl.psi.PerlVisitor)3 PsiPerlMethod (com.perl5.lang.perl.psi.PsiPerlMethod)3 Project (com.intellij.openapi.project.Project)2 IElementType (com.intellij.psi.tree.IElementType)2 PerlMethod (com.perl5.lang.perl.psi.PerlMethod)2 PerlUseStatementStub (com.perl5.lang.perl.psi.stubs.imports.PerlUseStatementStub)2 Nullable (org.jetbrains.annotations.Nullable)2 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)1 PsiElementResolveResult (com.intellij.psi.PsiElementResolveResult)1 ResolveResult (com.intellij.psi.ResolveResult)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 PerlExportDescriptor (com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor)1 PerlFancyMethodQuickFix (com.perl5.lang.perl.idea.quickfixes.PerlFancyMethodQuickFix)1 PerlNamespaceDefinitionElement (com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement)1