-
-
Notifications
You must be signed in to change notification settings - Fork 1k
1574: Introducing AnnotateWith with values. #2792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
3ccb0c2
#1574: AnnotateWith implementation (Work in progress)
39836d7
#1574: Support added for all singular forms of parameters.
70f89e9
#1574: Support added for array form of parameters.
0fe8edb
#1574: added an error for multiple values while only 1 value expected…
2931d7f
#1574: added checks on annotations being placed on correct target types.
80933ae
#1574: forgot to add additional test classes.
14a6abe
#1574 added comment to something that needs to be changed before this…
072a2b5
#1574: added support for meta-annotations for
01083a9
#1574: moved meta annotation behavior to util class to make it re-usa…
141ff6e
#1574: Changed behavior to match '@Mapping' and '@SubclassMapping' fo…
1777f98
#1574: refactoring to make it all fit together better.
609f3b1
#1574: fix build.
56d4665
#1574: replaced manual formatting with .ftl files.
b9299b3
#1574: add missing license header.
90bb493
#1574: Rename variables to better match java spec.
5878b6a
#1574: more renames and support for enums.
86268b8
#1574: missing javadoc and fixed long lines.
4f64413
#1574: documentation, javadoc and adjust GemGenerator to not import t…
ea688a3
Changes in the additional annotations builder
filiphr 648dc91
Use ClassAssert from AssertJ for checking for annotations on a class
filiphr 0faac4d
Reformat AnnotateWithTest so Checkstyle doesn't complain
filiphr a7a2fd2
Remove extra annotation
filiphr ae330cb
#1574: Merged all AnnotationElement ftl's and corresponding classes. …
48c7ac6
#1574: removed unnecessary test.
eb422e2
#1574: moved annotations above '@Override'.
5ff023c
#1574: rewritten enum structure. Moved missing enum value, unknown el…
f417fbb
#1574: moved not allowed error locations.
669fff6
#1475: annotateWith now also possible without specifying the element …
a1fcfd2
#1427: AnnotateWith now also usable for Spring "Component" annotation.
1b45a1d
#1574: Checkstyle and license header fixes.
9c4ce7d
#1574: Added compiler error for wrong type without specifying annotat…
8bc4aa8
#1574: Added compiler error for missing name parameter in AnnotateWit…
e62a948
#1574: added compiler error for situation with multiple elements but …
241eceb
Revert "#1427: AnnotateWith now also usable for Spring "Component" an…
905fb7f
#1574: add compiler errors for wrong usage of enum structure.
93857cd
#1574: always use default name 'value' in case it is missing.
3abaa29
#1574: update messages and fix test name
fc81cb8
#1574: Add compiler error for repeating not repeatable annotations.
2cb8605
#1574: added compiler error for defining same parameter twice using A…
8bfba39
#1574: Added compiler error for completely identical annotations.
9f727f3
Required parameter should be reported on the annotate with line
filiphr 60c8755
Change error message for duplicate and unknown parameters
filiphr c7eec33
Duplicated identical annotation should be a warning + remove not used…
filiphr 7e76cd6
#1574: added examples to javadoc. fixed line length.
8dbb1f7
#1574: remove paragraph tags
f9ba5c1
#1574: converted the more complex tests into fixture tests.
5c60c3d
#1574: introducing a NullEnum util class as default class for annotat…
b8045a0
#1574: fix javadoc
9117141
#1574: fix line ending
5e834d6
#1574: add missing license header.
f823f79
Move NullEnum to be package protected in the org.mapstruct package
filiphr 2ebdc60
Documentation and javadoc typo changes
filiphr 070b650
Simplify ConvertToProperty a bit
filiphr 4eb98a1
Simplify some creation of the annotation element in the annotation ba…
filiphr 701709f
#1574: Too many element parameters then specific error message.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| /* | ||
| * Copyright MapStruct Authors. | ||
| * | ||
| * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
| package org.mapstruct; | ||
|
|
||
| import java.lang.annotation.Annotation; | ||
| import java.lang.annotation.Repeatable; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| import static java.lang.annotation.ElementType.ANNOTATION_TYPE; | ||
| import static java.lang.annotation.ElementType.METHOD; | ||
| import static java.lang.annotation.ElementType.TYPE; | ||
| import static java.lang.annotation.RetentionPolicy.CLASS; | ||
|
|
||
| /** | ||
| * This can be used to have mapstruct generate additional annotations on classes/methods. | ||
| * <p> | ||
| * Examples based on the spring framework annotations. | ||
| * </p> | ||
| * Marking a class as `Lazy`: | ||
| * | ||
| * <pre><code> | ||
| * @AnnotateWith( value = Lazy.class ) | ||
| * @Mapper | ||
| * public interface FooMapper { | ||
| * // mapper code | ||
| * } | ||
| * </code></pre> | ||
| * | ||
| * The following code would be generated: | ||
| * | ||
| * <pre><code> | ||
| * @Lazy | ||
| * public class FooMapperImpl implements FooMapper { | ||
| * // mapper code | ||
| * } | ||
| * </code></pre> | ||
| * Setting the profile on the generated implementation: | ||
| * | ||
| * <pre><code> | ||
| * @AnnotateWith( value = Profile.class, elements = @AnnotateWith.Element( strings = "prod" ) ) | ||
| * @Mapper | ||
| * public interface FooMapper { | ||
| * // mapper code | ||
| * } | ||
| * </code></pre> | ||
| * | ||
| * The following code would be generated: | ||
| * | ||
| * <pre><code> | ||
| * @Profile( value = "prod" ) | ||
| * public class FooMapperImpl implements FooMapper { | ||
| * // mapper code | ||
| * } | ||
| * </code></pre> | ||
| * | ||
| * @author Ben Zegveld | ||
| * @since 1.6 | ||
| */ | ||
| @Repeatable( AnnotateWiths.class ) | ||
| @Retention( CLASS ) | ||
| @Target( { TYPE, METHOD, ANNOTATION_TYPE } ) | ||
| public @interface AnnotateWith { | ||
| /** | ||
| * @return the annotation class that needs to be added. | ||
| */ | ||
| Class<? extends Annotation> value(); | ||
|
|
||
| /** | ||
| * @return the annotation elements that are to be applied to this annotation. | ||
| */ | ||
| Element[] elements() default {}; | ||
|
|
||
| /** | ||
| * Used in combination with {@link AnnotateWith} to configure the annotation elements. Only 1 value type may be used | ||
| * within the same annotation at a time. For example mixing shorts and ints is not allowed. | ||
| * | ||
| * @author Ben Zegveld | ||
| * @since 1.6 | ||
| */ | ||
| @interface Element { | ||
| /** | ||
| * @return name of the annotation element. | ||
| */ | ||
| String name() default "value"; | ||
|
|
||
| /** | ||
| * cannot be used in conjunction with other value fields. | ||
| * | ||
| * @return short value(s) for the annotation element. | ||
| */ | ||
| short[] shorts() default {}; | ||
|
|
||
| /** | ||
| * cannot be used in conjunction with other value fields. | ||
| * | ||
| * @return byte value(s) for the annotation element. | ||
| */ | ||
| byte[] bytes() default {}; | ||
|
|
||
| /** | ||
| * cannot be used in conjunction with other value fields. | ||
| * | ||
| * @return int value(s) for the annotation element. | ||
| */ | ||
| int[] ints() default {}; | ||
|
|
||
| /** | ||
| * cannot be used in conjunction with other value fields. | ||
| * | ||
| * @return long value(s) for the annotation element. | ||
| */ | ||
| long[] longs() default {}; | ||
|
|
||
| /** | ||
| * cannot be used in conjunction with other value fields. | ||
| * | ||
| * @return float value(s) for the annotation element. | ||
| */ | ||
| float[] floats() default {}; | ||
|
|
||
| /** | ||
| * cannot be used in conjunction with other value fields. | ||
| * | ||
| * @return double value(s) for the annotation element. | ||
| */ | ||
| double[] doubles() default {}; | ||
|
|
||
| /** | ||
| * cannot be used in conjunction with other value fields. | ||
| * | ||
| * @return char value(s) for the annotation element. | ||
| */ | ||
| char[] chars() default {}; | ||
|
|
||
| /** | ||
| * cannot be used in conjunction with other value fields. | ||
| * | ||
| * @return boolean value(s) for the annotation element. | ||
| */ | ||
| boolean[] booleans() default {}; | ||
|
|
||
| /** | ||
| * cannot be used in conjunction with other value fields. | ||
| * | ||
| * @return string value(s) for the annotation element. | ||
| */ | ||
| String[] strings() default {}; | ||
|
|
||
| /** | ||
| * cannot be used in conjunction with other value fields. | ||
| * | ||
| * @return class value(s) for the annotation element. | ||
| */ | ||
| Class<?>[] classes() default {}; | ||
|
|
||
| /** | ||
| * only used in conjunction with the {@link #enums()} annotation element. | ||
| * | ||
| * @return the class of the enum. | ||
| */ | ||
| Class<? extends Enum<?>> enumClass() default NullEnum.class; | ||
|
|
||
| /** | ||
| * cannot be used in conjunction with other value fields. {@link #enumClass()} is also required when using | ||
| * {@link #enums()} | ||
| * | ||
| * @return enum value(s) for the annotation element. | ||
| */ | ||
| String[] enums() default {}; | ||
|
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Copyright MapStruct Authors. | ||
| * | ||
| * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
| package org.mapstruct; | ||
|
|
||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| import static java.lang.annotation.ElementType.METHOD; | ||
| import static java.lang.annotation.ElementType.TYPE; | ||
| import static java.lang.annotation.RetentionPolicy.CLASS; | ||
|
|
||
| /** | ||
| * This can be used to have mapstruct generate additional annotations on classes/methods. | ||
| * | ||
| * @author Ben Zegveld | ||
| * @since 1.6 | ||
| */ | ||
| @Retention( CLASS ) | ||
| @Target( { TYPE, METHOD } ) | ||
| public @interface AnnotateWiths { | ||
|
|
||
| /** | ||
| * The configuration of the additional annotations. | ||
| * | ||
| * @return The configuration of the additional annotations. | ||
| */ | ||
| AnnotateWith[] value(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /* | ||
| * Copyright MapStruct Authors. | ||
| * | ||
| * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
| package org.mapstruct; | ||
|
|
||
| /** | ||
| * To be used as a default value for enum class annotation elements. | ||
| * | ||
| * @author Ben Zegveld | ||
| * @since 1.6 | ||
| */ | ||
| enum NullEnum { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.