Search in sources :

Example 6 with PerlDelegatingLightNamedElement

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

the class PerlExceptionClassWrapper method calcLightElementsFromPsi.

@NotNull
@Override
public List<PerlDelegatingLightNamedElement> calcLightElementsFromPsi() {
    PsiElement firstChild = getFirstChild();
    List<PerlDelegatingLightNamedElement> result = new ArrayList<>();
    List<PsiElement> listElements = PerlArrayUtil.collectListElements(firstChild);
    for (int i = 0; i < listElements.size(); i++) {
        processExceptionElement(listElements, i, result);
    }
    return result;
}
Also used : PerlDelegatingLightNamedElement(com.perl5.lang.perl.psi.light.PerlDelegatingLightNamedElement) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with PerlDelegatingLightNamedElement

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

the class PerlClassAccessorWrapper method calcLightElementsFromPsi.

@NotNull
@Override
public List<PerlDelegatingLightNamedElement> calcLightElementsFromPsi() {
    String packageName = PerlPackageUtil.getContextPackageName(this);
    if (StringUtil.isEmpty(packageName)) {
        return Collections.emptyList();
    }
    List<PsiElement> listElements = getCallArgumentsList();
    if (listElements.isEmpty()) {
        return Collections.emptyList();
    }
    List<PerlDelegatingLightNamedElement> result = new ArrayList<>();
    for (PsiElement listElement : listElements) {
        if (!isAcceptableIdentifierElement(listElement)) {
            continue;
        }
        String baseName = ElementManipulators.getValueText(listElement);
        PerlSubAnnotations subAnnotations = computeSubAnnotations(this, listElement);
        for (Function<String, String> computation : getNamesComputations()) {
            result.add(new PerlClassAccessorMethod(this, baseName, computation, CLASS_ACCESSOR_METHOD, listElement, packageName, subAnnotations));
        }
    }
    return result;
}
Also used : PerlSubAnnotations(com.perl5.lang.perl.psi.utils.PerlSubAnnotations) PerlDelegatingLightNamedElement(com.perl5.lang.perl.psi.light.PerlDelegatingLightNamedElement) ArrayList(java.util.ArrayList) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with PerlDelegatingLightNamedElement

use of com.perl5.lang.perl.psi.light.PerlDelegatingLightNamedElement 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

PsiElement (com.intellij.psi.PsiElement)8 PerlDelegatingLightNamedElement (com.perl5.lang.perl.psi.light.PerlDelegatingLightNamedElement)6 NotNull (org.jetbrains.annotations.NotNull)6 PsiPerlAnonArray (com.perl5.lang.perl.psi.PsiPerlAnonArray)2 PsiPerlAnonHash (com.perl5.lang.perl.psi.PsiPerlAnonHash)2 PerlLightMethodDefinitionElement (com.perl5.lang.perl.psi.light.PerlLightMethodDefinitionElement)2 ArrayList (java.util.ArrayList)2 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)1 PsiReference (com.intellij.psi.PsiReference)1 IElementType (com.intellij.psi.tree.IElementType)1 PerlLightExceptionClassDefinition (com.perl5.lang.perl.parser.Exception.Class.psi.light.PerlLightExceptionClassDefinition)1 PerlLightConstantDefinitionElement (com.perl5.lang.perl.parser.constant.psi.light.PerlLightConstantDefinitionElement)1 PerlSubExpr (com.perl5.lang.perl.psi.PerlSubExpr)1 PsiPerlBlock (com.perl5.lang.perl.psi.PsiPerlBlock)1 PerlSubReference (com.perl5.lang.perl.psi.references.PerlSubReference)1 PerlSubAnnotations (com.perl5.lang.perl.psi.utils.PerlSubAnnotations)1 PerlSubArgument (com.perl5.lang.perl.psi.utils.PerlSubArgument)1 PerlHashEntry (com.perl5.lang.perl.util.PerlHashEntry)1