Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@
*/
package com.arellomobile.mvp.compiler;

import com.google.common.base.Preconditions;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.BiFunction;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
Expand Down Expand Up @@ -190,4 +196,29 @@ public static boolean hasEmptyConstructor(TypeElement element) {
public static String decapitalizeString(String string) {
return string == null || string.isEmpty() ? "" : string.length() == 1 ? string.toLowerCase() : Character.toLowerCase(string.charAt(0)) + string.substring(1);
}

public static <T> boolean equalsBy(
Collection<T> first,
Collection<T> second,
BiFunction<T, T, Boolean> predicate) {

Preconditions.checkArgument(predicate != null, "Require non null predicate!");
if (first != null && second != null) {
if (first.size() != second.size()) {
return false;
}
final Iterator<T> firstIterator = first.iterator();
final Iterator<T> secondIterator = second.iterator();
while (firstIterator.hasNext()) {
final T firstItem = firstIterator.next();
final T secondItem = secondIterator.next();
if (!predicate.apply(firstItem, secondItem)) {
return false;
}
}
return true;
} else {
return first != second;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.arellomobile.mvp.compiler.viewstate;

import com.arellomobile.mvp.compiler.MvpCompiler;
import com.arellomobile.mvp.compiler.Util;
import com.squareup.javapoet.ParameterSpec;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeVariableName;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.ExecutableType;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Types;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
* Date: 27-Jul-2017
Expand Down Expand Up @@ -134,13 +135,19 @@ public boolean equals(Object o) {

ViewMethod that = (ViewMethod) o;

return name.equals(that.name) && parameterSpecs.equals(that.parameterSpecs);
return Objects.equals(name, that.name) && Util.equalsBy(parameterSpecs, that.parameterSpecs,
(first, second) -> Objects.equals(first.type, second.type));
}

@Override
public int hashCode() {
int result = name.hashCode();
result = 31 * result + parameterSpecs.hashCode();
if (name == null && parameterSpecs == null) {
return 0;
}
int result = 31 + Objects.hashCode(name);
for (ParameterSpec spec : parameterSpecs) {
result = 31 * result + (spec != null ? Objects.hashCode(spec.type) : 0);
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import com.arellomobile.mvp.viewstate.MvpViewState;
import com.arellomobile.mvp.viewstate.ViewCommand;

import java.lang.Override;
import java.lang.String;
import view.strategies_inheritance.strategies.ChildDefaultStrategy;
import view.strategies_inheritance.strategies.Strategy1;
import view.strategies_inheritance.strategies.Strategy2;

public class ChildView$$State extends MvpViewState<ChildView> implements ChildView {

@Override
public void parentMethod1() {
ParentMethod1Command parentMethod1Command = new ParentMethod1Command();
Expand Down Expand Up @@ -57,6 +57,54 @@ public void childMethod() {
mViewCommands.afterApply(childMethodCommand);
}

@Override
public void parentMethodWithArg(final String i) {
ParentMethodWithArgCommand parentMethodWithArgCommand = new ParentMethodWithArgCommand(i);
mViewCommands.beforeApply(parentMethodWithArgCommand);

if (mViews == null || mViews.isEmpty()) {
return;
}

for (ChildView view : mViews) {
view.parentMethodWithArg(i);
}

mViewCommands.afterApply(parentMethodWithArgCommand);
}

@Override
public void parentMethodWithArg2(String i) {
ParentMethodWithArg2Command parentMethodWithArg2Command = new ParentMethodWithArg2Command(i);
mViewCommands.beforeApply(parentMethodWithArg2Command);

if (mViews == null || mViews.isEmpty()) {
return;
}

for (ChildView view : mViews) {
view.parentMethodWithArg2(i);
}

mViewCommands.afterApply(parentMethodWithArg2Command);
}

@Override
public void parentMethodWithArg3(String a) {
ParentMethodWithArg3Command parentMethodWithArg3Command = new ParentMethodWithArg3Command(a);
mViewCommands.beforeApply(parentMethodWithArg3Command);

if (mViews == null || mViews.isEmpty()) {
return;
}

for (ChildView view : mViews) {
view.parentMethodWithArg3(a);
}

mViewCommands.afterApply(parentMethodWithArg3Command);
}

@Override
public void childMethodWithStrategy() {
ChildMethodWithStrategyCommand childMethodWithStrategyCommand = new ChildMethodWithStrategyCommand();
Expand Down Expand Up @@ -105,7 +153,6 @@ public void parentMethodWithStrategy() {
mViewCommands.afterApply(parentMethodWithStrategyCommand);
}


public class ParentMethod1Command extends ViewCommand<ChildView> {
ParentMethod1Command() {
super("parentMethod1", ChildDefaultStrategy.class);
Expand Down Expand Up @@ -139,6 +186,51 @@ public void apply(ChildView mvpView) {
}
}

public class ParentMethodWithArgCommand extends ViewCommand<ChildView> {
public final String i;

ParentMethodWithArgCommand(final String i) {
super("parentMethodWithArg", ChildDefaultStrategy.class);

this.i = i;
}

@Override
public void apply(ChildView mvpView) {
mvpView.parentMethodWithArg(i);
}
}

public class ParentMethodWithArg2Command extends ViewCommand<ChildView> {
public final String i;

ParentMethodWithArg2Command(String i) {
super("parentMethodWithArg2", ChildDefaultStrategy.class);

this.i = i;
}

@Override
public void apply(ChildView mvpView) {
mvpView.parentMethodWithArg2(i);
}
}

public class ParentMethodWithArg3Command extends ViewCommand<ChildView> {
public final String a;

ParentMethodWithArg3Command(String a) {
super("parentMethodWithArg3", ChildDefaultStrategy.class);

this.a = a;
}

@Override
public void apply(ChildView mvpView) {
mvpView.parentMethodWithArg3(a);
}
}

public class ChildMethodWithStrategyCommand extends ViewCommand<ChildView> {
ChildMethodWithStrategyCommand() {
super("childMethodWithStrategy", Strategy2.class);
Expand Down Expand Up @@ -171,4 +263,4 @@ public void apply(ChildView mvpView) {
mvpView.parentMethodWithStrategy();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import view.strategies_inheritance.strategies.ChildDefaultStrategy;
import view.strategies_inheritance.strategies.Strategy2;

import javax.annotation.Nullable;

@StateStrategyType(ChildDefaultStrategy.class)
public interface ChildView extends ParentView {
void parentMethod1(); // ParentDefaultStrategy -> ChildDefaultStrategy
Expand All @@ -14,6 +16,13 @@ public interface ChildView extends ParentView {

void childMethod(); // ChildDefaultStrategy

@Override
void parentMethodWithArg(final String i); // ParentDefaultStrategy -> ChildDefaultStrategy

void parentMethodWithArg2(@Nullable String i); // ParentDefaultStrategy

void parentMethodWithArg3(String a); // ParentDefaultStrategy

@StateStrategyType(Strategy2.class)
void childMethodWithStrategy(); // Strategy2
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import com.arellomobile.mvp.viewstate.MvpViewState;
import com.arellomobile.mvp.viewstate.ViewCommand;

import java.lang.Override;
import java.lang.String;
import view.strategies_inheritance.strategies.ParentDefaultStrategy;
import view.strategies_inheritance.strategies.Strategy1;

public class ParentView$$State extends MvpViewState<ParentView> implements ParentView {

@Override
public void parentMethod1() {
ParentMethod1Command parentMethod1Command = new ParentMethod1Command();
Expand Down Expand Up @@ -56,6 +56,54 @@ public void parentMethod3() {
mViewCommands.afterApply(parentMethod3Command);
}

@Override
public void parentMethodWithArg(String i) {
ParentMethodWithArgCommand parentMethodWithArgCommand = new ParentMethodWithArgCommand(i);
mViewCommands.beforeApply(parentMethodWithArgCommand);

if (mViews == null || mViews.isEmpty()) {
return;
}

for (ParentView view : mViews) {
view.parentMethodWithArg(i);
}

mViewCommands.afterApply(parentMethodWithArgCommand);
}

@Override
public void parentMethodWithArg2(String i) {
ParentMethodWithArg2Command parentMethodWithArg2Command = new ParentMethodWithArg2Command(i);
mViewCommands.beforeApply(parentMethodWithArg2Command);

if (mViews == null || mViews.isEmpty()) {
return;
}

for (ParentView view : mViews) {
view.parentMethodWithArg2(i);
}

mViewCommands.afterApply(parentMethodWithArg2Command);
}

@Override
public void parentMethodWithArg3(String i) {
ParentMethodWithArg3Command parentMethodWithArg3Command = new ParentMethodWithArg3Command(i);
mViewCommands.beforeApply(parentMethodWithArg3Command);

if (mViews == null || mViews.isEmpty()) {
return;
}

for (ParentView view : mViews) {
view.parentMethodWithArg3(i);
}

mViewCommands.afterApply(parentMethodWithArg3Command);
}

@Override
public void parentMethodWithStrategy() {
ParentMethodWithStrategyCommand parentMethodWithStrategyCommand = new ParentMethodWithStrategyCommand();
Expand All @@ -72,7 +120,6 @@ public void parentMethodWithStrategy() {
mViewCommands.afterApply(parentMethodWithStrategyCommand);
}


public class ParentMethod1Command extends ViewCommand<ParentView> {
ParentMethod1Command() {
super("parentMethod1", ParentDefaultStrategy.class);
Expand Down Expand Up @@ -106,6 +153,51 @@ public void apply(ParentView mvpView) {
}
}

public class ParentMethodWithArgCommand extends ViewCommand<ParentView> {
public final String i;

ParentMethodWithArgCommand(String i) {
super("parentMethodWithArg", ParentDefaultStrategy.class);

this.i = i;
}

@Override
public void apply(ParentView mvpView) {
mvpView.parentMethodWithArg(i);
}
}

public class ParentMethodWithArg2Command extends ViewCommand<ParentView> {
public final String i;

ParentMethodWithArg2Command(String i) {
super("parentMethodWithArg2", ParentDefaultStrategy.class);

this.i = i;
}

@Override
public void apply(ParentView mvpView) {
mvpView.parentMethodWithArg2(i);
}
}

public class ParentMethodWithArg3Command extends ViewCommand<ParentView> {
public final String i;

ParentMethodWithArg3Command(String i) {
super("parentMethodWithArg3", ParentDefaultStrategy.class);

this.i = i;
}

@Override
public void apply(ParentView mvpView) {
mvpView.parentMethodWithArg3(i);
}
}

public class ParentMethodWithStrategyCommand extends ViewCommand<ParentView> {
ParentMethodWithStrategyCommand() {
super("parentMethodWithStrategy", Strategy1.class);
Expand All @@ -116,4 +208,4 @@ public void apply(ParentView mvpView) {
mvpView.parentMethodWithStrategy();
}
}
}
}
Loading