1818 */
1919package org .mapstruct .eclipse .internal ;
2020
21+ import static org .mapstruct .eclipse .internal .Bindings .containsAnnotation ;
22+ import static org .mapstruct .eclipse .internal .Bindings .findAllMethodNames ;
23+ import static org .mapstruct .eclipse .internal .Bindings .getAnnotationQualifiedName ;
24+ import static org .mapstruct .eclipse .internal .MapStructAPIConstants .MAPPINGS_FQ_NAME ;
25+ import static org .mapstruct .eclipse .internal .MapStructAPIConstants .MAPPINGS_SIMPLE_NAME ;
26+ import static org .mapstruct .eclipse .internal .MapStructAPIConstants .MAPPING_FQ_NAME ;
27+ import static org .mapstruct .eclipse .internal .MapStructAPIConstants .MAPPING_MEMBER_SOURCE ;
28+ import static org .mapstruct .eclipse .internal .MapStructAPIConstants .MAPPING_MEMBER_TARGET ;
29+ import static org .mapstruct .eclipse .internal .MapStructAPIConstants .MAPPING_SIMPLE_NAME ;
30+ import static org .mapstruct .eclipse .internal .MapStructAPIConstants .MAPPING_TARGET_FQ_NAME ;
31+ import static org .mapstruct .eclipse .internal .MapStructAPIConstants .TARGET_TYPE_FQ_NAME ;
32+ import static org .mapstruct .eclipse .internal .MapStructAPIConstants .VALUE_MAPPING_FQ_NAME ;
33+ import static org .mapstruct .eclipse .internal .MapStructAPIConstants .VALUE_MAPPING_SIMPLE_NAME ;
34+
2135import java .beans .Introspector ;
2236import java .util .ArrayList ;
2337import java .util .Arrays ;
4458import org .eclipse .jface .text .contentassist .CompletionProposal ;
4559import org .eclipse .jface .text .contentassist .ICompletionProposal ;
4660
47- import static org .mapstruct .eclipse .internal .Bindings .containsAnnotation ;
48- import static org .mapstruct .eclipse .internal .Bindings .findAllMethodNames ;
49- import static org .mapstruct .eclipse .internal .Bindings .getAnnotationQualifiedName ;
50- import static org .mapstruct .eclipse .internal .MapStructAPIConstants .MAPPINGS_FQ_NAME ;
51- import static org .mapstruct .eclipse .internal .MapStructAPIConstants .MAPPINGS_SIMPLE_NAME ;
52- import static org .mapstruct .eclipse .internal .MapStructAPIConstants .MAPPING_FQ_NAME ;
53- import static org .mapstruct .eclipse .internal .MapStructAPIConstants .MAPPING_MEMBER_SOURCE ;
54- import static org .mapstruct .eclipse .internal .MapStructAPIConstants .MAPPING_MEMBER_TARGET ;
55- import static org .mapstruct .eclipse .internal .MapStructAPIConstants .MAPPING_SIMPLE_NAME ;
56- import static org .mapstruct .eclipse .internal .MapStructAPIConstants .MAPPING_TARGET_FQ_NAME ;
57- import static org .mapstruct .eclipse .internal .MapStructAPIConstants .TARGET_TYPE_FQ_NAME ;
58-
5961/**
6062 * Computes MapStruct specific content assist completion proposals for the <code>@Mapping</code> annotation.
6163 *
@@ -86,20 +88,23 @@ private PropertyNameProposalCollector(int invocationOffset) {
8688 public boolean visit (MemberValuePair node ) {
8789 String annotationQualifiedName = getAnnotationQualifiedName ( node .resolveMemberValuePairBinding () );
8890
89- if ( MAPPING_FQ_NAME . equals ( annotationQualifiedName )
91+ if ( isSupportedAnnotation ( annotationQualifiedName )
9092 && isInRange ( invocationOffset , node .getValue ().getStartPosition (), node .getValue ().getLength () )
91- && isMappingAnnotationMethod ( node ) ) {
93+ && ( isSourceNode ( node ) || isTargetNode ( node ) ) ) {
9294
9395 valid = true ;
9496
95- if ( MAPPING_MEMBER_SOURCE .equals ( node .getName ().toString () ) ) {
96- source = true ;
97- }
97+ source = isSourceNode ( node );
9898 }
9999
100100 return false ;
101101 }
102102
103+ private boolean isSupportedAnnotation (String annotationQualifiedName ) {
104+ return MAPPING_FQ_NAME .equals ( annotationQualifiedName )
105+ || VALUE_MAPPING_FQ_NAME .equals ( annotationQualifiedName );
106+ }
107+
103108 @ Override
104109 public boolean visit (MethodDeclaration node ) {
105110 if ( isInRange ( invocationOffset , node .getStartPosition (), node .getLength () ) ) {
@@ -156,8 +161,8 @@ public void endVisit(MethodDeclaration node) {
156161 }
157162
158163 private boolean isEnumMapping () {
159- return ( sourceNameToType .size () == 1 && sourceNameToType .values ().iterator ().next ().isEnum ()
160- && resultType .isEnum () );
164+ return ( ( sourceNameToType .size () == 1 && sourceNameToType .values ().iterator ().next ().isEnum () )
165+ || resultType .isEnum () );
161166 }
162167
163168 public Collection <String > getProperties () {
@@ -178,7 +183,9 @@ public boolean isValidValue() {
178183 MAPPING_FQ_NAME ,
179184 MAPPING_SIMPLE_NAME ,
180185 MAPPINGS_SIMPLE_NAME ,
181- MAPPINGS_FQ_NAME );
186+ MAPPINGS_FQ_NAME ,
187+ VALUE_MAPPING_FQ_NAME ,
188+ VALUE_MAPPING_SIMPLE_NAME );
182189
183190 private static final String GET_PREFIX = "get" ; //$NON-NLS-1$
184191 private static final String SET_PREFIX = "set" ; //$NON-NLS-1$
@@ -255,15 +262,11 @@ private List<String> findProperties(Collection<String> methodNames, String metho
255262 return returnValue ;
256263 }
257264
258- /**
259- * Decides whether the given {@link MemberValuePair} is a <code>Mapping</code> annotation method.
260- */
261- private boolean isMappingAnnotationMethod (MemberValuePair node ) {
262- if ( MAPPING_MEMBER_SOURCE .equals ( node .getName ().toString () )
263- || MAPPING_MEMBER_TARGET .equals ( node .getName ().toString () ) ) {
264- return true ;
265- }
266- return false ;
265+ private boolean isTargetNode (MemberValuePair node ) {
266+ return MAPPING_MEMBER_TARGET .equals ( node .getName ().toString () );
267267 }
268268
269+ private boolean isSourceNode (MemberValuePair node ) {
270+ return MAPPING_MEMBER_SOURCE .equals ( node .getName ().toString () );
271+ }
269272}
0 commit comments