Search in sources :

Example 1 with ProblemLocationCore

use of org.eclipse.jdt.internal.ui.text.correction.ProblemLocationCore in project eclipse.jdt.ls by eclipse.

the class CodeActionHandler method getProblemLocationCores.

public static IProblemLocationCore[] getProblemLocationCores(ICompilationUnit unit, List<Diagnostic> diagnostics) {
    IProblemLocationCore[] locations = new IProblemLocationCore[diagnostics.size()];
    for (int i = 0; i < diagnostics.size(); i++) {
        Diagnostic diagnostic = diagnostics.get(i);
        int start = DiagnosticsHelper.getStartOffset(unit, diagnostic.getRange());
        int end = DiagnosticsHelper.getEndOffset(unit, diagnostic.getRange());
        boolean isError = diagnostic.getSeverity() == DiagnosticSeverity.Error;
        int problemId = getProblemId(diagnostic);
        List<String> arguments = new ArrayList<>();
        if (diagnostic.getData() instanceof JsonArray) {
            final JsonArray data = (JsonArray) diagnostic.getData();
            for (JsonElement e : data) {
                arguments.add(e.getAsString());
            }
        }
        locations[i] = new ProblemLocationCore(start, end - start, problemId, arguments.toArray(new String[0]), isError, IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
    }
    return locations;
}
Also used : JsonArray(com.google.gson.JsonArray) IProblemLocationCore(org.eclipse.jdt.internal.ui.text.correction.IProblemLocationCore) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) Diagnostic(org.eclipse.lsp4j.Diagnostic) ProblemLocationCore(org.eclipse.jdt.internal.ui.text.correction.ProblemLocationCore) IProblemLocationCore(org.eclipse.jdt.internal.ui.text.correction.IProblemLocationCore)

Aggregations

JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 ArrayList (java.util.ArrayList)1 IProblemLocationCore (org.eclipse.jdt.internal.ui.text.correction.IProblemLocationCore)1 ProblemLocationCore (org.eclipse.jdt.internal.ui.text.correction.ProblemLocationCore)1 Diagnostic (org.eclipse.lsp4j.Diagnostic)1