use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class TreeVisitor method visit.
public void visit(BLangConnector connectorNode) {
String connectorName = connectorNode.getName().getValue();
BSymbol connectorSymbol = connectorNode.symbol;
SymbolEnv connectorEnv = SymbolEnv.createConnectorEnv(connectorNode, connectorSymbol.scope, symbolEnv);
if (isWithinParameterContext(connectorName, NODE_TYPE_CONNECTOR)) {
this.populateSymbols(this.resolveAllVisibleSymbols(connectorEnv), connectorEnv);
setTerminateVisitor(true);
} else if (!ScopeResolverConstants.getResolverByClass(cursorPositionResolver).isCursorBeforeNode(connectorNode.getPosition(), connectorNode, this, this.documentServiceContext)) {
// Reset the previous node
this.setPreviousNode(null);
// TODO: Handle Annotation attachments
if (!(connectorNode.actions.isEmpty() && connectorNode.varDefs.isEmpty() && connectorNode.endpoints.isEmpty())) {
// Visit the endpoints
connectorNode.endpoints.forEach(bLangEndpoint -> this.acceptNode(bLangEndpoint, connectorEnv));
// Since the connector def does not contains a block statement, we consider the block owner only.
// Here it is Connector Definition
this.blockOwnerStack.push(connectorNode);
connectorNode.varDefs.forEach(varDef -> {
// Cursor position is calculated against the Connector scope resolver
cursorPositionResolver = ConnectorScopeResolver.class;
this.acceptNode(varDef, connectorEnv);
});
connectorNode.actions.forEach(action -> {
// Cursor position is calculated against the Connector scope resolver
cursorPositionResolver = ConnectorScopeResolver.class;
this.acceptNode(action, connectorEnv);
});
if (terminateVisitor) {
this.acceptNode(null, null);
}
this.blockOwnerStack.pop();
} else {
this.isCursorWithinBlock(connectorNode.getPosition(), connectorEnv);
}
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class TreeVisitor method visit.
@Override
public void visit(BLangObject objectNode) {
BSymbol objectSymbol = objectNode.symbol;
SymbolEnv objectEnv = SymbolEnv.createPkgLevelSymbolEnv(objectNode, objectSymbol.scope, symbolEnv);
blockOwnerStack.push(objectNode);
this.cursorPositionResolver = ObjectTypeScopeResolver.class;
objectNode.fields.forEach(field -> acceptNode(field, objectEnv));
// TODO: visit annotation and doc attachments
objectNode.functions.forEach(f -> acceptNode(f, objectEnv));
blockOwnerStack.pop();
this.cursorPositionResolver = TopLevelNodeScopeResolver.class;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class TreeVisitor method visit.
public void visit(BLangAction actionNode) {
String actionName = actionNode.getName().getValue();
BSymbol actionSymbol = actionNode.symbol;
SymbolEnv actionEnv = SymbolEnv.createResourceActionSymbolEnv(actionNode, actionSymbol.scope, symbolEnv);
if (this.isWithinParameterContext(actionName, NODE_TYPE_ACTION)) {
this.populateSymbols(this.resolveAllVisibleSymbols(actionEnv), actionEnv);
setTerminateVisitor(true);
} else if (!ScopeResolverConstants.getResolverByClass(cursorPositionResolver).isCursorBeforeNode(actionNode.getPosition(), actionNode, this, this.documentServiceContext)) {
// TODO: Handle Annotation attachments
// Visit the endpoints
actionNode.endpoints.forEach(bLangEndpoint -> this.acceptNode(bLangEndpoint, actionEnv));
// Cursor position is calculated against the resource parameter scope resolver since both are similar
cursorPositionResolver = ResourceParamScopeResolver.class;
actionNode.workers.forEach(w -> this.acceptNode(w, actionEnv));
// Cursor position is calculated against the Block statement scope resolver
cursorPositionResolver = BlockStatementScopeResolver.class;
this.blockOwnerStack.push(actionNode);
acceptNode(actionNode.body, actionEnv);
this.blockOwnerStack.pop();
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class TreeVisitor method visit.
public void visit(BLangService serviceNode) {
if (!ScopeResolverConstants.getResolverByClass(cursorPositionResolver).isCursorBeforeNode(serviceNode.getPosition(), serviceNode, this, this.documentServiceContext)) {
BSymbol serviceSymbol = serviceNode.symbol;
SymbolEnv serviceEnv = SymbolEnv.createPkgLevelSymbolEnv(serviceNode, serviceSymbol.scope, symbolEnv);
// Reset the previous node
this.setPreviousNode(null);
if (!(serviceNode.resources.isEmpty() && serviceNode.vars.isEmpty() && serviceNode.endpoints.isEmpty())) {
// Visit the endpoints
serviceNode.endpoints.forEach(bLangEndpoint -> this.acceptNode(bLangEndpoint, serviceEnv));
// Since the service does not contains a block statement, we consider the block owner only.
// Here it is service
this.blockOwnerStack.push(serviceNode);
serviceNode.vars.forEach(v -> {
this.cursorPositionResolver = ServiceScopeResolver.class;
this.acceptNode(v, serviceEnv);
});
serviceNode.resources.forEach(r -> {
this.cursorPositionResolver = ServiceScopeResolver.class;
this.acceptNode(r, serviceEnv);
});
if (terminateVisitor) {
this.acceptNode(null, null);
}
this.blockOwnerStack.pop();
} else {
this.isCursorWithinBlock(serviceNode.getPosition(), serviceEnv);
}
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol in project ballerina by ballerina-lang.
the class StatementContextResolver method resolveItems.
@Override
@SuppressWarnings("unchecked")
public ArrayList<CompletionItem> resolveItems(TextDocumentServiceContext completionContext) {
ArrayList<CompletionItem> completionItems = new ArrayList<>();
// action invocation or worker invocation
if (isInvocationOrFieldAccess(completionContext)) {
ArrayList<SymbolInfo> actionAndFunctions = new ArrayList<>();
PackageActionFunctionAndTypesFilter actionFunctionTypeFilter = new PackageActionFunctionAndTypesFilter();
actionAndFunctions.addAll(actionFunctionTypeFilter.filterItems(completionContext));
this.populateCompletionItemList(actionAndFunctions, completionItems);
} else {
CompletionItem xmlns = new CompletionItem();
xmlns.setLabel(ItemResolverConstants.XMLNS);
xmlns.setInsertText(Snippet.NAMESPACE_DECLARATION.toString());
xmlns.setInsertTextFormat(InsertTextFormat.Snippet);
xmlns.setDetail(ItemResolverConstants.SNIPPET_TYPE);
completionItems.add(xmlns);
// Add the var keyword
CompletionItem varKeyword = new CompletionItem();
varKeyword.setInsertText("var ");
varKeyword.setLabel("var");
varKeyword.setDetail(ItemResolverConstants.KEYWORD_TYPE);
completionItems.add(varKeyword);
StatementTemplateFilter statementTemplateFilter = new StatementTemplateFilter();
// Add the statement templates
completionItems.addAll(statementTemplateFilter.filterItems(completionContext));
// We need to remove the functions having a receiver symbol and the bTypes of the following
// ballerina.coordinator, ballerina.runtime, and anonStructs
ArrayList<String> invalidPkgs = new ArrayList<>(Arrays.asList("ballerina.runtime", "ballerina.transactions.coordinator"));
completionContext.get(CompletionKeys.VISIBLE_SYMBOLS_KEY).removeIf(symbolInfo -> {
BSymbol bSymbol = symbolInfo.getScopeEntry().symbol;
String symbolName = bSymbol.getName().getValue();
return (bSymbol instanceof BInvokableSymbol && ((BInvokableSymbol) bSymbol).receiverSymbol != null) || (bSymbol instanceof BPackageSymbol && invalidPkgs.contains(symbolName)) || (symbolName.startsWith("$anonStruct"));
});
populateCompletionItemList(completionContext.get(CompletionKeys.VISIBLE_SYMBOLS_KEY), completionItems);
// Now we need to sort the completion items and populate the completion items specific to the scope owner
// as an example, resource, action, function scopes are different from the if-else, while, and etc
Class itemSorter = completionContext.get(CompletionKeys.BLOCK_OWNER_KEY).getClass();
ItemSorters.getSorterByClass(itemSorter).sortItems(completionContext, completionItems);
}
return completionItems;
}
Aggregations