Search in sources :

Example 1 with SymbolEnter

use of org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolEnter 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)

Aggregations

IdentifierNode (org.ballerinalang.model.tree.IdentifierNode)1 TypeNode (org.ballerinalang.model.tree.types.TypeNode)1 BLangObject (org.wso2.ballerinalang.compiler.tree.BLangObject)1 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)1 BLangBuiltInRefTypeNode (org.wso2.ballerinalang.compiler.tree.types.BLangBuiltInRefTypeNode)1 BLangFunctionTypeNode (org.wso2.ballerinalang.compiler.tree.types.BLangFunctionTypeNode)1 BLangTupleTypeNode (org.wso2.ballerinalang.compiler.tree.types.BLangTupleTypeNode)1 BLangUnionTypeNode (org.wso2.ballerinalang.compiler.tree.types.BLangUnionTypeNode)1