|
7 | 7 |
|
8 | 8 | import java.util.Arrays; |
9 | 9 | import java.util.Objects; |
| 10 | +import java.util.Optional; |
10 | 11 | import java.util.stream.Collectors; |
11 | 12 | import java.util.stream.Stream; |
12 | 13 |
|
|
27 | 28 | import static com.intellij.codeInsight.AnnotationUtil.findAnnotation; |
28 | 29 | import static com.intellij.codeInsight.AnnotationUtil.getStringAttributeValue; |
29 | 30 | import static org.mapstruct.intellij.util.MapstructAnnotationUtils.findReferencedMapperClasses; |
| 31 | +import static org.mapstruct.intellij.util.MapstructUtil.NAMED_ANNOTATION_FQN; |
| 32 | +import static org.mapstruct.intellij.util.MapstructUtil.MAPPER_ANNOTATION_FQN; |
| 33 | +import static org.mapstruct.intellij.util.MapstructUtil.MAPPER_CONFIG_ANNOTATION_FQN; |
30 | 34 | import static org.mapstruct.intellij.util.MapstructUtil.asLookupWithRepresentableText; |
31 | 35 |
|
32 | 36 | /** |
@@ -67,13 +71,13 @@ PsiElement resolveInternal(@NotNull String value, @NotNull PsiMethod mappingMeth |
67 | 71 | @Nullable |
68 | 72 | private String getNamedValue(PsiMethod method) { |
69 | 73 |
|
70 | | - PsiAnnotation annotation = findAnnotation( method, true, MapstructUtil.NAMED_ANNOTATION_FQN ); |
| 74 | + PsiAnnotation namedAnnotation = findAnnotation( method, true, NAMED_ANNOTATION_FQN ); |
71 | 75 |
|
72 | | - if ( annotation == null ) { |
| 76 | + if ( namedAnnotation == null ) { |
73 | 77 | return null; |
74 | 78 | } |
75 | 79 |
|
76 | | - return getStringAttributeValue( annotation, "value" ); |
| 80 | + return getStringAttributeValue( namedAnnotation, "value" ); |
77 | 81 | } |
78 | 82 |
|
79 | 83 | @NotNull |
@@ -116,16 +120,15 @@ private Stream<PsiMethod> findAllNamedMethodsFromThisAndReferencedMappers(@NotNu |
116 | 120 | @NotNull |
117 | 121 | private Stream<PsiMethod> findNamedMethodsInUsedMappers(@Nullable PsiClass containingClass) { |
118 | 122 |
|
119 | | - PsiAnnotation mapperAnnotation = findAnnotation( |
120 | | - containingClass, |
121 | | - MapstructUtil.MAPPER_ANNOTATION_FQN |
122 | | - ); |
| 123 | + PsiAnnotation mapperOrMapperConfigAnnotation = |
| 124 | + Optional.ofNullable( findAnnotation( containingClass, MAPPER_ANNOTATION_FQN ) ) |
| 125 | + .orElseGet( () -> findAnnotation( containingClass, MAPPER_CONFIG_ANNOTATION_FQN ) ); |
123 | 126 |
|
124 | | - if ( mapperAnnotation == null ) { |
| 127 | + if ( mapperOrMapperConfigAnnotation == null ) { |
125 | 128 | return Stream.empty(); |
126 | 129 | } |
127 | 130 |
|
128 | | - return findReferencedMapperClasses( mapperAnnotation ) |
| 131 | + return findReferencedMapperClasses( mapperOrMapperConfigAnnotation ) |
129 | 132 | .flatMap( psiClass -> Arrays.stream( psiClass.getMethods() ) ) |
130 | 133 | .filter( MapstructUtil::isNamedMethod ); |
131 | 134 | } |
|
0 commit comments