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());
}
}
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;
}
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;
}
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);
}
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);
}
Aggregations