use of org.wso2.ballerinalang.compiler.tree.BLangDocumentation in project ballerina by ballerina-lang.
the class DocumentationTest method testDocStruct.
@Test(description = "Test doc struct.")
public void testDocStruct() {
CompileResult compileResult = BCompileUtil.compile("test-src/documentation/struct.bal");
Assert.assertEquals(0, compileResult.getWarnCount());
PackageNode packageNode = compileResult.getAST();
List<BLangDocumentation> docNodes = ((BLangStruct) packageNode.getStructs().get(0)).docAttachments;
BLangDocumentation dNode = docNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, " Documentation for Test struct\n");
Assert.assertEquals(dNode.getAttributes().size(), 3);
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "a");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " struct `field a` documentation\n");
Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "b");
Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " struct `field b` documentation\n");
Assert.assertEquals(dNode.getAttributes().get(2).documentationField.getValue(), "c");
Assert.assertEquals(dNode.getAttributes().get(2).documentationText, " struct `field c` documentation");
}
use of org.wso2.ballerinalang.compiler.tree.BLangDocumentation in project ballerina by ballerina-lang.
the class DocumentationTest method testNestedInline.
@Test(description = "Test doc nested inline.")
public void testNestedInline() {
CompileResult compileResult = BCompileUtil.compile("test-src/documentation/nested_inline.bal");
Assert.assertEquals(0, compileResult.getWarnCount());
PackageNode packageNode = compileResult.getAST();
BLangVariable constant = (BLangVariable) packageNode.getGlobalVariables().get(0);
List<BLangDocumentation> docNodes = constant.docAttachments;
BLangDocumentation dNode = docNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.getAttributes().size(), 0);
Assert.assertEquals(dNode.documentationText, "\n" + " Example of a string template:\n" + " ``` This starts ends triple backtick ``string s = string `hello {{name}}`;`` " + "ends triple backtick```\n" + "\n" + " Example for an xml literal:\n" + " ``xml x = xml `<{{tagName}}>hello</{{tagName}}>`;``\n");
}
use of org.wso2.ballerinalang.compiler.tree.BLangDocumentation in project ballerina by ballerina-lang.
the class DocumentationTest method testDocService.
@Test(description = "Test doc service.", enabled = false)
public void testDocService() {
CompileResult compileResult = BCompileUtil.compile("test-src/documentation/service.bal");
Assert.assertEquals(0, compileResult.getWarnCount());
PackageNode packageNode = compileResult.getAST();
BLangService service = (BLangService) packageNode.getServices().get(0);
List<BLangDocumentation> docNodes = service.docAttachments;
BLangDocumentation dNode = docNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "PizzaService HTTP Service");
dNode = service.getResources().get(0).docAttachments.get(0);
Assert.assertEquals(dNode.getAttributes().size(), 2);
Assert.assertEquals(dNode.documentationText, "Check orderPizza resource. ");
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "conn");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " HTTP connection. ");
Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "req");
Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " In request.");
dNode = service.getResources().get(1).docAttachments.get(0);
Assert.assertEquals(dNode.documentationText, "Check status resource. ");
Assert.assertEquals(dNode.getAttributes().size(), 2);
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "conn");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " HTTP connection. ");
Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "req");
Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " In request.");
}
use of org.wso2.ballerinalang.compiler.tree.BLangDocumentation in project ballerina by ballerina-lang.
the class SignatureHelpUtil method getSignatureInfoModel.
/**
* Get the required signature information filled model.
*
* @param bInvokableSymbol Invokable symbol
* @param signatureContext Signature operation context
* @return {@link SignatureInfoModel} SignatureInfoModel containing signature information
*/
private static SignatureInfoModel getSignatureInfoModel(BInvokableSymbol bInvokableSymbol, TextDocumentServiceContext signatureContext) {
Map<String, String> paramDescMap = new HashMap<>();
SignatureInfoModel signatureInfoModel = new SignatureInfoModel();
List<ParameterInfoModel> paramModels = new ArrayList<>();
String functionName = signatureContext.get(SignatureKeys.CALLABLE_ITEM_NAME);
CompilerContext compilerContext = signatureContext.get(DocumentServiceKeys.COMPILER_CONTEXT_KEY);
BLangPackage bLangPackage = signatureContext.get(DocumentServiceKeys.LS_PACKAGE_CACHE_KEY).findPackage(compilerContext, bInvokableSymbol.pkgID);
BLangFunction blangFunction = bLangPackage.getFunctions().stream().filter(bLangFunction -> bLangFunction.getName().getValue().equals(functionName)).findFirst().orElse(null);
if (!blangFunction.getDocumentationAttachments().isEmpty()) {
// Get the first documentation attachment
BLangDocumentation bLangDocumentation = blangFunction.getDocumentationAttachments().get(0);
signatureInfoModel.setSignatureDescription(bLangDocumentation.documentationText.trim());
bLangDocumentation.attributes.forEach(attribute -> {
if (attribute.docTag.equals(DocTag.PARAM)) {
paramDescMap.put(attribute.documentationField.getValue(), attribute.documentationText.trim());
}
});
} else {
// TODO: Should be deprecated in due course
// Iterate over the attachments list and extract the attachment Description Map
blangFunction.getAnnotationAttachments().forEach(annotationAttachment -> {
BLangExpression expr = annotationAttachment.expr;
if (expr instanceof BLangRecordLiteral) {
List<BLangRecordLiteral.BLangRecordKeyValue> recordKeyValues = ((BLangRecordLiteral) expr).keyValuePairs;
for (BLangRecordLiteral.BLangRecordKeyValue recordKeyValue : recordKeyValues) {
BLangExpression key = recordKeyValue.key.expr;
BLangExpression value = recordKeyValue.getValue();
if (key instanceof BLangSimpleVarRef && ((BLangSimpleVarRef) key).getVariableName().getValue().equals("value") && value instanceof BLangLiteral) {
String annotationValue = ((BLangLiteral) value).getValue().toString();
if (annotationAttachment.getAnnotationName().getValue().equals("Param")) {
String paramName = annotationValue.substring(0, annotationValue.indexOf(UtilSymbolKeys.PKG_DELIMITER_KEYWORD));
String annotationDesc = annotationValue.substring(annotationValue.indexOf(UtilSymbolKeys.PKG_DELIMITER_KEYWORD) + 1).trim();
paramDescMap.put(paramName, annotationDesc);
} else if (annotationAttachment.getAnnotationName().getValue().equals("Description")) {
signatureInfoModel.setSignatureDescription(annotationValue);
}
}
}
}
});
}
bInvokableSymbol.getParameters().forEach(bVarSymbol -> {
ParameterInfoModel parameterInfoModel = new ParameterInfoModel();
parameterInfoModel.setParamType(bVarSymbol.getType().toString());
parameterInfoModel.setParamValue(bVarSymbol.getName().getValue());
parameterInfoModel.setDescription(paramDescMap.get(bVarSymbol.getName().getValue()));
paramModels.add(parameterInfoModel);
});
signatureInfoModel.setParameterInfoModels(paramModels);
return signatureInfoModel;
}
use of org.wso2.ballerinalang.compiler.tree.BLangDocumentation in project ballerina by ballerina-lang.
the class BLangPackageBuilder method startDocumentationAttachment.
public void startDocumentationAttachment(DiagnosticPos currentPos) {
BLangDocumentation docAttachmentNode = (BLangDocumentation) TreeBuilder.createDocumentationNode();
docAttachmentNode.pos = currentPos;
docAttachmentStack.push(docAttachmentNode);
}
Aggregations