Skip to content

Commit

Permalink
Don't use scanner tokens if the diagnostic length is non-zero
Browse files Browse the repository at this point in the history
Signed-off-by: David Thompson <davthomp@redhat.com>
  • Loading branch information
datho7561 authored and mickaelistria committed May 27, 2024
1 parent 432816e commit 23d8dff
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public JavacProblemConverter(CompilerOptions options, Context context) {
}

/**
*
*
* @param diagnostic
* @param context
* @return a JavacProblem matching the given diagnostic, or <code>null</code> if problem is ignored
Expand Down Expand Up @@ -86,7 +86,7 @@ public JavacProblem createJavacProblem(Diagnostic<? extends JavaFileObject> diag
(int) diagnostic.getLineNumber(),
(int) diagnostic.getColumnNumber());
}

private static org.eclipse.jface.text.Position getDiagnosticPosition(Diagnostic<? extends JavaFileObject> diagnostic, Context context) {
if (diagnostic.getCode().contains(".dc")) { //javadoc
return getDefaultPosition(diagnostic);
Expand All @@ -105,7 +105,9 @@ private static org.eclipse.jface.text.Position getDiagnosticPosition(Diagnostic<
if (result != null) {
return result;
}
return getPositionUsingScanner(jcDiagnostic, context);
if (jcDiagnostic.getStartPosition() == jcDiagnostic.getEndPosition()) {
return getPositionUsingScanner(jcDiagnostic, context);
}
}
}
}
Expand Down Expand Up @@ -135,7 +137,7 @@ private static org.eclipse.jface.text.Position getPositionUsingScanner(JCDiagnos
Token prev = javacScanner.prevToken();
if( prev != null ) {
if( t.endPos == prev.endPos && t.pos == prev.pos && t.kind.equals(prev.kind)) {
t = null; // We're stuck in a loop. Give up.
t = null; // We're stuck in a loop. Give up.
}
}
}
Expand Down Expand Up @@ -291,7 +293,7 @@ private int toSeverity(int jdtProblemId, Diagnostic<? extends JavaFileObject> di
default -> ProblemSeverities.Error;
};
}

/**
* See the link below for Javac problem list:
* https://github.com/openjdk/jdk/blob/master/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties
Expand Down

0 comments on commit 23d8dff

Please sign in to comment.