Search in sources :

Example 16 with BLangTransformer

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");
}
Also used : BLangTransformer(org.wso2.ballerinalang.compiler.tree.BLangTransformer) BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) CompileResult(org.ballerinalang.launcher.util.CompileResult) BLangDeprecatedNode(org.wso2.ballerinalang.compiler.tree.BLangDeprecatedNode) PackageNode(org.ballerinalang.model.tree.PackageNode) Test(org.testng.annotations.Test)

Example 17 with BLangTransformer

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.");*/
}
Also used : BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) CompileResult(org.ballerinalang.launcher.util.CompileResult) PackageNode(org.ballerinalang.model.tree.PackageNode) Test(org.testng.annotations.Test)

Example 18 with BLangTransformer

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;
}
Also used : BLangTransformer(org.wso2.ballerinalang.compiler.tree.BLangTransformer) DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) TopLevelNode(org.ballerinalang.model.tree.TopLevelNode)

Example 19 with BLangTransformer

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);
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) ArrayList(java.util.ArrayList)

Aggregations

SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)7 BLangTransformer (org.wso2.ballerinalang.compiler.tree.BLangTransformer)6 ArrayList (java.util.ArrayList)4 BLangDocumentation (org.wso2.ballerinalang.compiler.tree.BLangDocumentation)4 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)4 CompileResult (org.ballerinalang.launcher.util.CompileResult)3 PackageNode (org.ballerinalang.model.tree.PackageNode)3 Test (org.testng.annotations.Test)3 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)3 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)2 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)2 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)2 BLangEnum (org.wso2.ballerinalang.compiler.tree.BLangEnum)2 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)2 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)2 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 DocumentServiceKeys (org.ballerinalang.langserver.DocumentServiceKeys)1