From b803983a0fd511225c6334ad6f62e5796576cf93 Mon Sep 17 00:00:00 2001 From: Sergey Valevich Date: Fri, 15 Mar 2019 16:11:44 +0300 Subject: [PATCH] added annotation to find exact package for moxy reflector deleaget --- .../mvp/compiler/MvpCompiler.java | 24 ++++++++++++------- .../mvp/RegisterMoxyReflectorDelegate.java | 11 +++++++++ .../mvp/RegisterMoxyReflectorPackages.java | 13 ---------- 3 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 moxy/src/main/java/com/arellomobile/mvp/RegisterMoxyReflectorDelegate.java delete mode 100644 moxy/src/main/java/com/arellomobile/mvp/RegisterMoxyReflectorPackages.java diff --git a/moxy-compiler/src/main/java/com/arellomobile/mvp/compiler/MvpCompiler.java b/moxy-compiler/src/main/java/com/arellomobile/mvp/compiler/MvpCompiler.java index 5f66f6d2..507533d2 100644 --- a/moxy-compiler/src/main/java/com/arellomobile/mvp/compiler/MvpCompiler.java +++ b/moxy-compiler/src/main/java/com/arellomobile/mvp/compiler/MvpCompiler.java @@ -1,6 +1,7 @@ package com.arellomobile.mvp.compiler; import com.arellomobile.mvp.InjectViewState; +import com.arellomobile.mvp.RegisterMoxyReflectorDelegate; import com.arellomobile.mvp.compiler.presenterbinder.InjectPresenterProcessor; import com.arellomobile.mvp.compiler.presenterbinder.PresenterBinderClassGenerator; import com.arellomobile.mvp.compiler.reflector.MoxyReflectorGenerator; @@ -76,10 +77,12 @@ public synchronized void init(ProcessingEnvironment processingEnv) { @Override public Set getSupportedAnnotationTypes() { Set supportedAnnotationTypes = new HashSet<>(); - Collections.addAll(supportedAnnotationTypes, + Collections.addAll( + supportedAnnotationTypes, InjectPresenter.class.getCanonicalName(), - InjectViewState.class.getCanonicalName() - ); + InjectViewState.class.getCanonicalName(), + RegisterMoxyReflectorDelegate.class.getCanonicalName() + ); return supportedAnnotationTypes; } @@ -141,16 +144,21 @@ private boolean throwableProcess(RoundEnvironment roundEnv) { return true; } - /** - * @return first package associated with this module. - * Probably should return module's top-level package - */ private String getMoxyReflectorDelegatePackage( final RoundEnvironment roundEnv ) { + final Set elements = roundEnv.getElementsAnnotatedWith(RegisterMoxyReflectorDelegate.class); + + if (elements.isEmpty()) { + getMessager().printMessage( + Diagnostic.Kind.ERROR, + "Cannot find any class annotated with " + RegisterMoxyReflectorDelegate.class.getSimpleName() + " in this module" + ); + } + return processingEnv .getElementUtils() - .getPackageOf(roundEnv.getElementsAnnotatedWith(InjectPresenter.class).iterator().next()) + .getPackageOf(elements.iterator().next()) .getQualifiedName() .toString(); } diff --git a/moxy/src/main/java/com/arellomobile/mvp/RegisterMoxyReflectorDelegate.java b/moxy/src/main/java/com/arellomobile/mvp/RegisterMoxyReflectorDelegate.java new file mode 100644 index 00000000..d133bbd9 --- /dev/null +++ b/moxy/src/main/java/com/arellomobile/mvp/RegisterMoxyReflectorDelegate.java @@ -0,0 +1,11 @@ +package com.arellomobile.mvp; + +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.TYPE; + +/** + * Register MoxyReflector package + */ +@Target(TYPE) +public @interface RegisterMoxyReflectorDelegate {} diff --git a/moxy/src/main/java/com/arellomobile/mvp/RegisterMoxyReflectorPackages.java b/moxy/src/main/java/com/arellomobile/mvp/RegisterMoxyReflectorPackages.java deleted file mode 100644 index 8b09c9be..00000000 --- a/moxy/src/main/java/com/arellomobile/mvp/RegisterMoxyReflectorPackages.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.arellomobile.mvp; - -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.TYPE; - -/** - * Register MoxyReflector packages from other modules - */ -@Target(value = TYPE) -public @interface RegisterMoxyReflectorPackages { - String[] value(); -}