Search in sources :

Example 6 with BLangStruct

use of org.wso2.ballerinalang.compiler.tree.BLangStruct in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addAnonStructType.

public void addAnonStructType(DiagnosticPos pos, Set<Whitespace> ws) {
    // Generate a name for the anonymous struct
    String genName = anonymousModelHelper.getNextAnonymousStructKey(pos.src.pkgID);
    IdentifierNode anonStructGenName = createIdentifier(genName);
    // Create an anonymous struct and add it to the list of structs in the current package.
    BLangStruct structNode = populateStructNode(pos, ws, anonStructGenName, true);
    this.compUnit.addTopLevelNode(structNode);
    addType(createUserDefinedType(pos, ws, (BLangIdentifier) TreeBuilder.createIdentifierNode(), structNode.name));
}
Also used : IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier)

Example 7 with BLangStruct

use of org.wso2.ballerinalang.compiler.tree.BLangStruct in project ballerina by ballerina-lang.

the class BLangPackageBuilder method populateStructNode.

private BLangStruct populateStructNode(DiagnosticPos pos, Set<Whitespace> ws, IdentifierNode name, boolean isAnonymous) {
    BLangStruct structNode = (BLangStruct) this.structStack.pop();
    structNode.pos = pos;
    structNode.addWS(ws);
    structNode.name = (BLangIdentifier) name;
    structNode.isAnonymous = isAnonymous;
    this.varListStack.pop().forEach(variableNode -> {
        ((BLangVariable) variableNode).docTag = DocTag.FIELD;
        structNode.addField(variableNode);
    });
    return structNode;
}
Also used : BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct)

Example 8 with BLangStruct

use of org.wso2.ballerinalang.compiler.tree.BLangStruct in project ballerina by ballerina-lang.

the class DocumentationTest method testDocAnnotation.

@Test(description = "Test doc annotation.")
public void testDocAnnotation() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/annotation.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 annotation\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 = ((BLangAnnotation) packageNode.getAnnotations().get(0)).docAttachments;
    dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
}
Also used : 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 9 with BLangStruct

use of org.wso2.ballerinalang.compiler.tree.BLangStruct 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");
}
Also used : 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 10 with BLangStruct

use of org.wso2.ballerinalang.compiler.tree.BLangStruct in project ballerina by ballerina-lang.

the class SymbolEnter method visit.

@Override
public void visit(BLangStruct structNode) {
    BSymbol structSymbol = Symbols.createStructSymbol(Flags.asMask(structNode.flagSet), names.fromIdNode(structNode.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
    structNode.symbol = structSymbol;
    // Create struct type
    structNode.symbol.type = new BStructType((BTypeSymbol) structNode.symbol);
    defineSymbol(structNode.pos, structSymbol);
}
Also used : BStructType(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol)

Aggregations

BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)20 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)11 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)10 ArrayList (java.util.ArrayList)7 Test (org.testng.annotations.Test)7 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)7 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)7 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)7 List (java.util.List)6 CompileResult (org.ballerinalang.launcher.util.CompileResult)6 IdentifierNode (org.ballerinalang.model.tree.IdentifierNode)6 PackageNode (org.ballerinalang.model.tree.PackageNode)6 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)6 BLangDocumentation (org.wso2.ballerinalang.compiler.tree.BLangDocumentation)6 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)6 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)6 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)5 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)5