-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fixbug] Fix generation of MoxyReflector in library modules
- Loading branch information
Showing
13 changed files
with
216 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
moxy-compiler/src/test/java/com/arellomobile/mvp/compiler/MultiModulesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.arellomobile.mvp.compiler; | ||
|
||
import com.google.testing.compile.Compilation; | ||
|
||
import org.junit.Test; | ||
|
||
import javax.tools.JavaFileObject; | ||
|
||
import static com.google.testing.compile.CompilationSubject.assertThat; | ||
import static com.google.testing.compile.JavaFileObjects.forResource; | ||
import static com.google.testing.compile.JavaFileObjects.forSourceLines; | ||
|
||
public class MultiModulesTest extends CompilerTest { | ||
|
||
@Test | ||
public void testLibraryModule() throws Exception { | ||
JavaFileObject[] sources = { | ||
forResource("multimodules/lib1/Lib1Presenter.java"), | ||
forResource("multimodules/lib1/Lib1View.java") | ||
}; | ||
|
||
JavaFileObject[] generatedSources = { | ||
forResource("multimodules/lib1/Lib1Presenter$$ViewStateProvider.java"), | ||
forResource("multimodules/lib1/Lib1View$$State.java"), | ||
forResource("multimodules/lib1/MoxyReflector.java") | ||
}; | ||
|
||
Compilation compilation = compileLibSourcesWithProcessor("multimodules.lib1", sources); | ||
Compilation exceptedCompilation = compileSources(generatedSources); | ||
|
||
assertThat(compilation).succeededWithoutWarnings(); | ||
assertExceptedFilesGenerated(compilation.generatedFiles(), exceptedCompilation.generatedFiles()); | ||
} | ||
|
||
@Test | ||
public void testRegisterMoxyReflectorPackages() throws Exception { | ||
JavaFileObject someClientClass = forSourceLines("multimodules.app.App", | ||
"package multimodules.app;", | ||
"import com.arellomobile.mvp.RegisterMoxyReflectorPackages;", | ||
"@RegisterMoxyReflectorPackages(\"multimodules.lib1\")", | ||
"public class App {}" | ||
); | ||
|
||
JavaFileObject[] sources = new JavaFileObject[]{ | ||
forResource("multimodules/app/AppPresenter.java"), | ||
forResource("multimodules/app/AppView.java"), | ||
someClientClass | ||
}; | ||
|
||
JavaFileObject[] exceptedSources = new JavaFileObject[]{ | ||
forResource("multimodules/app/AppPresenter$$ViewStateProvider.java"), | ||
forResource("multimodules/app/AppView$$State.java"), | ||
forResource("multimodules/app/MoxyReflector.java") | ||
}; | ||
|
||
Compilation compilation = compileSourcesWithProcessor(sources); | ||
Compilation exceptedCompilation = compileSources(exceptedSources); | ||
|
||
assertThat(compilation).succeededWithoutWarnings(); | ||
assertExceptedFilesGenerated(compilation.generatedFiles(), exceptedCompilation.generatedFiles()); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
moxy-compiler/src/test/resources/multimodules/app/AppPresenter$$ViewStateProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package multimodules.app; | ||
|
||
import com.arellomobile.mvp.MvpView; | ||
import com.arellomobile.mvp.ViewStateProvider; | ||
import com.arellomobile.mvp.viewstate.MvpViewState; | ||
|
||
public class AppPresenter$$ViewStateProvider extends ViewStateProvider { | ||
@Override | ||
public MvpViewState<? extends MvpView> getViewState() { | ||
return new AppView$$State(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
moxy-compiler/src/test/resources/multimodules/app/AppPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package multimodules.app; | ||
|
||
import com.arellomobile.mvp.InjectViewState; | ||
import com.arellomobile.mvp.MvpPresenter; | ||
|
||
@InjectViewState | ||
public class AppPresenter extends MvpPresenter<AppView> { | ||
} |
6 changes: 6 additions & 0 deletions
6
moxy-compiler/src/test/resources/multimodules/app/AppView$$State.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package multimodules.app; | ||
|
||
import com.arellomobile.mvp.viewstate.MvpViewState; | ||
|
||
public class AppView$$State extends MvpViewState<AppView> implements AppView { | ||
} |
6 changes: 6 additions & 0 deletions
6
moxy-compiler/src/test/resources/multimodules/app/AppView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package multimodules.app; | ||
|
||
import com.arellomobile.mvp.MvpView; | ||
|
||
public interface AppView extends MvpView { | ||
} |
47 changes: 47 additions & 0 deletions
47
moxy-compiler/src/test/resources/multimodules/app/MoxyReflector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.arellomobile.mvp; | ||
|
||
import java.lang.Class; | ||
import java.lang.Object; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import multimodules.app.AppPresenter; | ||
import multimodules.app.AppPresenter$$ViewStateProvider; | ||
|
||
public final class MoxyReflector { | ||
private static Map<Class<?>, Object> sViewStateProviders; | ||
|
||
private static Map<Class<?>, List<Object>> sPresenterBinders; | ||
|
||
private static Map<Class<?>, Object> sStrategies; | ||
|
||
static { | ||
sViewStateProviders = new HashMap<>(); | ||
sViewStateProviders.put(AppPresenter.class, new AppPresenter$$ViewStateProvider()); | ||
|
||
sPresenterBinders = new HashMap<>(); | ||
|
||
sStrategies = new HashMap<>(); | ||
|
||
sViewStateProviders.putAll(multimodules.lib1.MoxyReflector.getViewStateProviders()); | ||
sPresenterBinders.putAll(multimodules.lib1.MoxyReflector.getPresenterBinders()); | ||
sStrategies.putAll(multimodules.lib1.MoxyReflector.getStrategies()); | ||
} | ||
|
||
public static Object getViewState(Class<?> presenterClass) { | ||
ViewStateProvider viewStateProvider = (ViewStateProvider) sViewStateProviders.get(presenterClass); | ||
if (viewStateProvider == null) { | ||
return null; | ||
} | ||
|
||
return viewStateProvider.getViewState(); | ||
} | ||
|
||
public static List<Object> getPresenterBinders(Class<?> delegated) { | ||
return sPresenterBinders.get(delegated); | ||
} | ||
|
||
public static Object getStrategy(Class<?> strategyClass) { | ||
return sStrategies.get(strategyClass); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
moxy-compiler/src/test/resources/multimodules/lib1/Lib1Presenter$$ViewStateProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package multimodules.lib1; | ||
|
||
import com.arellomobile.mvp.MvpView; | ||
import com.arellomobile.mvp.ViewStateProvider; | ||
import com.arellomobile.mvp.viewstate.MvpViewState; | ||
|
||
public class Lib1Presenter$$ViewStateProvider extends ViewStateProvider { | ||
@Override | ||
public MvpViewState<? extends MvpView> getViewState() { | ||
return new Lib1View$$State(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
moxy-compiler/src/test/resources/multimodules/lib1/Lib1Presenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package multimodules.lib1; | ||
|
||
import com.arellomobile.mvp.InjectViewState; | ||
import com.arellomobile.mvp.MvpPresenter; | ||
|
||
@InjectViewState | ||
public class Lib1Presenter extends MvpPresenter<Lib1View> { | ||
} |
6 changes: 6 additions & 0 deletions
6
moxy-compiler/src/test/resources/multimodules/lib1/Lib1View$$State.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package multimodules.lib1; | ||
|
||
import com.arellomobile.mvp.viewstate.MvpViewState; | ||
|
||
public class Lib1View$$State extends MvpViewState<Lib1View> implements Lib1View { | ||
} |
6 changes: 6 additions & 0 deletions
6
moxy-compiler/src/test/resources/multimodules/lib1/Lib1View.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package multimodules.lib1; | ||
|
||
import com.arellomobile.mvp.MvpView; | ||
|
||
public interface Lib1View extends MvpView { | ||
} |
34 changes: 34 additions & 0 deletions
34
moxy-compiler/src/test/resources/multimodules/lib1/MoxyReflector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package multimodules.lib1; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public final class MoxyReflector { | ||
private static Map<Class<?>, Object> sViewStateProviders; | ||
|
||
private static Map<Class<?>, List<Object>> sPresenterBinders; | ||
|
||
private static Map<Class<?>, Object> sStrategies; | ||
|
||
static { | ||
sViewStateProviders = new HashMap<>(); | ||
sViewStateProviders.put(Lib1Presenter.class, new Lib1Presenter$$ViewStateProvider()); | ||
|
||
sPresenterBinders = new HashMap<>(); | ||
|
||
sStrategies = new HashMap<>(); | ||
} | ||
|
||
public static Map<Class<?>, Object> getViewStateProviders() { | ||
return sViewStateProviders; | ||
} | ||
|
||
public static Map<Class<?>, List<Object>> getPresenterBinders() { | ||
return sPresenterBinders; | ||
} | ||
|
||
public static Map<Class<?>, Object> getStrategies() { | ||
return sStrategies; | ||
} | ||
} |