use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class MatchStatementScopeResolver method isCursorBeforeNode.
/**
* Check whether the cursor is positioned before the given node start.
*
* @param nodePosition Position of the node
* @param node Node
* @param treeVisitor {@link TreeVisitor} current tree visitor instance
* @param completionContext Completion operation context
* @return {@link Boolean} Whether the cursor is before the node start or not
*/
@Override
public boolean isCursorBeforeNode(DiagnosticPos nodePosition, Node node, TreeVisitor treeVisitor, TextDocumentServiceContext completionContext) {
if (!(treeVisitor.getBlockOwnerStack().peek() instanceof BLangMatch)) {
// In the ideal case, this will not get triggered
return false;
}
BLangMatch matchNode = (BLangMatch) treeVisitor.getBlockOwnerStack().peek();
DiagnosticPos matchNodePos = CommonUtil.toZeroBasedPosition(matchNode.getPosition());
DiagnosticPos nodePos = CommonUtil.toZeroBasedPosition((DiagnosticPos) node.getPosition());
List<BLangMatch.BLangMatchStmtPatternClause> patternClauseList = matchNode.getPatternClauses();
int line = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getLine();
int col = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getCharacter();
int nodeLine = nodePos.getStartLine();
int nodeCol = nodePos.getStartColumn();
boolean isBeforeNode = false;
if ((line < nodeLine) || (line == nodeLine && col < nodeCol)) {
isBeforeNode = true;
} else if (patternClauseList.indexOf(node) == patternClauseList.size() - 1) {
isBeforeNode = (line < matchNodePos.getEndLine()) || (line == matchNodePos.getEndLine() && col < matchNodePos.getEndColumn());
}
if (isBeforeNode) {
Map<Name, Scope.ScopeEntry> visibleSymbolEntries = treeVisitor.resolveAllVisibleSymbols(treeVisitor.getSymbolEnv());
SymbolEnv matchEnv = createMatchEnv(matchNode, treeVisitor.getSymbolEnv());
treeVisitor.populateSymbols(visibleSymbolEntries, matchEnv);
treeVisitor.setTerminateVisitor(true);
}
return isBeforeNode;
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class MatchStatementScopeResolver method createMatchEnv.
private static SymbolEnv createMatchEnv(BLangMatch match, SymbolEnv env) {
SymbolEnv symbolEnv = new SymbolEnv(match, null);
env.copyTo(symbolEnv);
return symbolEnv;
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SignatureTreeVisitor method visit.
@Override
public void visit(BLangBlockStmt blockNode) {
SymbolEnv blockEnv = SymbolEnv.createBlockEnv(blockNode, symbolEnv);
blockNode.stmts.forEach(stmt -> this.acceptNode(stmt, blockEnv));
if (!terminateVisitor && this.isCursorWithinBlock()) {
Map<Name, Scope.ScopeEntry> visibleSymbolEntries = symbolResolver.getAllVisibleInScopeSymbols(blockEnv);
this.populateSymbols(visibleSymbolEntries);
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SignatureTreeVisitor method visit.
@Override
public void visit(BLangResource resourceNode) {
BSymbol resourceSymbol = resourceNode.symbol;
SymbolEnv resourceEnv = SymbolEnv.createResourceActionSymbolEnv(resourceNode, resourceSymbol.scope, symbolEnv);
resourceNode.workers.forEach(w -> this.acceptNode(w, resourceEnv));
this.blockOwnerStack.push(resourceNode);
acceptNode(resourceNode.body, resourceEnv);
this.blockOwnerStack.pop();
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SignatureTreeVisitor method visit.
@Override
public void visit(BLangConnector connectorNode) {
BSymbol connectorSymbol = connectorNode.symbol;
SymbolEnv connectorEnv = SymbolEnv.createConnectorEnv(connectorNode, connectorSymbol.scope, symbolEnv);
connectorNode.actions.forEach(action -> this.acceptNode(action, connectorEnv));
}
Aggregations