Skip to content

Commit 43e2731

Browse files
committed
#12 Introduce constants class for MapStruct API elements
1 parent 797ce50 commit 43e2731

File tree

3 files changed

+85
-10
lines changed

3 files changed

+85
-10
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Copyright 2012-2015 Gunnar Morling (http://www.gunnarmorling.de/)
3+
* and/or other contributors as indicated by the @authors tag. See the
4+
* copyright.txt file in the distribution for a full listing of all
5+
* contributors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.mapstruct.eclipse.internal;
20+
21+
/**
22+
* Constants for types from the MapStruct API
23+
*
24+
* @author Andreas Gudian
25+
*/
26+
public final class MapStructAPIConstants {
27+
private MapStructAPIConstants() {
28+
}
29+
30+
/**
31+
* MapStruct package
32+
*/
33+
private static final String ORG_MAPSTRUCT = "org.mapstruct."; //$NON-NLS-1$
34+
35+
/**
36+
* Simple name of the annotation Mapper
37+
*/
38+
public static final String MAPPER_SIMPLE_NAME = "Mapper"; //$NON-NLS-1$
39+
/**
40+
* Fully qualified name of the annotation Mapper
41+
*/
42+
public static final String MAPPER_FQ_NAME = ORG_MAPSTRUCT + MAPPER_SIMPLE_NAME;
43+
44+
/**
45+
* Simple name of the annotation Mapping
46+
*/
47+
public static final String MAPPING_SIMPLE_NAME = "Mapping"; //$NON-NLS-1$
48+
/**
49+
* Fully qualified name of the annotation Mapping
50+
*/
51+
public static final String MAPPING_FQ_NAME = ORG_MAPSTRUCT + MAPPING_SIMPLE_NAME;
52+
53+
/**
54+
* Simple name of the annotation Mappings
55+
*/
56+
public static final String MAPPINGS_SIMPLE_NAME = "Mappings"; //$NON-NLS-1$
57+
/**
58+
* Fully qualified name of the annotation Mappings
59+
*/
60+
public static final String MAPPINGS_FQ_NAME = ORG_MAPSTRUCT + MAPPINGS_SIMPLE_NAME;
61+
62+
/**
63+
* Member name of Mapping#source()
64+
*/
65+
public static final String MAPPING_MEMBER_SOURCE = "source"; //$NON-NLS-1$
66+
67+
/**
68+
* Member name of Mapping#target()
69+
*/
70+
public static final String MAPPING_MEMBER_TARGET = "target"; //$NON-NLS-1$
71+
}

org.mapstruct.eclipse/src/org/mapstruct/eclipse/internal/MapperAnnotationCompletionProposalComputer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
*/
3737
public class MapperAnnotationCompletionProposalComputer extends AbstractAnnotationCompletionProposalComputer {
3838

39-
private static final List<String> MAPPER_ANNOTATION_NAME = Arrays.asList( "Mapper" );
39+
private static final List<String> MAPPER_ANNOTATION_NAMES = Arrays.asList(
40+
MapStructAPIConstants.MAPPER_SIMPLE_NAME,
41+
MapStructAPIConstants.MAPPER_FQ_NAME );
4042

4143
private static final List<String> COMPONENT_MODEL_TYPES = Collections.unmodifiableList( Arrays.asList(
4244
"default",
@@ -46,7 +48,7 @@ public class MapperAnnotationCompletionProposalComputer extends AbstractAnnotati
4648

4749
@Override
4850
protected List<String> getAnnotationNames() {
49-
return MAPPER_ANNOTATION_NAME;
51+
return MAPPER_ANNOTATION_NAMES;
5052
}
5153

5254
@Override

org.mapstruct.eclipse/src/org/mapstruct/eclipse/internal/MappingAnnotationCompletionProposalComputer.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@
4848
*/
4949
public class MappingAnnotationCompletionProposalComputer extends AbstractAnnotationCompletionProposalComputer {
5050

51-
private static final String MAPPING_ANNOTATION_QUALIFIED_NAME = "org.mapstruct.Mapping"; //$NON-NLS-1$
52-
private static final List<String> MAPPING_ANNOTATION_NAMES = Arrays.asList( "Mappings", "Mapping" ); //$NON-NLS-1$ //$NON-NLS-2$
53-
private static final String SOURCE_ANNOTATION_METHOD = "source"; //$NON-NLS-1$
54-
private static final String TARGET_ANNOTATION_METHOD = "target"; //$NON-NLS-1$
51+
private static final List<String> MAPPING_ANNOTATION_NAMES = Arrays.asList(
52+
MapStructAPIConstants.MAPPING_FQ_NAME,
53+
MapStructAPIConstants.MAPPING_SIMPLE_NAME,
54+
MapStructAPIConstants.MAPPINGS_SIMPLE_NAME,
55+
MapStructAPIConstants.MAPPINGS_FQ_NAME );
56+
5557
private static final String GET_PREFIX = "get"; //$NON-NLS-1$
5658
private static final String SET_PREFIX = "set"; //$NON-NLS-1$
5759
private static final String IS_PREFIX = "is"; //$NON-NLS-1$
@@ -138,13 +140,13 @@ public boolean visit(MemberValuePair node) {
138140

139141
String annotationQualifiedName = getAnnotationQualifiedName( node.resolveMemberValuePairBinding() );
140142

141-
if ( MAPPING_ANNOTATION_QUALIFIED_NAME.equals( annotationQualifiedName )
143+
if ( MapStructAPIConstants.MAPPING_FQ_NAME.equals( annotationQualifiedName )
142144
&& isInRange( invocationOffset, node.getValue().getStartPosition(), node.getValue().getLength() )
143145
&& isMappingAnnotationMethod( node ) ) {
144146

145147
isValidValue.set( true );
146148

147-
if ( SOURCE_ANNOTATION_METHOD.equals( node.getName().toString() ) ) {
149+
if ( MapStructAPIConstants.MAPPING_MEMBER_SOURCE.equals( node.getName().toString() ) ) {
148150
isSource.set( true );
149151
}
150152

@@ -204,8 +206,8 @@ private Set<String> findProperties(Set<String> methodNames, String methodPrefix)
204206
* Decides whether the given {@link MemberValuePair} is a <code>Mapping</code> annotation method.
205207
*/
206208
private boolean isMappingAnnotationMethod(MemberValuePair node) {
207-
if ( SOURCE_ANNOTATION_METHOD.equals( node.getName().toString() )
208-
|| TARGET_ANNOTATION_METHOD.equals( node.getName().toString() ) ) {
209+
if ( MapStructAPIConstants.MAPPING_MEMBER_SOURCE.equals( node.getName().toString() )
210+
|| MapStructAPIConstants.MAPPING_MEMBER_TARGET.equals( node.getName().toString() ) ) {
209211
return true;
210212
}
211213
return false;

0 commit comments

Comments
 (0)