use of org.wso2.ballerinalang.compiler.tree.BLangNode 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.BLangNode in project ballerina by ballerina-lang.
the class SymbolEnter method defineNode.
public void defineNode(BLangNode node, SymbolEnv env) {
SymbolEnv prevEnv = this.env;
this.env = env;
node.accept(this);
this.env = prevEnv;
}
use of org.wso2.ballerinalang.compiler.tree.BLangNode in project ballerina by ballerina-lang.
the class TaintAnalyzer method visit.
public void visit(BLangPackage pkgNode) {
if (pkgNode.completedPhases.contains(CompilerPhase.TAINT_ANALYZE)) {
return;
}
SymbolEnv pkgEnv = symTable.pkgEnvMap.get(pkgNode.symbol);
SymbolEnv prevPkgEnv = this.currPkgEnv;
this.currPkgEnv = pkgEnv;
this.env = pkgEnv;
pkgNode.imports.forEach(impPkgNode -> impPkgNode.accept(this));
pkgNode.topLevelNodes.forEach(e -> ((BLangNode) e).accept(this));
// Do table generation for blocked invokables after all the import packages are scanned.
if (this.mainPkgEnv.equals(pkgEnv)) {
initialAnalysisComplete = true;
resolveBlockedInvokable();
initialAnalysisComplete = false;
}
this.currPkgEnv = prevPkgEnv;
pkgNode.completedPhases.add(CompilerPhase.TAINT_ANALYZE);
}
use of org.wso2.ballerinalang.compiler.tree.BLangNode in project ballerina by ballerina-lang.
the class CodeAnalyzer method visit.
@Override
public void visit(BLangPackage pkgNode) {
if (pkgNode.completedPhases.contains(CompilerPhase.CODE_ANALYZE)) {
return;
}
SymbolEnv pkgEnv = symTable.pkgEnvMap.get(pkgNode.symbol);
pkgNode.imports.forEach(impPkgNode -> analyzeNode(impPkgNode, pkgEnv));
pkgNode.topLevelNodes.forEach(topLevelNode -> analyzeNode((BLangNode) topLevelNode, pkgEnv));
pkgNode.completedPhases.add(CompilerPhase.CODE_ANALYZE);
}
use of org.wso2.ballerinalang.compiler.tree.BLangNode in project ballerina by ballerina-lang.
the class Types method checkForeachTypes.
List<BType> checkForeachTypes(BLangNode collection, int variableSize) {
BType collectionType = collection.type;
List<BType> errorTypes;
int maxSupportedTypes;
switch(collectionType.tag) {
case TypeTags.ARRAY:
BArrayType bArrayType = (BArrayType) collectionType;
if (variableSize == 1) {
return Lists.of(bArrayType.eType);
} else if (variableSize == 2) {
return Lists.of(symTable.intType, bArrayType.eType);
} else {
maxSupportedTypes = 2;
errorTypes = Lists.of(symTable.intType, bArrayType.eType);
}
break;
case TypeTags.MAP:
BMapType bMapType = (BMapType) collectionType;
if (variableSize == 1) {
return Lists.of(bMapType.constraint);
} else if (variableSize == 2) {
return Lists.of(symTable.stringType, bMapType.constraint);
} else {
maxSupportedTypes = 2;
errorTypes = Lists.of(symTable.stringType, bMapType.constraint);
}
break;
case TypeTags.JSON:
if (variableSize == 1) {
return Lists.of(symTable.jsonType);
} else {
maxSupportedTypes = 1;
errorTypes = Lists.of(symTable.jsonType);
}
break;
case TypeTags.XML:
if (variableSize == 1) {
return Lists.of(symTable.xmlType);
} else if (variableSize == 2) {
return Lists.of(symTable.intType, symTable.xmlType);
} else {
maxSupportedTypes = 2;
errorTypes = Lists.of(symTable.intType, symTable.xmlType);
}
break;
case TypeTags.TABLE:
BTableType tableType = (BTableType) collectionType;
if (variableSize == 1) {
return Lists.of(tableType.constraint);
} else {
maxSupportedTypes = 1;
errorTypes = Lists.of(tableType.constraint);
}
break;
case TypeTags.ERROR:
return Collections.nCopies(variableSize, symTable.errType);
default:
dlog.error(collection.pos, DiagnosticCode.ITERABLE_NOT_SUPPORTED_COLLECTION, collectionType);
return Collections.nCopies(variableSize, symTable.errType);
}
dlog.error(collection.pos, DiagnosticCode.ITERABLE_TOO_MANY_VARIABLES, collectionType);
errorTypes.addAll(Collections.nCopies(variableSize - maxSupportedTypes, symTable.errType));
return errorTypes;
}
Aggregations