Search in sources :

Example 16 with BLangAction

use of org.wso2.ballerinalang.compiler.tree.BLangAction in project ballerina by ballerina-lang.

the class ConnectorContextItemSorter method sortItems.

@Override
public void sortItems(TextDocumentServiceContext ctx, List<CompletionItem> completionItems) {
    BLangNode previousNode = ctx.get(CompletionKeys.PREVIOUS_NODE_KEY);
    /*
        Remove the statement type completion type. When the going through the parser
        rule contexts such as typeNameContext, we add the statements as well.
        Sorters are responsible for to the next level of such filtering.
         */
    this.removeCompletionsByType(new ArrayList<>(Collections.singletonList(ItemResolverConstants.STATEMENT_TYPE)), completionItems);
    if (previousNode == null) {
        this.populateWhenCursorBeforeOrAfterEp(completionItems);
    } else if (previousNode instanceof BLangVariableDef) {
        // BType bLangType = ((BLangVariableDef) previousNode).var.type;
        // if (bLangType instanceof BEndpointType) {
        // this.populateWhenCursorBeforeOrAfterEp(completionItems);
        // } else {
        this.setPriorities(completionItems);
        CompletionItem resItem = this.getActionSnippet();
        resItem.setSortText(Priority.PRIORITY160.toString());
        completionItems.add(resItem);
    // }
    } else if (previousNode instanceof BLangAction) {
        completionItems.clear();
        completionItems.add(this.getActionSnippet());
    }
}
Also used : BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) CompletionItem(org.eclipse.lsp4j.CompletionItem) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction)

Example 17 with BLangAction

use of org.wso2.ballerinalang.compiler.tree.BLangAction in project ballerina by ballerina-lang.

the class Generator method createDocForNode.

/**
 * Create documentation for actions.
 * @param actionNode ballerina action node.
 * @return documentation for actions.
 */
public static ActionDoc createDocForNode(BLangAction actionNode) {
    String actionName = actionNode.getName().value;
    List<Variable> parameters = new ArrayList<>();
    List<Variable> returnParams = new ArrayList<>();
    // Iterate through the parameters
    if (actionNode.getParameters().size() > 0) {
        for (BLangVariable param : actionNode.getParameters()) {
            String dataType = type(param);
            String desc = paramAnnotation(actionNode, param);
            Variable variable = new Variable(param.getName().value, dataType, desc);
            parameters.add(variable);
        }
    }
    // Iterate through the return types
    if (actionNode.getReturnParameters().size() > 0) {
        for (int i = 0; i < actionNode.getReturnParameters().size(); i++) {
            BLangVariable returnParam = actionNode.getReturnParameters().get(i);
            String dataType = type(returnParam);
            String desc = returnParamAnnotation(actionNode, i);
            Variable variable = new Variable(returnParam.getName().value, dataType, desc);
            returnParams.add(variable);
        }
    }
    return new ActionDoc(actionName, description(actionNode), new ArrayList<>(), parameters, returnParams);
}
Also used : ActionDoc(org.ballerinalang.docgen.model.ActionDoc) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Variable(org.ballerinalang.docgen.model.Variable) ArrayList(java.util.ArrayList) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 18 with BLangAction

use of org.wso2.ballerinalang.compiler.tree.BLangAction in project ballerina by ballerina-lang.

the class BallerinaConnectorDocGenTest method testConnectorWithSingleAction.

@Test(description = "Test single action in a connector file", enabled = false)
public void testConnectorWithSingleAction() {
    try {
        Map<String, BLangPackage> docsMap = BallerinaDocGenerator.generatePackageDocsFromBallerina(sourceRoot, "helloWorldConnector.bal");
        Assert.assertNotNull(docsMap);
        Assert.assertEquals(docsMap.size(), 1);
        BallerinaDocGenTestUtils.printDocMap(docsMap);
        BLangPackage balPackage = docsMap.get(".");
        List<BLangConnector> connectors = balPackage.getConnectors();
        Assert.assertEquals(connectors.size(), 1);
        BLangConnector connectorDoc = (BLangConnector) connectors.iterator().next();
        Assert.assertEquals(connectorDoc.getParameters().size(), 4);
        List<BLangAction> actions = connectorDoc.getActions();
        BLangAction action = actions.get(0);
        Assert.assertEquals(action.getParameters().size(), 1);
        Assert.assertEquals(action.getReturnParameters().size(), 1);
    } catch (IOException e) {
        Assert.fail();
    } finally {
        BallerinaDocGenTestUtils.cleanUp();
    }
}
Also used : BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) IOException(java.io.IOException) BLangConnector(org.wso2.ballerinalang.compiler.tree.BLangConnector) BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction) Test(org.testng.annotations.Test)

Example 19 with BLangAction

use of org.wso2.ballerinalang.compiler.tree.BLangAction in project ballerina by ballerina-lang.

the class BallerinaConnectorDocGenTest method testConnectorWithMultipleAction.

@Test(description = "Test single action in a connector file", enabled = false)
public void testConnectorWithMultipleAction() {
    try {
        Map<String, BLangPackage> docsMap = BallerinaDocGenerator.generatePackageDocsFromBallerina(sourceRoot, "balWith2Actions.bal");
        Assert.assertNotNull(docsMap);
        Assert.assertEquals(docsMap.size(), 1);
        BallerinaDocGenTestUtils.printDocMap(docsMap);
        BLangPackage balPackage = docsMap.get(".");
        List<BLangConnector> connectors = balPackage.getConnectors();
        Assert.assertEquals(connectors.size(), 1);
        BLangConnector connector = connectors.iterator().next();
        Assert.assertEquals(connector.getParameters().size(), 4);
        for (BLangAction action : connector.getActions()) {
            Assert.assertEquals(action.getParameters().size(), 1);
            Assert.assertEquals(action.getReturnParameters().size(), 1);
        }
    } catch (IOException e) {
        Assert.fail();
    } finally {
        BallerinaDocGenTestUtils.cleanUp();
    }
}
Also used : BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) IOException(java.io.IOException) BLangConnector(org.wso2.ballerinalang.compiler.tree.BLangConnector) BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction) Test(org.testng.annotations.Test)

Aggregations

BLangAction (org.wso2.ballerinalang.compiler.tree.BLangAction)11 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)8 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)6 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)6 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)5 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)5 ArrayList (java.util.ArrayList)4 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)4 BInvokableType (org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)4 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)4 List (java.util.List)3 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)3 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Variable (org.ballerinalang.docgen.model.Variable)2 DocumentServiceKeys (org.ballerinalang.langserver.DocumentServiceKeys)2 TextDocumentServiceContext (org.ballerinalang.langserver.TextDocumentServiceContext)2