public static boolean isDiagnosticCovering(Diagnostic diag, TextDocumentInfo doc, String string) { Range rng = diag.getRange(); String actualText = doc.getText(rng); return string.equals(actualText); }
public Quickfix(String CODE_ACTION_CMD_ID, Diagnostic diag, QuickfixData<T> data) { super(); this.CODE_ACTION_CMD_ID = CODE_ACTION_CMD_ID; this.range = diag.getRange(); this.diagMsg = diag.getMessage(); this.data = data; }
private String problemSumary(Editor editor, List<Diagnostic> actualProblems) throws Exception { StringBuilder buf = new StringBuilder(); for (Diagnostic p : actualProblems) { buf.append("\n----------------------\n"); String snippet = editor.getText(p.getRange()); buf.append("("+p.getRange().getStart().getLine()+", "+p.getRange().getStart().getCharacter()+")["+snippet+"]:\n"); buf.append(" "+p.getMessage()); } return buf.toString(); }
private 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 problemId = getProblemId(diagnostic); int start = DiagnosticsHelper.getStartOffset(unit, diagnostic.getRange()); int end = DiagnosticsHelper.getEndOffset(unit, diagnostic.getRange()); boolean isError = diagnostic.getSeverity() == DiagnosticSeverity.Error; locations[i] = new ProblemLocationCore(start, end - start, problemId, new String[0], isError, IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER); } return locations; }
@Override public int compare(Diagnostic o1, Diagnostic o2) { int diff = compare(o1.getRange().getStart(), o2.getRange().getStart()); if (diff!=0) return diff; diff = compare(o1.getRange().getEnd(), o2.getRange().getEnd()); if (diff!=0) return diff; return o1.getMessage().compareTo(o2.getMessage()); }
public List<CodeAction> getCodeActions(TextDocumentInfo doc, Diagnostic problem) throws Exception { CodeActionContext context = new CodeActionContext(ImmutableList.of(problem)); List<Either<Command, org.eclipse.lsp4j.CodeAction>> actions = getServer().getTextDocumentService().codeAction(new CodeActionParams(doc.getId(), problem.getRange(), context)).get(); return actions.stream() .map(e -> e.getLeft()) .map((command) -> new CodeAction(this, command)) .collect(Collectors.toList()); }
public static Condition<Diagnostic> isDiagnosticOnLine(int line) { return new Condition<>( (d) -> d.getRange().getStart().getLine()==line, "Diagnostic on line "+line ); }
boolean emptyRange = problem.getRange().getStart().equals(problem.getRange().getEnd()); String actualBadSnippet = emptyRange ? getCharAt(problem.getRange().getStart()) : getText(problem.getRange()); if (!spaceSensitive) { actualBadSnippet = actualBadSnippet.trim(); int start = doc.toOffset(problem.getRange().getStart()); int end = doc.toOffset(problem.getRange().getEnd());
/** * Get a problem that covers the given text in the editor. Throws exception * if no matching problem is found. */ public Diagnostic assertProblem(String coveredText) throws Exception { Editor editor = this; List<Diagnostic> problems = editor.reconcile(); for (Diagnostic p : problems) { String c = editor.getText(p.getRange()); if (c.equals(coveredText)) { return p; } } fail("No problem found covering the text '"+coveredText+"' in: \n" + problemSumary(editor, problems) ); return null; //unreachable but compiler doesn't know }
if (line == diagnostic.getRange().getStart().getLine()) { commands.addAll(CommandUtil.getCommandsByDiagnostic(diagnostic, params));
Diagnostic clone(Diagnostic diagnostic) { if (diagnostic == null) { return null; } String code = diagnostic.getCode(); String message = diagnostic.getMessage(); Range range = diagnostic.getRange(); List<DiagnosticRelatedInformation> relatedInformation = diagnostic.getRelatedInformation(); DiagnosticSeverity severity = diagnostic.getSeverity(); String source = diagnostic.getSource(); Diagnostic cloned = new Diagnostic(); cloned.setCode(code); cloned.setMessage(message); cloned.setRange(clone(range)); cloned.setRelatedInformation(cloneDRI(relatedInformation)); cloned.setSeverity(severity); cloned.setSource(source); return cloned; }