Skip to content

Commit 78d80fa

Browse files
committed
Refactor ValidatorHelper.canBePutInABundle()
This simpler implementation allows to check type variables, too.
1 parent 0c2b18e commit 78d80fa

1 file changed

Lines changed: 7 additions & 34 deletions

File tree

  • AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper

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

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,47 +1034,20 @@ public void hasValidLogLevel(Element element, IsValid isValid) {
10341034
}
10351035

10361036
public void canBePutInABundle(Element element, IsValid isValid) {
1037+
TypeMirror typeMirror = element.asType();
10371038
String typeString = element.asType().toString();
10381039

10391040
if (!isKnownBundleCompatibleType(typeString)) {
10401041

1041-
if (element.asType() instanceof DeclaredType) {
1042-
1043-
DeclaredType declaredType = (DeclaredType) element.asType();
1044-
typeString = declaredType.asElement().toString();
1045-
1046-
} else if (element.asType() instanceof ArrayType) {
1042+
if (typeMirror instanceof ArrayType) {
10471043
ArrayType arrayType = (ArrayType) element.asType();
1048-
TypeMirror componentType = arrayType.getComponentType();
1049-
1050-
if (componentType instanceof DeclaredType) {
1051-
1052-
DeclaredType declaredType = (DeclaredType) componentType;
1053-
typeString = declaredType.asElement().toString();
1054-
1055-
} else {
1056-
typeString = componentType.toString();
1057-
}
1058-
1059-
} else {
1060-
typeString = element.asType().toString();
1061-
}
1062-
1063-
TypeElement elementType = annotationHelper.typeElementFromQualifiedName(typeString);
1064-
1065-
if (elementType == null) {
1066-
elementType = getArrayEnclosingType(typeString);
1067-
1068-
if (elementType == null) {
1069-
annotationHelper.printAnnotationError(element, "Unrecognized type. Please let your attribute be primitive or implement Serializable or Parcelable");
1070-
isValid.invalidate();
1071-
}
1044+
typeMirror = arrayType.getComponentType();
10721045
}
10731046

1074-
if (elementType != null) {
1075-
TypeElement parcelableType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.PARCELABLE);
1076-
TypeElement serializableType = annotationHelper.typeElementFromQualifiedName("java.io.Serializable");
1077-
if (!annotationHelper.isSubtype(elementType, parcelableType) && !annotationHelper.isSubtype(elementType, serializableType)) {
1047+
if (typeMirror.getKind() != TypeKind.NONE) {
1048+
TypeMirror parcelableType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.PARCELABLE).asType();
1049+
TypeMirror serializableType = annotationHelper.typeElementFromQualifiedName("java.io.Serializable").asType();
1050+
if (!annotationHelper.isSubtype(typeMirror, parcelableType) && !annotationHelper.isSubtype(typeMirror, serializableType)) {
10781051
annotationHelper.printAnnotationError(element, "Unrecognized type. Please let your attribute be primitive or implement Serializable or Parcelable");
10791052
isValid.invalidate();
10801053
}

0 commit comments

Comments
 (0)