Search in sources :

Example 21 with Node

use of org.wso2.carbon.identity.core.model.Node 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);
        }
    }
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 22 with Node

use of org.wso2.carbon.identity.core.model.Node in project ballerina by ballerina-lang.

the class TopLevelNodeScopeResolver 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) {
    int line = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getLine();
    int col = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getCharacter();
    DiagnosticPos zeroBasedPos = CommonUtil.toZeroBasedPosition(nodePosition);
    int nodeSLine = zeroBasedPos.sLine;
    int nodeSCol = zeroBasedPos.sCol;
    if (line < nodeSLine || (line == nodeSLine && col <= nodeSCol)) {
        treeVisitor.setTerminateVisitor(true);
        return true;
    }
    return false;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)

Example 23 with Node

use of org.wso2.carbon.identity.core.model.Node in project ballerina by ballerina-lang.

the class BlockStatementScopeResolver method isCursorBeforeNode.

/**
 * Check whether the cursor position is located before the evaluating statement node.
 * @param nodePosition position of the node
 * @param node statement being evaluated
 * @return true|false
 */
@Override
public boolean isCursorBeforeNode(DiagnosticPos nodePosition, Node node, TreeVisitor treeVisitor, TextDocumentServiceContext completionContext) {
    int line = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getLine();
    int col = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getCharacter();
    DiagnosticPos zeroBasedPos = CommonUtil.toZeroBasedPosition(nodePosition);
    int nodeSLine = zeroBasedPos.sLine;
    int nodeSCol = zeroBasedPos.sCol;
    // node endLine for the BLangIf node has to calculate by considering the else node. End line of the BLangIf
    // node is the endLine of the else node.
    int nodeELine = node instanceof BLangIf ? getIfElseNodeEndLine((BLangIf) node) : zeroBasedPos.eLine;
    int nodeECol = zeroBasedPos.eCol;
    BLangBlockStmt bLangBlockStmt = treeVisitor.getBlockStmtStack().peek();
    Node blockOwner = treeVisitor.getBlockOwnerStack().peek();
    boolean isLastStatement = this.isNodeLastStatement(bLangBlockStmt, blockOwner, node);
    boolean isWithinScopeAfterLastChild = this.isWithinScopeAfterLastChildNode(treeVisitor, isLastStatement, nodeELine, nodeECol, line, col, node);
    if (line < nodeSLine || (line == nodeSLine && col < nodeSCol) || isWithinScopeAfterLastChild) {
        Map<Name, Scope.ScopeEntry> visibleSymbolEntries = treeVisitor.resolveAllVisibleSymbols(treeVisitor.getSymbolEnv());
        treeVisitor.populateSymbols(visibleSymbolEntries, null);
        treeVisitor.setTerminateVisitor(true);
        return true;
    }
    return false;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) Node(org.ballerinalang.model.tree.Node) BLangIf(org.wso2.ballerinalang.compiler.tree.statements.BLangIf) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 24 with Node

use of org.wso2.carbon.identity.core.model.Node 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;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangMatch(org.wso2.ballerinalang.compiler.tree.statements.BLangMatch) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 25 with Node

use of org.wso2.carbon.identity.core.model.Node in project ballerina by ballerina-lang.

the class ObjectTypeScopeResolver 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 BLangObject)) {
        return false;
    }
    BLangObject ownerObject = (BLangObject) treeVisitor.getBlockOwnerStack().peek();
    DiagnosticPos zeroBasedPos = CommonUtil.toZeroBasedPosition(nodePosition);
    DiagnosticPos blockOwnerPos = CommonUtil.toZeroBasedPosition((DiagnosticPos) treeVisitor.getBlockOwnerStack().peek().getPosition());
    int line = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getLine();
    int col = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getCharacter();
    boolean isLastField = false;
    if ((!ownerObject.fields.isEmpty() && node instanceof BLangVariable && ownerObject.fields.indexOf(node) == ownerObject.fields.size() - 1 && ownerObject.functions.isEmpty()) || (!ownerObject.functions.isEmpty() && node instanceof BLangFunction && ownerObject.functions.indexOf(node) == ownerObject.functions.size() - 1)) {
        isLastField = true;
    }
    if ((line < zeroBasedPos.getStartLine() || (line == zeroBasedPos.getStartLine() && col < zeroBasedPos.getStartColumn())) || (isLastField && ((blockOwnerPos.getEndLine() > line && zeroBasedPos.getEndLine() < line) || (blockOwnerPos.getEndLine() == line && blockOwnerPos.getEndColumn() > col)))) {
        Map<Name, Scope.ScopeEntry> visibleSymbolEntries = treeVisitor.resolveAllVisibleSymbols(treeVisitor.getSymbolEnv());
        treeVisitor.populateSymbols(visibleSymbolEntries, null);
        treeVisitor.setTerminateVisitor(true);
        return true;
    }
    return false;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Name(org.wso2.ballerinalang.compiler.util.Name)

Aggregations

ArrayList (java.util.ArrayList)33 Operation (io.swagger.v3.oas.annotations.Operation)26 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)26 Response (javax.ws.rs.core.Response)26 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)25 Test (org.testng.annotations.Test)24 Node (org.wso2.charon3.core.utils.codeutils.Node)22 ExpressionNode (org.wso2.charon3.core.utils.codeutils.ExpressionNode)20 IOException (java.io.IOException)19 Node (org.w3c.dom.Node)19 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)17 List (java.util.List)16 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)16 OperationNode (org.wso2.charon3.core.utils.codeutils.OperationNode)16 Artifacts (org.wso2.ei.dashboard.core.rest.model.Artifacts)15 CAppArtifacts (org.wso2.ei.dashboard.core.rest.model.CAppArtifacts)15 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)13 Ack (org.wso2.ei.dashboard.core.rest.model.Ack)13 Map (java.util.Map)12 NodeList (org.w3c.dom.NodeList)12