Search in sources :

Example 1 with IdentifierNode

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;
}
Also used : IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 2 with IdentifierNode

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));
}
Also used : BLangNameReference(org.wso2.ballerinalang.compiler.tree.BLangNameReference) IdentifierNode(org.ballerinalang.model.tree.IdentifierNode)

Example 3 with IdentifierNode

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);
    }
}
Also used : BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) BLangTupleTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangTupleTypeNode) TypeNode(org.ballerinalang.model.tree.types.TypeNode) BLangUnionTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangUnionTypeNode) BLangFunctionTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangFunctionTypeNode) BLangBuiltInRefTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangBuiltInRefTypeNode) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 4 with IdentifierNode

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));
}
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)

Example 5 with IdentifierNode

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;
}
Also used : IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

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