use of org.wso2.ballerinalang.compiler.tree.BLangStruct in project ballerina by ballerina-lang.
the class Desugar method rewriteObjectToStruct.
private BLangStruct rewriteObjectToStruct(BLangObject objectNode, SymbolEnv env) {
BLangStruct bLangStruct = (BLangStruct) TreeBuilder.createStructNode();
bLangStruct.name = objectNode.name;
bLangStruct.fields = objectNode.fields;
// bLangStruct.functions = rewrite(objectNode.functions, env);
bLangStruct.initFunction = objectNode.initFunction;
bLangStruct.annAttachments = rewrite(objectNode.annAttachments, env);
bLangStruct.docAttachments = rewrite(objectNode.docAttachments, env);
bLangStruct.deprecatedAttachments = rewrite(objectNode.deprecatedAttachments, env);
bLangStruct.isAnonymous = objectNode.isAnonymous;
bLangStruct.symbol = objectNode.symbol;
return bLangStruct;
}
use of org.wso2.ballerinalang.compiler.tree.BLangStruct in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addAnonObjectType.
public void addAnonObjectType(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 endStructDef.
public void endStructDef(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean publicStruct) {
BLangStruct structNode = populateStructNode(pos, ws, createIdentifier(identifier), false);
structNode.setName(this.createIdentifier(identifier));
if (publicStruct) {
structNode.flagSet.add(Flag.PUBLIC);
}
this.compUnit.addTopLevelNode(structNode);
}
use of org.wso2.ballerinalang.compiler.tree.BLangStruct 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.tree.BLangStruct 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();
}
}
}
Aggregations