mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#900 Use "@Generated" only when it's available on the classpath.
This commit is contained in:
parent
4297c0cd72
commit
f8bb31f98d
@ -24,7 +24,6 @@ import java.util.List;
|
|||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import javax.annotation.Generated;
|
|
||||||
import javax.lang.model.type.TypeKind;
|
import javax.lang.model.type.TypeKind;
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.model.common.Accessibility;
|
import org.mapstruct.ap.internal.model.common.Accessibility;
|
||||||
@ -64,6 +63,7 @@ public abstract class GeneratedType extends ModelElement {
|
|||||||
* Type representing the {@code @Generated} annotation
|
* Type representing the {@code @Generated} annotation
|
||||||
*/
|
*/
|
||||||
private final Type generatedType;
|
private final Type generatedType;
|
||||||
|
private final boolean generatedTypeAvailable;
|
||||||
|
|
||||||
// CHECKSTYLE:OFF
|
// CHECKSTYLE:OFF
|
||||||
protected GeneratedType(TypeFactory typeFactory, String packageName, String name, String superClassName,
|
protected GeneratedType(TypeFactory typeFactory, String packageName, String name, String superClassName,
|
||||||
@ -91,7 +91,14 @@ public abstract class GeneratedType extends ModelElement {
|
|||||||
this.versionInformation = versionInformation;
|
this.versionInformation = versionInformation;
|
||||||
this.accessibility = accessibility;
|
this.accessibility = accessibility;
|
||||||
|
|
||||||
this.generatedType = typeFactory.getType( Generated.class );
|
this.generatedTypeAvailable = typeFactory.isTypeAvailable( "javax.annotation.Generated" );
|
||||||
|
if ( generatedTypeAvailable ) {
|
||||||
|
this.generatedType = typeFactory.getType( "javax.annotation.Generated" );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.generatedType = null;
|
||||||
|
}
|
||||||
|
|
||||||
this.constructor = constructor;
|
this.constructor = constructor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,6 +152,10 @@ public abstract class GeneratedType extends ModelElement {
|
|||||||
return suppressGeneratorVersionComment;
|
return suppressGeneratorVersionComment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isGeneratedTypeAvailable() {
|
||||||
|
return generatedTypeAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
public VersionInformation getVersionInformation() {
|
public VersionInformation getVersionInformation() {
|
||||||
return versionInformation;
|
return versionInformation;
|
||||||
}
|
}
|
||||||
@ -156,7 +167,7 @@ public abstract class GeneratedType extends ModelElement {
|
|||||||
@Override
|
@Override
|
||||||
public SortedSet<Type> getImportTypes() {
|
public SortedSet<Type> getImportTypes() {
|
||||||
SortedSet<Type> importedTypes = new TreeSet<Type>();
|
SortedSet<Type> importedTypes = new TreeSet<Type>();
|
||||||
importedTypes.add( generatedType );
|
addIfImportRequired( importedTypes, generatedType );
|
||||||
|
|
||||||
for ( MappingMethod mappingMethod : methods ) {
|
for ( MappingMethod mappingMethod : methods ) {
|
||||||
for ( Type type : mappingMethod.getImportTypes() ) {
|
for ( Type type : mappingMethod.getImportTypes() ) {
|
||||||
|
@ -24,11 +24,13 @@ package ${packageName};
|
|||||||
import ${importedType.importName};
|
import ${importedType.importName};
|
||||||
</#list>
|
</#list>
|
||||||
|
|
||||||
|
<#if !generatedTypeAvailable>/*</#if>
|
||||||
@Generated(
|
@Generated(
|
||||||
value = "org.mapstruct.ap.MappingProcessor"<#if suppressGeneratorTimestamp == false>,
|
value = "org.mapstruct.ap.MappingProcessor"<#if suppressGeneratorTimestamp == false>,
|
||||||
date = "${.now?string("yyyy-MM-dd'T'HH:mm:ssZ")}"</#if><#if suppressGeneratorVersionComment == false>,
|
date = "${.now?string("yyyy-MM-dd'T'HH:mm:ssZ")}"</#if><#if suppressGeneratorVersionComment == false>,
|
||||||
comments = "version: ${versionInformation.mapStructVersion}, compiler: ${versionInformation.compiler}, environment: Java ${versionInformation.runtimeVersion} (${versionInformation.runtimeVendor})"</#if>
|
comments = "version: ${versionInformation.mapStructVersion}, compiler: ${versionInformation.compiler}, environment: Java ${versionInformation.runtimeVersion} (${versionInformation.runtimeVendor})"</#if>
|
||||||
)
|
)<#if !generatedTypeAvailable>
|
||||||
|
*/</#if>
|
||||||
<#list annotations as annotation>
|
<#list annotations as annotation>
|
||||||
<#nt><@includeModel object=annotation/>
|
<#nt><@includeModel object=annotation/>
|
||||||
</#list>
|
</#list>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user