Search in sources :

Example 11 with GlobalVariableDefinitionNode

use of org.ballerinalang.plugins.idea.psi.GlobalVariableDefinitionNode in project ballerina by ballerina-lang.

the class InvocationReference method resolve.

@Nullable
@Override
public PsiElement resolve() {
    IdentifierPSINode identifier = getElement();
    PsiElement parent = identifier.getParent();
    PsiElement prevSibling = parent.getPrevSibling();
    if (prevSibling == null) {
        return null;
    }
    PsiReference reference = prevSibling.findReferenceAt(prevSibling.getTextLength());
    if (reference == null) {
        return null;
    }
    PsiElement resolvedElement = reference.resolve();
    if (resolvedElement == null) {
        return null;
    }
    PsiElement definitionNode = resolvedElement.getParent();
    if (definitionNode instanceof VariableDefinitionNode || definitionNode instanceof ParameterNode || definitionNode instanceof GlobalVariableDefinitionNode) {
        StructDefinitionNode structDefinitionNode = BallerinaPsiImplUtil.resolveStructFromDefinitionNode(definitionNode);
        if (structDefinitionNode != null) {
            List<IdentifierPSINode> attachedFunctions = BallerinaPsiImplUtil.getAttachedFunctions(structDefinitionNode);
            for (IdentifierPSINode attachedFunction : attachedFunctions) {
                if (identifier.getText().equals(attachedFunction.getText())) {
                    return attachedFunction;
                }
            }
        }
    }
    return super.resolve();
}
Also used : VariableDefinitionNode(org.ballerinalang.plugins.idea.psi.VariableDefinitionNode) GlobalVariableDefinitionNode(org.ballerinalang.plugins.idea.psi.GlobalVariableDefinitionNode) ParameterNode(org.ballerinalang.plugins.idea.psi.ParameterNode) StructDefinitionNode(org.ballerinalang.plugins.idea.psi.StructDefinitionNode) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) GlobalVariableDefinitionNode(org.ballerinalang.plugins.idea.psi.GlobalVariableDefinitionNode) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GlobalVariableDefinitionNode (org.ballerinalang.plugins.idea.psi.GlobalVariableDefinitionNode)11 PsiElement (com.intellij.psi.PsiElement)10 PsiReference (com.intellij.psi.PsiReference)6 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)6 IdentifierPSINode (org.ballerinalang.plugins.idea.psi.IdentifierPSINode)6 ConstantDefinitionNode (org.ballerinalang.plugins.idea.psi.ConstantDefinitionNode)5 Annotation (com.intellij.lang.annotation.Annotation)4 AnnotationAttachmentNode (org.ballerinalang.plugins.idea.psi.AnnotationAttachmentNode)4 StructDefinitionNode (org.ballerinalang.plugins.idea.psi.StructDefinitionNode)4 VariableDefinitionNode (org.ballerinalang.plugins.idea.psi.VariableDefinitionNode)4 PsiFile (com.intellij.psi.PsiFile)3 IElementType (com.intellij.psi.tree.IElementType)3 LinkedList (java.util.LinkedList)3 ANTLRPsiNode (org.antlr.jetbrains.adaptor.psi.ANTLRPsiNode)3 FieldDefinitionNode (org.ballerinalang.plugins.idea.psi.FieldDefinitionNode)3 ResourceDefinitionNode (org.ballerinalang.plugins.idea.psi.ResourceDefinitionNode)3 ServiceBodyNode (org.ballerinalang.plugins.idea.psi.ServiceBodyNode)3 TypeNameNode (org.ballerinalang.plugins.idea.psi.TypeNameNode)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3