Search in sources :

Example 6 with ActionDefinitionNode

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

the class BallerinaPsiImplUtil method getAllActionsFromAConnector.

/**
 * Returns all actions/native actions defined in the given ConnectorDefinitionNode.
 *
 * @param connectorDefinitionNode PsiElement which represent a Connector Definition
 * @return List of all actions/native actions defined in the given ConnectorDefinitionNode.
 */
@NotNull
public static List<IdentifierPSINode> getAllActionsFromAConnector(@NotNull PsiElement connectorDefinitionNode) {
    List<IdentifierPSINode> results = new ArrayList<>();
    Collection<ActionDefinitionNode> actionDefinitionNodes = PsiTreeUtil.findChildrenOfType(connectorDefinitionNode, ActionDefinitionNode.class);
    for (ActionDefinitionNode definitionNode : actionDefinitionNodes) {
        IdentifierPSINode identifier = PsiTreeUtil.getChildOfType(definitionNode, IdentifierPSINode.class);
        results.add(identifier);
    }
    return results;
}
Also used : ActionDefinitionNode(org.ballerinalang.plugins.idea.psi.ActionDefinitionNode) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with ActionDefinitionNode

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

the class BallerinaPsiImplUtil method getAttachmentType.

/**
 * Returns the attachment type by checking the nodes.
 *
 * @param identifier identifier node of the annotation attachment node
 * @return attachment type.
 */
@Nullable
public static String getAttachmentType(@NotNull IdentifierPSINode identifier) {
    PsiElement parent = identifier.getParent();
    PsiElement superParent = parent.getParent();
    PsiElement nextSibling = PsiTreeUtil.skipSiblingsForward(superParent, PsiWhiteSpace.class, PsiComment.class, AnnotationAttachmentNode.class);
    String type = null;
    if (nextSibling == null) {
        AnnotationAttachmentNode annotationAttachmentNode = PsiTreeUtil.getParentOfType(identifier, AnnotationAttachmentNode.class);
        if (annotationAttachmentNode != null) {
            PsiElement definitionNode = annotationAttachmentNode.getParent();
            type = getAnnotationAttachmentType(definitionNode);
        }
    } else if (nextSibling instanceof DefinitionNode) {
        PsiElement[] children = nextSibling.getChildren();
        if (children.length != 0) {
            PsiElement definitionNode = children[0];
            type = getAnnotationAttachmentType(definitionNode);
        }
    } else if (nextSibling.getParent() instanceof ResourceDefinitionNode) {
        type = "resource";
    } else if (nextSibling instanceof ActionDefinitionNode || nextSibling.getParent() instanceof ActionDefinitionNode || parent instanceof ActionDefinitionNode) {
        type = "action";
    } else if (nextSibling.getParent() instanceof ParameterNode) {
        type = "parameter";
    }
    return type;
}
Also used : ResourceDefinitionNode(org.ballerinalang.plugins.idea.psi.ResourceDefinitionNode) ServiceDefinitionNode(org.ballerinalang.plugins.idea.psi.ServiceDefinitionNode) StructDefinitionNode(org.ballerinalang.plugins.idea.psi.StructDefinitionNode) ConstantDefinitionNode(org.ballerinalang.plugins.idea.psi.ConstantDefinitionNode) ConnectorDefinitionNode(org.ballerinalang.plugins.idea.psi.ConnectorDefinitionNode) GlobalVariableDefinitionNode(org.ballerinalang.plugins.idea.psi.GlobalVariableDefinitionNode) TransformerDefinitionNode(org.ballerinalang.plugins.idea.psi.TransformerDefinitionNode) EnumDefinitionNode(org.ballerinalang.plugins.idea.psi.EnumDefinitionNode) ActionDefinitionNode(org.ballerinalang.plugins.idea.psi.ActionDefinitionNode) AnnotationDefinitionNode(org.ballerinalang.plugins.idea.psi.AnnotationDefinitionNode) DefinitionNode(org.ballerinalang.plugins.idea.psi.DefinitionNode) VariableDefinitionNode(org.ballerinalang.plugins.idea.psi.VariableDefinitionNode) FunctionDefinitionNode(org.ballerinalang.plugins.idea.psi.FunctionDefinitionNode) FieldDefinitionNode(org.ballerinalang.plugins.idea.psi.FieldDefinitionNode) ResourceDefinitionNode(org.ballerinalang.plugins.idea.psi.ResourceDefinitionNode) ParameterNode(org.ballerinalang.plugins.idea.psi.ParameterNode) ReturnParameterNode(org.ballerinalang.plugins.idea.psi.ReturnParameterNode) CodeBlockParameterNode(org.ballerinalang.plugins.idea.psi.CodeBlockParameterNode) ActionDefinitionNode(org.ballerinalang.plugins.idea.psi.ActionDefinitionNode) QuotedLiteralString(org.ballerinalang.plugins.idea.psi.QuotedLiteralString) PsiElement(com.intellij.psi.PsiElement) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) AnnotationAttachmentNode(org.ballerinalang.plugins.idea.psi.AnnotationAttachmentNode) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with ActionDefinitionNode

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

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