[jOOQ/jOOQ#15619] On JDK 21, generated code should apply "this-escape" warning suppression
This commit is contained in:
parent
70f2c22335
commit
af4324acbe
@ -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"));
|
||||
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user