Search in sources :

Example 1 with BLangUserDefinedType

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

the class ParserUtils method createNewParameter.

/**
 * Create new parameter.
 *
 * @param name parameter name
 * @param type parameter type
 * @return {Parameter} parameter
 */
private static Parameter createNewParameter(String name, String type, BLangType typeNode) {
    Parameter parameter = new Parameter();
    parameter.setType(type);
    parameter.setName(name);
    BType bType = typeNode.type;
    if (bType instanceof BConnectorType) {
        parameter.setPkgAlias(((BLangUserDefinedType) typeNode).pkgAlias.toString());
        parameter.setConnector(true);
    }
    return parameter;
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BConnectorType(org.wso2.ballerinalang.compiler.semantics.model.types.BConnectorType) Parameter(org.ballerinalang.composer.service.ballerina.parser.service.model.lang.Parameter) BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType)

Example 2 with BLangUserDefinedType

use of org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType 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 3 with BLangUserDefinedType

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

the class SymbolResolver method visit.

public void visit(BLangUserDefinedType userDefinedTypeNode) {
    // 1) Resolve the package scope using the package alias.
    // If the package alias is not empty or null, then find the package scope,
    // if not use the current package scope.
    // 2) lookup the typename in the package scope returned from step 1.
    // 3) If the symbol is not found, then lookup in the root scope. e.g. for types such as 'error'
    BSymbol pkgSymbol = resolvePkgSymbol(userDefinedTypeNode.pos, this.env, names.fromIdNode(userDefinedTypeNode.pkgAlias));
    if (pkgSymbol == symTable.notFoundSymbol) {
        resultType = symTable.errType;
        return;
    }
    Name typeName = names.fromIdNode(userDefinedTypeNode.typeName);
    BSymbol symbol = symTable.notFoundSymbol;
    // Only valued types and ANNOTATION type allowed.
    if (env.scope.owner.tag == SymTag.ANNOTATION) {
        symbol = lookupMemberSymbol(userDefinedTypeNode.pos, pkgSymbol.scope, this.env, typeName, SymTag.ANNOTATION);
    }
    // 3) Lookup the current package scope.
    if (symbol == symTable.notFoundSymbol) {
        symbol = lookupMemberSymbol(userDefinedTypeNode.pos, pkgSymbol.scope, this.env, typeName, SymTag.VARIABLE_NAME);
    }
    if (symbol == symTable.notFoundSymbol) {
        // 4) Lookup the root scope for types such as 'error'
        symbol = lookupMemberSymbol(userDefinedTypeNode.pos, symTable.rootScope, this.env, typeName, SymTag.VARIABLE_NAME);
    }
    if (symbol == symTable.notFoundSymbol) {
        dlog.error(userDefinedTypeNode.pos, diagCode, typeName);
        resultType = symTable.errType;
        return;
    }
    if (symbol.kind == SymbolKind.CONNECTOR) {
        userDefinedTypeNode.flagSet = EnumSet.of(Flag.CONNECTOR);
    }
    resultType = symbol.type;
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 4 with BLangUserDefinedType

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

the class BLangPackageBuilder method addEndpointDefinition.

public void addEndpointDefinition(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean initExprExist) {
    final BLangEndpoint endpointNode = (BLangEndpoint) TreeBuilder.createEndpointNode();
    attachAnnotations(endpointNode);
    endpointNode.pos = pos;
    endpointNode.name = (BLangIdentifier) this.createIdentifier(identifier);
    endpointNode.endpointTypeNode = (BLangUserDefinedType) typeNodeStack.pop();
    if (initExprExist) {
        endpointNode.configurationExpr = (BLangExpression) this.exprNodeStack.pop();
    }
    endpointNode.addWS(ws);
    if (endpointListStack.empty()) {
        // Top level node.
        lastBuiltEndpoint = endpointNode;
        this.compUnit.addTopLevelNode(endpointNode);
    } else {
        endpointListStack.peek().add(endpointNode);
    }
}
Also used : BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 5 with BLangUserDefinedType

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

the class BLangPackageBuilder method createUserDefinedType.

private BLangUserDefinedType createUserDefinedType(DiagnosticPos pos, Set<Whitespace> ws, BLangIdentifier pkgAlias, BLangIdentifier name) {
    BLangUserDefinedType userDefinedType = (BLangUserDefinedType) TreeBuilder.createUserDefinedTypeNode();
    userDefinedType.pos = pos;
    userDefinedType.addWS(ws);
    userDefinedType.pkgAlias = pkgAlias;
    userDefinedType.typeName = name;
    return userDefinedType;
}
Also used : BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType)

Aggregations

BLangUserDefinedType (org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType)12 TypeNode (org.ballerinalang.model.tree.types.TypeNode)4 BLangNameReference (org.wso2.ballerinalang.compiler.tree.BLangNameReference)4 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)4 IdentifierNode (org.ballerinalang.model.tree.IdentifierNode)3 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)3 BLangAnnotation (org.wso2.ballerinalang.compiler.tree.BLangAnnotation)3 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)3 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)3 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Documentable (org.ballerinalang.docgen.model.Documentable)2 Link (org.ballerinalang.docgen.model.Link)2 PackageName (org.ballerinalang.docgen.model.PackageName)2 Page (org.ballerinalang.docgen.model.Page)2 Flag (org.ballerinalang.model.elements.Flag)2 EnumNode (org.ballerinalang.model.tree.EnumNode)2 NodeKind (org.ballerinalang.model.tree.NodeKind)2 BStructType (org.wso2.ballerinalang.compiler.semantics.model.types.BStructType)2