Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
3ccb0c2
#1574: AnnotateWith implementation (Work in progress)
Mar 7, 2022
39836d7
#1574: Support added for all singular forms of parameters.
Mar 8, 2022
70f89e9
#1574: Support added for array form of parameters.
Mar 9, 2022
0fe8edb
#1574: added an error for multiple values while only 1 value expected…
Mar 9, 2022
2931d7f
#1574: added checks on annotations being placed on correct target types.
Mar 15, 2022
80933ae
#1574: forgot to add additional test classes.
Mar 15, 2022
14a6abe
#1574 added comment to something that needs to be changed before this…
Mar 15, 2022
072a2b5
#1574: added support for meta-annotations for
Mar 15, 2022
01083a9
#1574: moved meta annotation behavior to util class to make it re-usa…
Mar 15, 2022
141ff6e
#1574: Changed behavior to match '@Mapping' and '@SubclassMapping' fo…
Mar 15, 2022
1777f98
#1574: refactoring to make it all fit together better.
Mar 15, 2022
609f3b1
#1574: fix build.
Mar 15, 2022
56d4665
#1574: replaced manual formatting with .ftl files.
Mar 18, 2022
b9299b3
#1574: add missing license header.
Mar 18, 2022
90bb493
#1574: Rename variables to better match java spec.
Jun 1, 2022
5878b6a
#1574: more renames and support for enums.
Jun 3, 2022
86268b8
#1574: missing javadoc and fixed long lines.
Jun 4, 2022
4f64413
#1574: documentation, javadoc and adjust GemGenerator to not import t…
Jun 4, 2022
ea688a3
Changes in the additional annotations builder
filiphr Jun 4, 2022
648dc91
Use ClassAssert from AssertJ for checking for annotations on a class
filiphr Jun 4, 2022
0faac4d
Reformat AnnotateWithTest so Checkstyle doesn't complain
filiphr Jun 4, 2022
a7a2fd2
Remove extra annotation
filiphr Jun 4, 2022
ae330cb
#1574: Merged all AnnotationElement ftl's and corresponding classes. …
Jun 4, 2022
48c7ac6
#1574: removed unnecessary test.
Jun 4, 2022
eb422e2
#1574: moved annotations above '@Override'.
Jun 4, 2022
5ff023c
#1574: rewritten enum structure. Moved missing enum value, unknown el…
Jun 4, 2022
f417fbb
#1574: moved not allowed error locations.
Jun 4, 2022
669fff6
#1475: annotateWith now also possible without specifying the element …
Jun 5, 2022
a1fcfd2
#1427: AnnotateWith now also usable for Spring "Component" annotation.
Jun 5, 2022
1b45a1d
#1574: Checkstyle and license header fixes.
Jun 5, 2022
9c4ce7d
#1574: Added compiler error for wrong type without specifying annotat…
Jun 5, 2022
8bc4aa8
#1574: Added compiler error for missing name parameter in AnnotateWit…
Jun 5, 2022
e62a948
#1574: added compiler error for situation with multiple elements but …
Jun 5, 2022
241eceb
Revert "#1427: AnnotateWith now also usable for Spring "Component" an…
Jun 5, 2022
905fb7f
#1574: add compiler errors for wrong usage of enum structure.
Jun 5, 2022
93857cd
#1574: always use default name 'value' in case it is missing.
Jun 5, 2022
3abaa29
#1574: update messages and fix test name
Jun 5, 2022
fc81cb8
#1574: Add compiler error for repeating not repeatable annotations.
Jun 5, 2022
2cb8605
#1574: added compiler error for defining same parameter twice using A…
Jun 5, 2022
8bfba39
#1574: Added compiler error for completely identical annotations.
Jun 5, 2022
9f727f3
Required parameter should be reported on the annotate with line
filiphr Jun 6, 2022
60c8755
Change error message for duplicate and unknown parameters
filiphr Jun 6, 2022
c7eec33
Duplicated identical annotation should be a warning + remove not used…
filiphr Jun 6, 2022
7e76cd6
#1574: added examples to javadoc. fixed line length.
Jun 6, 2022
8dbb1f7
#1574: remove paragraph tags
Jun 6, 2022
f9ba5c1
#1574: converted the more complex tests into fixture tests.
Jun 6, 2022
5c60c3d
#1574: introducing a NullEnum util class as default class for annotat…
Jun 6, 2022
b8045a0
#1574: fix javadoc
Jun 6, 2022
9117141
#1574: fix line ending
Jun 6, 2022
5e834d6
#1574: add missing license header.
Jun 6, 2022
f823f79
Move NullEnum to be package protected in the org.mapstruct package
filiphr Jun 18, 2022
2ebdc60
Documentation and javadoc typo changes
filiphr Jun 18, 2022
070b650
Simplify ConvertToProperty a bit
filiphr Jun 18, 2022
4eb98a1
Simplify some creation of the annotation element in the annotation ba…
filiphr Jun 18, 2022
701709f
#1574: Too many element parameters then specific error message.
Jul 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
#1574: Added compiler error for missing name parameter in AnnotateWit…
…h.Element when using multiple Element annotations.
  • Loading branch information
Ben Zegveld authored and Ben Zegveld committed Jun 5, 2022
commit 8bc4aa8477893aa96f25679b1d188859ee60a0bb
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,19 @@ private boolean isValid(Type annotationType, List<ElementGem> eleGems, Element e
if ( !annotationIsAllowed( annotationType, element, annotationMirror ) ) {
isValid = false;
}
if ( !annotationIsComplete( annotationType, eleGems, element ) ) {
isValid = false;
}

List<ExecutableElement> annotationParameters = methodsIn( annotationType.getTypeElement()
List<ExecutableElement> annotationElements = methodsIn( annotationType.getTypeElement()
.getEnclosedElements() );
if ( !allRequiredParametersArePresent( annotationType, annotationParameters, eleGems, element ) ) {
if ( !allRequiredElementsArePresent( annotationType, annotationElements, eleGems, element ) ) {
isValid = false;
}
if ( !allParametersAreKnownInAnnotation( annotationType, annotationParameters, eleGems, element ) ) {
if ( !allElementsAreKnownInAnnotation( annotationType, annotationElements, eleGems, element ) ) {
isValid = false;
}
if ( !allParametersAreOfCorrectType( annotationType, annotationParameters, eleGems, element ) ) {
if ( !allElementsAreOfCorrectType( annotationType, annotationElements, eleGems, element ) ) {
isValid = false;
}
if ( !enumConstructionIsCorrectlyUsed( eleGems, element ) ) {
Expand Down Expand Up @@ -272,6 +275,23 @@ private boolean enumConstructionIsCorrectlyUsed(List<ElementGem> eleGems, Elemen
return isValid;
}

private boolean annotationIsComplete(Type annotationType, List<ElementGem> eleGems, Element element) {
boolean isValid = true;
if ( eleGems.size() > 1 ) {
for ( ElementGem elementGem : eleGems ) {
if ( elementGem.name().getValue() == null ) {
isValid = false;
messager.printMessage(
element,
elementGem.mirror(),
Message.ANNOTATE_WITH_NAME_NOT_DEFINED,
annotationType.describe() );
}
}
}
return isValid;
}

private boolean annotationIsAllowed(Type annotationType, Element element, AnnotationMirror annotationMirror) {
Target target = annotationType.getTypeElement().getAnnotation( Target.class );
if ( target == null ) {
Expand Down Expand Up @@ -314,7 +334,7 @@ private boolean isMethodTarget(Element element) {
return element.getKind() == ElementKind.METHOD;
}

private boolean allParametersAreKnownInAnnotation(Type annotationType, List<ExecutableElement> annotationParameters,
private boolean allElementsAreKnownInAnnotation(Type annotationType, List<ExecutableElement> annotationParameters,
List<ElementGem> eleGems, Element element) {
List<String> allowedAnnotationParameters = annotationParameters.stream()
.map( ee -> ee.getSimpleName().toString() )
Expand All @@ -338,7 +358,7 @@ private boolean allParametersAreKnownInAnnotation(Type annotationType, List<Exec
return isValid;
}

private boolean allRequiredParametersArePresent(Type annotationType, List<ExecutableElement> annotationParameters,
private boolean allRequiredElementsArePresent(Type annotationType, List<ExecutableElement> annotationParameters,
List<ElementGem> elements, Element element) {

boolean valid = true;
Expand Down Expand Up @@ -371,7 +391,7 @@ private boolean allRequiredParametersArePresent(Type annotationType, List<Execut
return valid;
}

private boolean allParametersAreOfCorrectType(Type annotationType, List<ExecutableElement> annotationParameters,
private boolean allElementsAreOfCorrectType(Type annotationType, List<ExecutableElement> annotationParameters,
List<ElementGem> elements,
Element element) {
Map<String, ExecutableElement> annotationParametersByName =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ public enum Message {
ANNOTATE_WITH_NOT_ALLOWED_ON_CLASS( "Annotation \"%s\" is not allowed on classes." ),
ANNOTATE_WITH_NOT_ALLOWED_ON_METHODS( "Annotation \"%s\" is not allowed on methods." ),
ANNOTATE_WITH_ENUM_VALUE_DOES_NOT_EXIST( "Enum \"%s\" does not have value \"%s\"." ),
ANNOTATE_WITH_ENUM_CLASS_NOT_DEFINED( "\"enumClass=...\" is required when using \"enums=...\"." ),
ANNOTATE_WITH_ENUM_CLASS_NOT_DEFINED( "\"enumClass=...\" is required when using \"enums=...\" for \"%s\"." ),
ANNOTATE_WITH_NAME_NOT_DEFINED( "\"name=...\" is required in each @AnnotateWith.Element annotation with multiple annotations for annotation \"%s\"." ),
;
// CHECKSTYLE:ON

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,22 @@ public void erroneousMapperWithWrongParameter() {
@WithClasses({ ErroneousMultipleArrayValuesMapper.class, CustomAnnotationWithParams.class })
public void erroneousMapperUsingMultipleValuesInsteadOfSingle() {
}

@ProcessorTest
@ExpectedCompilationOutcome(
value = CompilationResult.FAILED,
diagnostics = {
@Diagnostic(
kind = javax.tools.Diagnostic.Kind.ERROR,
type = ErroneousMapperWithMissingAnnotationElementName.class,
line = 16,
alternativeLine = 19,
message = "\"name=...\" is required in each @AnnotateWith.Element annotation with multiple annotations "
+ "for annotation \"CustomAnnotationWithTwoAnnotationElements\"."
)
}
)
@WithClasses({ErroneousMapperWithMissingAnnotationElementName.class, CustomAnnotationWithTwoAnnotationElements.class})
public void erroneousMapperWithMissingAnnotationElementName() {
}
}