use of org.wso2.ballerinalang.compiler.tree.BLangNode in project ballerina by ballerina-lang.
the class BallerinaTextDocumentService method completion.
@Override
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(TextDocumentPositionParams position) {
return CompletableFuture.supplyAsync(() -> {
List<CompletionItem> completions;
TextDocumentServiceContext completionContext = new TextDocumentServiceContext();
completionContext.put(DocumentServiceKeys.POSITION_KEY, position);
completionContext.put(DocumentServiceKeys.FILE_URI_KEY, position.getTextDocument().getUri());
completionContext.put(DocumentServiceKeys.LS_PACKAGE_CACHE_KEY, lSPackageCache);
try {
BLangPackage bLangPackage = TextDocumentServiceUtil.getBLangPackage(completionContext, documentManager, false, CompletionCustomErrorStrategy.class, false).get(0);
completionContext.put(DocumentServiceKeys.CURRENT_PACKAGE_NAME_KEY, bLangPackage.symbol.getName().getValue());
completionContext.put(DocumentServiceKeys.CURRENT_BLANG_PACKAGE_CONTEXT_KEY, bLangPackage);
// Visit the package to resolve the symbols
TreeVisitor treeVisitor = new TreeVisitor(completionContext);
bLangPackage.accept(treeVisitor);
BLangNode symbolEnvNode = completionContext.get(CompletionKeys.SYMBOL_ENV_NODE_KEY);
if (symbolEnvNode == null) {
completions = CompletionItemResolver.getResolverByClass(TopLevelResolver.class).resolveItems(completionContext);
} else {
completions = CompletionItemResolver.getResolverByClass(symbolEnvNode.getClass()).resolveItems(completionContext);
}
} catch (Exception | AssertionError e) {
completions = new ArrayList<>();
}
return Either.forLeft(completions);
});
}
use of org.wso2.ballerinalang.compiler.tree.BLangNode in project ballerina by ballerina-lang.
the class TaintAnalyzer method analyzeNode.
// Private
private <T extends BLangNode, U extends SymbolEnv> void analyzeNode(T t, U u) {
SymbolEnv prevEnv = this.env;
this.env = u;
t.accept(this);
this.env = prevEnv;
}
use of org.wso2.ballerinalang.compiler.tree.BLangNode in project ballerina by ballerina-lang.
the class CodeAnalyzer method analyzeNode.
private void analyzeNode(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 SemanticAnalyzer method analyzeNode.
BType analyzeNode(BLangNode node, SymbolEnv env, BType expType, DiagnosticCode diagCode) {
SymbolEnv prevEnv = this.env;
BType preExpType = this.expType;
DiagnosticCode preDiagCode = this.diagCode;
// TODO Check the possibility of using a try/finally here
this.env = env;
this.expType = expType;
this.diagCode = diagCode;
node.accept(this);
this.env = prevEnv;
this.expType = preExpType;
this.diagCode = preDiagCode;
return resType;
}
use of org.wso2.ballerinalang.compiler.tree.BLangNode in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
// Visitor methods
public void visit(BLangPackage pkgNode) {
if (pkgNode.completedPhases.contains(CompilerPhase.TYPE_CHECK)) {
return;
}
SymbolEnv pkgEnv = this.symTable.pkgEnvMap.get(pkgNode.symbol);
// Visit all the imported packages
pkgNode.imports.forEach(importNode -> analyzeDef(importNode, pkgEnv));
// Then visit each top-level element sorted using the compilation unit
pkgNode.topLevelNodes.forEach(topLevelNode -> analyzeDef((BLangNode) topLevelNode, pkgEnv));
analyzeDef(pkgNode.initFunction, pkgEnv);
analyzeDef(pkgNode.startFunction, pkgEnv);
analyzeDef(pkgNode.stopFunction, pkgEnv);
pkgNode.completedPhases.add(CompilerPhase.TYPE_CHECK);
}
Aggregations