[jdk25] Fix support for generated warnings

This commit is contained in:
Rawi01 committed 2025-07-26 12:49:55 +02:00
1 parent 4e1542fc5e
commit 39361edfc8
1 file changed
+13 -25
+13 -25
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2020 The Project Lombok Authors.
* Copyright (C) 2009-2025 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -41,6 +41,7 @@ import lombok.core.CleanupRegistry;
import lombok.core.CleanupTask;
import lombok.permit.Permit;
import com.sun.tools.javac.code.Lint.LintCategory;
import com.sun.tools.javac.code.Source;
import com.sun.tools.javac.code.Symtab;
import com.sun.tools.javac.model.JavacElements;
@@ -581,9 +582,6 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> {
case ERROR:
errorLogger.error(pos, message);
break;
case MANDATORY_WARNING:
errorLogger.mandatoryWarning(pos, message);
break;
case WARNING:
errorLogger.warning(pos, message);
break;
@@ -658,14 +656,8 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> {
warning1(pos, message);
}
final void mandatoryWarning(DiagnosticPosition pos, String message) {
increment(warningCount);
mandatoryWarning1(pos, message);
}
abstract void error1(DiagnosticPosition pos, String message);
abstract void warning1(DiagnosticPosition pos, String message);
abstract void mandatoryWarning1(DiagnosticPosition pos, String message);
abstract void note(DiagnosticPosition pos, String message);
private void increment(Field field) {
@@ -689,7 +681,6 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> {
for (Field field : log.getClass().getFields()) {
if (field.getName().equals("multipleErrors")) {
hasMultipleErrors = true;
break;
}
}
if (hasMultipleErrors) return new JdkBefore9(log, messager, errorCount);
@@ -723,10 +714,6 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> {
log.warning(pos, "proc.messager", message);
}
@Override void mandatoryWarning1(DiagnosticPosition pos, String message) {
log.mandatoryWarning(pos, "proc.messager", message);
}
@Override void note(DiagnosticPosition pos, String message) {
log.note(pos, "proc.messager", message);
}
@@ -735,7 +722,7 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> {
static class Jdk9Plus extends ErrorLog {
private static final String PROC_MESSAGER = "proc.messager";
private Object multiple;
private Method errorMethod, warningMethod, mandatoryWarningMethod, noteMethod;
private Method errorMethod, warningMethod, noteMethod;
private Method errorKey, warningKey, noteKey;
private JCDiagnostic.Factory diags;
@@ -756,7 +743,6 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> {
Class<?> lc = log.getClass();
this.errorMethod = Permit.getMethod(lc, "error", df, DiagnosticPosition.class, errorCls);
this.warningMethod = Permit.getMethod(lc, "warning", DiagnosticPosition.class, warningCls);
this.mandatoryWarningMethod = Permit.getMethod(lc, "mandatoryWarning", DiagnosticPosition.class, warningCls);
this.noteMethod = Permit.getMethod(lc, "note", DiagnosticPosition.class, noteCls);
Field diagsField = Permit.getField(lc.getSuperclass(), "diags");
@@ -764,7 +750,10 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> {
Class<?> dc = this.diags.getClass();
this.errorKey = Permit.getMethod(dc, "errorKey", String.class, Object[].class);
this.warningKey = Permit.getMethod(dc, "warningKey", String.class, Object[].class);
this.warningKey = Permit.permissiveGetMethod(dc, "warningKey", String.class, Object[].class);
if (warningKey == null) {
this.warningKey = Permit.getMethod(dc, "warningKey", LintCategory.class, String.class, Object[].class);
}
this.noteKey = Permit.getMethod(dc, "noteKey", String.class, Object[].class);
} catch (Throwable t) {
//t.printStackTrace();
@@ -778,16 +767,15 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> {
@Override
void warning1(DiagnosticPosition pos, String message) {
Object warning = Permit.invokeSneaky(this.warningKey, diags, PROC_MESSAGER, new Object[] { message });
Object warning;
if (this.warningKey.getParameterTypes().length == 3) {
warning = Permit.invokeSneaky(this.warningKey, diags, null, PROC_MESSAGER, new Object[] { message });
} else {
warning = Permit.invokeSneaky(this.warningKey, diags, PROC_MESSAGER, new Object[] { message });
}
if (warning != null) Permit.invokeSneaky(warningMethod, log, pos, warning);
}
@Override
void mandatoryWarning1(DiagnosticPosition pos, String message) {
Object warning = Permit.invokeSneaky(this.warningKey, diags, PROC_MESSAGER, new Object[] { message });
if (warning != null) Permit.invokeSneaky(mandatoryWarningMethod, log, pos, warning);
}
@Override
void note(DiagnosticPosition pos, String message) {
Object note = Permit.invokeSneaky(this.noteKey, diags, PROC_MESSAGER, new Object[] { message });