public class CompileUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
JDK8_GEN_CLASS |
static String |
JDK9UP_GEN_CLASS |
| Modifier and Type | Method and Description |
|---|---|
static String |
getGeneratedAnnotationClassName(int jdkMajorVersion)
Determine the correct 'Generated' annotation class name based on the Java major version.
|
static int |
getMajorJavaVersion()
The major version number of the current runtime.
|
static int |
getMajorJavaVersion(SourceVersion srcVersion)
Determine the major version from the SourceVersion.
|
static int |
getMajorJavaVersion(String versionString)
Determine the major version from the java.version System property String.
|
static boolean |
isGeneratedVersionDeterministic(int sourceVersion,
int jdkMajorVersion)
Do we know for sure which JDK version to generate for?
|
public static final String JDK8_GEN_CLASS
public static final String JDK9UP_GEN_CLASS
public static String getGeneratedAnnotationClassName(int jdkMajorVersion)
@javax.annotation.Generated annotation to mark a generated class.
Java 9 and beyond uses @javax.annotation.processing.Generated
Both annotations are SOURCE level retention, so they are only present in the source code and no record of them is compiled into the binary. Thus, the determination of which one to use is based only on the Java version used to compile, not the -source or -target settings.
jdkMajorVersion - The Java version in integer form. Use '8' for 1.8.public static boolean isGeneratedVersionDeterministic(int sourceVersion,
int jdkMajorVersion)
There is one case that cannot be determined: When
ProcessingEnvironment.getSourceVersion() reports version 8* and the current JDK is
greater than 8. See https://github.com/eeverman/andhow/issues/630
*Source versions less than 8 are not supported by AndHow.
sourceVersion - jdkMajorVersion - public static int getMajorJavaVersion(SourceVersion srcVersion)
SourceVersion is available at compile time to the AnnotationProcessor and it marks the Java version that the source code needs to be compatible with. This may be different than the current JDK.
srcVersion - As given to the AnnotationProcessor in the ProcessingEnvironment.public static int getMajorJavaVersion()
This uses the System.getProperty("java.version") and the
getMajorJavaVersion(String) method.
public static int getMajorJavaVersion(String versionString)
The java.version string is parsed and major version returned. All versions are integers, thus version `1.8` returns `8`, JDK '10' return 10. A RuntimeException is thrown if the version cannot be parsed.
Java 10 introduces the Runtime.version(), which would remove the need for this method, however, its not available in JDK 8.
versionString - as returned from System.getProperty("java.version")Copyright © 2022. All rights reserved.