mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#2895 Generate more readable annotations
This commit is contained in:
parent
68571de01b
commit
21069e5a2e
@ -6,4 +6,17 @@
|
|||||||
|
|
||||||
-->
|
-->
|
||||||
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.Annotation" -->
|
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.Annotation" -->
|
||||||
@<@includeModel object=type/><#if (properties?size > 0) >(<#list properties as property><@includeModel object=property/><#if property_has_next>, </#if></#list>)</#if>
|
<#switch properties?size>
|
||||||
|
<#case 0>
|
||||||
|
@<@includeModel object=type/><#rt>
|
||||||
|
<#break>
|
||||||
|
<#case 1>
|
||||||
|
@<@includeModel object=type/>(<@includeModel object=properties[0]/>)<#rt>
|
||||||
|
<#break>
|
||||||
|
<#default>
|
||||||
|
@<@includeModel object=type/>(
|
||||||
|
<#list properties as property>
|
||||||
|
<#nt><@includeModel object=property/><#if property_has_next>,</#if>
|
||||||
|
</#list>
|
||||||
|
)<#rt>
|
||||||
|
</#switch>
|
@ -42,8 +42,13 @@ public class AnnotateWithTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ProcessorTest
|
@ProcessorTest
|
||||||
@WithClasses( { CustomNamedMapper.class, CustomAnnotationWithParamsContainer.class,
|
@WithClasses( {
|
||||||
CustomAnnotationWithParams.class } )
|
CustomNamedMapper.class,
|
||||||
|
CustomAnnotationWithParamsContainer.class,
|
||||||
|
CustomAnnotationWithParams.class,
|
||||||
|
CustomClassOnlyAnnotation.class,
|
||||||
|
CustomMethodOnlyAnnotation.class,
|
||||||
|
} )
|
||||||
public void annotationWithValue() {
|
public void annotationWithValue() {
|
||||||
generatedSource.addComparisonToFixtureFor( CustomNamedMapper.class );
|
generatedSource.addComparisonToFixtureFor( CustomNamedMapper.class );
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import org.mapstruct.Mapper;
|
|||||||
* @author Ben Zegveld
|
* @author Ben Zegveld
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
|
@AnnotateWith( CustomClassOnlyAnnotation.class )
|
||||||
@AnnotateWith( value = CustomAnnotationWithParams.class, elements = {
|
@AnnotateWith( value = CustomAnnotationWithParams.class, elements = {
|
||||||
@Element( name = "stringArray", strings = "test" ),
|
@Element( name = "stringArray", strings = "test" ),
|
||||||
@Element( name = "stringParam", strings = "test" ),
|
@Element( name = "stringParam", strings = "test" ),
|
||||||
@ -35,6 +36,43 @@ import org.mapstruct.Mapper;
|
|||||||
@Element( name = "shortArray", shorts = 3 ),
|
@Element( name = "shortArray", shorts = 3 ),
|
||||||
@Element( name = "shortParam", shorts = 1 )
|
@Element( name = "shortParam", shorts = 1 )
|
||||||
} )
|
} )
|
||||||
|
@AnnotateWith( value = CustomAnnotationWithParams.class, elements = {
|
||||||
|
@Element(name = "stringParam", strings = "single value")
|
||||||
|
})
|
||||||
public interface CustomNamedMapper {
|
public interface CustomNamedMapper {
|
||||||
|
|
||||||
|
@AnnotateWith(value = CustomAnnotationWithParams.class, elements = {
|
||||||
|
@Element(name = "stringParam", strings = "double method value"),
|
||||||
|
@Element(name = "stringArray", strings = { "first", "second" }),
|
||||||
|
})
|
||||||
|
@AnnotateWith(value = CustomAnnotationWithParams.class, elements = {
|
||||||
|
@Element(name = "stringParam", strings = "single method value")
|
||||||
|
})
|
||||||
|
@AnnotateWith( CustomMethodOnlyAnnotation.class )
|
||||||
|
Target map(Source source);
|
||||||
|
|
||||||
|
class Target {
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
public Target(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Source {
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
public Source(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,50 @@ import javax.annotation.processing.Generated;
|
|||||||
date = "2022-06-06T16:48:18+0200",
|
date = "2022-06-06T16:48:18+0200",
|
||||||
comments = "version: , compiler: javac, environment: Java 11.0.12 (Azul Systems, Inc.)"
|
comments = "version: , compiler: javac, environment: Java 11.0.12 (Azul Systems, Inc.)"
|
||||||
)
|
)
|
||||||
@CustomAnnotationWithParams(stringArray = "test", stringParam = "test", booleanArray = true, booleanParam = true, byteArray = 16, byteParam = 19, charArray = 'd', charParam = 'a', enumArray = AnnotateWithEnum.EXISTING, enumParam = AnnotateWithEnum.EXISTING, doubleArray = 0.3, doubleParam = 1.2, floatArray = 0.300000011920929f, floatParam = 1.2000000476837158f, intArray = 3, intParam = 1, longArray = 3L, longParam = 1L, shortArray = 3, shortParam = 1)
|
@CustomClassOnlyAnnotation
|
||||||
|
@CustomAnnotationWithParams(
|
||||||
|
stringArray = "test",
|
||||||
|
stringParam = "test",
|
||||||
|
booleanArray = true,
|
||||||
|
booleanParam = true,
|
||||||
|
byteArray = 16,
|
||||||
|
byteParam = 19,
|
||||||
|
charArray = 'd',
|
||||||
|
charParam = 'a',
|
||||||
|
enumArray = AnnotateWithEnum.EXISTING,
|
||||||
|
enumParam = AnnotateWithEnum.EXISTING,
|
||||||
|
doubleArray = 0.3,
|
||||||
|
doubleParam = 1.2,
|
||||||
|
floatArray = 0.300000011920929f,
|
||||||
|
floatParam = 1.2000000476837158f,
|
||||||
|
intArray = 3,
|
||||||
|
intParam = 1,
|
||||||
|
longArray = 3L,
|
||||||
|
longParam = 1L,
|
||||||
|
shortArray = 3,
|
||||||
|
shortParam = 1
|
||||||
|
)
|
||||||
|
@CustomAnnotationWithParams(stringParam = "single value")
|
||||||
public class CustomNamedMapperImpl implements CustomNamedMapper {
|
public class CustomNamedMapperImpl implements CustomNamedMapper {
|
||||||
|
|
||||||
|
@CustomAnnotationWithParams(
|
||||||
|
stringParam = "double method value",
|
||||||
|
stringArray = { "first", "second" }
|
||||||
|
)
|
||||||
|
@CustomAnnotationWithParams(stringParam = "single method value")
|
||||||
|
@CustomMethodOnlyAnnotation
|
||||||
|
@Override
|
||||||
|
public Target map(Source source) {
|
||||||
|
if ( source == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String value = null;
|
||||||
|
|
||||||
|
value = source.getValue();
|
||||||
|
|
||||||
|
Target target = new Target( value );
|
||||||
|
|
||||||
|
return target;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,18 @@ import org.mapstruct.Mapper;
|
|||||||
date = "2022-06-06T16:48:23+0200",
|
date = "2022-06-06T16:48:23+0200",
|
||||||
comments = "version: , compiler: javac, environment: Java 11.0.12 (Azul Systems, Inc.)"
|
comments = "version: , compiler: javac, environment: Java 11.0.12 (Azul Systems, Inc.)"
|
||||||
)
|
)
|
||||||
@CustomAnnotationWithParams(stringArray = { "test1", "test2" }, booleanArray = { false, true }, byteArray = { 8, 31 }, charArray = { 'b', 'c' }, doubleArray = { 1.2, 3.4 }, floatArray = { 1.2000000476837158f, 3.4000000953674316f }, intArray = { 12, 34 }, longArray = { 12L, 34L }, shortArray = { 12, 34 }, classArray = { Mapper.class, CustomAnnotationWithParams.class }, stringParam = "required parameter")
|
@CustomAnnotationWithParams(
|
||||||
|
stringArray = { "test1", "test2" },
|
||||||
|
booleanArray = { false, true },
|
||||||
|
byteArray = { 8, 31 },
|
||||||
|
charArray = { 'b', 'c' },
|
||||||
|
doubleArray = { 1.2, 3.4 },
|
||||||
|
floatArray = { 1.2000000476837158f, 3.4000000953674316f },
|
||||||
|
intArray = { 12, 34 },
|
||||||
|
longArray = { 12L, 34L },
|
||||||
|
shortArray = { 12, 34 },
|
||||||
|
classArray = { Mapper.class, CustomAnnotationWithParams.class },
|
||||||
|
stringParam = "required parameter"
|
||||||
|
)
|
||||||
public class MultipleArrayValuesMapperImpl implements MultipleArrayValuesMapper {
|
public class MultipleArrayValuesMapperImpl implements MultipleArrayValuesMapper {
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user