use of org.wso2.ballerinalang.compiler.tree.BLangNameReference in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addTypeInitExpression.
public void addTypeInitExpression(DiagnosticPos pos, Set<Whitespace> ws, String initName, boolean typeAvailable, boolean exprAvailable) {
BLangTypeInit objectInitNode = (BLangTypeInit) TreeBuilder.createObjectInitNode();
objectInitNode.pos = pos;
objectInitNode.addWS(ws);
if (typeAvailable) {
objectInitNode.userDefinedType = (BLangUserDefinedType) typeNodeStack.pop();
}
BLangInvocation invocationNode = (BLangInvocation) TreeBuilder.createInvocationNode();
invocationNode.pos = pos;
invocationNode.addWS(ws);
if (exprAvailable) {
List<ExpressionNode> exprNodes = exprNodeListStack.pop();
Set<Whitespace> cws = commaWsStack.pop();
exprNodes.forEach(exprNode -> {
invocationNode.argExprs.add((BLangExpression) exprNode);
objectInitNode.argsExpr.add((BLangExpression) exprNode);
});
invocationNode.addWS(cws);
objectInitNode.addWS(cws);
}
// TODO check whether pkgName can be be empty
IdentifierNode pkgNameNode = TreeBuilder.createIdentifierNode();
IdentifierNode nameNode = createIdentifier(initName);
BLangNameReference nameReference = new BLangNameReference(pos, ws, pkgNameNode, nameNode);
invocationNode.name = (BLangIdentifier) nameReference.name;
invocationNode.addWS(nameReference.ws);
invocationNode.pkgAlias = (BLangIdentifier) nameReference.pkgAlias;
objectInitNode.objectInitInvocation = invocationNode;
this.addExpressionNode(objectInitNode);
}
Aggregations