Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent multiple errors from being reported at the same offset #449

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
package org.eclipse.jdt.internal.javac;

import java.io.IOException;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

import javax.tools.Diagnostic;
import javax.tools.JavaFileObject;
Expand Down Expand Up @@ -49,6 +51,10 @@ public class JavacProblemConverter {
private final CompilerOptions compilerOptions;
private final Context context;

private final Set<FileAndPosition> existingProblems = new HashSet<>();

private final record FileAndPosition(String filePath, int position) {}

public JavacProblemConverter(Map<String, String> options, Context context) {
this(new CompilerOptions(options), context);
}
Expand All @@ -74,6 +80,11 @@ public JavacProblem createJavacProblem(Diagnostic<? extends JavaFileObject> diag
return null;
}
org.eclipse.jface.text.Position diagnosticPosition = getDiagnosticPosition(diagnostic, context);
FileAndPosition fileAndPosition = new FileAndPosition(diagnostic.getSource().toUri().toString(), diagnosticPosition.getOffset());
if (existingProblems.contains(fileAndPosition)) {
return null;
}
existingProblems.add(fileAndPosition);
return new JavacProblem(
diagnostic.getSource().getName().toCharArray(),
diagnostic.getMessage(Locale.getDefault()),
Expand Down
Loading