|
25 | 25 | import static org.androidannotations.helper.CanonicalNameConstants.HTTP_MESSAGE_CONVERTER; |
26 | 26 | import static org.androidannotations.helper.CanonicalNameConstants.INTERNET_PERMISSION; |
27 | 27 | import static org.androidannotations.helper.ModelConstants.GENERATION_SUFFIX; |
| 28 | +import static org.androidannotations.helper.ModelConstants.VALID_ENHANCED_COMPONENT_ANNOTATIONS; |
| 29 | +import static org.androidannotations.helper.ModelConstants.VALID_ENHANCED_VIEW_SUPPORT_ANNOTATIONS; |
28 | 30 |
|
29 | 31 | import java.lang.annotation.Annotation; |
30 | 32 | import java.util.ArrayList; |
|
49 | 51 | import javax.lang.model.util.Elements; |
50 | 52 |
|
51 | 53 | import org.androidannotations.annotations.EActivity; |
52 | | -import org.androidannotations.annotations.EApplication; |
53 | 54 | import org.androidannotations.annotations.EBean; |
54 | 55 | import org.androidannotations.annotations.EFragment; |
55 | | -import org.androidannotations.annotations.EProvider; |
56 | | -import org.androidannotations.annotations.EReceiver; |
57 | | -import org.androidannotations.annotations.EService; |
58 | | -import org.androidannotations.annotations.EView; |
59 | | -import org.androidannotations.annotations.EViewGroup; |
60 | 56 | import org.androidannotations.annotations.Trace; |
61 | 57 | import org.androidannotations.annotations.ViewById; |
62 | 58 | import org.androidannotations.annotations.rest.Delete; |
@@ -91,12 +87,6 @@ public class ValidatorHelper { |
91 | 87 |
|
92 | 88 | private static final Collection<Integer> VALID_LOG_LEVELS = Arrays.asList(LOG_VERBOSE, LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR); |
93 | 89 |
|
94 | | - @SuppressWarnings("unchecked") |
95 | | - private static final List<Class<? extends Annotation>> VALID_ENHANCED_VIEW_SUPPORT_ANNOTATIONS = asList(EActivity.class, EViewGroup.class, EView.class, EBean.class, EFragment.class); |
96 | | - |
97 | | - @SuppressWarnings("unchecked") |
98 | | - private static final List<Class<? extends Annotation>> VALID_ENHANCED_COMPONENT_ANNOTATIONS = asList(EApplication.class, EActivity.class, EViewGroup.class, EView.class, EBean.class, EService.class, EReceiver.class, EProvider.class, EFragment.class); |
99 | | - |
100 | 90 | protected final TargetAnnotationHelper annotationHelper; |
101 | 91 |
|
102 | 92 | public ValidatorHelper(TargetAnnotationHelper targetAnnotationHelper) { |
@@ -159,6 +149,13 @@ public void isNotPrivate(Element element, IsValid valid) { |
159 | 149 | } |
160 | 150 | } |
161 | 151 |
|
| 152 | + public void isPublic(Element element, IsValid valid) { |
| 153 | + if (!annotationHelper.isPublic(element)) { |
| 154 | + valid.invalidate(); |
| 155 | + annotationHelper.printAnnotationError(element, "%s cannot be used on a non public element"); |
| 156 | + } |
| 157 | + } |
| 158 | + |
162 | 159 | public void enclosingElementHasEBeanAnnotation(Element element, AnnotationElements validatedElements, IsValid valid) { |
163 | 160 | Element enclosingElement = element.getEnclosingElement(); |
164 | 161 | hasClassAnnotation(element, enclosingElement, validatedElements, EBean.class, valid); |
@@ -467,6 +464,15 @@ public void returnTypeIsVoid(ExecutableElement executableElement, IsValid valid) |
467 | 464 | } |
468 | 465 | } |
469 | 466 |
|
| 467 | + public void returnTypeIsNotVoid(ExecutableElement executableElement, IsValid valid) { |
| 468 | + TypeMirror returnType = executableElement.getReturnType(); |
| 469 | + |
| 470 | + if (returnType.getKind() == TypeKind.VOID) { |
| 471 | + valid.invalidate(); |
| 472 | + annotationHelper.printAnnotationError(executableElement, "%s can only be used on a method with a return type non void"); |
| 473 | + } |
| 474 | + } |
| 475 | + |
470 | 476 | public void zeroOrOneParameter(ExecutableElement executableElement, IsValid valid) { |
471 | 477 | List<? extends VariableElement> parameters = executableElement.getParameters(); |
472 | 478 |
|
@@ -682,6 +688,14 @@ public void extendsType(Element element, String typeQualifiedName, IsValid valid |
682 | 688 | } |
683 | 689 | } |
684 | 690 |
|
| 691 | + public void hasExactlyOneParameter(ExecutableElement executableElement, IsValid valid) { |
| 692 | + List<? extends VariableElement> parameters = executableElement.getParameters(); |
| 693 | + if (parameters.size() != 1) { |
| 694 | + valid.invalidate(); |
| 695 | + annotationHelper.printAnnotationError(executableElement, "%s can only be used on a method with exactly one parameter, instead of " + parameters.size()); |
| 696 | + } |
| 697 | + } |
| 698 | + |
685 | 699 | public void hasOneOrTwoParametersAndFirstIsBoolean(ExecutableElement executableElement, IsValid valid) { |
686 | 700 | List<? extends VariableElement> parameters = executableElement.getParameters(); |
687 | 701 |
|
|
0 commit comments