Search in sources :

Example 1 with ConnectorDefinitionNode

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

the class BallerinaFoldingBuilder method buildConnectorFoldRegions.

private void buildConnectorFoldRegions(@NotNull List<FoldingDescriptor> descriptors, @NotNull PsiElement root) {
    // Get all connectors.
    Collection<ConnectorDefinitionNode> connectorNodes = PsiTreeUtil.findChildrenOfType(root, ConnectorDefinitionNode.class);
    for (ConnectorDefinitionNode connectorNode : connectorNodes) {
        // Get the connector body. This is used to calculate the start offset.
        ConnectorBodyNode connectorBodyNode = PsiTreeUtil.getChildOfType(connectorNode, ConnectorBodyNode.class);
        if (connectorBodyNode == null) {
            continue;
        }
        // Add folding descriptor.
        addFoldingDescriptor(descriptors, connectorNode, connectorBodyNode);
        // We need to add folding support to actions as well. So get all actions in the connector.
        Collection<ActionDefinitionNode> actionDefinitionNodes = PsiTreeUtil.findChildrenOfType(root, ActionDefinitionNode.class);
        for (ActionDefinitionNode actionDefinitionNode : actionDefinitionNodes) {
            // Get the action body. This is used to calculate the start offset.
            CallableUnitBodyNode callableUnitBodyNode = PsiTreeUtil.getChildOfType(actionDefinitionNode, CallableUnitBodyNode.class);
            if (callableUnitBodyNode == null) {
                continue;
            }
            // Add folding descriptor.
            addFoldingDescriptor(descriptors, actionDefinitionNode, callableUnitBodyNode);
        }
    }
}
Also used : ConnectorBodyNode(org.ballerinalang.plugins.idea.psi.ConnectorBodyNode) ActionDefinitionNode(org.ballerinalang.plugins.idea.psi.ActionDefinitionNode) CallableUnitBodyNode(org.ballerinalang.plugins.idea.psi.CallableUnitBodyNode) ConnectorDefinitionNode(org.ballerinalang.plugins.idea.psi.ConnectorDefinitionNode)

Example 2 with ConnectorDefinitionNode

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

the class BallerinaDocumentationProvider method getSignature.

@NotNull
private static String getSignature(PsiElement element) {
    if (element == null) {
        return "";
    }
    StringBuilder stringBuilder = new StringBuilder();
    // element will be an identifier. So we need to get the parent of the element to identify the type to
    // generate the signature.
    PsiElement parent = element.getParent();
    // Generate the signature according to the parent type.
    if (parent instanceof FunctionDefinitionNode) {
        // Add the function signature.
        stringBuilder.append("function ");
        stringBuilder.append(element.getText());
        // Get parameters.
        String params = getParameterString(parent, false);
        // Add parameters.
        stringBuilder.append("(");
        stringBuilder.append(params);
        stringBuilder.append(")");
        // Get return types. These can be either return types or return parameters.
        List<String> returnParamsList = getReturnTypes(parent);
        String returnParams = StringUtil.join(returnParamsList, ", ");
        if (!returnParams.isEmpty()) {
            // Add return types/parameters.
            stringBuilder.append("(");
            stringBuilder.append(returnParams);
            stringBuilder.append(")");
        }
    } else if (parent instanceof ActionDefinitionNode || parent instanceof AnyIdentifierNameNode) {
        // Add the action signature.
        stringBuilder.append("action ");
        stringBuilder.append(element.getText());
        // Get parameters.
        String params = getParameterString(parent, false);
        // Add parameters.
        stringBuilder.append("(");
        stringBuilder.append(params);
        stringBuilder.append(")");
        // Get return types/parameters.
        List<String> returnParamsList = getReturnTypes(parent);
        String returnParams = StringUtil.join(returnParamsList, ", ");
        if (!returnParams.isEmpty()) {
            // Add return types/parameters.
            stringBuilder.append("(");
            stringBuilder.append(returnParams);
            stringBuilder.append(")");
        }
    } else if (parent instanceof ConnectorDefinitionNode) {
        // Add the connector signature.
        stringBuilder.append("connector ");
        stringBuilder.append(element.getText());
        // Get parameters.
        String params = getParameterString(parent, false);
        // Add parameters.
        stringBuilder.append("(");
        stringBuilder.append(params);
        stringBuilder.append(")");
    } else if (parent instanceof StructDefinitionNode) {
        // Add the function signature.
        stringBuilder.append("struct ");
        stringBuilder.append(element.getText());
        stringBuilder.append(" { }");
    } else if (parent instanceof ConstantDefinitionNode) {
        // Add the function signature.
        stringBuilder.append(parent.getText());
    }
    // If the doc is available, add package to the top.
    if (!stringBuilder.toString().isEmpty()) {
        // Add the containing package to the quick doc if there is any.
        PsiElement packagePathNode = getContainingPackage(element);
        if (packagePathNode != null) {
            stringBuilder.insert(0, packagePathNode.getText() + "<br><br>");
        }
    }
    // Return the signature.
    return stringBuilder.toString();
}
Also used : AnyIdentifierNameNode(org.ballerinalang.plugins.idea.psi.AnyIdentifierNameNode) ConstantDefinitionNode(org.ballerinalang.plugins.idea.psi.ConstantDefinitionNode) FunctionDefinitionNode(org.ballerinalang.plugins.idea.psi.FunctionDefinitionNode) StructDefinitionNode(org.ballerinalang.plugins.idea.psi.StructDefinitionNode) ActionDefinitionNode(org.ballerinalang.plugins.idea.psi.ActionDefinitionNode) LinkedList(java.util.LinkedList) ParameterTypeNameList(org.ballerinalang.plugins.idea.psi.ParameterTypeNameList) List(java.util.List) ConnectorDefinitionNode(org.ballerinalang.plugins.idea.psi.ConnectorDefinitionNode) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ConnectorDefinitionNode

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

the class BallerinaStructureViewElement method getChildren.

@NotNull
@Override
public TreeElement[] getChildren() {
    // The element can be one of BallerinaFile, ConnectorDefinitionNode instance.
    if (element instanceof BallerinaFile) {
        List<TreeElement> treeElements = new ArrayList<>();
        // Add services.
        Collection<ServiceDefinitionNode> services = PsiTreeUtil.findChildrenOfType(element, ServiceDefinitionNode.class);
        for (PsiElement service : services) {
            // In here, instead of using the service, we use service.getParent(). This is done because we
            // want to show resources under a service node. This is how the sub nodes can be added.
            treeElements.add(new BallerinaStructureViewElement(service));
        }
        // Add functions.
        Collection<FunctionDefinitionNode> functions = PsiTreeUtil.findChildrenOfType(element, FunctionDefinitionNode.class);
        for (PsiElement function : functions) {
            treeElements.add(new BallerinaStructureViewElement(function));
        }
        // Add connectors.
        Collection<ConnectorDefinitionNode> connectors = PsiTreeUtil.findChildrenOfType(element, ConnectorDefinitionNode.class);
        for (PsiElement connector : connectors) {
            // In here, instead of using the connector, we use connector.getParent(). This is done because we
            // want to show actions under a connector node. This is how the sub nodes can be added.
            treeElements.add(new BallerinaStructureViewElement(connector));
        }
        // Add annotations.
        Collection<AnnotationDefinitionNode> annotations = PsiTreeUtil.findChildrenOfType(element, AnnotationDefinitionNode.class);
        for (PsiElement annotation : annotations) {
            treeElements.add(new BallerinaStructureViewElement(annotation));
        }
        // Add structs
        Collection<StructDefinitionNode> structs = PsiTreeUtil.findChildrenOfType(element, StructDefinitionNode.class);
        for (PsiElement struct : structs) {
            treeElements.add(new BallerinaStructureViewElement(struct));
        }
        // Convert the list to an array and return.
        return treeElements.toArray(new TreeElement[treeElements.size()]);
    } else if (element instanceof ConnectorDefinitionNode) {
        // If the element is a ConnectorDefinitionNode instance, we get all actions.
        List<TreeElement> treeElements = new ArrayList<>();
        // Add actions.
        Collection<ActionDefinitionNode> actions = PsiTreeUtil.findChildrenOfType(element, ActionDefinitionNode.class);
        for (PsiElement action : actions) {
            treeElements.add(new BallerinaStructureViewElement(action));
        }
        // Convert the list to an array and return.
        return treeElements.toArray(new TreeElement[treeElements.size()]);
    } else if (element instanceof ServiceDefinitionNode) {
        // If the element is a ServiceDefinitionNode instance, we get all resources.
        List<TreeElement> treeElements = new ArrayList<>();
        // Add resources.
        Collection<ResourceDefinitionNode> resources = PsiTreeUtil.findChildrenOfType(element, ResourceDefinitionNode.class);
        for (PsiElement resource : resources) {
            treeElements.add(new BallerinaStructureViewElement(resource));
        }
        // Convert the list to an array and return.
        return treeElements.toArray(new TreeElement[treeElements.size()]);
    } else if (element instanceof FunctionDefinitionNode || element instanceof ResourceDefinitionNode || element instanceof ActionDefinitionNode) {
        // If the element is a FunctionDefinitionNode instance, we get all workers.
        List<TreeElement> treeElements = new ArrayList<>();
        // Add workers.
        Collection<WorkerDeclarationNode> workers = PsiTreeUtil.findChildrenOfType(element, WorkerDeclarationNode.class);
        for (PsiElement worker : workers) {
            treeElements.add(new BallerinaStructureViewElement(worker));
        }
        // Convert the list to an array and return.
        return treeElements.toArray(new TreeElement[treeElements.size()]);
    }
    // If the element type other than what we check above, return an empty array.
    return new TreeElement[0];
}
Also used : BallerinaFile(org.ballerinalang.plugins.idea.psi.BallerinaFile) WorkerDeclarationNode(org.ballerinalang.plugins.idea.psi.WorkerDeclarationNode) ActionDefinitionNode(org.ballerinalang.plugins.idea.psi.ActionDefinitionNode) ArrayList(java.util.ArrayList) ConnectorDefinitionNode(org.ballerinalang.plugins.idea.psi.ConnectorDefinitionNode) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) SortableTreeElement(com.intellij.ide.util.treeView.smartTree.SortableTreeElement) ServiceDefinitionNode(org.ballerinalang.plugins.idea.psi.ServiceDefinitionNode) ResourceDefinitionNode(org.ballerinalang.plugins.idea.psi.ResourceDefinitionNode) FunctionDefinitionNode(org.ballerinalang.plugins.idea.psi.FunctionDefinitionNode) StructDefinitionNode(org.ballerinalang.plugins.idea.psi.StructDefinitionNode) AnnotationDefinitionNode(org.ballerinalang.plugins.idea.psi.AnnotationDefinitionNode) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ConnectorDefinitionNode

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

the class BallerinaKeywordsCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    PsiElement element = parameters.getPosition();
    PsiElement parent = element.getParent();
    if (element instanceof LeafPsiElement) {
        IElementType elementType = ((LeafPsiElement) element).getElementType();
        if (elementType == BallerinaTypes.FLOATING_POINT) {
            return;
        }
    }
    if (parent instanceof NameReferenceNode) {
        PsiElement prevVisibleLeaf = PsiTreeUtil.prevVisibleLeaf(element);
        if (prevVisibleLeaf != null && "public".equals(prevVisibleLeaf.getText())) {
            result.addAllElements(getFileLevelKeywordsAsLookups(false, true, true));
        }
        if (prevVisibleLeaf instanceof IdentifierPSINode) {
            result.addElement(getAttachKeyword());
            return;
        }
        ANTLRPsiNode definitionParent = PsiTreeUtil.getParentOfType(parent, CallableUnitBodyNode.class, ServiceBodyNode.class, ConnectorBodyNode.class);
        if (definitionParent != null && prevVisibleLeaf != null && "=".equals(prevVisibleLeaf.getText())) {
            result.addElement(getCreateKeyword());
            result.addElement(getTypeOfKeyword());
            result.addElement(getLengthOfKeyword());
            result.addAllElements(getValueKeywords());
        }
        ExpressionNode expressionNode = PsiTreeUtil.getParentOfType(parent, ExpressionNode.class);
        if (expressionNode != null && expressionNode.getChildren().length == 1) {
            PsiReference referenceAt = parent.findReferenceAt(0);
            if (referenceAt == null || referenceAt instanceof NameReference) {
                result.addAllElements(getValueKeywords());
            }
            PsiElement nextVisibleLeaf = PsiTreeUtil.nextVisibleLeaf(element);
            if ((prevVisibleLeaf != null && "(".equals(prevVisibleLeaf.getText())) || (nextVisibleLeaf != null && ")".equals(nextVisibleLeaf.getText()) && !":".equals(prevVisibleLeaf.getText()))) {
                addOtherTypeAsLookup(result);
                addValueTypesAsLookups(result);
                addReferenceTypesAsLookups(result);
            }
        }
        AnnotationAttachmentNode attachmentNode = PsiTreeUtil.getParentOfType(parent, AnnotationAttachmentNode.class);
        if (attachmentNode != null) {
            result.addAllElements(getValueKeywords());
        }
        TypeNameNode typeNameNode = PsiTreeUtil.getParentOfType(parent, TypeNameNode.class);
        if (typeNameNode != null && prevVisibleLeaf != null && !prevVisibleLeaf.getText().matches("[:.=]")) {
            AnnotationDefinitionNode annotationDefinitionNode = PsiTreeUtil.getParentOfType(typeNameNode, AnnotationDefinitionNode.class);
            if (annotationDefinitionNode == null) {
                addOtherTypeAsLookup(result);
                addXmlnsAsLookup(result);
                addValueTypesAsLookups(result);
                addReferenceTypesAsLookups(result);
            }
        }
    }
    if (parent instanceof StatementNode) {
        PsiElement prevVisibleSibling = PsiTreeUtil.prevVisibleLeaf(element);
        if (prevVisibleSibling != null && "=".equals(prevVisibleSibling.getText())) {
            result.addElement(getCreateKeyword());
            result.addElement(getTypeOfKeyword());
            result.addElement(getLengthOfKeyword());
        }
    }
    if (parent instanceof ConstantDefinitionNode || parent instanceof PsiErrorElement) {
        PsiElement prevVisibleSibling = PsiTreeUtil.prevVisibleLeaf(element);
        if (prevVisibleSibling != null && "const".equals(prevVisibleSibling.getText())) {
            addValueTypesAsLookups(result);
            return;
        }
    }
    if (parent instanceof PsiErrorElement) {
        PsiElement prevVisibleSibling = PsiTreeUtil.prevVisibleLeaf(element);
        PsiElement definitionNode = PsiTreeUtil.getParentOfType(element, FunctionDefinitionNode.class, ServiceDefinitionNode.class, ConnectorDefinitionNode.class, ResourceDefinitionNode.class);
        if (definitionNode != null) {
            if (prevVisibleSibling != null && "=".equals(prevVisibleSibling.getText())) {
                result.addElement(getCreateKeyword());
                result.addAllElements(getValueKeywords());
                result.addElement(getTypeOfKeyword());
                result.addElement(getLengthOfKeyword());
            }
            if (prevVisibleSibling != null && prevVisibleSibling.getText().matches("[;{}]") && !(prevVisibleSibling.getParent() instanceof AnnotationAttachmentNode)) {
                // Todo - change method
                addOtherTypeAsLookup(result);
                addXmlnsAsLookup(result);
                addValueTypesAsLookups(result);
                addReferenceTypesAsLookups(result);
                if (definitionNode instanceof FunctionDefinitionNode) {
                    result.addAllElements(getFunctionSpecificKeywords());
                }
                if (definitionNode instanceof ResourceDefinitionNode) {
                    result.addAllElements(getResourceSpecificKeywords());
                }
                if (definitionNode instanceof ServiceDefinitionNode) {
                    result.addAllElements(getServiceSpecificKeywords());
                }
                if (definitionNode instanceof ConnectorDefinitionNode) {
                    result.addAllElements(getConnectorSpecificKeywords());
                }
                if (!(definitionNode instanceof ServiceDefinitionNode || definitionNode instanceof ConnectorDefinitionNode)) {
                    result.addAllElements(getCommonKeywords());
                }
            }
            if (prevVisibleSibling != null && !prevVisibleSibling.getText().matches("[{}]")) /*|| !(prevVisibleSibling.getParent() instanceof AnnotationAttachmentNode)*/
            {
                result.addAllElements(getValueKeywords());
            }
        }
        ConnectorBodyNode connectorBodyNode = PsiTreeUtil.getParentOfType(element, ConnectorBodyNode.class);
        if (connectorBodyNode != null) {
            result.addAllElements(getConnectorSpecificKeywords());
        }
        ConnectorDefinitionNode connectorDefinitionNode = PsiTreeUtil.getParentOfType(element, ConnectorDefinitionNode.class);
        if (connectorDefinitionNode != null) {
            result.addAllElements(getConnectorSpecificKeywords());
        }
        return;
    }
    if (parent instanceof NameReferenceNode) {
        RecordKeyValueNode recordKeyValueNode = PsiTreeUtil.getParentOfType(parent, RecordKeyValueNode.class);
        if (recordKeyValueNode == null) {
            PsiElement prevVisibleSibling = PsiTreeUtil.prevVisibleLeaf(element);
            if (prevVisibleSibling != null && "{".equals(prevVisibleSibling.getText())) {
                FunctionDefinitionNode functionDefinitionNode = PsiTreeUtil.getParentOfType(element, FunctionDefinitionNode.class);
                if (functionDefinitionNode != null) {
                    // Todo - change method
                    addOtherTypeAsLookup(result);
                    addXmlnsAsLookup(result);
                    addValueTypesAsLookups(result);
                    addReferenceTypesAsLookups(result);
                    result.addAllElements(getFunctionSpecificKeywords());
                    result.addAllElements(getCommonKeywords());
                    result.addAllElements(getValueKeywords());
                }
                ServiceBodyNode serviceBodyNode = PsiTreeUtil.getParentOfType(element, ServiceBodyNode.class);
                if (serviceBodyNode != null) {
                    result.addAllElements(getServiceSpecificKeywords());
                }
                ConnectorBodyNode connectorBodyNode = PsiTreeUtil.getParentOfType(element, ConnectorBodyNode.class);
                if (connectorBodyNode != null) {
                    result.addAllElements(getConnectorSpecificKeywords());
                }
            } else if (prevVisibleSibling != null && "}".equals(prevVisibleSibling.getText())) {
                result.addAllElements(getFileLevelKeywordsAsLookups(true, false, false));
            }
        }
    }
    if (parent instanceof ResourceDefinitionNode) {
        result.addAllElements(getServiceSpecificKeywords());
    }
    if (parent.getPrevSibling() == null) {
        GlobalVariableDefinitionNode globalVariableDefinitionNode = PsiTreeUtil.getParentOfType(element, GlobalVariableDefinitionNode.class);
        if (globalVariableDefinitionNode != null) {
            PsiElement prevVisibleSibling = PsiTreeUtil.prevVisibleLeaf(element);
            if (prevVisibleSibling != null && !(";".equals(prevVisibleSibling.getText()))) {
                if (!(prevVisibleSibling.getText().matches("[:=]") || prevVisibleSibling instanceof IdentifierPSINode || "create".equals(prevVisibleSibling.getText()))) {
                    if (prevVisibleSibling instanceof LeafPsiElement) {
                        IElementType elementType = ((LeafPsiElement) prevVisibleSibling).getElementType();
                        if (BallerinaParserDefinition.KEYWORDS.contains(elementType)) {
                            return;
                        }
                    }
                    result.addAllElements(getCommonKeywords());
                }
                return;
            }
            PsiElement definitionNode = globalVariableDefinitionNode.getParent();
            PackageDeclarationNode prevPackageDeclarationNode = PsiTreeUtil.getPrevSiblingOfType(definitionNode, PackageDeclarationNode.class);
            ImportDeclarationNode prevImportDeclarationNode = PsiTreeUtil.getPrevSiblingOfType(definitionNode, ImportDeclarationNode.class);
            ConstantDefinitionNode prevConstantDefinitionNode = PsiTreeUtil.getPrevSiblingOfType(definitionNode, ConstantDefinitionNode.class);
            DefinitionNode prevDefinitionNode = PsiTreeUtil.getPrevSiblingOfType(definitionNode, DefinitionNode.class);
            GlobalVariableDefinitionNode prevGlobalVariableDefinition = PsiTreeUtil.findChildOfType(prevDefinitionNode, GlobalVariableDefinitionNode.class);
            if (prevPackageDeclarationNode == null && prevImportDeclarationNode == null && prevConstantDefinitionNode == null && prevGlobalVariableDefinition == null) {
                result.addAllElements(getFileLevelKeywordsAsLookups(true, true, true));
            } else if ((prevPackageDeclarationNode != null || prevImportDeclarationNode != null) && prevConstantDefinitionNode == null && prevGlobalVariableDefinition == null) {
                result.addAllElements(getFileLevelKeywordsAsLookups(true, false, true));
            } else {
                result.addAllElements(getFileLevelKeywordsAsLookups(true, false, false));
            }
            addTypeNamesAsLookups(result);
        }
    }
    if (element instanceof IdentifierPSINode) {
        PsiReference reference = element.findReferenceAt(element.getTextLength());
        if (reference instanceof WorkerReference) {
            result.addAllElements(getWorkerInteractionKeywords());
        }
    }
}
Also used : RecordKeyValueNode(org.ballerinalang.plugins.idea.psi.RecordKeyValueNode) NameReference(org.ballerinalang.plugins.idea.psi.references.NameReference) ConstantDefinitionNode(org.ballerinalang.plugins.idea.psi.ConstantDefinitionNode) ImportDeclarationNode(org.ballerinalang.plugins.idea.psi.ImportDeclarationNode) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) FunctionDefinitionNode(org.ballerinalang.plugins.idea.psi.FunctionDefinitionNode) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) WorkerReference(org.ballerinalang.plugins.idea.psi.references.WorkerReference) PsiElement(com.intellij.psi.PsiElement) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) ServiceBodyNode(org.ballerinalang.plugins.idea.psi.ServiceBodyNode) AnnotationAttachmentNode(org.ballerinalang.plugins.idea.psi.AnnotationAttachmentNode) ConnectorBodyNode(org.ballerinalang.plugins.idea.psi.ConnectorBodyNode) PsiReference(com.intellij.psi.PsiReference) StatementNode(org.ballerinalang.plugins.idea.psi.StatementNode) ANTLRPsiNode(org.antlr.jetbrains.adaptor.psi.ANTLRPsiNode) ConnectorDefinitionNode(org.ballerinalang.plugins.idea.psi.ConnectorDefinitionNode) PackageDeclarationNode(org.ballerinalang.plugins.idea.psi.PackageDeclarationNode) IElementType(com.intellij.psi.tree.IElementType) PsiErrorElement(com.intellij.psi.PsiErrorElement) ResourceDefinitionNode(org.ballerinalang.plugins.idea.psi.ResourceDefinitionNode) AnnotationDefinitionNode(org.ballerinalang.plugins.idea.psi.AnnotationDefinitionNode) ServiceDefinitionNode(org.ballerinalang.plugins.idea.psi.ServiceDefinitionNode) DefinitionNode(org.ballerinalang.plugins.idea.psi.DefinitionNode) ConstantDefinitionNode(org.ballerinalang.plugins.idea.psi.ConstantDefinitionNode) ConnectorDefinitionNode(org.ballerinalang.plugins.idea.psi.ConnectorDefinitionNode) FunctionDefinitionNode(org.ballerinalang.plugins.idea.psi.FunctionDefinitionNode) GlobalVariableDefinitionNode(org.ballerinalang.plugins.idea.psi.GlobalVariableDefinitionNode) ResourceDefinitionNode(org.ballerinalang.plugins.idea.psi.ResourceDefinitionNode) ServiceDefinitionNode(org.ballerinalang.plugins.idea.psi.ServiceDefinitionNode) ExpressionNode(org.ballerinalang.plugins.idea.psi.ExpressionNode) TypeNameNode(org.ballerinalang.plugins.idea.psi.TypeNameNode) AnnotationDefinitionNode(org.ballerinalang.plugins.idea.psi.AnnotationDefinitionNode) NameReferenceNode(org.ballerinalang.plugins.idea.psi.NameReferenceNode) GlobalVariableDefinitionNode(org.ballerinalang.plugins.idea.psi.GlobalVariableDefinitionNode)

Example 5 with ConnectorDefinitionNode

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

the class BallerinaPsiImplUtil method getConnectorDefinition.

@Nullable
public static ConnectorDefinitionNode getConnectorDefinition(@NotNull EndpointDeclarationNode node) {
    ConnectorReferenceNode connectorReferenceNode = PsiTreeUtil.getChildOfType(node, ConnectorReferenceNode.class);
    if (connectorReferenceNode == null) {
        return null;
    }
    PsiReference reference = connectorReferenceNode.findReferenceAt(connectorReferenceNode.getTextLength());
    if (reference == null) {
        return null;
    }
    PsiElement resolvedElement = reference.resolve();
    if (resolvedElement == null) {
        return null;
    }
    if (resolvedElement.getParent() instanceof ConnectorDefinitionNode) {
        return ((ConnectorDefinitionNode) resolvedElement.getParent());
    }
    return null;
}
Also used : ConnectorReferenceNode(org.ballerinalang.plugins.idea.psi.ConnectorReferenceNode) PsiReference(com.intellij.psi.PsiReference) ConnectorDefinitionNode(org.ballerinalang.plugins.idea.psi.ConnectorDefinitionNode) PsiElement(com.intellij.psi.PsiElement) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) 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