use of org.ballerinalang.model.tree.IdentifierNode in project ballerina by ballerina-lang.
the class SymbolEnter method createReceiver.
private BLangVariable createReceiver(BLangStruct struct) {
BLangVariable receiver = (BLangVariable) TreeBuilder.createVariableNode();
receiver.pos = struct.pos;
IdentifierNode name = createIdentifier(Names.SELF.getValue());
receiver.setName(name);
receiver.docTag = DocTag.RECEIVER;
BLangUserDefinedType structTypeNode = (BLangUserDefinedType) TreeBuilder.createUserDefinedTypeNode();
structTypeNode.pkgAlias = new BLangIdentifier();
structTypeNode.typeName = struct.name;
receiver.setTypeNode(structTypeNode);
return receiver;
}
use of org.ballerinalang.model.tree.IdentifierNode in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addNameReference.
public void addNameReference(DiagnosticPos currentPos, Set<Whitespace> ws, String pkgName, String name) {
IdentifierNode pkgNameNode = createIdentifier(pkgName);
IdentifierNode nameNode = createIdentifier(name);
nameReferenceStack.push(new BLangNameReference(currentPos, ws, pkgNameNode, nameNode));
}
use of org.ballerinalang.model.tree.IdentifierNode in project ballerina by ballerina-lang.
the class BLangPackageBuilder method endTypeDefinition.
public void endTypeDefinition(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean publicStruct) {
// TODO only adding object type for now
if (!this.objectStack.isEmpty()) {
BLangObject objectNode = (BLangObject) this.objectStack.pop();
objectNode.pos = pos;
objectNode.setName(this.createIdentifier(identifier));
if (publicStruct) {
objectNode.flagSet.add(Flag.PUBLIC);
}
objectNode.isAnonymous = false;
// Create an user defined type with object type
TypeNode objectType = createUserDefinedType(pos, ws, (BLangIdentifier) TreeBuilder.createIdentifierNode(), objectNode.name);
// Create and add receiver to attached functions
BLangVariable receiver = (BLangVariable) TreeBuilder.createVariableNode();
receiver.pos = pos;
IdentifierNode name = createIdentifier(Names.SELF.getValue());
receiver.setName(name);
receiver.addWS(ws);
receiver.docTag = DocTag.RECEIVER;
receiver.setTypeNode(objectType);
// Cache receiver to add to init function in symbolEnter
objectNode.receiver = receiver;
objectNode.functions.forEach(f -> f.setReceiver(receiver));
this.compUnit.addTopLevelNode(objectNode);
}
}
use of org.ballerinalang.model.tree.IdentifierNode 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.ballerinalang.model.tree.IdentifierNode in project ballerina by ballerina-lang.
the class BLangPackageBuilder method generateBasicVarNode.
private VariableNode generateBasicVarNode(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean exprAvailable) {
BLangVariable var = (BLangVariable) TreeBuilder.createVariableNode();
var.pos = pos;
IdentifierNode name = this.createIdentifier(identifier);
var.setName(name);
var.addWS(ws);
var.setTypeNode(this.typeNodeStack.pop());
if (exprAvailable) {
var.setInitialExpression(this.exprNodeStack.pop());
}
return var;
}
Aggregations