Skip to content

Commit a29dc48

Browse files
Merge pull request #12 from Omega-R/develop
Remove default strategy
2 parents 1462b06 + 1808aec commit a29dc48

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

moxy-androidx-sample/src/main/kotlin/example/com/moxy_androidx_sample/contract/Contract.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package example.com.moxy_androidx_sample.contract
22

3+
import com.omegar.mvp.viewstate.strategy.AddToEndSingleStrategy
4+
import com.omegar.mvp.viewstate.strategy.StateStrategyType
35
import example.com.moxy_androidx_sample.fifth.Contract
46
import example.com.moxy_androidx_sample.first.FirstView
57
import example.com.moxy_androidx_sample.packagee.Item
68
import example.com.moxy_androidx_sample.second.SecondView
79

810
interface Contract {
911

12+
@StateStrategyType(AddToEndSingleStrategy::class)
1013
interface MainView : FirstView<Item>, SecondView, Contract.FifthView {
1114

1215
fun printLog(msg: Double?, log: String?)

moxy-compiler/src/main/java/com/omegar/mvp/compiler/MvpCompiler.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,6 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
114114
} catch (RuntimeException e) {
115115
getMessager().printMessage(Diagnostic.Kind.OTHER, "Moxy compilation failed. Could you copy stack trace above and write us (or make issue on Github)?");
116116
e.printStackTrace();
117-
String s = Stream
118-
.of(e.getStackTrace())
119-
.map(StackTraceElement::toString)
120-
.collect(Collectors.joining("\n"));
121-
getMessager().printMessage(Diagnostic.Kind.ERROR, "Moxy compilation failed; see the compiler error output for details (" + s + ")");
122117
}
123118

124119
return true;

moxy-compiler/src/main/java/com/omegar/mvp/compiler/viewstate/ViewInterfaceProcessor.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.omegar.mvp.compiler.ElementProcessor;
44
import com.omegar.mvp.compiler.MvpCompiler;
55
import com.omegar.mvp.compiler.Util;
6-
import com.omegar.mvp.viewstate.strategy.AddToEndStrategy;
76
import com.omegar.mvp.viewstate.strategy.StateStrategyType;
87
import com.squareup.javapoet.ParameterSpec;
98

@@ -41,7 +40,6 @@
4140
*/
4241
public class ViewInterfaceProcessor extends ElementProcessor<TypeElement, List<ViewInterfaceInfo>> {
4342
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());
4543

4644
private TypeElement viewInterfaceElement;
4745
private String viewInterfaceName;
@@ -157,7 +155,7 @@ private Set<ViewInterfaceInfo> generateInfos(TypeElement element) {
157155
}
158156

159157
private void getMethods(TypeElement typeElement,
160-
TypeElement defaultStrategy,
158+
TypeElement parentStrategy,
161159
List<ViewMethod> rootMethods,
162160
List<ViewMethod> superinterfacesMethods) {
163161
for (Element element : typeElement.getEnclosedElements()) {
@@ -189,7 +187,22 @@ private void getMethods(TypeElement typeElement,
189187
if (strategyClassFromAnnotation != null) {
190188
strategyClass = (TypeElement) ((DeclaredType) strategyClassFromAnnotation).asElement();
191189
} 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+
}
193206
}
194207

195208
// get tag from annotation

0 commit comments

Comments
 (0)