Skip to content

Commit a0891eb

Browse files
Merge pull request #26 from Omega-R/develop
Develop
2 parents c9d1e7e + 1091c81 commit a0891eb

File tree

16 files changed

+263
-145
lines changed

16 files changed

+263
-145
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import com.omegar.mvp.presenter.InjectPresenter
77
import example.com.moxy_androidx_sample.contract.Contract
88
import example.com.moxy_androidx_sample.packagee.Item
99

10-
class MainActivity : BaseActivity(R.layout.activity_main), Contract.MainView, SecondInterface {
10+
class MainActivity : BaseActivity(R.layout.activity_main), Contract.MainView<Double>, SecondInterface {
1111
// override fun fourth(item: String?) {
1212
// TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
1313
// }

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
@@ -3,7 +3,7 @@ package example.com.moxy_androidx_sample
33
import android.util.Log
44
import example.com.moxy_androidx_sample.contract.Contract
55

6-
class MainPresenter : BasePresenter<Contract.MainView>() {
6+
class MainPresenter : BasePresenter<Contract.MainView<Double>>() {
77

88
override fun onFirstViewAttach() {
99
super.onFirstViewAttach()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import example.com.moxy_androidx_sample.BaseView
66

77
interface Contract {
88

9-
interface MainView : BaseView {
9+
interface MainView<D: Number> : BaseView {
1010

1111
@StateStrategyType(ADD_TO_END_SINGLE)
12-
fun printLog(msg: Double?, log: String?)
12+
fun printLog(msg: D?, log: String?)
1313

1414
}
1515

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

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.omegar.mvp.compiler.reflector.MoxyReflectorProcessor;
1616
import com.omegar.mvp.compiler.viewstate.ElementToViewInterfaceInfoProcessor;
1717
import com.omegar.mvp.compiler.viewstate.ViewInterfaceInfoToViewStateJavaFileProcessor;
18+
import com.omegar.mvp.compiler.viewstate.ViewInterfaceInfoValidator;
1819
import com.omegar.mvp.compiler.viewstateprovider.ElementToPresenterInfoProcessor;
1920
import com.omegar.mvp.compiler.viewstateprovider.NormalPresenterValidator;
2021
import com.omegar.mvp.compiler.viewstateprovider.PresenterInfoToViewStateProviderJavaFileProcessor;
@@ -53,7 +54,7 @@
5354
*
5455
* @author Yuri Shmakov
5556
*/
56-
57+
@SuppressWarnings("NewApi")
5758
@AutoService(Processor.class)
5859
@IncrementalAnnotationProcessor(IncrementalAnnotationProcessorType.DYNAMIC)
5960
public class MvpCompiler extends AbstractProcessor {
@@ -134,10 +135,8 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
134135
}
135136

136137
private boolean throwableProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
137-
138138
String currentMoxyReflectorPackage = mOptions.getOrDefault(OPTION_MOXY_REFLECTOR_PACKAGE, DEFAULT_MOXY_REFLECTOR_PACKAGE);
139139

140-
141140
Publisher<TypeElement> presenterContainerElementPublisher = new Publisher<>();
142141
Publisher<TypeElement> presenterElementPublisher = new Publisher<>();
143142
Publisher<TypeElement> viewElementPublisher = new Publisher<>();
@@ -146,6 +145,36 @@ private boolean throwableProcess(Set<? extends TypeElement> annotations, RoundEn
146145

147146
JavaFileWriter fileWriter = new JavaFileWriter(processingEnv.getFiler());
148147

148+
// moxyReflectorPipeline
149+
new Pipeline.Builder<>(
150+
QuadPublisher.collectQuad(
151+
presenterElementPublisher,
152+
presenterContainerElementPublisher,
153+
strategiesElementPublisher,
154+
reflectorPackagesPublisher))
155+
.addProcessor(new MoxyReflectorProcessor(currentMoxyReflectorPackage))
156+
.buildPipeline(fileWriter)
157+
.start();
158+
159+
160+
// viewStatePipeline
161+
new Pipeline.Builder<>(viewElementPublisher)
162+
.addProcessor(new ElementToViewInterfaceInfoProcessor(mElements, mTypes, mMessager, strategiesElementPublisher))
163+
.uniqueFilter()
164+
.addValidator(new ViewInterfaceInfoValidator(mElements, currentMoxyReflectorPackage))
165+
.addProcessor(new ViewInterfaceInfoToViewStateJavaFileProcessor(mElements, mTypes, currentMoxyReflectorPackage, reflectorPackagesPublisher))
166+
.buildPipeline(fileWriter)
167+
.start();
168+
169+
// viewStateProviderPipeline
170+
new Pipeline.Builder<>(new ElementsAnnotatedGenerator<>(roundEnv, mMessager, mInjectViewStateAnnotation))
171+
.addProcessor(new ElementToPresenterInfoProcessor(mElements, viewElementPublisher))
172+
.addValidator(new NormalPresenterValidator())
173+
.copyTypeElementTo(presenterElementPublisher)
174+
.addProcessor(new PresenterInfoToViewStateProviderJavaFileProcessor().withCache())
175+
.buildPipeline(fileWriter)
176+
.start();
177+
149178
if (mInjectPresenterAnnotation.contains(annotations)) {
150179
checkInjectors(roundEnv, new PresenterInjectorRules(mElements, mMessager, mInjectPresenterAnnotation, Modifier.PUBLIC, Modifier.PROTECTED, Modifier.DEFAULT));
151180

@@ -162,35 +191,7 @@ private boolean throwableProcess(Set<? extends TypeElement> annotations, RoundEn
162191
presenterContainerElementPublisher.finish();
163192
}
164193

165-
// viewStateProviderPipeline
166-
new Pipeline.Builder<>(new ElementsAnnotatedGenerator<>(roundEnv, mMessager, mInjectViewStateAnnotation))
167-
.addProcessor(new ElementToPresenterInfoProcessor(mElements, viewElementPublisher))
168-
.addValidator(new NormalPresenterValidator())
169-
.copyTypeElementTo(presenterElementPublisher)
170-
.addProcessor(new PresenterInfoToViewStateProviderJavaFileProcessor().withCache())
171-
.buildPipeline(fileWriter)
172-
.start();
173-
174-
// viewStatePipeline
175-
new Pipeline.Builder<>(viewElementPublisher)
176-
.addProcessor(new ElementToViewInterfaceInfoProcessor(mElements, mTypes, mMessager, strategiesElementPublisher))
177-
.uniqueFilter()
178-
.addProcessor(new ViewInterfaceInfoToViewStateJavaFileProcessor(mElements, mTypes, currentMoxyReflectorPackage, reflectorPackagesPublisher))
179-
.buildPipeline(fileWriter)
180-
.start();
181-
182-
183-
// moxyReflectorPipeline
184-
new Pipeline.Builder<>(
185-
QuadPublisher.collectQuad(
186-
presenterElementPublisher,
187-
presenterContainerElementPublisher,
188-
strategiesElementPublisher,
189-
reflectorPackagesPublisher))
190-
.addProcessor(new MoxyReflectorProcessor(currentMoxyReflectorPackage))
191-
.buildPipeline(fileWriter)
192-
.start();
193-
194+
fileWriter.shutdown();
194195

195196
return true;
196197
}
Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,88 @@
11
package com.omegar.mvp.compiler.entity;
22

3+
import com.omegar.mvp.MvpProcessor;
4+
import com.omegar.mvp.compiler.Util;
35
import com.squareup.javapoet.ClassName;
46
import com.squareup.javapoet.ParameterizedTypeName;
57
import com.squareup.javapoet.TypeName;
68
import com.squareup.javapoet.TypeVariableName;
79

8-
import java.util.Collections;
910
import java.util.List;
1011
import java.util.stream.Collectors;
1112

1213
import javax.annotation.Nullable;
1314
import javax.lang.model.element.TypeElement;
15+
import javax.lang.model.util.Elements;
1416

1517
/**
1618
* Date: 27-Jul-2017
1719
* Time: 13:04
1820
*
1921
* @author Evgeny Kursakov
2022
*/
23+
@SuppressWarnings("NewApi")
2124
public class ViewInterfaceInfo implements TypeElementHolder {
2225
@Nullable
23-
private final ViewInterfaceInfo superInterfaceInfo;
24-
private final TypeElement element;
25-
private final ClassName name;
26-
private final List<TypeVariableName> typeVariables;
27-
private final List<ViewMethod> methods;
26+
private final TypeElement mSuperInterfaceType;
27+
private final TypeElement mElement;
28+
private final ClassName mName;
29+
private final List<TypeVariableName> mTypeVariables;
30+
private final List<ViewMethod> mMethods;
2831

2932
public ViewInterfaceInfo(TypeElement element, List<ViewMethod> methods) {
3033
this(null, element, methods);
3134
}
3235

33-
public ViewInterfaceInfo(@Nullable ViewInterfaceInfo superInterfaceInfo, TypeElement element, List<ViewMethod> methods) {
34-
this.superInterfaceInfo = superInterfaceInfo;
35-
this.element = element;
36-
this.name = ClassName.get(element);
37-
this.methods = methods;
36+
public ViewInterfaceInfo(@Nullable TypeElement superInterfaceType, TypeElement element, List<ViewMethod> methods) {
37+
mSuperInterfaceType = superInterfaceType;
38+
mElement = element;
39+
mName = ClassName.get(element);
40+
mMethods = methods;
3841

39-
this.typeVariables = element.getTypeParameters().stream()
42+
mTypeVariables = element.getTypeParameters().stream()
4043
.map(TypeVariableName::get)
4144
.collect(Collectors.toList());
4245

4346
}
4447

4548
@Nullable
46-
public ViewInterfaceInfo getSuperInterfaceInfo() {
47-
return superInterfaceInfo;
49+
public TypeElement getSuperInterfaceType() {
50+
return mSuperInterfaceType;
4851
}
4952

5053
public TypeElement getTypeElement() {
51-
return element;
54+
return mElement;
5255
}
5356

5457
public ClassName getName() {
55-
return name;
58+
return mName;
5659
}
5760

5861
public TypeName getNameWithTypeVariables() {
59-
if (typeVariables.isEmpty()) {
60-
return name;
62+
if (mTypeVariables.isEmpty()) {
63+
return mName;
6164
} else {
62-
TypeVariableName[] names = new TypeVariableName[typeVariables.size()];
63-
typeVariables.toArray(names);
65+
TypeVariableName[] names = new TypeVariableName[mTypeVariables.size()];
66+
mTypeVariables.toArray(names);
6467

65-
return ParameterizedTypeName.get(name, names);
68+
return ParameterizedTypeName.get(mName, names);
6669
}
6770
}
6871

6972
public List<TypeVariableName> getTypeVariables() {
70-
return typeVariables;
73+
return mTypeVariables;
7174
}
7275

7376
public List<ViewMethod> getMethods() {
74-
return methods;
77+
return mMethods;
7578
}
7679

77-
public TypeElement getSuperClassElement() {
78-
return superInterfaceInfo == null ? null : superInterfaceInfo.getTypeElement();
80+
public String getViewStateFullName(Elements elements) {
81+
return getViewStateFullName(elements, mElement);
82+
}
83+
84+
public String getViewStateSimpleName(Elements elements) {
85+
return getViewStateSimpleName(elements, mElement);
7986
}
8087

8188
@Override
@@ -85,19 +92,29 @@ public boolean equals(Object o) {
8592

8693
ViewInterfaceInfo that = (ViewInterfaceInfo) o;
8794

88-
return name != null ? name.equals(that.name) : that.name == null;
95+
return mName != null ? mName.equals(that.mName) : that.mName == null;
8996
}
9097

9198
@Override
9299
public int hashCode() {
93-
return name != null ? name.hashCode() : 0;
100+
return mName != null ? mName.hashCode() : 0;
94101
}
95102

96103
@Override
97104
public String toString() {
98105
return "ViewInterfaceInfo{" +
99-
"superInterfaceInfo=" + superInterfaceInfo +
100-
", element=" + element +
106+
"superInterfaceInfo=" + mSuperInterfaceType +
107+
", element=" + mElement +
101108
'}';
102109
}
110+
111+
public static String getViewStateFullName(Elements elements, TypeElement viewTypeElement) {
112+
return Util.getFullClassName(elements, viewTypeElement) + MvpProcessor.VIEW_STATE_SUFFIX;
113+
}
114+
115+
public static String getViewStateSimpleName(Elements elements, TypeElement viewTypeElement) {
116+
return Util.getSimpleClassName(elements, viewTypeElement) + MvpProcessor.VIEW_STATE_SUFFIX;
117+
}
118+
119+
103120
}

moxy-compiler/src/main/java/com/omegar/mvp/compiler/entity/ViewMethod.java

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

33
import com.omegar.mvp.compiler.MvpCompiler;
4+
import com.omegar.mvp.compiler.Util;
45
import com.squareup.javapoet.ParameterSpec;
56
import com.squareup.javapoet.TypeName;
67
import com.squareup.javapoet.TypeVariableName;
@@ -23,6 +24,7 @@
2324
*
2425
* @author Evgeny Kursakov
2526
*/
27+
@SuppressWarnings("NewApi")
2628
public class ViewMethod {
2729
private final ExecutableElement methodElement;
2830
private final String name;
@@ -48,9 +50,9 @@ public ViewMethod(Types types, DeclaredType targetInterfaceElement, ViewMethod m
4850
}
4951

5052
public ViewMethod(Types types, DeclaredType targetInterfaceElement,
51-
ExecutableElement methodElement,
52-
TypeElement strategy,
53-
String tag) {
53+
ExecutableElement methodElement,
54+
TypeElement strategy,
55+
String tag) {
5456
this.methodElement = methodElement;
5557
this.name = methodElement.getSimpleName().toString();
5658
this.strategy = strategy;
@@ -138,7 +140,7 @@ public String getArgumentsString() {
138140
}
139141

140142
public String getCommandClassName() {
141-
return name.substring(0, 1).toUpperCase() + name.substring(1) + uniqueSuffix + "Command";
143+
return Util.capitalizeString(name) + uniqueSuffix + "Command";
142144
}
143145

144146
public String getEnclosedClassName() {

moxy-compiler/src/main/java/com/omegar/mvp/compiler/pipeline/CollectListPublisher.java renamed to moxy-compiler/src/main/java/com/omegar/mvp/compiler/pipeline/CollectSetPublisher.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
package com.omegar.mvp.compiler.pipeline;
22

3-
import com.omegar.mvp.compiler.MvpCompiler;
4-
5-
import java.util.ArrayList;
6-
import java.util.List;
7-
8-
import javax.annotation.Nullable;
9-
import javax.tools.Diagnostic;
3+
import java.util.LinkedHashSet;
4+
import java.util.Set;
105

116
/**
127
* Created by Anton Knyazev on 05.12.2020.
138
*/
149

15-
public class CollectListPublisher<I> extends Publisher<List<I>>{
10+
public class CollectSetPublisher<I> extends Publisher<Set<I>>{
1611

17-
private final List<I> mResult = new ArrayList<>();
12+
private final Set<I> mResult = new LinkedHashSet<>();
1813
private final Publisher<I> mPublisher;
1914

20-
public CollectListPublisher(Publisher<I> publisher) {
15+
public CollectSetPublisher(Publisher<I> publisher) {
2116
mPublisher = publisher;
2217
}
2318

2419
@Override
25-
public void publish(PipelineContext<List<I>> context) {
20+
public void publish(PipelineContext<Set<I>> context) {
2621
super.publish(context);
2722
mPublisher.publish(new LocalContext());
2823
}
@@ -36,9 +31,9 @@ public void next(I nextData) {
3631

3732
@Override
3833
public void finish() {
39-
CollectListPublisher.this.next(new ArrayList<>(mResult));
34+
CollectSetPublisher.this.next(new LinkedHashSet<>(mResult));
4035
mResult.clear();
41-
CollectListPublisher.this.finish();
36+
CollectSetPublisher.this.finish();
4237
}
4338
}
4439

0 commit comments

Comments
 (0)