use of org.wso2.ballerinalang.compiler.tree.BLangTransformer in project ballerina by ballerina-lang.
the class DocumentationTest method testDeprecatedTransformer.
@Test(description = "Test doc deprecated Transformer.")
public void testDeprecatedTransformer() {
CompileResult compileResult = BCompileUtil.compile("test-src/documentation/deprecated_transformer.bal");
Assert.assertEquals(0, compileResult.getWarnCount());
PackageNode packageNode = compileResult.getAST();
List<BLangDeprecatedNode> dNodes = ((BLangTransformer) packageNode.getTransformers().get(0)).deprecatedAttachments;
BLangDeprecatedNode dNode = dNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + " This Transformer is deprecated use\n" + " `transformer <Person p, Employee e> Bar(any defaultAddress) { e.name = p.firstName; }\n" + " ` instead.\n");
List<BLangDocumentation> docNodes = ((BLangTransformer) packageNode.getTransformers().get(0)).docAttachments;
BLangDocumentation docNode = docNodes.get(0);
Assert.assertNotNull(docNode);
Assert.assertEquals(docNode.documentationText, "\n Transformer Foo Person -> Employee\n ");
Assert.assertEquals(docNode.getAttributes().size(), 3);
Assert.assertEquals(docNode.getAttributes().get(0).documentationField.getValue(), "p");
Assert.assertEquals(docNode.getAttributes().get(0).documentationText, " input struct Person source used for transformation\n ");
Assert.assertEquals(docNode.getAttributes().get(1).documentationField.getValue(), "e");
Assert.assertEquals(docNode.getAttributes().get(1).documentationText, " output struct Employee struct which Person transformed to\n ");
Assert.assertEquals(docNode.getAttributes().get(2).documentationField.getValue(), "defaultAddress");
Assert.assertEquals(docNode.getAttributes().get(2).documentationText, " address which serves Eg: `POSTCODE 112`\n");
}
use of org.wso2.ballerinalang.compiler.tree.BLangTransformer in project ballerina by ballerina-lang.
the class DocumentationTest method testMultiple.
@Test(description = "Test doc multiple.")
public void testMultiple() {
CompileResult compileResult = BCompileUtil.compile("test-src/documentation/multiple.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 Tst struct\n");
Assert.assertEquals(dNode.getAttributes().size(), 3);
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "a");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " annotation `field a` documentation\n");
Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "b");
Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " annotation `field b` documentation\n");
Assert.assertEquals(dNode.getAttributes().get(2).documentationField.getValue(), "c");
Assert.assertEquals(dNode.getAttributes().get(2).documentationText, " annotation `field c` documentation");
docNodes = ((BLangEnum) packageNode.getEnums().get(0)).docAttachments;
dNode = docNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, " Documentation for state enum\n");
Assert.assertEquals(dNode.getAttributes().size(), 2);
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "foo");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " enum `field foo` documentation\n");
Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "bar");
Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " enum `field bar` documentation");
docNodes = ((BLangTransformer) packageNode.getTransformers().get(0)).docAttachments;
dNode = docNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + " Transformer Foo Person -> Employee\n" + " ");
Assert.assertEquals(dNode.getAttributes().size(), 3);
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "p");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " input struct Person source used for transformation\n ");
Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "e");
Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " output struct Employee struct which Person transformed to\n ");
Assert.assertEquals(dNode.getAttributes().get(2).documentationField.getValue(), "defaultAddress");
Assert.assertEquals(dNode.getAttributes().get(2).documentationText, " address which serves Eg: `POSTCODE 112`\n");
BLangService service = (BLangService) packageNode.getServices().get(0);
docNodes = service.docAttachments;
dNode = docNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "PizzaService HTTP Service");
/*
// Commented due to https://github.com/ballerina-lang/ballerina/issues/5586 issue
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.BLangTransformer in project ballerina by ballerina-lang.
the class CommandUtil method getTransformerDocumentationByPosition.
/**
* Get the Documentation attachment for the transformer.
* @param bLangPackage BLangPackage built
* @param line Start line of the transformer in the source
* @return {@link String} Documentation attachment for the transformer
*/
static DocAttachmentInfo getTransformerDocumentationByPosition(BLangPackage bLangPackage, int line) {
for (TopLevelNode topLevelNode : bLangPackage.topLevelNodes) {
if (topLevelNode instanceof BLangTransformer) {
BLangTransformer transformerNode = (BLangTransformer) topLevelNode;
DiagnosticPos transformerPos = CommonUtil.toZeroBasedPosition(transformerNode.getPosition());
int transformerStart = transformerPos.getStartLine();
if (transformerStart == line) {
return getTransformerNodeDocumentation(transformerNode, line);
}
}
}
return null;
}
use of org.wso2.ballerinalang.compiler.tree.BLangTransformer in project ballerina by ballerina-lang.
the class CommandUtil method getTransformerNodeDocumentation.
static DocAttachmentInfo getTransformerNodeDocumentation(BLangTransformer bLangTransformer, int replaceFrom) {
List<String> attributes = new ArrayList<>();
DiagnosticPos transformerPos = CommonUtil.toZeroBasedPosition(bLangTransformer.getPosition());
int offset = transformerPos.getStartColumn();
attributes.add(getDocAttributeFromBLangVariable(bLangTransformer.source, offset));
bLangTransformer.retParams.forEach(bLangVariable -> attributes.add(getDocAttributeFromBLangVariable(bLangVariable, offset)));
bLangTransformer.requiredParams.forEach(bLangVariable -> attributes.add(getDocAttributeFromBLangVariable(bLangVariable, offset)));
return new DocAttachmentInfo(getDocumentationAttachment(attributes, transformerPos.getStartColumn()), replaceFrom);
}
Aggregations