Skip to content

Commit

Permalink
Prevent multiple errors from being reported at the same offset
Browse files Browse the repository at this point in the history
Fixes #320

Signed-off-by: David Thompson <davthomp@redhat.com>
  • Loading branch information
datho7561 committed Jun 3, 2024
1 parent 1315ae5 commit d14dedb
Showing 1 changed file with 11 additions and 0 deletions.
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

0 comments on commit d14dedb

Please sign in to comment.