1515 */
1616package org .androidannotations .helper ;
1717
18- import com .sun .codemodel .JFieldRef ;
18+ import java .lang .annotation .Annotation ;
19+ import java .lang .reflect .InvocationTargetException ;
20+ import java .lang .reflect .Method ;
21+ import java .util .ArrayList ;
22+ import java .util .List ;
23+ import java .util .Map ;
24+
25+ import javax .annotation .processing .ProcessingEnvironment ;
26+ import javax .lang .model .element .AnnotationMirror ;
27+ import javax .lang .model .element .AnnotationValue ;
28+ import javax .lang .model .element .Element ;
29+ import javax .lang .model .element .ExecutableElement ;
30+ import javax .lang .model .element .Modifier ;
31+ import javax .lang .model .element .NestingKind ;
32+ import javax .lang .model .element .TypeElement ;
33+ import javax .lang .model .type .DeclaredType ;
34+ import javax .lang .model .type .MirroredTypeException ;
35+ import javax .lang .model .type .TypeMirror ;
36+ import javax .lang .model .util .Elements ;
37+ import javax .lang .model .util .Types ;
38+
1939import org .androidannotations .annotations .OnActivityResult ;
2040import org .androidannotations .annotations .OptionsItem ;
2141import org .androidannotations .annotations .ResId ;
2646import org .androidannotations .rclass .IRInnerClass ;
2747import org .androidannotations .rclass .RInnerClass ;
2848
29- import javax .annotation .processing .ProcessingEnvironment ;
30- import javax .lang .model .element .*;
31- import javax .lang .model .type .DeclaredType ;
32- import javax .lang .model .type .MirroredTypeException ;
33- import javax .lang .model .type .TypeMirror ;
34- import javax .lang .model .util .Elements ;
35- import javax .lang .model .util .Types ;
36- import java .lang .annotation .Annotation ;
37- import java .lang .reflect .InvocationTargetException ;
38- import java .lang .reflect .Method ;
39- import java .util .ArrayList ;
40- import java .util .List ;
41- import java .util .Map ;
49+ import com .sun .codemodel .JFieldRef ;
4250
4351public class AnnotationHelper {
4452
53+ public static final String DEFAULT_FIELD_NAME_VALUE = "value" ;
54+ public static final String DEFAULT_FIELD_NAME_RESNAME = "resName" ;
55+
4556 private static final Logger LOGGER = LoggerFactory .getLogger (AnnotationHelper .class );
4657
4758 private final ProcessingEnvironment processingEnv ;
@@ -150,9 +161,13 @@ public Types getTypeUtils() {
150161 * @see #extractAnnotationResources(Element, String, IRInnerClass, boolean)
151162 */
152163 public List <JFieldRef > extractAnnotationFieldRefs (ProcessHolder holder , Element element , String annotationName , IRInnerClass rInnerClass , boolean useElementName ) {
164+ return extractAnnotationFieldRefs (holder , element , annotationName , rInnerClass , useElementName , DEFAULT_FIELD_NAME_VALUE , DEFAULT_FIELD_NAME_RESNAME );
165+ }
166+
167+ public List <JFieldRef > extractAnnotationFieldRefs (ProcessHolder holder , Element element , String annotationName , IRInnerClass rInnerClass , boolean useElementName , String idFieldName , String resFieldName ) {
153168 List <JFieldRef > fieldRefs = new ArrayList <JFieldRef >();
154169
155- for (String refQualifiedName : extractAnnotationResources (element , annotationName , rInnerClass , useElementName )) {
170+ for (String refQualifiedName : extractAnnotationResources (element , annotationName , rInnerClass , useElementName , idFieldName , resFieldName )) {
156171 fieldRefs .add (RInnerClass .extractIdStaticRef (holder , refQualifiedName ));
157172 }
158173
@@ -178,7 +193,11 @@ public List<JFieldRef> extractAnnotationFieldRefs(ProcessHolder holder, Element
178193 * class
179194 */
180195 public List <String > extractAnnotationResources (Element element , String annotationName , IRInnerClass rInnerClass , boolean useElementName ) {
181- int [] values = extractAnnotationResIdValueParameter (element , annotationName );
196+ return extractAnnotationResources (element , annotationName , rInnerClass , useElementName , DEFAULT_FIELD_NAME_VALUE , DEFAULT_FIELD_NAME_RESNAME );
197+ }
198+
199+ public List <String > extractAnnotationResources (Element element , String annotationName , IRInnerClass rInnerClass , boolean useElementName , String idFieldName , String resFieldName ) {
200+ int [] values = extractAnnotationResIdValueParameter (element , annotationName , idFieldName );
182201
183202 List <String > resourceIdQualifiedNames = new ArrayList <String >();
184203 /*
@@ -187,7 +206,7 @@ public List<String> extractAnnotationResources(Element element, String annotatio
187206 */
188207 if (defaultResIdValue (values )) {
189208
190- String [] resNames = extractAnnotationResNameParameter (element , annotationName );
209+ String [] resNames = extractAnnotationResNameParameter (element , annotationName , resFieldName );
191210
192211 if (defaultResName (resNames )) {
193212 /*
@@ -244,10 +263,14 @@ public boolean defaultResIdValue(int[] values) {
244263 }
245264
246265 public String [] extractAnnotationResNameParameter (Element element , String annotationName ) {
266+ return extractAnnotationResNameParameter (element , annotationName , DEFAULT_FIELD_NAME_RESNAME );
267+ }
268+
269+ public String [] extractAnnotationResNameParameter (Element element , String annotationName , String fieldName ) {
247270 /*
248271 * Annotation resName() parameter can be a String or a String[]
249272 */
250- Object annotationResName = extractAnnotationParameter (element , annotationName , "resName" );
273+ Object annotationResName = extractAnnotationParameter (element , annotationName , fieldName );
251274 if (annotationResName == null ) {
252275 // This case happened during refactoring, if the id has been changed
253276 // in the layout and compiler throws an error on the annotation
@@ -266,10 +289,14 @@ public String[] extractAnnotationResNameParameter(Element element, String annota
266289 }
267290
268291 public int [] extractAnnotationResIdValueParameter (Element element , String annotationName ) {
292+ return extractAnnotationResIdValueParameter (element , annotationName , DEFAULT_FIELD_NAME_VALUE );
293+ }
294+
295+ public int [] extractAnnotationResIdValueParameter (Element element , String annotationName , String fieldName ) {
269296 /*
270297 * Annotation value() parameter can be an int or an int[]
271298 */
272- Object annotationValue = extractAnnotationParameter (element , annotationName , "value" );
299+ Object annotationValue = extractAnnotationParameter (element , annotationName , fieldName );
273300 if (annotationValue == null ) {
274301 // This case happened during refactoring, if the id has been changed
275302 // in the layout and compiler throws an error on the annotation
@@ -375,7 +402,7 @@ public DeclaredType extractAnnotationClassParameter(Element element, String anno
375402 }
376403
377404 public DeclaredType extractAnnotationClassParameter (Element element , String annotationName ) {
378- return extractAnnotationClassParameter (element , annotationName , "value" );
405+ return extractAnnotationClassParameter (element , annotationName , DEFAULT_FIELD_NAME_VALUE );
379406 }
380407
381408 public boolean hasOneOfClassAnnotations (Element element , Class <? extends Annotation > validAnnotation ) {
0 commit comments