Search in sources :

Example 41 with BLangIdentifier

use of org.wso2.ballerinalang.compiler.tree.BLangIdentifier in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addNamedArgument.

public void addNamedArgument(DiagnosticPos pos, Set<Whitespace> ws, String name) {
    BLangNamedArgsExpression namedArg = (BLangNamedArgsExpression) TreeBuilder.createNamedArgNode();
    namedArg.pos = pos;
    namedArg.addWS(ws);
    namedArg.name = (BLangIdentifier) this.createIdentifier(name);
    namedArg.expr = (BLangExpression) this.exprNodeStack.pop();
    addExpressionNode(namedArg);
}
Also used : BLangNamedArgsExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangNamedArgsExpression)

Example 42 with BLangIdentifier

use of org.wso2.ballerinalang.compiler.tree.BLangIdentifier 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)

Example 43 with BLangIdentifier

use of org.wso2.ballerinalang.compiler.tree.BLangIdentifier in project ballerina by ballerina-lang.

the class PackageLoader method addImportPkg.

// Private methods
private void addImportPkg(BLangPackage bLangPackage, String orgName, String sourcePkgName, String version) {
    List<Name> nameComps = getPackageNameComps(sourcePkgName);
    List<BLangIdentifier> pkgNameComps = new ArrayList<>();
    nameComps.forEach(comp -> {
        IdentifierNode node = TreeBuilder.createIdentifierNode();
        node.setValue(comp.value);
        pkgNameComps.add((BLangIdentifier) node);
    });
    BLangIdentifier orgNameNode = (BLangIdentifier) TreeBuilder.createIdentifierNode();
    orgNameNode.setValue(orgName);
    BLangIdentifier versionNode = (BLangIdentifier) TreeBuilder.createIdentifierNode();
    versionNode.setValue(version);
    BLangImportPackage importDcl = (BLangImportPackage) TreeBuilder.createImportPackageNode();
    importDcl.pos = bLangPackage.pos;
    importDcl.pkgNameComps = pkgNameComps;
    importDcl.orgName = orgNameNode;
    importDcl.version = versionNode;
    BLangIdentifier alias = (BLangIdentifier) TreeBuilder.createIdentifierNode();
    alias.setValue(names.merge(Names.DOT, nameComps.get(nameComps.size() - 1)).value);
    importDcl.alias = alias;
    bLangPackage.imports.add(importDcl);
}
Also used : IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) ArrayList(java.util.ArrayList) BLangImportPackage(org.wso2.ballerinalang.compiler.tree.BLangImportPackage) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 44 with BLangIdentifier

use of org.wso2.ballerinalang.compiler.tree.BLangIdentifier in project ballerina by ballerina-lang.

the class SwaggerConverterUtils method getAlias.

/**
 * Gets the alias for a given package from a bLang file root node.
 * @param topCompilationUnit The root node.
 * @param packageName The package name.
 * @return The alias.
 */
private static String getAlias(BLangCompilationUnit topCompilationUnit, String packageName) {
    for (TopLevelNode topLevelNode : topCompilationUnit.getTopLevelNodes()) {
        if (topLevelNode instanceof BLangImportPackage) {
            BLangImportPackage importPackage = (BLangImportPackage) topLevelNode;
            String packagePath = importPackage.getPackageName().stream().map(BLangIdentifier::getValue).collect(Collectors.joining("."));
            if (packageName.equals(packagePath)) {
                return importPackage.getAlias().getValue();
            }
        }
    }
    return null;
}
Also used : BLangImportPackage(org.wso2.ballerinalang.compiler.tree.BLangImportPackage) TopLevelNode(org.ballerinalang.model.tree.TopLevelNode)

Aggregations

BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)20 BLangNameReference (org.wso2.ballerinalang.compiler.tree.BLangNameReference)9 IdentifierNode (org.ballerinalang.model.tree.IdentifierNode)8 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)7 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)7 BLangUserDefinedType (org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType)6 ArrayList (java.util.ArrayList)5 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)5 BLangImportPackage (org.wso2.ballerinalang.compiler.tree.BLangImportPackage)5 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)4 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)4 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)4 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)4 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)4 Name (org.wso2.ballerinalang.compiler.util.Name)4 SelectExpressionNode (org.ballerinalang.model.tree.clauses.SelectExpressionNode)3 ExpressionNode (org.ballerinalang.model.tree.expressions.ExpressionNode)3 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)3 List (java.util.List)2 Set (java.util.Set)2