Search in sources :

Example 1 with BLangType

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

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

the class SymbolResolver method visit.

@Override
public void visit(BLangFunctionTypeNode functionTypeNode) {
    List<BType> paramTypes = new ArrayList<>();
    List<BType> retParamTypes = new ArrayList<>();
    functionTypeNode.getParamTypeNode().forEach(t -> paramTypes.add(resolveTypeNode((BLangType) t, env)));
    functionTypeNode.getReturnParamTypeNode().forEach(t -> retParamTypes.add(resolveTypeNode((BLangType) t, env)));
    resultType = new BInvokableType(paramTypes, retParamTypes, null);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) ArrayList(java.util.ArrayList) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)

Example 3 with BLangType

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

the class BLangPackageBuilder method addTupleType.

public void addTupleType(DiagnosticPos pos, Set<Whitespace> ws, int members) {
    BLangTupleTypeNode tupleTypeNode = (BLangTupleTypeNode) TreeBuilder.createTupleTypeNode();
    for (int i = 0; i < members; i++) {
        final BLangType member = (BLangType) this.typeNodeStack.pop();
        tupleTypeNode.memberTypeNodes.add(0, member);
    }
    tupleTypeNode.pos = pos;
    tupleTypeNode.addWS(ws);
    this.typeNodeStack.push(tupleTypeNode);
}
Also used : BLangTupleTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangTupleTypeNode) BLangType(org.wso2.ballerinalang.compiler.tree.types.BLangType) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 4 with BLangType

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

the class BLangPackageBuilder method addCatchClause.

public void addCatchClause(DiagnosticPos poc, Set<Whitespace> ws, String paramName) {
    BLangVariable variableNode = (BLangVariable) TreeBuilder.createVariableNode();
    variableNode.typeNode = (BLangType) this.typeNodeStack.pop();
    variableNode.name = (BLangIdentifier) createIdentifier(paramName);
    variableNode.pos = variableNode.typeNode.pos;
    variableNode.addWS(removeNthFromLast(ws, 3));
    BLangCatch catchNode = (BLangCatch) TreeBuilder.createCatchNode();
    catchNode.pos = poc;
    catchNode.addWS(ws);
    catchNode.body = (BLangBlockStmt) this.blockNodeStack.pop();
    catchNode.param = variableNode;
    tryCatchFinallyNodesStack.peek().catchBlocks.add(catchNode);
}
Also used : BLangCatch(org.wso2.ballerinalang.compiler.tree.statements.BLangCatch) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 5 with BLangType

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

the class BLangPackageBuilder method createTypeCastExpr.

public void createTypeCastExpr(DiagnosticPos pos, Set<Whitespace> ws) {
    BLangTypeCastExpr typeCastNode = (BLangTypeCastExpr) TreeBuilder.createTypeCastNode();
    typeCastNode.pos = pos;
    typeCastNode.addWS(ws);
    typeCastNode.expr = (BLangExpression) exprNodeStack.pop();
    typeCastNode.typeNode = (BLangType) typeNodeStack.pop();
    addExpressionNode(typeCastNode);
}
Also used : BLangTypeCastExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeCastExpr)

Aggregations

BLangType (org.wso2.ballerinalang.compiler.tree.types.BLangType)5 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)3 CompletionItem (org.eclipse.lsp4j.CompletionItem)2 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)2 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)2 ArrayList (java.util.ArrayList)1 EnumSet (java.util.EnumSet)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Parameter (org.ballerinalang.composer.service.ballerina.parser.service.model.lang.Parameter)1 Whitespace (org.ballerinalang.model.Whitespace)1 DiagnosticCode (org.ballerinalang.util.diagnostic.DiagnosticCode)1 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)1 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)1 BConnectorType (org.wso2.ballerinalang.compiler.semantics.model.types.BConnectorType)1 BInvokableType (org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)1 BUnionType (org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType)1 BLangAction (org.wso2.ballerinalang.compiler.tree.BLangAction)1 BLangAnnotation (org.wso2.ballerinalang.compiler.tree.BLangAnnotation)1 BLangAnnotationAttachmentPoint (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)1