Search in sources :

Example 71 with IdentifierPSINode

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

the class ActionInvocationReference method getVariants.

@NotNull
@Override
public Object[] getVariants() {
    IdentifierPSINode identifier = getElement();
    PsiElement parent = identifier.getParent();
    PsiElement prevVisibleLeaf = PsiTreeUtil.prevVisibleLeaf(identifier);
    PsiElement resolvedElement = null;
    if (prevVisibleLeaf != null && ".".equals(prevVisibleLeaf.getText())) {
        PsiElement prevSibling = prevVisibleLeaf.getPrevSibling();
        if (prevSibling != null) {
            PsiReference reference = prevSibling.findReferenceAt(prevSibling.getTextLength());
            if (reference == null) {
                return new Object[0];
            }
            resolvedElement = reference.resolve();
        } else {
            PsiElement variableReference = PsiTreeUtil.prevVisibleLeaf(prevVisibleLeaf);
            if (variableReference != null) {
                PsiReference reference = variableReference.findReferenceAt(variableReference.getTextLength());
                if (reference == null) {
                    return new Object[0];
                }
                resolvedElement = reference.resolve();
            }
        }
    } else {
        ConnectorReferenceNode connectorReferenceNode = PsiTreeUtil.getChildOfType(parent, ConnectorReferenceNode.class);
        if (connectorReferenceNode == null) {
            return new Object[0];
        }
        PsiReference reference = connectorReferenceNode.findReferenceAt(connectorReferenceNode.getTextLength());
        if (reference == null) {
            return new Object[0];
        }
        resolvedElement = reference.resolve();
    }
    if (resolvedElement == null) {
        return new Object[0];
    }
    PsiElement connectorNode = resolvedElement.getParent();
    if (connectorNode instanceof VariableDefinitionNode || connectorNode instanceof CodeBlockParameterNode) {
        connectorNode = BallerinaPsiImplUtil.resolveConnectorFromVariableDefinitionNode(connectorNode);
    } else if (connectorNode instanceof EndpointDeclarationNode) {
        connectorNode = BallerinaPsiImplUtil.getConnectorDefinition(((EndpointDeclarationNode) connectorNode));
    }
    if (connectorNode == null) {
        return new Object[0];
    }
    List<IdentifierPSINode> actions = BallerinaPsiImplUtil.getAllActionsFromAConnector(connectorNode);
    List<LookupElement> results = BallerinaCompletionUtils.createActionLookupElements(actions);
    return results.toArray(new LookupElement[results.size()]);
}
Also used : VariableDefinitionNode(org.ballerinalang.plugins.idea.psi.VariableDefinitionNode) EndpointDeclarationNode(org.ballerinalang.plugins.idea.psi.EndpointDeclarationNode) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) PsiReference(com.intellij.psi.PsiReference) ConnectorReferenceNode(org.ballerinalang.plugins.idea.psi.ConnectorReferenceNode) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiElement(com.intellij.psi.PsiElement) CodeBlockParameterNode(org.ballerinalang.plugins.idea.psi.CodeBlockParameterNode) NotNull(org.jetbrains.annotations.NotNull)

Example 72 with IdentifierPSINode

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

the class AnnotationAttributeReference method getVariants.

@NotNull
@Override
public Object[] getVariants() {
    IdentifierPSINode identifier = getElement();
    AnnotationAttachmentNode annotationAttachmentNode = PsiTreeUtil.getParentOfType(identifier, AnnotationAttachmentNode.class);
    if (annotationAttachmentNode == null) {
        return new Object[0];
    }
    AnnotationReferenceNode annotationReferenceNode = PsiTreeUtil.getChildOfType(annotationAttachmentNode, AnnotationReferenceNode.class);
    if (annotationReferenceNode == null) {
        return new Object[0];
    }
    int textLength = annotationReferenceNode.getTextLength();
    PsiReference reference = annotationReferenceNode.findReferenceAt(textLength);
    if (reference == null) {
        return new Object[0];
    }
    PsiElement annotationName = reference.resolve();
    if (annotationName == null || !(annotationName instanceof IdentifierPSINode)) {
        return new Object[0];
    }
    PsiElement annotationDefinition = annotationName.getParent();
    Collection<FieldDefinitionNode> fieldDefinitionNodes = PsiTreeUtil.findChildrenOfType(annotationDefinition, FieldDefinitionNode.class);
    List<LookupElement> results = BallerinaCompletionUtils.createFieldLookupElements(fieldDefinitionNodes, (IdentifierPSINode) annotationName, PackageCompletionInsertHandler.INSTANCE_WITH_AUTO_POPUP);
    return results.toArray(new LookupElement[results.size()]);
}
Also used : IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) PsiReference(com.intellij.psi.PsiReference) FieldDefinitionNode(org.ballerinalang.plugins.idea.psi.FieldDefinitionNode) LookupElement(com.intellij.codeInsight.lookup.LookupElement) AnnotationReferenceNode(org.ballerinalang.plugins.idea.psi.AnnotationReferenceNode) PsiElement(com.intellij.psi.PsiElement) AnnotationAttachmentNode(org.ballerinalang.plugins.idea.psi.AnnotationAttachmentNode) NotNull(org.jetbrains.annotations.NotNull)

Example 73 with IdentifierPSINode

use of org.ballerinalang.plugins.idea.psi.IdentifierPSINode 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)

Example 74 with IdentifierPSINode

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

the class InvocationReference method getStructDefinitionNode.

private StructDefinitionNode getStructDefinitionNode() {
    IdentifierPSINode identifier = getElement();
    PsiElement structReference = identifier.getPrevSibling();
    if (".".equals(structReference.getText())) {
        structReference = PsiTreeUtil.prevVisibleLeaf(structReference);
    }
    if (structReference == null) {
        return null;
    }
    PsiReference reference = structReference.findReferenceAt(structReference.getTextLength());
    if (reference == null) {
        return null;
    }
    PsiElement resolvedElement = reference.resolve();
    if (resolvedElement == null || !(resolvedElement instanceof IdentifierPSINode)) {
        return null;
    }
    return BallerinaPsiImplUtil.findStructDefinition((IdentifierPSINode) resolvedElement);
}
Also used : IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement)

Example 75 with IdentifierPSINode

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

the class NameReference method resolve.

@Nullable
@Override
public PsiElement resolve() {
    IdentifierPSINode identifier = getElement();
    PsiElement parent = identifier.getParent();
    PackageNameNode packageNameNode = PsiTreeUtil.getChildOfType(parent, PackageNameNode.class);
    if (packageNameNode == null) {
        return resolveInCurrentPackage();
    } else {
        return resolveInPackage(packageNameNode);
    }
}
Also used : PackageNameNode(org.ballerinalang.plugins.idea.psi.PackageNameNode) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

IdentifierPSINode (org.ballerinalang.plugins.idea.psi.IdentifierPSINode)109 PsiElement (com.intellij.psi.PsiElement)70 NotNull (org.jetbrains.annotations.NotNull)63 LinkedList (java.util.LinkedList)58 LookupElement (com.intellij.codeInsight.lookup.LookupElement)48 Nullable (org.jetbrains.annotations.Nullable)32 PsiDirectory (com.intellij.psi.PsiDirectory)29 PsiReference (com.intellij.psi.PsiReference)25 PsiFile (com.intellij.psi.PsiFile)24 PackageNameNode (org.ballerinalang.plugins.idea.psi.PackageNameNode)20 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)17 ScopeNode (org.antlr.jetbrains.adaptor.psi.ScopeNode)15 PrioritizedLookupElement (com.intellij.codeInsight.completion.PrioritizedLookupElement)12 FieldDefinitionNode (org.ballerinalang.plugins.idea.psi.FieldDefinitionNode)12 StructDefinitionNode (org.ballerinalang.plugins.idea.psi.StructDefinitionNode)12 VariableDefinitionNode (org.ballerinalang.plugins.idea.psi.VariableDefinitionNode)10 GlobalVariableDefinitionNode (org.ballerinalang.plugins.idea.psi.GlobalVariableDefinitionNode)9 TypeNameNode (org.ballerinalang.plugins.idea.psi.TypeNameNode)9 ArrayList (java.util.ArrayList)8 NameReferenceNode (org.ballerinalang.plugins.idea.psi.NameReferenceNode)8