[jOOQ/jOOQ#15619] On JDK 21, generated code should apply "this-escape" warning suppression

This commit is contained in:
Lukas Eder 2023-09-28 14:37:17 +02:00
parent 70f2c22335
commit af4324acbe
2 changed files with 36 additions and 0 deletions

View File

@ -10222,6 +10222,8 @@ public class JavaGenerator extends AbstractGenerator {
if (scala) {}
else if (kotlin)
out.println("@Suppress(\"UNCHECKED_CAST\")");
else if (Internal.javaVersion() >= 21)
out.println("@%s({ \"all\", \"unchecked\", \"rawtypes\", \"this-escape\" })", out.ref("java.lang.SuppressWarnings"));
else
out.println("@%s({ \"all\", \"unchecked\", \"rawtypes\" })", out.ref("java.lang.SuppressWarnings"));

View File

@ -107,6 +107,8 @@ import org.jooq.exception.DataAccessException;
import org.jooq.exception.DataTypeException;
import org.jooq.impl.QOM.CreateTable;
import org.jooq.impl.QOM.GenerationLocation;
import org.jooq.tools.reflect.Reflect;
import org.jooq.tools.reflect.ReflectException;
// ...
// ...
@ -997,4 +999,36 @@ public final class Internal {
public static final ConverterContext converterContext() {
return CONVERTER_SCOPE.get();
}
private static final Lazy<Integer> JAVA_VERSION = Lazy.of(() -> {
try {
return Reflect.onClass(Runtime.class)
// Since Java 9
.call("version")
// Since Java 10
.call("feature")
.get();
}
catch (ReflectException e) {
return 8;
}
});
/**
* Get the Java version (relevant to jOOQ) as an int.
* <p>
* Supported versions are:
* <ul>
* <li>8</li>
* <li>11</li>
* <li>17</li>
* <li>21</li>
* </ul>
*/
public static final int javaVersion() {
return JAVA_VERSION.get();
}
}