mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#1551 Use javax.annotation.processing.Generated if it is available and source version is at least RELEASE_9
This commit is contained in:
parent
0e0fd313e5
commit
6d5243dc2f
@ -283,8 +283,8 @@ If the `@Generated` annotation is not available, MapStruct will detect this situ
|
|||||||
|
|
||||||
[NOTE]
|
[NOTE]
|
||||||
=====
|
=====
|
||||||
In Java 9 `java.annotation.processing.Generated` was added, which is considered as a general purpose annotation for any code generators
|
In Java 9 `java.annotation.processing.Generated` was added (part of the `java.compiler` module),
|
||||||
and is part of the `java.compiler` module. Support for it is planned within https://github.com/mapstruct/mapstruct/issues/1551[#1551]
|
if this annotation is available then it will be used.
|
||||||
=====
|
=====
|
||||||
|
|
||||||
[[defining-mapper]]
|
[[defining-mapper]]
|
||||||
|
@ -74,12 +74,18 @@ public abstract class GeneratedType extends ModelElement {
|
|||||||
this.versionInformation = versionInformation;
|
this.versionInformation = versionInformation;
|
||||||
this.accessibility = accessibility;
|
this.accessibility = accessibility;
|
||||||
|
|
||||||
this.generatedTypeAvailable = typeFactory.isTypeAvailable( "javax.annotation.Generated" );
|
if ( versionInformation.isSourceVersionAtLeast9() &&
|
||||||
if ( generatedTypeAvailable ) {
|
typeFactory.isTypeAvailable( "javax.annotation.processing.Generated" ) ) {
|
||||||
|
this.generatedType = typeFactory.getType( "javax.annotation.processing.Generated" );
|
||||||
|
this.generatedTypeAvailable = true;
|
||||||
|
}
|
||||||
|
else if ( typeFactory.isTypeAvailable( "javax.annotation.Generated" ) ) {
|
||||||
this.generatedType = typeFactory.getType( "javax.annotation.Generated" );
|
this.generatedType = typeFactory.getType( "javax.annotation.Generated" );
|
||||||
|
this.generatedTypeAvailable = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.generatedType = null;
|
this.generatedType = null;
|
||||||
|
this.generatedTypeAvailable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.constructor = constructor;
|
this.constructor = constructor;
|
||||||
|
@ -11,6 +11,7 @@ import java.net.URL;
|
|||||||
import java.util.jar.Manifest;
|
import java.util.jar.Manifest;
|
||||||
|
|
||||||
import javax.annotation.processing.ProcessingEnvironment;
|
import javax.annotation.processing.ProcessingEnvironment;
|
||||||
|
import javax.lang.model.SourceVersion;
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.version.VersionInformation;
|
import org.mapstruct.ap.internal.version.VersionInformation;
|
||||||
|
|
||||||
@ -37,15 +38,19 @@ public class DefaultVersionInformation implements VersionInformation {
|
|||||||
private final String runtimeVersion;
|
private final String runtimeVersion;
|
||||||
private final String runtimeVendor;
|
private final String runtimeVendor;
|
||||||
private final String compiler;
|
private final String compiler;
|
||||||
|
private final boolean sourceVersionAtLeast9;
|
||||||
private final boolean eclipseJDT;
|
private final boolean eclipseJDT;
|
||||||
private final boolean javac;
|
private final boolean javac;
|
||||||
|
|
||||||
DefaultVersionInformation(String runtimeVersion, String runtimeVendor, String compiler) {
|
DefaultVersionInformation(String runtimeVersion, String runtimeVendor, String compiler,
|
||||||
|
SourceVersion sourceVersion) {
|
||||||
this.runtimeVersion = runtimeVersion;
|
this.runtimeVersion = runtimeVersion;
|
||||||
this.runtimeVendor = runtimeVendor;
|
this.runtimeVendor = runtimeVendor;
|
||||||
this.compiler = compiler;
|
this.compiler = compiler;
|
||||||
this.eclipseJDT = compiler.startsWith( COMPILER_NAME_ECLIPSE_JDT );
|
this.eclipseJDT = compiler.startsWith( COMPILER_NAME_ECLIPSE_JDT );
|
||||||
this.javac = compiler.startsWith( COMPILER_NAME_JAVAC );
|
this.javac = compiler.startsWith( COMPILER_NAME_JAVAC );
|
||||||
|
// If the difference between the source version and RELEASE_6 is more that 2 than we are at least on 9
|
||||||
|
this.sourceVersionAtLeast9 = sourceVersion.compareTo( SourceVersion.RELEASE_6 ) > 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -68,6 +73,11 @@ public class DefaultVersionInformation implements VersionInformation {
|
|||||||
return this.compiler;
|
return this.compiler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSourceVersionAtLeast9() {
|
||||||
|
return sourceVersionAtLeast9;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEclipseJDTCompiler() {
|
public boolean isEclipseJDTCompiler() {
|
||||||
return eclipseJDT;
|
return eclipseJDT;
|
||||||
@ -84,7 +94,12 @@ public class DefaultVersionInformation implements VersionInformation {
|
|||||||
|
|
||||||
String compiler = getCompiler( processingEnv );
|
String compiler = getCompiler( processingEnv );
|
||||||
|
|
||||||
return new DefaultVersionInformation( runtimeVersion, runtimeVendor, compiler );
|
return new DefaultVersionInformation(
|
||||||
|
runtimeVersion,
|
||||||
|
runtimeVendor,
|
||||||
|
compiler,
|
||||||
|
processingEnv.getSourceVersion()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getCompiler(ProcessingEnvironment processingEnv) {
|
private static String getCompiler(ProcessingEnvironment processingEnv) {
|
||||||
|
@ -19,6 +19,8 @@ public interface VersionInformation {
|
|||||||
|
|
||||||
String getCompiler();
|
String getCompiler();
|
||||||
|
|
||||||
|
boolean isSourceVersionAtLeast9();
|
||||||
|
|
||||||
boolean isEclipseJDTCompiler();
|
boolean isEclipseJDTCompiler();
|
||||||
|
|
||||||
boolean isJavacCompiler();
|
boolean isJavacCompiler();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user