Search in sources :

Example 1 with ServiceDefinitionNode

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

the class BallerinaRunConfigurationProducerBase method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(@NotNull T configuration, @NotNull ConfigurationContext context, Ref<PsiElement> sourceElement) {
    // This method will be called with each configuration type. So we need to return true for correct
    // configuration type after updating the configurations.
    PsiFile file = getFileFromContext(context);
    if (file == null) {
        return false;
    }
    // Get the element. This will be an identifier element.
    PsiElement element = sourceElement.get();
    // Get the FunctionDefinitionNode parent from element (if exists).
    FunctionDefinitionNode functionNode = PsiTreeUtil.getParentOfType(element, FunctionDefinitionNode.class);
    // Get the ServiceDefinitionNode parent from element (if exists).
    ServiceDefinitionNode serviceDefinitionNode = PsiTreeUtil.getParentOfType(element, ServiceDefinitionNode.class);
    // Setup configuration for Ballerina test files.
    if (file.getName().endsWith(BallerinaConstants.BALLERINA_TEST_FILE_SUFFIX) && functionNode != null && BallerinaRunUtil.isTestFunction(functionNode)) {
        if (!(configuration instanceof BallerinaTestConfiguration)) {
            return false;
        }
        PackageDeclarationNode packageDeclarationNode = PsiTreeUtil.findChildOfType(file, PackageDeclarationNode.class);
        // Get the package path node. We need this to get the package path of the file.
        FullyQualifiedPackageNameNode fullyQualifiedPackageNameNode = PsiTreeUtil.findChildOfType(packageDeclarationNode, FullyQualifiedPackageNameNode.class);
        String packageInFile = "";
        if (fullyQualifiedPackageNameNode != null) {
            // Regardless of the OS, separator character will be "/".
            packageInFile = fullyQualifiedPackageNameNode.getText().replaceAll("\\.", "/");
        }
        RunnerAndConfigurationSettings existingConfigurations = context.findExisting();
        if (existingConfigurations != null) {
            // Get the RunConfiguration.
            RunConfiguration existingConfiguration = existingConfigurations.getConfiguration();
            // Run configuration might be an application configuration. So we need to check the type.
            if (existingConfiguration instanceof BallerinaTestConfiguration) {
                // Set other configurations.
                setTestConfigurations((BallerinaTestConfiguration) existingConfiguration, file, packageInFile);
                return true;
            }
            return false;
        } else {
            // If an existing configuration is not found and the configuration provided is of correct type.
            String configName = getConfigurationName(file);
            // Set the config name. This will be the file name.
            configuration.setName(configName);
            // Set the file path.
            configuration.setFilePath(file.getVirtualFile().getPath());
            // Set the module.
            Module module = context.getModule();
            if (module != null) {
                configuration.setModule(module);
            }
            // Set other configurations.
            setTestConfigurations((BallerinaTestConfiguration) configuration, file, packageInFile);
            return true;
        }
    }
    // Get the declared package in the file if available.
    String packageInFile = "";
    boolean isPackageDeclared = false;
    // Get the PackageDeclarationNode if available.
    PackageDeclarationNode packageDeclarationNode = PsiTreeUtil.findChildOfType(file, PackageDeclarationNode.class);
    if (packageDeclarationNode != null) {
        isPackageDeclared = true;
    }
    // Get the package path node. We need this to get the package path of the file.
    FullyQualifiedPackageNameNode fullyQualifiedPackageNameNode = PsiTreeUtil.findChildOfType(packageDeclarationNode, FullyQualifiedPackageNameNode.class);
    if (fullyQualifiedPackageNameNode != null) {
        // Regardless of the OS, separator character will be "/".
        packageInFile = fullyQualifiedPackageNameNode.getText().replaceAll("\\.", "/");
    }
    // Get existing configuration if available.
    RunnerAndConfigurationSettings existingConfigurations = context.findExisting();
    if (existingConfigurations != null) {
        // Get the RunConfiguration.
        RunConfiguration existingConfiguration = existingConfigurations.getConfiguration();
        // Run configuration might be an application configuration. So we need to check the type.
        if (existingConfiguration instanceof BallerinaApplicationConfiguration) {
            // Set other configurations.
            setConfigurations((BallerinaApplicationConfiguration) existingConfiguration, file, functionNode, serviceDefinitionNode, packageInFile, isPackageDeclared);
            return true;
        }
    } else if (configuration instanceof BallerinaApplicationConfiguration) {
        // If an existing configuration is not found and the configuration provided is of correct type.
        String configName = getConfigurationName(file);
        // Set the config name. This will be the file name.
        configuration.setName(configName);
        // Set the file path.
        configuration.setFilePath(file.getVirtualFile().getPath());
        // Set the module.
        Module module = context.getModule();
        if (module != null) {
            configuration.setModule(module);
        }
        // Set other configurations.
        setConfigurations((BallerinaApplicationConfiguration) configuration, file, functionNode, serviceDefinitionNode, packageInFile, isPackageDeclared);
        return true;
    }
    // Return false if the provided configuration type cannot be applied.
    return false;
}
Also used : BallerinaTestConfiguration(org.ballerinalang.plugins.idea.runconfig.test.BallerinaTestConfiguration) PackageDeclarationNode(org.ballerinalang.plugins.idea.psi.PackageDeclarationNode) BallerinaApplicationConfiguration(org.ballerinalang.plugins.idea.runconfig.application.BallerinaApplicationConfiguration) ServiceDefinitionNode(org.ballerinalang.plugins.idea.psi.ServiceDefinitionNode) FullyQualifiedPackageNameNode(org.ballerinalang.plugins.idea.psi.FullyQualifiedPackageNameNode) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) FunctionDefinitionNode(org.ballerinalang.plugins.idea.psi.FunctionDefinitionNode) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement)

Example 2 with ServiceDefinitionNode

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

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

the class BallerinaParserDefinition method createElement.

@NotNull
public PsiElement createElement(ASTNode node) {
    IElementType elementType = node.getElementType();
    if (elementType instanceof TokenIElementType) {
        return new ANTLRPsiNode(node);
    }
    if (!(elementType instanceof RuleIElementType)) {
        return new ANTLRPsiNode(node);
    }
    RuleIElementType ruleElType = (RuleIElementType) elementType;
    switch(ruleElType.getRuleIndex()) {
        case BallerinaParser.RULE_functionDefinition:
            return new FunctionDefinitionNode(node);
        case BallerinaParser.RULE_callableUnitBody:
            return new CallableUnitBodyNode(node);
        case BallerinaParser.RULE_nameReference:
            return new NameReferenceNode(node);
        case BallerinaParser.RULE_variableReference:
            return new VariableReferenceNode(node);
        case BallerinaParser.RULE_variableDefinitionStatement:
            return new VariableDefinitionNode(node);
        case BallerinaParser.RULE_parameter:
            return new ParameterNode(node);
        case BallerinaParser.RULE_resourceDefinition:
            return new ResourceDefinitionNode(node);
        case BallerinaParser.RULE_packageName:
            return new PackageNameNode(node);
        case BallerinaParser.RULE_fullyQualifiedPackageName:
            return new FullyQualifiedPackageNameNode(node);
        case BallerinaParser.RULE_expressionList:
            return new ExpressionListNode(node);
        case BallerinaParser.RULE_expression:
            return new ExpressionNode(node);
        case BallerinaParser.RULE_functionInvocation:
            return new FunctionInvocationNode(node);
        case BallerinaParser.RULE_compilationUnit:
            return new CompilationUnitNode(node);
        case BallerinaParser.RULE_packageDeclaration:
            return new PackageDeclarationNode(node);
        case BallerinaParser.RULE_annotationAttachment:
            return new AnnotationAttachmentNode(node);
        case BallerinaParser.RULE_serviceBody:
            return new ServiceBodyNode(node);
        case BallerinaParser.RULE_importDeclaration:
            return new ImportDeclarationNode(node);
        case BallerinaParser.RULE_statement:
            return new StatementNode(node);
        case BallerinaParser.RULE_typeName:
            return new TypeNameNode(node);
        case BallerinaParser.RULE_constantDefinition:
            return new ConstantDefinitionNode(node);
        case BallerinaParser.RULE_structDefinition:
            return new StructDefinitionNode(node);
        case BallerinaParser.RULE_simpleLiteral:
            return new SimpleLiteralNode(node);
        case BallerinaParser.RULE_packageAlias:
            return new AliasNode(node);
        case BallerinaParser.RULE_parameterList:
            return new ParameterListNode(node);
        case BallerinaParser.RULE_fieldDefinition:
            return new FieldDefinitionNode(node);
        case BallerinaParser.RULE_parameterTypeNameList:
            return new ParameterTypeNameList(node);
        case BallerinaParser.RULE_parameterTypeName:
            return new ConnectorInitNode(node);
        case BallerinaParser.RULE_serviceDefinition:
            return new ServiceDefinitionNode(node);
        case BallerinaParser.RULE_valueTypeName:
            return new ValueTypeNameNode(node);
        case BallerinaParser.RULE_annotationDefinition:
            return new AnnotationAttributeValueNode(node);
        case BallerinaParser.RULE_structBody:
            return new StructBodyNode(node);
        case BallerinaParser.RULE_returnParameter:
            return new ReturnParameterNode(node);
        case BallerinaParser.RULE_attachmentPoint:
            return new AttachmentPointNode(node);
        case BallerinaParser.RULE_definition:
            return new DefinitionNode(node);
        case BallerinaParser.RULE_ifElseStatement:
            return new IfElseStatementNode(node);
        case BallerinaParser.RULE_assignmentStatement:
            return new AssignmentStatementNode(node);
        case BallerinaParser.RULE_variableReferenceList:
            return new VariableReferenceListNode(node);
        case BallerinaParser.RULE_recordLiteral:
            return new RecordLiteralNode(node);
        case BallerinaParser.RULE_globalVariableDefinition:
            return new GlobalVariableDefinitionNode(node);
        case BallerinaParser.RULE_recordKeyValue:
            return new RecordKeyValueNode(node);
        case BallerinaParser.RULE_forkJoinStatement:
            return new ForkJoinStatementNode(node);
        case BallerinaParser.RULE_returnStatement:
            return new ReturnStatementNode(node);
        case BallerinaParser.RULE_throwStatement:
            return new ThrowStatementNode(node);
        case BallerinaParser.RULE_transformerDefinition:
            return new TransformerDefinitionNode(node);
        case BallerinaParser.RULE_workerReply:
            return new WorkerReplyNode(node);
        case BallerinaParser.RULE_triggerWorker:
            return new TriggerWorkerNode(node);
        case BallerinaParser.RULE_workerDeclaration:
            return new WorkerDeclarationNode(node);
        case BallerinaParser.RULE_workerBody:
            return new WorkerBodyNode(node);
        case BallerinaParser.RULE_joinConditions:
            return new JoinConditionNode(node);
        case BallerinaParser.RULE_field:
            return new FieldNode(node);
        case BallerinaParser.RULE_recordKey:
            return new RecordKeyNode(node);
        case BallerinaParser.RULE_recordValue:
            return new RecordValueNode(node);
        case BallerinaParser.RULE_functionReference:
            return new FunctionReferenceNode(node);
        case BallerinaParser.RULE_codeBlockBody:
            return new CodeBlockBodyNode(node);
        case BallerinaParser.RULE_nonEmptyCodeBlockBody:
            return new NonEmptyCodeBlockBodyNode(node);
        case BallerinaParser.RULE_tryCatchStatement:
            return new TryCatchStatementNode(node);
        case BallerinaParser.RULE_catchClause:
            return new CatchClauseNode(node);
        case BallerinaParser.RULE_codeBlockParameter:
            return new CodeBlockParameterNode(node);
        case BallerinaParser.RULE_foreachStatement:
            return new ForEachStatementNode(node);
        case BallerinaParser.RULE_joinClause:
            return new JoinClauseNode(node);
        case BallerinaParser.RULE_timeoutClause:
            return new TimeoutClauseNode(node);
        case BallerinaParser.RULE_xmlAttrib:
            return new XmlAttribNode(node);
        case BallerinaParser.RULE_namespaceDeclaration:
            return new NamespaceDeclarationNode(node);
        case BallerinaParser.RULE_stringTemplateLiteral:
            return new StringTemplateLiteralNode(node);
        case BallerinaParser.RULE_stringTemplateContent:
            return new StringTemplateContentNode(node);
        case BallerinaParser.RULE_typeConversion:
            return new TypeConversionNode(node);
        case BallerinaParser.RULE_xmlContent:
            return new XmlContentNode(node);
        case BallerinaParser.RULE_invocation:
            return new InvocationNode(node);
        case BallerinaParser.RULE_enumDefinition:
            return new EnumDefinitionNode(node);
        case BallerinaParser.RULE_enumField:
            return new EnumFieldNode(node);
        case BallerinaParser.RULE_builtInReferenceTypeName:
            return new BuiltInReferenceTypeNameNode(node);
        case BallerinaParser.RULE_referenceTypeName:
            return new ReferenceTypeNameNode(node);
        case BallerinaParser.RULE_functionTypeName:
            return new FunctionTypeNameNode(node);
        case BallerinaParser.RULE_lambdaFunction:
            return new LambdaFunctionNode(node);
        case BallerinaParser.RULE_endpointDeclaration:
            return new EndpointDeclarationNode(node);
        case BallerinaParser.RULE_anonStructTypeName:
            return new AnonStructTypeNameNode(node);
        case BallerinaParser.RULE_userDefineTypeName:
            return new UserDefinedTypeName(node);
        case BallerinaParser.RULE_anyIdentifierName:
            return new AnyIdentifierNameNode(node);
        case BallerinaParser.RULE_documentationAttachment:
            return new DocumentationAttachmentNode(node);
        case BallerinaParser.RULE_documentationTemplateInlineCode:
            return new DocumentationTemplateInlineCodeNode(node);
        case BallerinaParser.RULE_singleBackTickDocInlineCode:
            return new SingleBackTickDocInlineCodeNode(node);
        case BallerinaParser.RULE_doubleBackTickDocInlineCode:
            return new DoubleBackTickInlineCodeNode(node);
        case BallerinaParser.RULE_tripleBackTickDocInlineCode:
            return new TripleBackTickInlineCodeNode(node);
        case BallerinaParser.RULE_deprecatedAttachment:
            return new DeprecatedAttachmentNode(node);
        case BallerinaParser.RULE_deprecatedText:
            return new DeprecatedTextNode(node);
        case BallerinaParser.RULE_singleBackTickDeprecatedInlineCode:
            return new SingleBackTickDeprecatedInlineCodeNode(node);
        case BallerinaParser.RULE_doubleBackTickDeprecatedInlineCode:
            return new DoubleBackTickDeprecatedInlineCodeNode(node);
        case BallerinaParser.RULE_tripleBackTickDeprecatedInlineCode:
            return new TripleBackTickDeprecatedInlineCodeNode(node);
        case BallerinaParser.RULE_documentationTemplateAttributeDescription:
            return new DocumentationTemplateAttributeDescriptionNode(node);
        case BallerinaParser.RULE_formalParameterList:
            return new FormalParameterListNode(node);
        case BallerinaParser.RULE_integerLiteral:
            return new IntegerLiteralNode(node);
        case BallerinaParser.RULE_matchPatternClause:
            return new MatchPatternClauseNode(node);
        default:
            return new ANTLRPsiNode(node);
    }
}
Also used : RecordKeyValueNode(org.ballerinalang.plugins.idea.psi.RecordKeyValueNode) ReturnStatementNode(org.ballerinalang.plugins.idea.psi.ReturnStatementNode) TransformerDefinitionNode(org.ballerinalang.plugins.idea.psi.TransformerDefinitionNode) TimeoutClauseNode(org.ballerinalang.plugins.idea.psi.TimeoutClauseNode) FunctionTypeNameNode(org.ballerinalang.plugins.idea.psi.FunctionTypeNameNode) ConstantDefinitionNode(org.ballerinalang.plugins.idea.psi.ConstantDefinitionNode) BuiltInReferenceTypeNameNode(org.ballerinalang.plugins.idea.psi.BuiltInReferenceTypeNameNode) JoinConditionNode(org.ballerinalang.plugins.idea.psi.JoinConditionNode) AttachmentPointNode(org.ballerinalang.plugins.idea.psi.AttachmentPointNode) ThrowStatementNode(org.ballerinalang.plugins.idea.psi.ThrowStatementNode) ConnectorInitNode(org.ballerinalang.plugins.idea.psi.ConnectorInitNode) CatchClauseNode(org.ballerinalang.plugins.idea.psi.CatchClauseNode) SingleBackTickDeprecatedInlineCodeNode(org.ballerinalang.plugins.idea.psi.SingleBackTickDeprecatedInlineCodeNode) VariableReferenceNode(org.ballerinalang.plugins.idea.psi.VariableReferenceNode) XmlContentNode(org.ballerinalang.plugins.idea.psi.XmlContentNode) MatchPatternClauseNode(org.ballerinalang.plugins.idea.psi.MatchPatternClauseNode) GlobalVariableDefinitionNode(org.ballerinalang.plugins.idea.psi.GlobalVariableDefinitionNode) VariableDefinitionNode(org.ballerinalang.plugins.idea.psi.VariableDefinitionNode) DocumentationAttachmentNode(org.ballerinalang.plugins.idea.psi.DocumentationAttachmentNode) ForkJoinStatementNode(org.ballerinalang.plugins.idea.psi.ForkJoinStatementNode) ForEachStatementNode(org.ballerinalang.plugins.idea.psi.ForEachStatementNode) FunctionDefinitionNode(org.ballerinalang.plugins.idea.psi.FunctionDefinitionNode) RecordLiteralNode(org.ballerinalang.plugins.idea.psi.RecordLiteralNode) IntegerLiteralNode(org.ballerinalang.plugins.idea.psi.IntegerLiteralNode) ReferenceTypeNameNode(org.ballerinalang.plugins.idea.psi.ReferenceTypeNameNode) BuiltInReferenceTypeNameNode(org.ballerinalang.plugins.idea.psi.BuiltInReferenceTypeNameNode) TokenIElementType(org.antlr.jetbrains.adaptor.lexer.TokenIElementType) ServiceBodyNode(org.ballerinalang.plugins.idea.psi.ServiceBodyNode) ReturnParameterNode(org.ballerinalang.plugins.idea.psi.ReturnParameterNode) AliasNode(org.ballerinalang.plugins.idea.psi.AliasNode) TriggerWorkerNode(org.ballerinalang.plugins.idea.psi.TriggerWorkerNode) ExpressionListNode(org.ballerinalang.plugins.idea.psi.ExpressionListNode) WorkerDeclarationNode(org.ballerinalang.plugins.idea.psi.WorkerDeclarationNode) AssignmentStatementNode(org.ballerinalang.plugins.idea.psi.AssignmentStatementNode) FieldNode(org.ballerinalang.plugins.idea.psi.FieldNode) EnumFieldNode(org.ballerinalang.plugins.idea.psi.EnumFieldNode) SimpleLiteralNode(org.ballerinalang.plugins.idea.psi.SimpleLiteralNode) ThrowStatementNode(org.ballerinalang.plugins.idea.psi.ThrowStatementNode) ForEachStatementNode(org.ballerinalang.plugins.idea.psi.ForEachStatementNode) StatementNode(org.ballerinalang.plugins.idea.psi.StatementNode) AssignmentStatementNode(org.ballerinalang.plugins.idea.psi.AssignmentStatementNode) IfElseStatementNode(org.ballerinalang.plugins.idea.psi.IfElseStatementNode) ForkJoinStatementNode(org.ballerinalang.plugins.idea.psi.ForkJoinStatementNode) ReturnStatementNode(org.ballerinalang.plugins.idea.psi.ReturnStatementNode) TryCatchStatementNode(org.ballerinalang.plugins.idea.psi.TryCatchStatementNode) WorkerBodyNode(org.ballerinalang.plugins.idea.psi.WorkerBodyNode) TryCatchStatementNode(org.ballerinalang.plugins.idea.psi.TryCatchStatementNode) TripleBackTickInlineCodeNode(org.ballerinalang.plugins.idea.psi.TripleBackTickInlineCodeNode) FunctionInvocationNode(org.ballerinalang.plugins.idea.psi.FunctionInvocationNode) InvocationNode(org.ballerinalang.plugins.idea.psi.InvocationNode) DeprecatedAttachmentNode(org.ballerinalang.plugins.idea.psi.DeprecatedAttachmentNode) RecordKeyNode(org.ballerinalang.plugins.idea.psi.RecordKeyNode) ResourceDefinitionNode(org.ballerinalang.plugins.idea.psi.ResourceDefinitionNode) EnumFieldNode(org.ballerinalang.plugins.idea.psi.EnumFieldNode) PackageNameNode(org.ballerinalang.plugins.idea.psi.PackageNameNode) FullyQualifiedPackageNameNode(org.ballerinalang.plugins.idea.psi.FullyQualifiedPackageNameNode) StructDefinitionNode(org.ballerinalang.plugins.idea.psi.StructDefinitionNode) DocumentationTemplateAttributeDescriptionNode(org.ballerinalang.plugins.idea.psi.DocumentationTemplateAttributeDescriptionNode) ParameterTypeNameList(org.ballerinalang.plugins.idea.psi.ParameterTypeNameList) FunctionTypeNameNode(org.ballerinalang.plugins.idea.psi.FunctionTypeNameNode) TypeNameNode(org.ballerinalang.plugins.idea.psi.TypeNameNode) ReferenceTypeNameNode(org.ballerinalang.plugins.idea.psi.ReferenceTypeNameNode) BuiltInReferenceTypeNameNode(org.ballerinalang.plugins.idea.psi.BuiltInReferenceTypeNameNode) ValueTypeNameNode(org.ballerinalang.plugins.idea.psi.ValueTypeNameNode) AnonStructTypeNameNode(org.ballerinalang.plugins.idea.psi.AnonStructTypeNameNode) SingleBackTickDocInlineCodeNode(org.ballerinalang.plugins.idea.psi.SingleBackTickDocInlineCodeNode) CallableUnitBodyNode(org.ballerinalang.plugins.idea.psi.CallableUnitBodyNode) NonEmptyCodeBlockBodyNode(org.ballerinalang.plugins.idea.psi.NonEmptyCodeBlockBodyNode) EnumDefinitionNode(org.ballerinalang.plugins.idea.psi.EnumDefinitionNode) GlobalVariableDefinitionNode(org.ballerinalang.plugins.idea.psi.GlobalVariableDefinitionNode) LambdaFunctionNode(org.ballerinalang.plugins.idea.psi.LambdaFunctionNode) ImportDeclarationNode(org.ballerinalang.plugins.idea.psi.ImportDeclarationNode) NonEmptyCodeBlockBodyNode(org.ballerinalang.plugins.idea.psi.NonEmptyCodeBlockBodyNode) CodeBlockBodyNode(org.ballerinalang.plugins.idea.psi.CodeBlockBodyNode) StringTemplateLiteralNode(org.ballerinalang.plugins.idea.psi.StringTemplateLiteralNode) VariableReferenceListNode(org.ballerinalang.plugins.idea.psi.VariableReferenceListNode) CompilationUnitNode(org.ballerinalang.plugins.idea.psi.CompilationUnitNode) AnonStructTypeNameNode(org.ballerinalang.plugins.idea.psi.AnonStructTypeNameNode) DocumentationTemplateInlineCodeNode(org.ballerinalang.plugins.idea.psi.DocumentationTemplateInlineCodeNode) DoubleBackTickInlineCodeNode(org.ballerinalang.plugins.idea.psi.DoubleBackTickInlineCodeNode) StringTemplateContentNode(org.ballerinalang.plugins.idea.psi.StringTemplateContentNode) UserDefinedTypeName(org.ballerinalang.plugins.idea.psi.UserDefinedTypeName) ReturnParameterNode(org.ballerinalang.plugins.idea.psi.ReturnParameterNode) ParameterNode(org.ballerinalang.plugins.idea.psi.ParameterNode) CodeBlockParameterNode(org.ballerinalang.plugins.idea.psi.CodeBlockParameterNode) XmlAttribNode(org.ballerinalang.plugins.idea.psi.XmlAttribNode) EndpointDeclarationNode(org.ballerinalang.plugins.idea.psi.EndpointDeclarationNode) WorkerReplyNode(org.ballerinalang.plugins.idea.psi.WorkerReplyNode) JoinClauseNode(org.ballerinalang.plugins.idea.psi.JoinClauseNode) AnnotationAttachmentNode(org.ballerinalang.plugins.idea.psi.AnnotationAttachmentNode) DeprecatedTextNode(org.ballerinalang.plugins.idea.psi.DeprecatedTextNode) AnyIdentifierNameNode(org.ballerinalang.plugins.idea.psi.AnyIdentifierNameNode) RuleIElementType(org.antlr.jetbrains.adaptor.lexer.RuleIElementType) ANTLRPsiNode(org.antlr.jetbrains.adaptor.psi.ANTLRPsiNode) RecordValueNode(org.ballerinalang.plugins.idea.psi.RecordValueNode) PackageDeclarationNode(org.ballerinalang.plugins.idea.psi.PackageDeclarationNode) IfElseStatementNode(org.ballerinalang.plugins.idea.psi.IfElseStatementNode) IElementType(com.intellij.psi.tree.IElementType) RuleIElementType(org.antlr.jetbrains.adaptor.lexer.RuleIElementType) TokenIElementType(org.antlr.jetbrains.adaptor.lexer.TokenIElementType) FormalParameterListNode(org.ballerinalang.plugins.idea.psi.FormalParameterListNode) ParameterListNode(org.ballerinalang.plugins.idea.psi.ParameterListNode) ConstantDefinitionNode(org.ballerinalang.plugins.idea.psi.ConstantDefinitionNode) GlobalVariableDefinitionNode(org.ballerinalang.plugins.idea.psi.GlobalVariableDefinitionNode) TransformerDefinitionNode(org.ballerinalang.plugins.idea.psi.TransformerDefinitionNode) EnumDefinitionNode(org.ballerinalang.plugins.idea.psi.EnumDefinitionNode) 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) ServiceDefinitionNode(org.ballerinalang.plugins.idea.psi.ServiceDefinitionNode) StructDefinitionNode(org.ballerinalang.plugins.idea.psi.StructDefinitionNode) DefinitionNode(org.ballerinalang.plugins.idea.psi.DefinitionNode) FullyQualifiedPackageNameNode(org.ballerinalang.plugins.idea.psi.FullyQualifiedPackageNameNode) ServiceDefinitionNode(org.ballerinalang.plugins.idea.psi.ServiceDefinitionNode) NamespaceDeclarationNode(org.ballerinalang.plugins.idea.psi.NamespaceDeclarationNode) ExpressionNode(org.ballerinalang.plugins.idea.psi.ExpressionNode) DoubleBackTickDeprecatedInlineCodeNode(org.ballerinalang.plugins.idea.psi.DoubleBackTickDeprecatedInlineCodeNode) TripleBackTickDeprecatedInlineCodeNode(org.ballerinalang.plugins.idea.psi.TripleBackTickDeprecatedInlineCodeNode) TypeConversionNode(org.ballerinalang.plugins.idea.psi.TypeConversionNode) FunctionReferenceNode(org.ballerinalang.plugins.idea.psi.FunctionReferenceNode) FieldDefinitionNode(org.ballerinalang.plugins.idea.psi.FieldDefinitionNode) AnnotationAttributeValueNode(org.ballerinalang.plugins.idea.psi.AnnotationAttributeValueNode) StructBodyNode(org.ballerinalang.plugins.idea.psi.StructBodyNode) ValueTypeNameNode(org.ballerinalang.plugins.idea.psi.ValueTypeNameNode) NameReferenceNode(org.ballerinalang.plugins.idea.psi.NameReferenceNode) FunctionInvocationNode(org.ballerinalang.plugins.idea.psi.FunctionInvocationNode) CodeBlockParameterNode(org.ballerinalang.plugins.idea.psi.CodeBlockParameterNode) FormalParameterListNode(org.ballerinalang.plugins.idea.psi.FormalParameterListNode) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ServiceDefinitionNode

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

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

the class BallerinaFoldingBuilder method buildServiceFoldingRegions.

private void buildServiceFoldingRegions(@NotNull List<FoldingDescriptor> descriptors, @NotNull PsiElement root) {
    // Get all services.
    Collection<ServiceDefinitionNode> serviceDefinitionNodes = PsiTreeUtil.findChildrenOfType(root, ServiceDefinitionNode.class);
    for (ServiceDefinitionNode serviceDefinitionNode : serviceDefinitionNodes) {
        // Get the service body. This is used to calculate the start offset.
        ServiceBodyNode serviceBodyNode = PsiTreeUtil.getChildOfType(serviceDefinitionNode, ServiceBodyNode.class);
        if (serviceBodyNode == null) {
            continue;
        }
        // Add folding descriptor.
        addFoldingDescriptor(descriptors, serviceDefinitionNode, serviceBodyNode);
        // We need to add folding support to resources as well. So get all resources in the service.
        Collection<ResourceDefinitionNode> resourceDefinitionNodes = PsiTreeUtil.findChildrenOfType(root, ResourceDefinitionNode.class);
        for (ResourceDefinitionNode resourceDefinitionNode : resourceDefinitionNodes) {
            // Get the resource body. This is used to calculate the start offset.
            CallableUnitBodyNode callableUnitBodyNode = PsiTreeUtil.getChildOfType(resourceDefinitionNode, CallableUnitBodyNode.class);
            if (callableUnitBodyNode == null) {
                continue;
            }
            // Add folding descriptor.
            addFoldingDescriptor(descriptors, resourceDefinitionNode, callableUnitBodyNode);
        }
    }
}
Also used : ServiceDefinitionNode(org.ballerinalang.plugins.idea.psi.ServiceDefinitionNode) ResourceDefinitionNode(org.ballerinalang.plugins.idea.psi.ResourceDefinitionNode) CallableUnitBodyNode(org.ballerinalang.plugins.idea.psi.CallableUnitBodyNode) ServiceBodyNode(org.ballerinalang.plugins.idea.psi.ServiceBodyNode)

Aggregations

ServiceDefinitionNode (org.ballerinalang.plugins.idea.psi.ServiceDefinitionNode)5 FunctionDefinitionNode (org.ballerinalang.plugins.idea.psi.FunctionDefinitionNode)4 ResourceDefinitionNode (org.ballerinalang.plugins.idea.psi.ResourceDefinitionNode)4 PsiElement (com.intellij.psi.PsiElement)3 PackageDeclarationNode (org.ballerinalang.plugins.idea.psi.PackageDeclarationNode)3 IElementType (com.intellij.psi.tree.IElementType)2 ANTLRPsiNode (org.antlr.jetbrains.adaptor.psi.ANTLRPsiNode)2 AnnotationAttachmentNode (org.ballerinalang.plugins.idea.psi.AnnotationAttachmentNode)2 AnnotationDefinitionNode (org.ballerinalang.plugins.idea.psi.AnnotationDefinitionNode)2 CallableUnitBodyNode (org.ballerinalang.plugins.idea.psi.CallableUnitBodyNode)2 ConnectorDefinitionNode (org.ballerinalang.plugins.idea.psi.ConnectorDefinitionNode)2 FullyQualifiedPackageNameNode (org.ballerinalang.plugins.idea.psi.FullyQualifiedPackageNameNode)2 ServiceBodyNode (org.ballerinalang.plugins.idea.psi.ServiceBodyNode)2 StructDefinitionNode (org.ballerinalang.plugins.idea.psi.StructDefinitionNode)2 WorkerDeclarationNode (org.ballerinalang.plugins.idea.psi.WorkerDeclarationNode)2 NotNull (org.jetbrains.annotations.NotNull)2 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)1 SortableTreeElement (com.intellij.ide.util.treeView.smartTree.SortableTreeElement)1