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));
}
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;
}
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);
}
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");
}
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);
}
Aggregations