Skip to content

Commit

Permalink
Merge pull request #12 from Omega-R/develop
Browse files Browse the repository at this point in the history
Remove default strategy
  • Loading branch information
anton-knyazev committed Oct 8, 2019
2 parents 1462b06 + 1808aec commit a29dc48
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package example.com.moxy_androidx_sample.contract

import com.omegar.mvp.viewstate.strategy.AddToEndSingleStrategy
import com.omegar.mvp.viewstate.strategy.StateStrategyType
import example.com.moxy_androidx_sample.fifth.Contract
import example.com.moxy_androidx_sample.first.FirstView
import example.com.moxy_androidx_sample.packagee.Item
import example.com.moxy_androidx_sample.second.SecondView

interface Contract {

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

fun printLog(msg: Double?, log: String?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
} catch (RuntimeException e) {
getMessager().printMessage(Diagnostic.Kind.OTHER, "Moxy compilation failed. Could you copy stack trace above and write us (or make issue on Github)?");
e.printStackTrace();
String s = Stream
.of(e.getStackTrace())
.map(StackTraceElement::toString)
.collect(Collectors.joining("\n"));
getMessager().printMessage(Diagnostic.Kind.ERROR, "Moxy compilation failed; see the compiler error output for details (" + s + ")");
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.omegar.mvp.compiler.ElementProcessor;
import com.omegar.mvp.compiler.MvpCompiler;
import com.omegar.mvp.compiler.Util;
import com.omegar.mvp.viewstate.strategy.AddToEndStrategy;
import com.omegar.mvp.viewstate.strategy.StateStrategyType;
import com.squareup.javapoet.ParameterSpec;

Expand Down Expand Up @@ -41,7 +40,6 @@
*/
public class ViewInterfaceProcessor extends ElementProcessor<TypeElement, List<ViewInterfaceInfo>> {
private static final String STATE_STRATEGY_TYPE_ANNOTATION = StateStrategyType.class.getName();
private static final TypeElement DEFAULT_STATE_STRATEGY = MvpCompiler.getElementUtils().getTypeElement(AddToEndStrategy.class.getCanonicalName());

private TypeElement viewInterfaceElement;
private String viewInterfaceName;
Expand Down Expand Up @@ -157,7 +155,7 @@ private Set<ViewInterfaceInfo> generateInfos(TypeElement element) {
}

private void getMethods(TypeElement typeElement,
TypeElement defaultStrategy,
TypeElement parentStrategy,
List<ViewMethod> rootMethods,
List<ViewMethod> superinterfacesMethods) {
for (Element element : typeElement.getEnclosedElements()) {
Expand Down Expand Up @@ -189,7 +187,22 @@ private void getMethods(TypeElement typeElement,
if (strategyClassFromAnnotation != null) {
strategyClass = (TypeElement) ((DeclaredType) strategyClassFromAnnotation).asElement();
} else {
strategyClass = defaultStrategy != null ? defaultStrategy : DEFAULT_STATE_STRATEGY;
if (parentStrategy != null) {
strategyClass = parentStrategy;
} else {
String message = String.format("You are trying generate ViewState for %s. " +
"But %s interface and \"%s\" method don't provide Strategy type. " +
"Please annotate your %s interface or method with Strategy." + "\n\n" +
"For example:\n@StateStrategyType(AddToEndSingleStrategy::class)" + "\n" + "fun %s",
typeElement.getSimpleName(),
typeElement.getSimpleName(),
methodElement.getSimpleName(),
typeElement.getSimpleName(),
methodElement.getSimpleName()
);
MvpCompiler.getMessager().printMessage(Diagnostic.Kind.ERROR, message);
return;
}
}

// get tag from annotation
Expand Down

0 comments on commit a29dc48

Please sign in to comment.