Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  Remove possible annotate StateStrategyType for interface Remove deprecreated annotation GenerateViewState
  • Loading branch information
anton-knyazev committed Dec 11, 2019
2 parents d99c851 + d7799dc commit ae6ec6b
Show file tree
Hide file tree
Showing 18 changed files with 29 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import com.omegar.mvp.viewstate.strategy.AddToEndSingleStrategy;
import com.omegar.mvp.viewstate.strategy.StateStrategyType;

@StateStrategyType(AddToEndSingleStrategy.class)
public interface BaseView extends MvpView {

@StateStrategyType(AddToEndSingleStrategy.class)
void testFunction();

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import example.com.moxy_androidx_sample.second.SecondView

interface Contract {

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

@StateStrategyType(AddToEndSingleStrategy::class)
fun printLog(msg: Double?, log: String?)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

public interface Contract {

@StateStrategyType(AddToEndSingleStrategy.class)
interface FifthView extends FourthView<String> {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import example.com.moxy_androidx_sample.BaseView;
import example.com.moxy_androidx_sample.third.ThirdView;

@StateStrategyType(AddToEndSingleStrategy.class)
public interface FirstView<M> extends BaseView, ThirdView {

@StateStrategyType(AddToEndSingleStrategy.class)
void firstMethod(List<M> item);

@StateStrategyType(AddToEndSingleStrategy.class)
void firstCopyMethod(List<Location> item);

@StateStrategyType(AddToEndSingleStrategy.class)
void firstLog(M m);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import com.omegar.mvp.viewstate.strategy.AddToEndSingleStrategy
import com.omegar.mvp.viewstate.strategy.StateStrategyType
import example.com.moxy_androidx_sample.BaseView

@StateStrategyType(AddToEndSingleStrategy::class)
interface FourthView<R> : BaseView {

@StateStrategyType(AddToEndSingleStrategy::class)
fun fourth(item: R)

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import example.com.moxy_androidx_sample.BaseView;

@StateStrategyType(AddToEndSingleStrategy.class)
public interface SecondView extends BaseView {

@StateStrategyType(AddToEndSingleStrategy.class)
void secondMethod();

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import example.com.moxy_androidx_sample.BaseView;

@StateStrategyType(AddToEndSingleStrategy.class)
public interface ThirdView extends BaseView {

@StateStrategyType(AddToEndSingleStrategy.class)
void thirdMethod();

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.omegar.mvp.compiler;

import com.google.auto.service.AutoService;
import com.omegar.mvp.GenerateViewState;
import com.omegar.mvp.InjectViewState;
import com.omegar.mvp.RegisterMoxyReflectorPackages;
import com.omegar.mvp.compiler.presenterbinder.InjectPresenterProcessor;
Expand Down Expand Up @@ -95,8 +94,7 @@ public Set<String> getSupportedAnnotationTypes() {
Collections.addAll(supportedAnnotationTypes,
InjectPresenter.class.getCanonicalName(),
InjectViewState.class.getCanonicalName(),
RegisterMoxyReflectorPackages.class.getCanonicalName(),
GenerateViewState.class.getCanonicalName());
RegisterMoxyReflectorPackages.class.getCanonicalName());
return supportedAnnotationTypes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.TypeParameterElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
Expand Down Expand Up @@ -115,10 +114,8 @@ private Set<ViewInterfaceInfo> generateInfos(TypeElement element) {

List<ViewMethod> methods = new ArrayList<>();

TypeElement interfaceStateStrategyType = getInterfaceStateStrategyType(element);

// Get methods for input class
getMethods(element, interfaceStateStrategyType, new ArrayList<>(), methods);
getMethods(element, new ArrayList<>(), methods);

// Add methods from super interfaces
ViewInterfaceInfo superInterfaceInfo = null;
Expand Down Expand Up @@ -155,7 +152,6 @@ private Set<ViewInterfaceInfo> generateInfos(TypeElement element) {
}

private void getMethods(TypeElement typeElement,
TypeElement parentStrategy,
List<ViewMethod> rootMethods,
List<ViewMethod> superinterfacesMethods) {
for (Element element : typeElement.getEnclosedElements()) {
Expand Down Expand Up @@ -187,22 +183,19 @@ private void getMethods(TypeElement typeElement,
if (strategyClassFromAnnotation != null) {
strategyClass = (TypeElement) ((DeclaredType) strategyClassFromAnnotation).asElement();
} else {
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;
}
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 Expand Up @@ -259,37 +252,6 @@ private void checkStrategyAndTagEquals(ViewMethod method, ViewMethod existingMet
}
}

private List<ViewMethod> iterateInterfaces(TypeElement parentElement,
TypeElement parentDefaultStrategy,
List<ViewMethod> rootMethods,
List<ViewMethod> superinterfacesMethods) {
for (TypeMirror typeMirror : parentElement.getInterfaces()) {
final TypeElement anInterface = (TypeElement) ((DeclaredType) typeMirror).asElement();

final List<? extends TypeMirror> typeArguments = ((DeclaredType) typeMirror).getTypeArguments();
final List<? extends TypeParameterElement> typeParameters = anInterface.getTypeParameters();

if (typeArguments.size() > typeParameters.size()) {
throw new IllegalArgumentException("Code generation for interface " + anInterface.getSimpleName() + " failed. Simplify your generics.");
}

TypeElement defaultStrategy = parentDefaultStrategy != null ? parentDefaultStrategy : getInterfaceStateStrategyType(anInterface);

getMethods(anInterface, defaultStrategy, rootMethods, superinterfacesMethods);

iterateInterfaces(anInterface, defaultStrategy, rootMethods, superinterfacesMethods);
}

return superinterfacesMethods;
}

private TypeElement getInterfaceStateStrategyType(TypeElement typeElement) {
AnnotationMirror annotation = Util.getAnnotation(typeElement, STATE_STRATEGY_TYPE_ANNOTATION);
TypeMirror value = Util.getAnnotationValueAsTypeMirror(annotation, "value");
if (value != null && value.getKind() == TypeKind.DECLARED) {
return (TypeElement) ((DeclaredType) value).asElement();
} else {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import view.strategies_inheritance.strategies.ChildDefaultStrategy;
import view.strategies_inheritance.strategies.Strategy2;

@StateStrategyType(ChildDefaultStrategy.class)
public interface ChildView extends ParentView {
@StateStrategyType(ChildDefaultStrategy.class)
void parentMethod1(); // ParentDefaultStrategy -> ChildDefaultStrategy

@StateStrategyType(Strategy2.class)
void parentMethod2(); // ParentDefaultStrategy -> Strategy2

@StateStrategyType(ChildDefaultStrategy.class)
void childMethod(); // ChildDefaultStrategy

@StateStrategyType(Strategy2.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import view.strategies_inheritance.strategies.ParentDefaultStrategy;
import view.strategies_inheritance.strategies.Strategy1;

@StateStrategyType(ParentDefaultStrategy.class)
public interface ParentView extends MvpView {
@StateStrategyType(ParentDefaultStrategy.class)
void parentMethod1(); // ParentDefaultStrategy

@StateStrategyType(ParentDefaultStrategy.class)
void parentMethod2(); // ParentDefaultStrategy

@StateStrategyType(ParentDefaultStrategy.class)
void parentMethod3(); // ParentDefaultStrategy

@StateStrategyType(Strategy1.class)
Expand Down
17 changes: 0 additions & 17 deletions moxy/src/main/java/com/omegar/mvp/GenerateViewState.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @author Yuri Shmakov
* @author Alexander Blinov
*/
@Target(value = {ElementType.TYPE, ElementType.METHOD})
@Target(value = {ElementType.METHOD})
@Retention(value = RetentionPolicy.RUNTIME)
public @interface StateStrategyType {
Class<? extends StateStrategy> value();
Expand Down
2 changes: 0 additions & 2 deletions moxy/src/test/java/com/omegar/mvp/view/ChildView.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.omegar.mvp.view;

import com.omegar.mvp.GenerateViewState;
import com.omegar.mvp.viewstate.strategy.SkipStrategy;
import com.omegar.mvp.viewstate.strategy.StateStrategyType;

Expand All @@ -10,7 +9,6 @@
*
* @author Savin Mikhail
*/
@GenerateViewState
@StateStrategyType(SkipStrategy.class)
public interface ChildView extends ParentView, SimpleInterface {
@Override
Expand Down
2 changes: 0 additions & 2 deletions moxy/src/test/java/com/omegar/mvp/view/ParentView.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.omegar.mvp.view;

import com.omegar.mvp.GenerateViewState;
import com.omegar.mvp.MvpView;
import com.omegar.mvp.viewstate.strategy.AddToEndSingleStrategy;
import com.omegar.mvp.viewstate.strategy.StateStrategyType;
Expand All @@ -11,7 +10,6 @@
*
* @author Savin Mikhail
*/
@GenerateViewState
public interface ParentView extends MvpView {
void withoutStrategyMethod();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package view;

import com.omegar.mvp.GenerateViewState;

/**
* Date: 26.02.2016
* Time: 12:09
*
* @author Savin Mikhail
*/
@GenerateViewState
public interface ViewStateChildWithIncorrectStrategyTagView extends ViewStateParentView, ViewStateParentStrategyTagView {

}
2 changes: 0 additions & 2 deletions moxy/src/test/resources/view/ViewStateForClassView.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package view;

import com.omegar.mvp.GenerateViewState;
import com.omegar.mvp.MvpView;

/**
Expand All @@ -9,7 +8,6 @@
*
* @author Savin Mikhail
*/
@GenerateViewState
public class ViewStateForClassView implements MvpView {
public void showProgress() {

Expand Down
3 changes: 0 additions & 3 deletions moxy/src/test/resources/view/ViewStateForNotView.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package view;

import com.omegar.mvp.GenerateViewState;

/**
* Date: 26.02.2016
* Time: 11:08
*
* @author Savin Mikhail
*/
@GenerateViewState
public interface ViewStateForNotView {
}

0 comments on commit ae6ec6b

Please sign in to comment.