use of org.wso2.ballerinalang.compiler.tree.BLangFunction in project ballerina by ballerina-lang.
the class DocumentationTest method testDocConnectorFunction.
@Test(description = "Test doc connector/function.", enabled = false)
public void testDocConnectorFunction() {
CompileResult compileResult = BCompileUtil.compile("test-src/documentation/connector_function.bal");
Assert.assertEquals(0, compileResult.getWarnCount());
PackageNode packageNode = compileResult.getAST();
BLangConnector connector = (BLangConnector) packageNode.getConnectors().get(0);
List<BLangDocumentation> docNodes = connector.docAttachments;
BLangDocumentation dNode = docNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.getAttributes().size(), 2);
Assert.assertEquals(dNode.documentationText, "Test Connector\n");
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "url");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " url for endpoint\n");
Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "path");
Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " path for endpoint\n");
dNode = connector.getActions().get(0).docAttachments.get(0);
Assert.assertEquals(dNode.getAttributes().size(), 1);
Assert.assertEquals(dNode.documentationText, "Test Connector action testAction ");
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "s");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " which represent successful or not");
dNode = connector.getActions().get(1).docAttachments.get(0);
Assert.assertEquals(dNode.documentationText, "Test Connector action testSend ");
Assert.assertEquals(dNode.getAttributes().size(), 2);
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "ep");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " which represent successful or not ");
Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "s");
Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " which represent successful or not");
docNodes = ((BLangFunction) packageNode.getFunctions().get(0)).docAttachments;
dNode = docNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + "Gets a access parameter value (`true` or `false`) for a given key. " + "Please note that #foo will always be bigger than #bar.\n" + "Example:\n" + "``SymbolEnv pkgEnv = symbolEnter.packageEnvs.get(pkgNode.symbol);``\n");
Assert.assertEquals(dNode.getAttributes().size(), 3);
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "file");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " file path ``C:\\users\\OddThinking\\Documents\\My Source\\Widget\\foo.src``\n");
Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "accessMode");
Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " read or write mode\n");
Assert.assertEquals(dNode.getAttributes().get(2).documentationField.getValue(), "successful");
Assert.assertEquals(dNode.getAttributes().get(2).documentationText, " boolean `true` or `false`\n");
docNodes = ((BLangStruct) packageNode.getStructs().get(0)).docAttachments;
dNode = docNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, " Documentation for File struct\n");
Assert.assertEquals(dNode.getAttributes().size(), 1);
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "path");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " struct `field path` documentation\n");
}
use of org.wso2.ballerinalang.compiler.tree.BLangFunction in project ballerina by ballerina-lang.
the class DocumentationTest method testDeprecated.
@Test(description = "Test doc deprecated.", enabled = false)
public void testDeprecated() {
CompileResult compileResult = BCompileUtil.compile("test-src/documentation/deprecated.bal");
Assert.assertEquals(compileResult.getWarnCount(), 0);
PackageNode packageNode = compileResult.getAST();
List<BLangDeprecatedNode> dNodes = ((BLangFunction) packageNode.getFunctions().get(0)).deprecatedAttachments;
BLangDeprecatedNode dNode = dNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + " This function is deprecated use `openFile(string accessMode){}` instead.\n");
dNodes = ((BLangStruct) packageNode.getStructs().get(0)).deprecatedAttachments;
dNode = dNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + " This Struct is deprecated use `File2` instead.\n");
dNodes = ((BLangEnum) packageNode.getEnums().get(0)).deprecatedAttachments;
dNode = dNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + " This Enum is deprecated use `Enum2` instead.\n");
dNodes = ((BLangEnum) packageNode.getEnums().get(0)).deprecatedAttachments;
dNode = dNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + " This Enum is deprecated use `Enum2` instead.\n");
dNodes = ((BLangVariable) packageNode.getGlobalVariables().get(0)).deprecatedAttachments;
dNode = dNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "use ```const string testConst = " + "\"TestConstantDocumentation\";``` instead");
dNodes = ((BLangConnector) packageNode.getConnectors().get(0)).deprecatedAttachments;
dNode = dNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + " This Connector is deprecated use `Connector(string url2){}` instead.\n");
dNodes = ((BLangConnector) packageNode.getConnectors().get(0)).getActions().get(0).deprecatedAttachments;
dNode = dNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + " This action is deprecated use `Connector.test(string url2){}` instead.\n" + " ");
dNodes = ((BLangService) packageNode.getServices().get(0)).deprecatedAttachments;
dNode = dNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + " This Service is deprecated use `PizzaHutService{}` instead.\n");
dNodes = ((BLangService) packageNode.getServices().get(0)).getResources().get(0).deprecatedAttachments;
dNode = dNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "This Resource is deprecated use `PizzaHutService.orderFromPizza()` instead.");
}
use of org.wso2.ballerinalang.compiler.tree.BLangFunction in project ballerina by ballerina-lang.
the class DocumentationTest method testDocNativeFunction.
@Test(description = "Test doc native function.")
public void testDocNativeFunction() {
CompileResult compileResult = BCompileUtil.compile("test-src/documentation/native_function.bal", CompilerPhase.TYPE_CHECK);
Assert.assertEquals(1, compileResult.getWarnCount());
BAssertUtil.validateWarning(compileResult, 0, "no such documentable attribute 'successful' with doc prefix 'P'", 6, 1);
PackageNode packageNode = compileResult.getAST();
List<BLangDocumentation> docNodes = ((BLangFunction) packageNode.getFunctions().get(0)).docAttachments;
BLangDocumentation dNode = docNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + "Gets a access parameter value (`true` or `false`) for a given key. " + "Please note that #foo will always be bigger than #bar.\n" + "Example:\n" + "``SymbolEnv pkgEnv = symbolEnter.packageEnvs.get(pkgNode.symbol);``\n");
Assert.assertEquals(dNode.getAttributes().size(), 2);
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "accessMode");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " read or write mode\n");
Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "successful");
Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " boolean `true` or `false`\n");
}
use of org.wso2.ballerinalang.compiler.tree.BLangFunction in project ballerina by ballerina-lang.
the class CommandUtil method getFunctionNodeDocumentation.
static DocAttachmentInfo getFunctionNodeDocumentation(FunctionNode bLangFunction, int replaceFrom) {
DiagnosticPos functionPos = CommonUtil.toZeroBasedPosition((DiagnosticPos) bLangFunction.getPosition());
int offset = functionPos.getStartColumn();
List<String> attributes = new ArrayList<>();
if (bLangFunction.getReceiver() != null && bLangFunction.getReceiver() instanceof BLangVariable) {
BLangVariable receiverNode = (BLangVariable) bLangFunction.getReceiver();
attributes.add(getDocumentationAttribute(receiverNode.docTag.getValue(), receiverNode.getName().getValue(), offset));
}
bLangFunction.getParameters().forEach(bLangVariable -> attributes.add(getDocAttributeFromBLangVariable((BLangVariable) bLangVariable, offset)));
bLangFunction.getReturnParameters().forEach(bLangVariable -> {
if (!bLangVariable.getName().getValue().isEmpty()) {
attributes.add(getDocAttributeFromBLangVariable((BLangVariable) bLangVariable, offset));
}
});
return new DocAttachmentInfo(getDocumentationAttachment(attributes, functionPos.getStartColumn()), replaceFrom);
}
use of org.wso2.ballerinalang.compiler.tree.BLangFunction in project ballerina by ballerina-lang.
the class CommandUtil method getFunctionDocumentationByPosition.
/**
* Get the Documentation attachment for the function.
* @param bLangPackage BLangPackage built
* @param line Start line of the function in the source
* @return {@link String} Documentation attachment for the function
*/
static DocAttachmentInfo getFunctionDocumentationByPosition(BLangPackage bLangPackage, int line) {
List<FunctionNode> filteredFunctions = new ArrayList<>();
for (TopLevelNode topLevelNode : bLangPackage.topLevelNodes) {
if (topLevelNode instanceof BLangFunction) {
filteredFunctions.add((BLangFunction) topLevelNode);
} else if (topLevelNode instanceof BLangObject) {
filteredFunctions.addAll(((BLangObject) topLevelNode).getFunctions());
}
for (FunctionNode filteredFunction : filteredFunctions) {
DiagnosticPos functionPos = CommonUtil.toZeroBasedPosition((DiagnosticPos) filteredFunction.getPosition());
int functionStart = functionPos.getStartLine();
if (functionStart == line) {
return getFunctionNodeDocumentation(filteredFunction, line);
}
}
}
return null;
}
Aggregations