|
3 | 3 | import com.omegar.mvp.compiler.ElementProcessor; |
4 | 4 | import com.omegar.mvp.compiler.MvpCompiler; |
5 | 5 | import com.omegar.mvp.compiler.Util; |
6 | | -import com.omegar.mvp.viewstate.strategy.AddToEndStrategy; |
7 | 6 | import com.omegar.mvp.viewstate.strategy.StateStrategyType; |
8 | 7 | import com.squareup.javapoet.ParameterSpec; |
9 | 8 |
|
|
41 | 40 | */ |
42 | 41 | public class ViewInterfaceProcessor extends ElementProcessor<TypeElement, List<ViewInterfaceInfo>> { |
43 | 42 | private static final String STATE_STRATEGY_TYPE_ANNOTATION = StateStrategyType.class.getName(); |
44 | | - private static final TypeElement DEFAULT_STATE_STRATEGY = MvpCompiler.getElementUtils().getTypeElement(AddToEndStrategy.class.getCanonicalName()); |
45 | 43 |
|
46 | 44 | private TypeElement viewInterfaceElement; |
47 | 45 | private String viewInterfaceName; |
@@ -157,7 +155,7 @@ private Set<ViewInterfaceInfo> generateInfos(TypeElement element) { |
157 | 155 | } |
158 | 156 |
|
159 | 157 | private void getMethods(TypeElement typeElement, |
160 | | - TypeElement defaultStrategy, |
| 158 | + TypeElement parentStrategy, |
161 | 159 | List<ViewMethod> rootMethods, |
162 | 160 | List<ViewMethod> superinterfacesMethods) { |
163 | 161 | for (Element element : typeElement.getEnclosedElements()) { |
@@ -189,7 +187,22 @@ private void getMethods(TypeElement typeElement, |
189 | 187 | if (strategyClassFromAnnotation != null) { |
190 | 188 | strategyClass = (TypeElement) ((DeclaredType) strategyClassFromAnnotation).asElement(); |
191 | 189 | } else { |
192 | | - strategyClass = defaultStrategy != null ? defaultStrategy : DEFAULT_STATE_STRATEGY; |
| 190 | + if (parentStrategy != null) { |
| 191 | + strategyClass = parentStrategy; |
| 192 | + } else { |
| 193 | + String message = String.format("You are trying generate ViewState for %s. " + |
| 194 | + "But %s interface and \"%s\" method don't provide Strategy type. " + |
| 195 | + "Please annotate your %s interface or method with Strategy." + "\n\n" + |
| 196 | + "For example:\n@StateStrategyType(AddToEndSingleStrategy::class)" + "\n" + "fun %s", |
| 197 | + typeElement.getSimpleName(), |
| 198 | + typeElement.getSimpleName(), |
| 199 | + methodElement.getSimpleName(), |
| 200 | + typeElement.getSimpleName(), |
| 201 | + methodElement.getSimpleName() |
| 202 | + ); |
| 203 | + MvpCompiler.getMessager().printMessage(Diagnostic.Kind.ERROR, message); |
| 204 | + return; |
| 205 | + } |
193 | 206 | } |
194 | 207 |
|
195 | 208 | // get tag from annotation |
|
0 commit comments