#2895 Generate more readable annotations

This commit is contained in:
Filip Hrisafov 2022-08-29 21:15:01 +02:00
parent 68571de01b
commit 21069e5a2e
5 changed files with 117 additions and 5 deletions

View File

@ -6,4 +6,17 @@
-->
<#-- @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>

View File

@ -42,8 +42,13 @@ public class AnnotateWithTest {
}
@ProcessorTest
@WithClasses( { CustomNamedMapper.class, CustomAnnotationWithParamsContainer.class,
CustomAnnotationWithParams.class } )
@WithClasses( {
CustomNamedMapper.class,
CustomAnnotationWithParamsContainer.class,
CustomAnnotationWithParams.class,
CustomClassOnlyAnnotation.class,
CustomMethodOnlyAnnotation.class,
} )
public void annotationWithValue() {
generatedSource.addComparisonToFixtureFor( CustomNamedMapper.class );
}

View File

@ -13,6 +13,7 @@ import org.mapstruct.Mapper;
* @author Ben Zegveld
*/
@Mapper
@AnnotateWith( CustomClassOnlyAnnotation.class )
@AnnotateWith( value = CustomAnnotationWithParams.class, elements = {
@Element( name = "stringArray", strings = "test" ),
@Element( name = "stringParam", strings = "test" ),
@ -35,6 +36,43 @@ import org.mapstruct.Mapper;
@Element( name = "shortArray", shorts = 3 ),
@Element( name = "shortParam", shorts = 1 )
} )
@AnnotateWith( value = CustomAnnotationWithParams.class, elements = {
@Element(name = "stringParam", strings = "single value")
})
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;
}
}
}

View File

@ -12,6 +12,50 @@ import javax.annotation.processing.Generated;
date = "2022-06-06T16:48:18+0200",
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 {
@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;
}
}

View File

@ -13,6 +13,18 @@ import org.mapstruct.Mapper;
date = "2022-06-06T16:48:23+0200",
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 {
}