Skip to content

Commit

Permalink
Un-static JavacProblem converter
Browse files Browse the repository at this point in the history
  • Loading branch information
mickaelistria committed Jul 2, 2024
1 parent ed70cd1 commit b8c8b50
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public JavacProblem createJavacProblem(Diagnostic<? extends JavaFileObject> diag
(int) diagnostic.getColumnNumber());
}

private static org.eclipse.jface.text.Position getDiagnosticPosition(Diagnostic<? extends JavaFileObject> diagnostic, Context context) {
private org.eclipse.jface.text.Position getDiagnosticPosition(Diagnostic<? extends JavaFileObject> diagnostic, Context context) {
if (diagnostic.getCode().contains(".dc")) { //javadoc
return getDefaultPosition(diagnostic);
}
Expand Down Expand Up @@ -324,7 +324,7 @@ private int toSeverity(int jdtProblemId, Diagnostic<? extends JavaFileObject> di
* And the examples to reproduce the Javac problems:
* https://github.com/openjdk/jdk/tree/master/test/langtools/tools/javac/diags/examples
*/
public static int toProblemId(Diagnostic<? extends JavaFileObject> diagnostic) {
public int toProblemId(Diagnostic<? extends JavaFileObject> diagnostic) {
String javacDiagnosticCode = diagnostic.getCode();
return switch (javacDiagnosticCode) {
case "compiler.err.expected" -> IProblem.ParsingErrorInsertTokenAfter;
Expand Down Expand Up @@ -442,7 +442,7 @@ private static int convertUnresolvedVariable(Diagnostic<?> diagnostic) {
return IProblem.UnresolvedVariable;
}

private static int convertUndefinedMethod(Diagnostic<?> diagnostic) {
private int convertUndefinedMethod(Diagnostic<?> diagnostic) {
JCDiagnostic diagnosticArg = getDiagnosticArgumentByType(diagnostic, JCDiagnostic.class);
if (diagnosticArg != null) {
Type receiverArg = getDiagnosticArgumentByType(diagnosticArg, Type.class);
Expand All @@ -461,7 +461,7 @@ private static int convertUndefinedMethod(Diagnostic<?> diagnostic) {
return IProblem.UndefinedMethod;
}

private static <T> T getDiagnosticArgumentByType(Diagnostic<?> diagnostic, Class<T> type) {
private <T> T getDiagnosticArgumentByType(Diagnostic<?> diagnostic, Class<T> type) {
if (!(diagnostic instanceof JCDiagnostic jcDiagnostic)) {
return null;
}
Expand All @@ -478,7 +478,7 @@ private static <T> T getDiagnosticArgumentByType(Diagnostic<?> diagnostic, Class
return null;
}

private static Object[] getDiagnosticArguments(Diagnostic<?> diagnostic) {
private Object[] getDiagnosticArguments(Diagnostic<?> diagnostic) {
if (!(diagnostic instanceof JCDiagnostic jcDiagnostic)) {
return new Object[0];
}
Expand All @@ -487,7 +487,7 @@ private static Object[] getDiagnosticArguments(Diagnostic<?> diagnostic) {
}

// compiler.err.prob.found.req -> TypeMismatch, ReturnTypeMismatch, IllegalCast, VoidMethodReturnsValue...
private static int convertTypeMismatch(Diagnostic<?> diagnostic) {
private int convertTypeMismatch(Diagnostic<?> diagnostic) {
Diagnostic<?> diagnosticArg = getDiagnosticArgumentByType(diagnostic, Diagnostic.class);
if (diagnosticArg != null) {
if ("compiler.misc.inconvertible.types".equals(diagnosticArg.getCode())) {
Expand All @@ -505,7 +505,7 @@ private static int convertTypeMismatch(Diagnostic<?> diagnostic) {
return IProblem.TypeMismatch;
}

private static int convertUnresolvedSymbol(Diagnostic<? extends JavaFileObject> javacDiagnostic) {
private int convertUnresolvedSymbol(Diagnostic<? extends JavaFileObject> javacDiagnostic) {
if (javacDiagnostic instanceof JCDiagnostic jcDiagnostic) {
Object[] args = jcDiagnostic.getArgs();
if (args != null) {
Expand All @@ -525,7 +525,7 @@ private static int convertUnresolvedSymbol(Diagnostic<? extends JavaFileObject>
return IProblem.UndefinedName;
}

private static int convertNotVisibleAccess(Diagnostic<?> diagnostic) {
private int convertNotVisibleAccess(Diagnostic<?> diagnostic) {
if (diagnostic instanceof JCDiagnostic jcDiagnostic) {
Object[] args = jcDiagnostic.getArgs();
if (args != null && args.length > 0) {
Expand All @@ -550,7 +550,7 @@ private static int convertNotVisibleAccess(Diagnostic<?> diagnostic) {
return 0;
}

private static int convertAmbiguous(Diagnostic<?> diagnostic) {
private int convertAmbiguous(Diagnostic<?> diagnostic) {
Kinds.KindName kind = getDiagnosticArgumentByType(diagnostic, Kinds.KindName.class);
return switch (kind) {
case CLASS -> IProblem.AmbiguousType;
Expand Down

0 comments on commit b8c8b50

Please sign in to comment.