Search in sources :

Example 86 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project ballerina by ballerina-lang.

the class CommonUtil method prepareTempCompilerContext.

/**
 * Prepare a new compiler context.
 * @return {@link CompilerContext} Prepared compiler context
 */
public static CompilerContext prepareTempCompilerContext() {
    CompilerContext context = new CompilerContext();
    CompilerOptions options = CompilerOptions.getInstance(context);
    options.put(PROJECT_DIR, "");
    options.put(COMPILER_PHASE, CompilerPhase.DESUGAR.toString());
    options.put(PRESERVE_WHITESPACE, "false");
    context.put(SourceDirectory.class, new NullSourceDirectory());
    return context;
}
Also used : CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) CompilerOptions(org.wso2.ballerinalang.compiler.util.CompilerOptions) NullSourceDirectory(org.ballerinalang.langserver.workspace.repository.NullSourceDirectory)

Example 87 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project ballerina by ballerina-lang.

the class TreeVisitor method isCursorWithinEndpointDef.

/**
 * Check whether the cursor is within the endpoint definition node.
 * @param nodePosition  Diagnostic position of the current node
 * @return              {@link Boolean} whether the cursor is within the node or not
 */
private boolean isCursorWithinEndpointDef(DiagnosticPos nodePosition) {
    int line = documentServiceContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getLine();
    int column = documentServiceContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getCharacter();
    int nodeSLine = nodePosition.sLine;
    int nodeELine = nodePosition.eLine;
    int nodeSCol = nodePosition.sCol;
    int nodeECol = nodePosition.eCol;
    return (line > nodeSLine && line < nodeELine) || (line > nodeSLine && line == nodeELine && column < nodeECol) || (line == nodeSLine && column > nodeSCol && line < nodeELine) || (line == nodeSLine && line == nodeELine && column > nodeSCol && column < nodeECol);
}
Also used : BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 88 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project ballerina by ballerina-lang.

the class HoverUtil method getDocumentationContent.

/**
 * Get documentation content.
 *
 * @param docAnnotation list of doc annotation
 * @return {@link Hover} hover object.
 */
private static Hover getDocumentationContent(List<BLangDocumentation> docAnnotation) {
    Hover hover = new Hover();
    StringBuilder content = new StringBuilder();
    BLangDocumentation bLangDocumentation = docAnnotation.get(0);
    Map<String, List<BLangDocumentationAttribute>> filterAttributes = filterDocumentationAttributes(docAnnotation.get(0));
    if (!bLangDocumentation.documentationText.isEmpty()) {
        content.append(getFormattedHoverDocContent(ContextConstants.DESCRIPTION, bLangDocumentation.documentationText));
    }
    if (filterAttributes.get(ContextConstants.DOC_RECEIVER) != null) {
        content.append(getFormattedHoverDocContent(ContextConstants.DOC_RECEIVER, getDocAttributes(filterAttributes.get(ContextConstants.DOC_RECEIVER))));
    }
    if (filterAttributes.get(ContextConstants.DOC_PARAM) != null) {
        content.append(getFormattedHoverDocContent(ContextConstants.DOC_PARAM, getDocAttributes(filterAttributes.get(ContextConstants.DOC_PARAM))));
    }
    if (filterAttributes.get(ContextConstants.DOC_FIELD) != null) {
        content.append(getFormattedHoverDocContent(ContextConstants.DOC_FIELD, getDocAttributes(filterAttributes.get(ContextConstants.DOC_FIELD))));
    }
    if (filterAttributes.get(ContextConstants.DOC_RETURN) != null) {
        content.append(getFormattedHoverDocContent(ContextConstants.DOC_RETURN, getDocAttributes(filterAttributes.get(ContextConstants.DOC_RETURN))));
    }
    if (filterAttributes.get(ContextConstants.DOC_VARIABLE) != null) {
        content.append(getFormattedHoverDocContent(ContextConstants.DOC_VARIABLE, getDocAttributes(filterAttributes.get(ContextConstants.DOC_VARIABLE))));
    }
    List<Either<String, MarkedString>> contents = new ArrayList<>();
    contents.add(Either.forLeft(content.toString()));
    hover.setContents(contents);
    return hover;
}
Also used : Hover(org.eclipse.lsp4j.Hover) ArrayList(java.util.ArrayList) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) ArrayList(java.util.ArrayList) List(java.util.List) MarkedString(org.eclipse.lsp4j.MarkedString)

Example 89 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project ballerina by ballerina-lang.

the class RenameUtil method getRenameTextEdits.

/**
 * Get the list of rename related TextEdits.
 *
 * @param locationList      List of locations of occurrences
 * @param documentManager   {@link WorkspaceDocumentManager} instance
 * @param newName           New name to be replaced with
 * @param replaceSymbolName Symbol name being replaced
 * @return {@link List}         List of TextEdits
 */
public static List<TextDocumentEdit> getRenameTextEdits(List<Location> locationList, WorkspaceDocumentManager documentManager, String newName, String replaceSymbolName) {
    Map<String, ArrayList<Location>> documentLocationMap = new HashMap<>();
    List<TextDocumentEdit> documentEdits = new ArrayList<>();
    Comparator<Location> locationComparator = (location1, location2) -> location1.getRange().getStart().getCharacter() - location2.getRange().getStart().getCharacter();
    locationList.forEach(location -> {
        if (documentLocationMap.containsKey(location.getUri())) {
            documentLocationMap.get(location.getUri()).add(location);
        } else {
            documentLocationMap.put(location.getUri(), (ArrayList<Location>) Lists.of(location));
        }
    });
    documentLocationMap.forEach((uri, locations) -> {
        Collections.sort(locations, locationComparator);
        String fileContent = documentManager.getFileContent(CommonUtil.getPath(new LSDocument(uri)));
        String[] contentComponents = fileContent.split("\\n|\\r\\n|\\r");
        int lastNewLineCharIndex = Math.max(fileContent.lastIndexOf("\n"), fileContent.lastIndexOf("\r"));
        int lastCharCol = fileContent.substring(lastNewLineCharIndex + 1).length();
        for (Location location : locations) {
            int line = location.getRange().getStart().getLine();
            StringBuilder lineComponent = new StringBuilder(contentComponents[line]);
            int index = lineComponent.indexOf(replaceSymbolName);
            while (index >= 0) {
                char previousChar = lineComponent.charAt(index - 1);
                if (Character.isLetterOrDigit(previousChar) || String.valueOf(previousChar).equals("_")) {
                    index = lineComponent.indexOf(replaceSymbolName, index + replaceSymbolName.length());
                } else {
                    lineComponent.replace(index, index + replaceSymbolName.length(), newName);
                    index = lineComponent.indexOf(replaceSymbolName, index + newName.length());
                }
            }
            contentComponents[line] = lineComponent.toString();
        }
        Range range = new Range(new Position(0, 0), new Position(contentComponents.length, lastCharCol));
        TextEdit textEdit = new TextEdit(range, String.join("\r\n", Arrays.asList(contentComponents)));
        VersionedTextDocumentIdentifier textDocumentIdentifier = new VersionedTextDocumentIdentifier();
        textDocumentIdentifier.setUri(uri);
        TextDocumentEdit textDocumentEdit = new TextDocumentEdit(textDocumentIdentifier, Collections.singletonList(textEdit));
        documentEdits.add(textDocumentEdit);
    });
    return documentEdits;
}
Also used : CommonUtil(org.ballerinalang.langserver.common.utils.CommonUtil) Arrays(java.util.Arrays) Range(org.eclipse.lsp4j.Range) HashMap(java.util.HashMap) Lists(org.wso2.ballerinalang.util.Lists) ArrayList(java.util.ArrayList) LSDocument(org.ballerinalang.langserver.common.LSDocument) List(java.util.List) TextEdit(org.eclipse.lsp4j.TextEdit) TextDocumentEdit(org.eclipse.lsp4j.TextDocumentEdit) Map(java.util.Map) Location(org.eclipse.lsp4j.Location) Position(org.eclipse.lsp4j.Position) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) WorkspaceDocumentManager(org.ballerinalang.langserver.workspace.WorkspaceDocumentManager) RenameParams(org.eclipse.lsp4j.RenameParams) Comparator(java.util.Comparator) Collections(java.util.Collections) HashMap(java.util.HashMap) Position(org.eclipse.lsp4j.Position) ArrayList(java.util.ArrayList) TextDocumentEdit(org.eclipse.lsp4j.TextDocumentEdit) Range(org.eclipse.lsp4j.Range) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) LSDocument(org.ballerinalang.langserver.common.LSDocument) TextEdit(org.eclipse.lsp4j.TextEdit) Location(org.eclipse.lsp4j.Location)

Example 90 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link 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)

Aggregations

PreparedStatement (java.sql.PreparedStatement)47 ArrayList (java.util.ArrayList)47 Connection (java.sql.Connection)43 SQLException (java.sql.SQLException)41 ResultSet (java.sql.ResultSet)37 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)26 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)18 HashSet (java.util.HashSet)16 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)15 IOException (java.io.IOException)14 HashMap (java.util.HashMap)14 List (java.util.List)13 Map (java.util.Map)13 Expression (org.wso2.siddhi.query.api.expression.Expression)13 CompilerContext (org.wso2.ballerinalang.compiler.util.CompilerContext)12 TimeConstant (org.wso2.siddhi.query.api.expression.constant.TimeConstant)12 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)11 API (org.wso2.carbon.apimgt.core.models.API)11 UserStoreException (org.wso2.carbon.user.api.UserStoreException)10 SiddhiQLParser (org.wso2.siddhi.query.compiler.SiddhiQLParser)10