use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addVarToStruct.
public void addVarToStruct(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean exprAvailable, int annotCount, boolean isPrivate) {
Set<Whitespace> wsForSemiColon = removeNthFromLast(ws, 0);
BLangStruct structNode = (BLangStruct) this.structStack.peek();
structNode.addWS(wsForSemiColon);
BLangVariable field = addVar(pos, ws, identifier, exprAvailable, annotCount);
if (!isPrivate) {
field.flagSet.add(Flag.PUBLIC);
}
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD in project ballerina by ballerina-lang.
the class TreeVisitor method visit.
public void visit(BLangStruct structNode) {
if (!ScopeResolverConstants.getResolverByClass(cursorPositionResolver).isCursorBeforeNode(structNode.getPosition(), structNode, this, this.documentServiceContext)) {
BSymbol structSymbol = structNode.symbol;
SymbolEnv structEnv = SymbolEnv.createPkgLevelSymbolEnv(structNode, structSymbol.scope, symbolEnv);
if (structNode.fields.isEmpty() && isCursorWithinBlock(structNode.getPosition(), structEnv)) {
symbolEnv = structEnv;
Map<Name, Scope.ScopeEntry> visibleSymbolEntries = this.resolveAllVisibleSymbols(symbolEnv);
this.populateSymbols(visibleSymbolEntries, null);
this.setTerminateVisitor(true);
} else if (!structNode.fields.isEmpty()) {
// Since the struct definition do not have a block statement within, we push null
this.blockStmtStack.push(null);
this.blockOwnerStack.push(structNode);
// Cursor position is calculated against the Block statement scope resolver
this.cursorPositionResolver = BlockStatementScopeResolver.class;
structNode.fields.forEach(field -> acceptNode(field, structEnv));
this.blockStmtStack.pop();
this.blockOwnerStack.pop();
}
}
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD in project ballerina by ballerina-lang.
the class Generator method createDocForNode.
/**
* Create documentation for structs.
* @param structNode ballerina struct node.
* @return documentation for structs.
*/
public static StructDoc createDocForNode(BLangStruct structNode) {
String structName = structNode.getName().value;
// Check if its an anonymous struct
if (structName.contains(ANONYMOUS_STRUCT)) {
structName = "Anonymous Struct";
}
List<Field> fields = new ArrayList<>();
// Iterate through the struct fields
if (structNode.getFields().size() > 0) {
for (BLangVariable param : structNode.getFields()) {
String dataType = type(param);
String desc = fieldAnnotation(structNode, param);
String defaultValue = "";
if (null != param.getInitialExpression()) {
defaultValue = param.getInitialExpression().toString();
}
Field variable = new Field(param.getName().value, dataType, desc, defaultValue);
fields.add(variable);
}
}
return new StructDoc(structName, description(structNode), new ArrayList<>(), fields);
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD in project ballerina by ballerina-lang.
the class HtmlDocTest method testEnumPropertiesExtracted.
@Test(description = "Enum properties should be available via construct")
public void testEnumPropertiesExtracted() throws Exception {
BLangPackage bLangPackage = createPackage("package x.y; " + "@Description { value:\"The direction of the parameter\"}\n" + "@Field { value:\"IN: IN parameters are used to send values to stored procedures\"}\n" + "@Field { value:\"OUT: OUT parameters are used to get values from stored procedures\"}\n" + "public enum Direction { IN,OUT}");
EnumDoc enumDoc = Generator.createDocForNode(bLangPackage.getEnums().get(0));
Assert.assertEquals(enumDoc.name, "Direction", "Enum name should be extracted");
Assert.assertEquals(enumDoc.description, "The direction of the parameter", "Description of the " + "enum should be extracted");
// Enumerators inside the enum
Assert.assertEquals(enumDoc.enumerators.get(0).name, "IN", "Enumerator name should be extracted");
Assert.assertEquals(enumDoc.enumerators.get(0).description, "IN parameters are used to send values to " + "stored procedures", "Description of the enumerator should be extracted");
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD in project ballerina by ballerina-lang.
the class HtmlDocTest method testStructPropertiesExtracted.
@Test(description = "Struct properties should be available via construct")
public void testStructPropertiesExtracted() throws Exception {
BLangPackage bLangPackage = createPackage("package x.y; " + "@Description { value:\"Message sent by the client\"}" + "@Field {value:\"count: Number of retries\"}\n" + "@Field {value:\"interval: Retry interval in millisecond\"}" + "struct Message {int interval;int count;}");
StructDoc structDoc = Generator.createDocForNode(bLangPackage.getStructs().get(0));
Assert.assertEquals(structDoc.name, "Message", "Struct name should be extracted");
Assert.assertEquals(structDoc.description, "Message sent by the client", "Description of the " + "struct should be extracted");
// Struct fields
Assert.assertEquals(structDoc.fields.get(0).name, "interval", "Struct field name should be extracted");
Assert.assertEquals(structDoc.fields.get(0).dataType, "int", "Struct field type should be extracted");
Assert.assertEquals(structDoc.fields.get(0).description, "Retry interval in millisecond", "Description of the struct field should be extracted");
}
Aggregations