@Override public IProblemRequestor getProblemRequestor(ICompilationUnit cu) { return new DiagnosticsHandler(connection, cu); } }
@Override public void acceptProblem(IProblem problem) { if (reportAllErrors || isSyntaxLikeError(problem)) { problems.add(problem); } }
public static List<Diagnostic> toDiagnosticsArray(IOpenable openable, List<IProblem> problems) { List<Diagnostic> array = new ArrayList<>(problems.size()); for (IProblem problem : problems) { Diagnostic diag = new Diagnostic(); diag.setSource(JavaLanguageServerPlugin.SERVER_SOURCE_ID); diag.setMessage(problem.getMessage()); diag.setCode(Integer.toString(problem.getID())); diag.setSeverity(convertSeverity(problem)); diag.setRange(convertRange(openable, problem)); array.add(diag); } return array; }
new DiagnosticsHandler(connection, unit).clearDiagnostics(); } else if (unit.hasUnsavedChanges()) { unit.discardWorkingCopy();
@Override public void endReporting() { JavaLanguageServerPlugin.logInfo(problems.size() + " problems reported for " + this.uri.substring(this.uri.lastIndexOf('/'))); PublishDiagnosticsParams $ = new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), toDiagnosticsArray(this.cu, problems)); this.connection.publishDiagnostics($); }
default: String error = getError(problem); JavaLanguageServerPlugin.logInfo(problem.getMessage() + " is of type " + error);
private void publishDiagnostics(ICompilationUnit unit, IProgressMonitor monitor) throws JavaModelException { final DiagnosticsHandler handler = new DiagnosticsHandler(connection, unit); WorkingCopyOwner wcOwner = new WorkingCopyOwner() { /* (non-Javadoc) * @see org.eclipse.jdt.core.WorkingCopyOwner#createBuffer(org.eclipse.jdt.core.ICompilationUnit) */ @Override public IBuffer createBuffer(ICompilationUnit workingCopy) { ICompilationUnit original = workingCopy.getPrimary(); IResource resource = original.getResource(); if (resource instanceof IFile) { return new DocumentAdapter(workingCopy, (IFile) resource); } return DocumentAdapter.Null; } /* (non-Javadoc) * @see org.eclipse.jdt.core.WorkingCopyOwner#getProblemRequestor(org.eclipse.jdt.core.ICompilationUnit) */ @Override public IProblemRequestor getProblemRequestor(ICompilationUnit workingCopy) { return handler; } }; unit.reconcile(ICompilationUnit.NO_AST, true, wcOwner, monitor); }