2929import static org .androidannotations .helper .ModelConstants .VALID_ENHANCED_VIEW_SUPPORT_ANNOTATIONS ;
3030
3131import java .lang .annotation .Annotation ;
32- import java .util .*;
32+ import java .util .ArrayList ;
33+ import java .util .Arrays ;
34+ import java .util .Collection ;
35+ import java .util .HashMap ;
36+ import java .util .List ;
37+ import java .util .Map ;
38+ import java .util .Set ;
39+ import java .util .TreeSet ;
3340
3441import javax .lang .model .element .AnnotationMirror ;
3542import javax .lang .model .element .Element ;
4653import javax .lang .model .util .ElementFilter ;
4754import javax .lang .model .util .Elements ;
4855
49- import org .androidannotations .annotations .*;
56+ import org .androidannotations .annotations .EActivity ;
57+ import org .androidannotations .annotations .EBean ;
58+ import org .androidannotations .annotations .EFragment ;
59+ import org .androidannotations .annotations .EIntentService ;
60+ import org .androidannotations .annotations .EService ;
61+ import org .androidannotations .annotations .Receiver ;
62+ import org .androidannotations .annotations .Trace ;
63+ import org .androidannotations .annotations .ViewById ;
5064import org .androidannotations .annotations .rest .Delete ;
5165import org .androidannotations .annotations .rest .Get ;
5266import org .androidannotations .annotations .rest .Head ;
@@ -93,7 +107,6 @@ public class ValidatorHelper {
93107 private static final List <Receiver .RegisterAt > VALID_SERVICE_REGISTER_AT = Arrays .asList (Receiver .RegisterAt .OnCreateOnDestroy );
94108 private static final List <Receiver .RegisterAt > VALID_FRAGMENT_REGISTER_AT = Arrays .asList (Receiver .RegisterAt .OnCreateOnDestroy , Receiver .RegisterAt .OnResumeOnPause , Receiver .RegisterAt .OnStartOnStop , Receiver .RegisterAt .OnAttachOnDetach );
95109
96-
97110 protected final TargetAnnotationHelper annotationHelper ;
98111
99112 public final ValidatorParameterHelper param ;
@@ -1058,14 +1071,19 @@ public void validateConverters(Element element, IsValid valid) {
10581071 Element converterElement = converterType .asElement ();
10591072 if (converterElement .getKind ().isClass ()) {
10601073 if (!annotationHelper .isAbstract (converterElement )) {
1061- List <ExecutableElement > constructors = ElementFilter .constructorsIn (converterElement .getEnclosedElements ());
1062- for (ExecutableElement constructor : constructors ) {
1063- if (annotationHelper .isPublic (constructor ) && constructor .getParameters ().isEmpty ()) {
1064- return ;
1074+ if (converterElement .getAnnotation (EBean .class ) == null ) {
1075+ List <ExecutableElement > constructors = ElementFilter .constructorsIn (converterElement .getEnclosedElements ());
1076+ boolean hasPublicWithNoArgumentConstructor = false ;
1077+ for (ExecutableElement constructor : constructors ) {
1078+ if (annotationHelper .isPublic (constructor ) && constructor .getParameters ().isEmpty ()) {
1079+ hasPublicWithNoArgumentConstructor = true ;
1080+ }
1081+ }
1082+ if (!hasPublicWithNoArgumentConstructor ) {
1083+ valid .invalidate ();
1084+ annotationHelper .printAnnotationError (element , "The converter class must have a public no argument constructor" );
10651085 }
10661086 }
1067- valid .invalidate ();
1068- annotationHelper .printAnnotationError (element , "The converter class must have a public no argument constructor" );
10691087 } else {
10701088 valid .invalidate ();
10711089 annotationHelper .printAnnotationError (element , "The converter class must not be abstract" );
@@ -1079,28 +1097,6 @@ public void validateConverters(Element element, IsValid valid) {
10791097 annotationHelper .printAnnotationError (element , "The converter class must be a subtype of " + HTTP_MESSAGE_CONVERTER );
10801098 }
10811099 }
1082-
1083- }
1084-
1085- public void isDebuggable (Element element , AndroidManifest androidManifest , IsValid valid ) {
1086- if (!androidManifest .isDebuggable ()) {
1087- valid .invalidate ();
1088- annotationHelper .printAnnotationError (element , "The application must be in debuggable mode. Please set android:debuggable to true in your AndroidManifest.xml file." );
1089- }
1090- }
1091-
1092- public void hasInternetPermission (Element element , AndroidManifest androidManifest , IsValid valid ) {
1093- if (androidManifest .isLibraryProject ()) {
1094- return ;
1095- }
1096-
1097- String internetPermissionQualifiedName = INTERNET_PERMISSION ;
1098-
1099- List <String > permissionQualifiedNames = androidManifest .getPermissionQualifiedNames ();
1100- if (!permissionQualifiedNames .contains (internetPermissionQualifiedName )) {
1101- valid .invalidate ();
1102- annotationHelper .printAnnotationError (element , "Your application must require the INTERNET permission." );
1103- }
11041100 }
11051101
11061102 public void validateInterceptors (Element element , IsValid valid ) {
@@ -1116,14 +1112,19 @@ public void validateInterceptors(Element element, IsValid valid) {
11161112 Element interceptorElement = interceptorType .asElement ();
11171113 if (interceptorElement .getKind ().isClass ()) {
11181114 if (!annotationHelper .isAbstract (interceptorElement )) {
1119- List <ExecutableElement > constructors = ElementFilter .constructorsIn (interceptorElement .getEnclosedElements ());
1120- for (ExecutableElement constructor : constructors ) {
1121- if (annotationHelper .isPublic (constructor ) && constructor .getParameters ().isEmpty ()) {
1122- return ;
1115+ if (interceptorElement .getAnnotation (EBean .class ) == null ) {
1116+ List <ExecutableElement > constructors = ElementFilter .constructorsIn (interceptorElement .getEnclosedElements ());
1117+ boolean hasPublicWithNoArgumentConstructor = false ;
1118+ for (ExecutableElement constructor : constructors ) {
1119+ if (annotationHelper .isPublic (constructor ) && constructor .getParameters ().isEmpty ()) {
1120+ hasPublicWithNoArgumentConstructor = true ;
1121+ }
1122+ }
1123+ if (!hasPublicWithNoArgumentConstructor ) {
1124+ valid .invalidate ();
1125+ annotationHelper .printAnnotationError (element , "The interceptor class must have a public no argument constructor or be annotated with @EBean" );
11231126 }
11241127 }
1125- valid .invalidate ();
1126- annotationHelper .printAnnotationError (element , "The interceptor class must have a public no argument constructor" );
11271128 } else {
11281129 valid .invalidate ();
11291130 annotationHelper .printAnnotationError (element , "The interceptor class must not be abstract" );
@@ -1139,6 +1140,27 @@ public void validateInterceptors(Element element, IsValid valid) {
11391140 }
11401141 }
11411142
1143+ public void isDebuggable (Element element , AndroidManifest androidManifest , IsValid valid ) {
1144+ if (!androidManifest .isDebuggable ()) {
1145+ valid .invalidate ();
1146+ annotationHelper .printAnnotationError (element , "The application must be in debuggable mode. Please set android:debuggable to true in your AndroidManifest.xml file." );
1147+ }
1148+ }
1149+
1150+ public void hasInternetPermission (Element element , AndroidManifest androidManifest , IsValid valid ) {
1151+ if (androidManifest .isLibraryProject ()) {
1152+ return ;
1153+ }
1154+
1155+ String internetPermissionQualifiedName = INTERNET_PERMISSION ;
1156+
1157+ List <String > permissionQualifiedNames = androidManifest .getPermissionQualifiedNames ();
1158+ if (!permissionQualifiedNames .contains (internetPermissionQualifiedName )) {
1159+ valid .invalidate ();
1160+ annotationHelper .printAnnotationError (element , "Your application must require the INTERNET permission." );
1161+ }
1162+ }
1163+
11421164 public void hasBeforeTextChangedMethodParameters (ExecutableElement executableElement , IsValid valid ) {
11431165 List <? extends VariableElement > parameters = executableElement .getParameters ();
11441166 boolean charSequenceParameterFound = false ;
@@ -1352,9 +1374,9 @@ public void hasRightRegisterAtValueDependingOnEnclosingElement(Element element,
13521374 for (Map .Entry <String , List <Receiver .RegisterAt >> validRegisterAt : validRegisterAts .entrySet ()) {
13531375 String enclosingType = validRegisterAt .getKey ();
13541376 Collection <Receiver .RegisterAt > validRegisterAtValues = validRegisterAt .getValue ();
1355- if (extendsType (enclosingElement , enclosingType ) && !validRegisterAtValues .contains (registerAt )) {
1377+ if (extendsType (enclosingElement , enclosingType ) && !validRegisterAtValues .contains (registerAt )) {
13561378 valid .invalidate ();
1357- annotationHelper .printAnnotationError (element , "The parameter registerAt of @Receiver in " + enclosingType + " can only be one of the following values : " + validRegisterAtValues );
1379+ annotationHelper .printAnnotationError (element , "The parameter registerAt of @Receiver in " + enclosingType + " can only be one of the following values : " + validRegisterAtValues );
13581380 }
13591381 }
13601382 }
0 commit comments