Search in sources :

Example 6 with ConnectorDefinitionNode

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

the class BallerinaPsiImplUtil method resolveConnectorFromVariableDefinitionNode.

@Nullable
public static ConnectorDefinitionNode resolveConnectorFromVariableDefinitionNode(@NotNull PsiElement definitionNode) {
    NameReferenceNode nameReferenceNode = PsiTreeUtil.findChildOfType(definitionNode, NameReferenceNode.class);
    if (nameReferenceNode == null) {
        return null;
    }
    PsiElement nameIdentifier = nameReferenceNode.getNameIdentifier();
    if (nameIdentifier == null) {
        return null;
    }
    PsiReference typeNameNodeReference = nameIdentifier.getReference();
    if (typeNameNodeReference == null) {
        return null;
    }
    PsiElement resolvedDefElement = typeNameNodeReference.resolve();
    if (resolvedDefElement == null) {
        return null;
    }
    if (!(resolvedDefElement.getParent() instanceof ConnectorDefinitionNode)) {
        return null;
    }
    return ((ConnectorDefinitionNode) resolvedDefElement.getParent());
}
Also used : PsiReference(com.intellij.psi.PsiReference) ConnectorDefinitionNode(org.ballerinalang.plugins.idea.psi.ConnectorDefinitionNode) NameReferenceNode(org.ballerinalang.plugins.idea.psi.NameReferenceNode) PsiElement(com.intellij.psi.PsiElement) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with ConnectorDefinitionNode

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

the class ActionInvocationReference method resolve.

@Nullable
@Override
public PsiElement resolve() {
    IdentifierPSINode identifier = getElement();
    PsiElement parent = identifier.getParent();
    PsiElement prevVisibleLeaf = PsiTreeUtil.prevVisibleLeaf(parent);
    PsiReference variableReference = null;
    if (prevVisibleLeaf != null && ".".equals(prevVisibleLeaf.getText())) {
        PsiElement connectorVariable = PsiTreeUtil.prevVisibleLeaf(prevVisibleLeaf);
        if (connectorVariable != null) {
            variableReference = connectorVariable.findReferenceAt(connectorVariable.getTextLength());
        }
    } else {
        PsiElement prevSibling = parent.getPrevSibling();
        variableReference = prevSibling.findReferenceAt(prevSibling.getTextLength());
    }
    if (variableReference == null) {
        return null;
    }
    PsiElement variableDefinition = variableReference.resolve();
    if (variableDefinition == null) {
        return null;
    }
    PsiElement variableDefinitionParent = variableDefinition.getParent();
    ConnectorDefinitionNode connectorDefinitionNode;
    if (variableDefinitionParent instanceof EndpointDeclarationNode) {
        connectorDefinitionNode = BallerinaPsiImplUtil.getConnectorDefinition(((EndpointDeclarationNode) variableDefinitionParent));
    } else {
        connectorDefinitionNode = BallerinaPsiImplUtil.resolveConnectorFromVariableDefinitionNode(variableDefinitionParent);
    }
    if (connectorDefinitionNode == null) {
        return null;
    }
    Collection<ActionDefinitionNode> actionDefinitionNodes = PsiTreeUtil.findChildrenOfType(connectorDefinitionNode, ActionDefinitionNode.class);
    for (ActionDefinitionNode actionDefinitionNode : actionDefinitionNodes) {
        IdentifierPSINode actionIdentifier = PsiTreeUtil.getChildOfType(actionDefinitionNode, IdentifierPSINode.class);
        if (actionIdentifier == null) {
            continue;
        }
        if (actionIdentifier.getText().equals(identifier.getText())) {
            return actionIdentifier;
        }
    }
    return null;
}
Also used : EndpointDeclarationNode(org.ballerinalang.plugins.idea.psi.EndpointDeclarationNode) ActionDefinitionNode(org.ballerinalang.plugins.idea.psi.ActionDefinitionNode) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) PsiReference(com.intellij.psi.PsiReference) ConnectorDefinitionNode(org.ballerinalang.plugins.idea.psi.ConnectorDefinitionNode) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ConnectorDefinitionNode (org.ballerinalang.plugins.idea.psi.ConnectorDefinitionNode)7 PsiElement (com.intellij.psi.PsiElement)6 PsiReference (com.intellij.psi.PsiReference)4 ActionDefinitionNode (org.ballerinalang.plugins.idea.psi.ActionDefinitionNode)4 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)3 FunctionDefinitionNode (org.ballerinalang.plugins.idea.psi.FunctionDefinitionNode)3 Nullable (org.jetbrains.annotations.Nullable)3 List (java.util.List)2 AnnotationDefinitionNode (org.ballerinalang.plugins.idea.psi.AnnotationDefinitionNode)2 ConnectorBodyNode (org.ballerinalang.plugins.idea.psi.ConnectorBodyNode)2 ConstantDefinitionNode (org.ballerinalang.plugins.idea.psi.ConstantDefinitionNode)2 IdentifierPSINode (org.ballerinalang.plugins.idea.psi.IdentifierPSINode)2 NameReferenceNode (org.ballerinalang.plugins.idea.psi.NameReferenceNode)2 ResourceDefinitionNode (org.ballerinalang.plugins.idea.psi.ResourceDefinitionNode)2 ServiceDefinitionNode (org.ballerinalang.plugins.idea.psi.ServiceDefinitionNode)2 StructDefinitionNode (org.ballerinalang.plugins.idea.psi.StructDefinitionNode)2 NotNull (org.jetbrains.annotations.NotNull)2 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)1 SortableTreeElement (com.intellij.ide.util.treeView.smartTree.SortableTreeElement)1 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)1