Search in sources :

Example 1 with BLangBuiltInRefTypeNode

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

the class BLangPackageBuilder method addConstraintType.

public void addConstraintType(DiagnosticPos pos, Set<Whitespace> ws, String typeName) {
    BLangNameReference nameReference = nameReferenceStack.pop();
    BLangUserDefinedType constraintType = (BLangUserDefinedType) TreeBuilder.createUserDefinedTypeNode();
    constraintType.pos = pos;
    constraintType.pkgAlias = (BLangIdentifier) nameReference.pkgAlias;
    constraintType.typeName = (BLangIdentifier) nameReference.name;
    constraintType.addWS(nameReference.ws);
    Set<Whitespace> refTypeWS = removeNthFromLast(ws, 2);
    BLangBuiltInRefTypeNode refType = (BLangBuiltInRefTypeNode) TreeBuilder.createBuiltInReferenceTypeNode();
    refType.typeKind = TreeUtils.stringToTypeKind(typeName);
    refType.pos = pos;
    refType.addWS(refTypeWS);
    BLangConstrainedType constrainedType = (BLangConstrainedType) TreeBuilder.createConstrainedTypeNode();
    constrainedType.type = refType;
    constrainedType.constraint = constraintType;
    constrainedType.pos = pos;
    constrainedType.addWS(ws);
    addType(constrainedType);
}
Also used : BLangConstrainedType(org.wso2.ballerinalang.compiler.tree.types.BLangConstrainedType) BLangNameReference(org.wso2.ballerinalang.compiler.tree.BLangNameReference) BLangBuiltInRefTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangBuiltInRefTypeNode) BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType) Whitespace(org.ballerinalang.model.Whitespace)

Example 2 with BLangBuiltInRefTypeNode

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

the class BLangPackageBuilder method addConstraintTypeWithTypeName.

public void addConstraintTypeWithTypeName(DiagnosticPos pos, Set<Whitespace> ws, String typeName) {
    Set<Whitespace> refTypeWS = removeNthFromLast(ws, 2);
    BLangBuiltInRefTypeNode refType = (BLangBuiltInRefTypeNode) TreeBuilder.createBuiltInReferenceTypeNode();
    refType.typeKind = TreeUtils.stringToTypeKind(typeName);
    refType.pos = pos;
    refType.addWS(refTypeWS);
    BLangConstrainedType constrainedType = (BLangConstrainedType) TreeBuilder.createConstrainedTypeNode();
    constrainedType.type = refType;
    constrainedType.constraint = (BLangType) this.typeNodeStack.pop();
    constrainedType.pos = pos;
    constrainedType.addWS(ws);
    addType(constrainedType);
}
Also used : BLangConstrainedType(org.wso2.ballerinalang.compiler.tree.types.BLangConstrainedType) BLangBuiltInRefTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangBuiltInRefTypeNode) Whitespace(org.ballerinalang.model.Whitespace)

Example 3 with BLangBuiltInRefTypeNode

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

the class BLangPackageBuilder method addBuiltInReferenceType.

public void addBuiltInReferenceType(DiagnosticPos pos, Set<Whitespace> ws, String typeName) {
    BLangBuiltInRefTypeNode refType = (BLangBuiltInRefTypeNode) TreeBuilder.createBuiltInReferenceTypeNode();
    refType.typeKind = TreeUtils.stringToTypeKind(typeName);
    refType.pos = pos;
    refType.addWS(ws);
    addType(refType);
}
Also used : BLangBuiltInRefTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangBuiltInRefTypeNode)

Example 4 with BLangBuiltInRefTypeNode

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

the class ParserUtils method getReceiverType.

/**
 * Extract receiverType from the function receiver.
 *
 * @param receiver receiver
 * @return receiverType
 */
private static String getReceiverType(VariableNode receiver) {
    if (receiver == null) {
        return null;
    }
    TypeNode typeNode = receiver.getTypeNode();
    String receiverType = null;
    if (typeNode instanceof BLangUserDefinedType) {
        receiverType = ((BLangUserDefinedType) typeNode).getTypeName().getValue();
    } else if (typeNode instanceof BLangBuiltInRefTypeNode) {
        receiverType = ((BLangBuiltInRefTypeNode) typeNode).getTypeKind().typeName();
    } else if (typeNode instanceof BLangValueType) {
        receiverType = ((BLangValueType) typeNode).getTypeKind().typeName();
    } else {
        return null;
    }
    return receiverType;
}
Also used : BLangValueType(org.wso2.ballerinalang.compiler.tree.types.BLangValueType) BLangBuiltInRefTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangBuiltInRefTypeNode) BLangBuiltInRefTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangBuiltInRefTypeNode) TypeNode(org.ballerinalang.model.tree.types.TypeNode) BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType)

Aggregations

BLangBuiltInRefTypeNode (org.wso2.ballerinalang.compiler.tree.types.BLangBuiltInRefTypeNode)4 Whitespace (org.ballerinalang.model.Whitespace)2 BLangConstrainedType (org.wso2.ballerinalang.compiler.tree.types.BLangConstrainedType)2 BLangUserDefinedType (org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType)2 TypeNode (org.ballerinalang.model.tree.types.TypeNode)1 BLangNameReference (org.wso2.ballerinalang.compiler.tree.BLangNameReference)1 BLangValueType (org.wso2.ballerinalang.compiler.tree.types.BLangValueType)1