Search in sources :

Example 11 with BLangType

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

the class ServiceContextItemSorter method sortItems.

@Override
public void sortItems(TextDocumentServiceContext ctx, List<CompletionItem> completionItems) {
    BLangNode previousNode = ctx.get(CompletionKeys.PREVIOUS_NODE_KEY);
    /*
        Remove the statement type completion type. When the going through the parser
        rule contexts such as typeNameContext, we add the statements as well.
        Sorters are responsible for to the next level of such filtering.
         */
    this.removeCompletionsByType(new ArrayList<>(Collections.singletonList(ItemResolverConstants.STATEMENT_TYPE)), completionItems);
    if (previousNode == null) {
        this.populateWhenCursorBeforeOrAfterEp(completionItems);
    } else if (previousNode instanceof BLangVariableDef) {
        // BType bLangType = ((BLangVariableDef) previousNode).var.type;
        // if (bLangType instanceof BEndpointType) {
        // this.populateWhenCursorBeforeOrAfterEp(completionItems);
        // } else {
        this.setPriorities(completionItems);
        CompletionItem resItem = this.getResourceSnippet();
        resItem.setSortText(Priority.PRIORITY160.toString());
        completionItems.add(resItem);
    // }
    } else if (previousNode instanceof BLangResource) {
        completionItems.clear();
        completionItems.add(this.getResourceSnippet());
    }
}
Also used : BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) CompletionItem(org.eclipse.lsp4j.CompletionItem) BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)

Example 12 with BLangType

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

the class SymbolResolver method resolveTypeNode.

public BType resolveTypeNode(BLangType typeNode, SymbolEnv env, DiagnosticCode diagCode) {
    SymbolEnv prevEnv = this.env;
    DiagnosticCode preDiagCode = this.diagCode;
    this.env = env;
    this.diagCode = diagCode;
    typeNode.accept(this);
    this.env = prevEnv;
    this.diagCode = preDiagCode;
    // if it is not already a union type, JSON type, or any type
    if (typeNode.nullable && this.resultType.tag == TypeTags.UNION) {
        BUnionType unionType = (BUnionType) this.resultType;
        unionType.memberTypes.add(symTable.nullType);
        unionType.setNullable(true);
    } else if (typeNode.nullable && resultType.tag != TypeTags.JSON && resultType.tag != TypeTags.ANY) {
        Set<BType> memberTypes = new HashSet<BType>(2) {

            {
                add(resultType);
                add(symTable.nullType);
            }
        };
        this.resultType = new BUnionType(null, memberTypes, true);
    }
    typeNode.type = resultType;
    return resultType;
}
Also used : BUnionType(org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType) EnumSet(java.util.EnumSet) Set(java.util.Set) HashSet(java.util.HashSet) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) DiagnosticCode(org.ballerinalang.util.diagnostic.DiagnosticCode)

Example 13 with BLangType

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

the class SymbolResolver method visitBuiltInTypeNode.

private void visitBuiltInTypeNode(BLangType typeNode, TypeKind typeKind, SymbolEnv env) {
    Name typeName = names.fromTypeKind(typeKind);
    BSymbol typeSymbol = lookupMemberSymbol(typeNode.pos, symTable.rootScope, env, typeName, SymTag.TYPE);
    if (typeSymbol == symTable.notFoundSymbol) {
        dlog.error(typeNode.pos, diagCode, typeName);
    }
    resultType = typeNode.type = typeSymbol.type;
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 14 with BLangType

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

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

the class BLangPackageBuilder method createTypeConversionExpr.

public void createTypeConversionExpr(DiagnosticPos pos, Set<Whitespace> ws, boolean namedTransformer) {
    BLangTypeConversionExpr typeConversionNode = (BLangTypeConversionExpr) TreeBuilder.createTypeConversionNode();
    typeConversionNode.pos = pos;
    typeConversionNode.addWS(ws);
    typeConversionNode.typeNode = (BLangType) typeNodeStack.pop();
    typeConversionNode.expr = (BLangExpression) exprNodeStack.pop();
    if (namedTransformer) {
        typeConversionNode.transformerInvocation = (BLangInvocation) exprNodeStack.pop();
    }
    addExpressionNode(typeConversionNode);
}
Also used : BLangTypeConversionExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr)

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