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());
}
}
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);
}
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();
}
}
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();
}
}
Aggregations