|
15 | 15 | */ |
16 | 16 | package com.googlecode.androidannotations.helper; |
17 | 17 |
|
18 | | -import static java.util.Arrays.asList; |
19 | | - |
20 | | -import java.util.ArrayList; |
21 | | -import java.util.List; |
22 | | - |
23 | 18 | import javax.lang.model.element.TypeElement; |
| 19 | +import javax.lang.model.type.DeclaredType; |
| 20 | +import javax.lang.model.type.NoType; |
| 21 | +import javax.lang.model.type.TypeMirror; |
24 | 22 |
|
25 | 23 | import com.googlecode.androidannotations.processing.EBeanHolder; |
26 | 24 |
|
|
29 | 27 | */ |
30 | 28 | public class SherlockHelper { |
31 | 29 |
|
32 | | - public static final List<String> SHERLOCK_ACTIVITY_CLASS_NAMES = asList( // |
33 | | - "com.actionbarsherlock.app.SherlockActivity", // |
34 | | - "com.actionbarsherlock.app.SherlockFragmentActivity", // |
35 | | - "com.actionbarsherlock.app.SherlockListActivity", // |
36 | | - "com.actionbarsherlock.app.SherlockExpandableListActivity.java", // |
37 | | - "com.actionbarsherlock.app.SherlockMapActivity", // |
38 | | - "com.actionbarsherlock.app.SherlockPreferenceActivity" // |
39 | | - ); |
40 | | - |
41 | 30 | private final AnnotationHelper annotationHelper; |
42 | 31 |
|
43 | | - private final List<TypeElement> sherlockActivityTypeElements = new ArrayList<TypeElement>(); |
44 | | - |
45 | 32 | public SherlockHelper(AnnotationHelper annotationHelper) { |
46 | 33 | this.annotationHelper = annotationHelper; |
47 | | - |
48 | | - for (String sherlockClassName : SHERLOCK_ACTIVITY_CLASS_NAMES) { |
49 | | - TypeElement sherlockActivityTypeElement = annotationHelper.typeElementFromQualifiedName(sherlockClassName); |
50 | | - if (sherlockActivityTypeElement != null) { |
51 | | - sherlockActivityTypeElements.add(sherlockActivityTypeElement); |
52 | | - } |
53 | | - } |
54 | 34 | } |
55 | 35 |
|
56 | 36 | /** |
57 | 37 | * Checks whether the Activity extends one of the ActionBarSherlock Activity |
58 | 38 | * types |
59 | 39 | */ |
60 | 40 | public boolean usesSherlock(EBeanHolder holder) { |
61 | | - TypeElement annotatedType = annotationHelper.typeElementFromQualifiedName(holder.eBean._extends().fullName()); |
62 | | - for (TypeElement sherlockActivityTypeElement : sherlockActivityTypeElements) { |
63 | | - if (annotationHelper.isSubtype(annotatedType, sherlockActivityTypeElement)) { |
| 41 | + TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(holder.eBean._extends().fullName()); |
| 42 | + |
| 43 | + TypeMirror superType; |
| 44 | + while (!((superType = typeElement.getSuperclass()) instanceof NoType)) { |
| 45 | + typeElement = (TypeElement) ((DeclaredType) superType).asElement(); |
| 46 | + if (typeElement.getQualifiedName().toString().startsWith("com.actionbarsherlock.app")) { |
64 | 47 | return true; |
65 | 48 | } |
66 | 49 | } |
|
0 commit comments