Search in sources :

Example 6 with IdentifierNode

use of org.ballerinalang.model.tree.IdentifierNode in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addEndpointVariable.

public void addEndpointVariable(DiagnosticPos pos, Set<Whitespace> ws, String endpointName) {
    BLangVariable var = (BLangVariable) TreeBuilder.createVariableNode();
    var.pos = pos;
    // endpointName has to be redefine at semantic analyze phase. So appending $ to make it work.
    IdentifierNode name = this.createIdentifier("$" + endpointName);
    var.setName(name);
    var.addWS(ws);
    // Type will be calculated at SymEnter phase.
    if (varListStack.empty()) {
        varListStack.push(new ArrayList<>());
    }
    varListStack.peek().add(0, var);
}
Also used : IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 7 with IdentifierNode

use of org.ballerinalang.model.tree.IdentifierNode in project ballerina by ballerina-lang.

the class BLangPackageBuilder method generateObjectVarNode.

private VariableNode generateObjectVarNode(DiagnosticPos pos, Set<Whitespace> ws, boolean isField, String identifier, boolean exprAvailable) {
    BLangVariable var = (BLangVariable) TreeBuilder.createVariableNode();
    var.pos = pos;
    IdentifierNode name = this.createIdentifier(identifier);
    var.setName(name);
    var.addWS(ws);
    var.isField = isField;
    if (!isField) {
        var.setTypeNode(this.typeNodeStack.pop());
    }
    if (exprAvailable) {
        var.setInitialExpression(this.exprNodeStack.pop());
    }
    return var;
}
Also used : IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 8 with IdentifierNode

use of org.ballerinalang.model.tree.IdentifierNode in project ballerina by ballerina-lang.

the class BLangPackageBuilder method createIdentifier.

private IdentifierNode createIdentifier(String value) {
    IdentifierNode node = TreeBuilder.createIdentifierNode();
    if (value == null) {
        return node;
    }
    if (value.startsWith(IDENTIFIER_LITERAL_PREFIX) && value.endsWith(IDENTIFIER_LITERAL_SUFFIX)) {
        node.setValue(value.substring(2, value.length() - 1));
        node.setLiteral(true);
    } else {
        node.setValue(value);
        node.setLiteral(false);
    }
    return node;
}
Also used : IdentifierNode(org.ballerinalang.model.tree.IdentifierNode)

Example 9 with IdentifierNode

use of org.ballerinalang.model.tree.IdentifierNode in project ballerina by ballerina-lang.

the class ASTBuilderUtil method createFunction.

static BLangFunction createFunction(DiagnosticPos pos, String name) {
    final BLangFunction bLangFunction = (BLangFunction) TreeBuilder.createFunctionNode();
    final IdentifierNode funcName = createIdentifier(pos, name);
    bLangFunction.setName(funcName);
    bLangFunction.flagSet = EnumSet.of(Flag.LAMBDA);
    bLangFunction.pos = pos;
    // Create body of the function
    bLangFunction.body = createBlockStmt(pos);
    return bLangFunction;
}
Also used : BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) IdentifierNode(org.ballerinalang.model.tree.IdentifierNode)

Example 10 with IdentifierNode

use of org.ballerinalang.model.tree.IdentifierNode 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));
}
Also used : IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier)

Aggregations

IdentifierNode (org.ballerinalang.model.tree.IdentifierNode)14 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)5 BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)4 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)4 Whitespace (org.ballerinalang.model.Whitespace)3 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)3 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)3 CaseFormat (com.google.common.base.CaseFormat)2 JsonArray (com.google.gson.JsonArray)2 JsonElement (com.google.gson.JsonElement)2 JsonNull (com.google.gson.JsonNull)2 JsonObject (com.google.gson.JsonObject)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 Paths (java.nio.file.Paths)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2