Skip to content

Commit 865e991

Browse files
committed
Print an error if we annotate an android MenuItem in a SherlockActivity and vice-versa
1 parent 5e38b20 commit 865e991

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/ThirdPartyLibHelper.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ public boolean usesHoloEverywhere(EBeanHolder holder) {
5454
*/
5555
public boolean usesActionBarSherlock(EBeanHolder holder) {
5656
TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(holder.generatedClass._extends().fullName());
57+
return usesActionBarSherlock(typeElement);
58+
}
5759

60+
/**
61+
* Checks whether the Activity extends one of the ActionBarSherlock Activity
62+
* types
63+
*/
64+
public boolean usesActionBarSherlock(TypeElement typeElement) {
5865
TypeMirror superType;
5966
while (!((superType = typeElement.getSuperclass()) instanceof NoType)) {
6067
typeElement = (TypeElement) ((DeclaredType) superType).asElement();

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/ValidatorHelper.java‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ public class ValidatorHelper {
7878

7979
private static final List<String> ANDROID_FRAGMENT_QUALIFIED_NAMES = asList(CanonicalNameConstants.FRAGMENT, CanonicalNameConstants.SUPPORT_V4_FRAGMENT);
8080

81-
private static final List<String> ANDROID_MENU_ITEM_QUALIFIED_NAMES = asList(CanonicalNameConstants.MENU_ITEM, CanonicalNameConstants.SHERLOCK_MENU_ITEM);
82-
8381
private static final String METHOD_NAME_SET_ROOT_URL = "setRootUrl";
8482

8583
private static final List<String> VALID_PREF_RETURN_TYPES = Arrays.asList("int", "boolean", "float", "long", CanonicalNameConstants.STRING);
@@ -92,9 +90,12 @@ public class ValidatorHelper {
9290

9391
public final ValidatorParameterHelper param;
9492

93+
private final ThirdPartyLibHelper thirdPartyLibHelper;
94+
9595
public ValidatorHelper(TargetAnnotationHelper targetAnnotationHelper) {
9696
annotationHelper = targetAnnotationHelper;
9797
param = new ValidatorParameterHelper(annotationHelper);
98+
thirdPartyLibHelper = new ThirdPartyLibHelper(annotationHelper);
9899
}
99100

100101
public void isNotFinal(Element element, IsValid valid) {
@@ -500,7 +501,17 @@ public void extendsContext(Element element, IsValid valid) {
500501
}
501502

502503
public void extendsMenuItem(Element element, IsValid valid) {
503-
extendsOneOfTypes(element, ANDROID_MENU_ITEM_QUALIFIED_NAMES, valid);
504+
Element enclosingElement = element.getEnclosingElement();
505+
String enclosingQualifiedName = enclosingElement.asType().toString();
506+
TypeElement enclosingTypeElement = annotationHelper.typeElementFromQualifiedName(enclosingQualifiedName);
507+
508+
if (enclosingTypeElement != null) {
509+
if (thirdPartyLibHelper.usesActionBarSherlock(enclosingTypeElement)) {
510+
extendsType(element, CanonicalNameConstants.SHERLOCK_MENU_ITEM, valid);
511+
} else {
512+
extendsType(element, CanonicalNameConstants.MENU_ITEM, valid);
513+
}
514+
}
504515
}
505516

506517
public void extendsOrmLiteDaoWithValidModelParameter(Element element, IsValid valid) {

0 commit comments

Comments
 (0)