Search in sources :

Example 11 with BLangNameReference

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);
}
Also used : BLangTypeInit(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeInit) BLangNameReference(org.wso2.ballerinalang.compiler.tree.BLangNameReference) ExpressionNode(org.ballerinalang.model.tree.expressions.ExpressionNode) SelectExpressionNode(org.ballerinalang.model.tree.clauses.SelectExpressionNode) IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) Whitespace(org.ballerinalang.model.Whitespace)

Aggregations

BLangNameReference (org.wso2.ballerinalang.compiler.tree.BLangNameReference)11 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)3 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)3 BLangUserDefinedType (org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType)3 Whitespace (org.ballerinalang.model.Whitespace)2 IdentifierNode (org.ballerinalang.model.tree.IdentifierNode)2 SelectExpressionNode (org.ballerinalang.model.tree.clauses.SelectExpressionNode)2 ExpressionNode (org.ballerinalang.model.tree.expressions.ExpressionNode)2 ServiceNode (org.ballerinalang.model.tree.ServiceNode)1 BLangAnnotationAttachment (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment)1 BLangAnnotationAttachmentPoint (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)1 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)1 BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)1 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)1 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)1 BLangTypeInit (org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeInit)1 BLangBuiltInRefTypeNode (org.wso2.ballerinalang.compiler.tree.types.BLangBuiltInRefTypeNode)1 BLangConstrainedType (org.wso2.ballerinalang.compiler.tree.types.BLangConstrainedType)1