Skip to content

Commit 2b4ce75

Browse files
Merge pull request #24 from Omega-R/develop
Fix multi module issues
2 parents 2751eec + ce7e676 commit 2b4ce75

File tree

10 files changed

+97
-19
lines changed

10 files changed

+97
-19
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package example.com.moxy_androidx_sample;
2+
3+
import com.omegar.mvp.InjectViewState;
4+
import com.omegar.mvp.MvpPresenter;
5+
6+
/**
7+
* Created by Anton Knyazev on 23.10.2020.
8+
*/
9+
public class BasePresenter<T extends BaseView> extends MvpPresenter<T> {
10+
11+
12+
}

moxy-androidx-sample/src/main/kotlin/example/com/moxy_androidx_sample/MainPresenter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.omegar.mvp.InjectViewState
55
import com.omegar.mvp.MvpPresenter
66
import example.com.moxy_androidx_sample.contract.Contract
77

8-
class MainPresenter : MvpPresenter<Contract.MainView>() {
8+
class MainPresenter : BasePresenter<Contract.MainView>() {
99

1010
override fun onFirstViewAttach() {
1111
super.onFirstViewAttach()

moxy-compiler/src/main/java/com/omegar/mvp/compiler/MvpCompiler.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.IOException;
2020
import java.lang.annotation.Annotation;
2121
import java.util.ArrayList;
22+
import java.util.Arrays;
2223
import java.util.Collections;
2324
import java.util.HashSet;
2425
import java.util.List;
@@ -55,6 +56,7 @@ public class MvpCompiler extends AbstractProcessor {
5556
public static final String MOXY_REFLECTOR_DEFAULT_PACKAGE = "com.omegar.mvp";
5657

5758
private static final String OPTION_MOXY_REFLECTOR_PACKAGE = "moxyReflectorPackage";
59+
private static final String OPTION_MOXY_REGISTER_REFLECTOR_PACKAGES = "moxyRegisterReflectorPackages";
5860

5961
private static Messager sMessager;
6062
private static Types sTypeUtils;
@@ -145,7 +147,16 @@ private boolean throwableProcess(RoundEnvironment roundEnv) {
145147
moxyReflectorPackage = MOXY_REFLECTOR_DEFAULT_PACKAGE;
146148
}
147149

148-
List<String> additionalMoxyReflectorPackages = getAdditionalMoxyReflectorPackages(roundEnv);
150+
String moxyRegisterReflectorPackage = sOptions.get(OPTION_MOXY_REGISTER_REFLECTOR_PACKAGES);
151+
152+
List<String> additionalMoxyReflectorPackages = new ArrayList<>();
153+
154+
if (moxyRegisterReflectorPackage != null) {
155+
String[] strings = moxyRegisterReflectorPackage.split(",");
156+
additionalMoxyReflectorPackages.addAll(Arrays.asList(strings));
157+
}
158+
159+
additionalMoxyReflectorPackages.addAll(getAdditionalMoxyReflectorPackages(roundEnv));
149160

150161
JavaFile moxyReflector = MoxyReflectorGenerator.generate(
151162
moxyReflectorPackage,

moxy-compiler/src/main/java/com/omegar/mvp/compiler/Util.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import javax.lang.model.type.TypeMirror;
4040
import javax.lang.model.type.TypeVariable;
4141
import javax.lang.model.type.WildcardType;
42-
import javax.tools.Diagnostic;
4342

4443
/**
4544
* Utilities for handling types in annotation processors
@@ -60,54 +59,56 @@ public static String fillGenerics(Map<String, String> types, List<? extends Type
6059
}
6160

6261
public static String fillGenerics(Map<String, String> types, List<? extends TypeMirror> params, String separator) {
63-
String result = "";
62+
StringBuilder result = new StringBuilder();
6463

6564
for (TypeMirror param : params) {
6665
if (result.length() > 0) {
67-
result += separator;
66+
result.append(separator);
6867
}
6968

7069
/**
7170
* "if" block's order is critically! E.g. IntersectionType is TypeVariable.
7271
*/
7372
if (param instanceof WildcardType) {
74-
result += "?";
73+
result.append("?");
7574
final TypeMirror extendsBound = ((WildcardType) param).getExtendsBound();
7675
if (extendsBound != null) {
77-
result += " extends " + fillGenerics(types, extendsBound);
76+
result.append(" extends ").append(fillGenerics(types, extendsBound));
7877
}
7978
final TypeMirror superBound = ((WildcardType) param).getSuperBound();
8079
if (superBound != null) {
81-
result += " super " + fillGenerics(types, superBound);
80+
result.append(" super ").append(fillGenerics(types, superBound));
8281
}
8382
} else if (param instanceof IntersectionType) {
84-
result += "?";
83+
result.append("?");
8584
final List<? extends TypeMirror> bounds = ((IntersectionType) param).getBounds();
8685

8786
if (!bounds.isEmpty()) {
88-
result += " extends " + fillGenerics(types, bounds, " & ");
87+
result.append(" extends ").append(fillGenerics(types, bounds, " & "));
8988
}
9089
} else if (param instanceof DeclaredType) {
91-
result += ((DeclaredType) param).asElement();
90+
result.append(((DeclaredType) param).asElement());
9291

9392
final List<? extends TypeMirror> typeArguments = ((DeclaredType) param).getTypeArguments();
9493
if (!typeArguments.isEmpty()) {
9594
final String s = fillGenerics(types, typeArguments);
9695

97-
result += "<" + s + ">";
96+
result.append("<").append(s).append(">");
9897
}
9998
} else if (param instanceof TypeVariable) {
10099
String type = types.get(param.toString());
100+
101101
if (type == null) {
102-
type = param.toString();
102+
type = ((TypeVariable) param).getUpperBound().toString();
103103
}
104-
result += type;
104+
result.append(type);
105+
105106
} else {
106-
result += param;
107+
result.append(param);
107108
}
108109
}
109110

110-
return result;
111+
return result.toString();
111112
}
112113

113114
public static String getFullClassName(TypeMirror typeMirror) {
@@ -207,6 +208,11 @@ public static boolean hasEmptyConstructor(TypeElement element) {
207208
return false;
208209
}
209210

211+
public static String capitalizeString(String string) {
212+
return string == null || string.isEmpty() ? "" : string.length() == 1 ? string.toUpperCase() : Character.toUpperCase(string.charAt(0)) + string.substring(1);
213+
}
214+
215+
210216
public static String decapitalizeString(String string) {
211217
return string == null || string.isEmpty() ? "" : string.length() == 1 ? string.toLowerCase() : Character.toLowerCase(string.charAt(0)) + string.substring(1);
212218
}

moxy-compiler/src/main/java/com/omegar/mvp/compiler/presenterbinder/TargetPresenterField.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.omegar.mvp.compiler.presenterbinder;
22

33
import com.omegar.mvp.MvpProcessor;
4+
import com.omegar.mvp.compiler.Util;
45
import com.omegar.mvp.presenter.PresenterType;
56
import com.squareup.javapoet.ParameterizedTypeName;
67
import com.squareup.javapoet.TypeName;
@@ -48,7 +49,7 @@ TypeName getTypeName() {
4849
}
4950

5051
String getGeneratedClassName() {
51-
return name + MvpProcessor.PRESENTER_BINDER_INNER_SUFFIX;
52+
return Util.capitalizeString(name) + MvpProcessor.PRESENTER_BINDER_INNER_SUFFIX;
5253
}
5354

5455
String getTag() {

moxy-compiler/src/main/java/com/omegar/mvp/compiler/reflector/MoxyReflectorGenerator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class MoxyReflectorGenerator {
4747
private static final TypeName MAP_CLASS_TO_LIST_OF_OBJECT_TYPE_NAME // Map<Class<*>, List<Object>>
4848
= ParameterizedTypeName.get(ClassName.get(Map.class), CLASS_WILDCARD_TYPE_NAME, LIST_OF_OBJECT_TYPE_NAME);
4949

50+
5051
public static JavaFile generate(String destinationPackage,
5152
List<TypeElement> presenterClassNames,
5253
List<TypeElement> presentersContainers,
@@ -170,6 +171,7 @@ private static CodeBlock generateStaticInitializer(List<TypeElement> presenterCl
170171
builder.addStatement("sStrategies.putAll($T.getStrategies())", moxyReflector);
171172
}
172173

174+
173175
return builder.build();
174176
}
175177

moxy-compiler/src/main/java/com/omegar/mvp/compiler/viewstate/ViewStateClassGenerator.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.omegar.mvp.compiler.viewstate;
22

33
import com.omegar.mvp.MvpProcessor;
4+
import com.omegar.mvp.NotGenerateParentClasses;
45
import com.omegar.mvp.compiler.JavaFilesGenerator;
56
import com.omegar.mvp.compiler.MvpCompiler;
67
import com.omegar.mvp.compiler.Util;
@@ -51,17 +52,32 @@ public final class ViewStateClassGenerator extends JavaFilesGenerator<List<ViewI
5152
public List<JavaFile> generate(List<ViewInterfaceInfo> list) {
5253
if (list.isEmpty()) return Collections.emptyList();
5354
List<JavaFile> fileList = new ArrayList<>();
55+
NotGenerateParentClasses annotation = null;
56+
int filterEnd = -1;
5457
for (int i = 0; i < list.size(); i++) {
5558
ViewInterfaceInfo info = list.get(i);
5659

60+
if (annotation == null) {
61+
annotation = info.getElement()
62+
.getAnnotation(NotGenerateParentClasses.class);
63+
if (annotation != null) {
64+
filterEnd = i;
65+
}
66+
}
67+
5768
JavaFile javaFile = filesMap.get(info);
5869
if (javaFile == null) {
5970
javaFile = generate(info);
60-
fileList.add(javaFile);
6171
filesMap.put(info, javaFile);
6272
}
73+
6374
fileList.add(javaFile);
6475
}
76+
77+
if (filterEnd >= 0) {
78+
return fileList.subList(filterEnd, fileList.size());
79+
}
80+
6581
return fileList;
6682
}
6783

moxy-compiler/src/main/java/com/omegar/mvp/compiler/viewstateprovider/InjectViewStateProcessor.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,17 @@ private String getViewStateClassName(TypeElement typeElement) {
6262
}
6363

6464
TypeElement viewTypeElement = MvpCompiler.getElementUtils().getTypeElement(view);
65+
6566
if (viewTypeElement == null) {
66-
throw new IllegalArgumentException("View \"" + view + "\" for " + typeElement + " cannot be found");
67+
view = getViewClassFromGeneric(typeElement);
68+
if (view.contains("<")) {
69+
view = view.substring(0, view.indexOf("<"));
70+
}
71+
viewTypeElement = MvpCompiler.getElementUtils().getTypeElement(view);
72+
}
73+
74+
if (viewTypeElement == null) {
75+
throw new IllegalArgumentException("View \"" + view + "\" for " + typeElement + " cannot be found. \n 1. " + getViewStateClassFromAnnotationParams(typeElement) + "\n 2. " + getViewClassFromAnnotationParams(typeElement) + "\n3. " + getViewClassFromGeneric(typeElement));
6776
}
6877

6978
usedViews.add(viewTypeElement);
@@ -141,6 +150,7 @@ private String getViewClassFromGeneric(TypeElement typeElement) {
141150
types.put(typeParameters.get(i).toString(), fillGenerics(parentTypes, typeArguments.get(i)));
142151
}
143152

153+
144154
if (superclassElement.toString().equals(MVP_PRESENTER_CLASS)) {
145155
// MvpPresenter is typed only on View class
146156
return fillGenerics(parentTypes, typeArguments);

moxy/src/main/java/com/omegar/mvp/InjectViewState.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@
2121
Class<? extends MvpViewState> value() default DefaultViewState.class;
2222

2323
Class<? extends MvpView> view() default DefaultView.class;
24+
2425
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.omegar.mvp;
2+
3+
import com.omegar.mvp.viewstate.MvpViewState;
4+
5+
import java.lang.annotation.Inherited;
6+
import java.lang.annotation.Target;
7+
8+
import static java.lang.annotation.ElementType.TYPE;
9+
10+
/**
11+
* Created by Anton Knyazev on 28.08.2020.
12+
*/
13+
@Target(value = TYPE)
14+
@Inherited
15+
public @interface NotGenerateParentClasses {
16+
17+
18+
}
19+

0 commit comments

Comments
 (0)