-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release 1.2.3
- Loading branch information
Showing
19 changed files
with
176 additions
and
18 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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Tue Aug 02 23:16:00 EEST 2016 | ||
#Thu Jan 04 22:33:23 EET 2018 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip |
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 @@ | ||
/build |
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 @@ | ||
apply plugin: 'java' | ||
|
||
dependencies { | ||
compile fileTree(include: ['*.jar'], dir: 'libs') | ||
} | ||
|
||
sourceCompatibility = "1.7" | ||
targetCompatibility = "1.7" |
12 changes: 12 additions & 0 deletions
12
rainbowmvp-annotations/src/main/java/com/ne1c/rainbowmvp/annotaions/PresenterTag.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 com.ne1c.rainbowmvp.annotaions; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.CLASS) | ||
public @interface PresenterTag { | ||
String value(); | ||
} |
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 @@ | ||
/build |
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 @@ | ||
import org.gradle.internal.jvm.Jvm | ||
|
||
apply plugin: 'java' | ||
|
||
dependencies { | ||
implementation files(Jvm.current().getToolsJar()) | ||
implementation project(':rainbowmvp-annotations') | ||
implementation 'com.squareup:javapoet:1.9.0' | ||
} | ||
|
||
sourceCompatibility = "1.7" | ||
targetCompatibility = "1.7" |
114 changes: 114 additions & 0 deletions
114
rainbowmvp-processor/src/main/java/com/ne1c/rainbowmvp/processor/PresenterTagProcessor.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,114 @@ | ||
package com.ne1c.rainbowmvp.processor; | ||
|
||
import com.ne1c.rainbowmvp.annotaions.PresenterTag; | ||
import com.squareup.javapoet.JavaFile; | ||
import com.squareup.javapoet.MethodSpec; | ||
import com.squareup.javapoet.ParameterizedTypeName; | ||
import com.squareup.javapoet.TypeSpec; | ||
import com.sun.source.util.Trees; | ||
import com.sun.tools.javac.code.Type; | ||
import com.sun.tools.javac.processing.JavacProcessingEnvironment; | ||
import com.sun.tools.javac.tree.JCTree; | ||
import com.sun.tools.javac.tree.TreeMaker; | ||
import com.sun.tools.javac.util.Names; | ||
|
||
import java.io.IOException; | ||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
|
||
import javax.annotation.processing.AbstractProcessor; | ||
import javax.annotation.processing.Filer; | ||
import javax.annotation.processing.Messager; | ||
import javax.annotation.processing.ProcessingEnvironment; | ||
import javax.annotation.processing.RoundEnvironment; | ||
import javax.lang.model.SourceVersion; | ||
import javax.lang.model.element.Element; | ||
import javax.lang.model.element.ElementKind; | ||
import javax.lang.model.element.Modifier; | ||
import javax.lang.model.element.TypeElement; | ||
import javax.lang.model.type.TypeMirror; | ||
import javax.tools.Diagnostic; | ||
|
||
// Run for debug: ./gradlew --no-daemon -Dorg.gradle.debug=true :sample:clean :sample:compileDebugJavaWithJavac | ||
|
||
public class PresenterTagProcessor extends AbstractProcessor { | ||
private Messager messager; | ||
private Filer filer; | ||
private TreeMaker treeMaker; | ||
private Trees trees; | ||
private Names names; | ||
|
||
@Override | ||
public synchronized void init(ProcessingEnvironment env) { | ||
super.init(env); | ||
|
||
trees = Trees.instance(env); | ||
messager = env.getMessager(); | ||
filer = env.getFiler(); | ||
|
||
JavacProcessingEnvironment javacEnv = (JavacProcessingEnvironment) env; | ||
treeMaker = TreeMaker.instance(javacEnv.getContext()); | ||
names = Names.instance(javacEnv.getContext()); | ||
} | ||
|
||
@Override | ||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { | ||
for (Element e : roundEnv.getElementsAnnotatedWith(PresenterTag.class)) { | ||
if (e.getKind() != ElementKind.CLASS) { | ||
messager.printMessage(Diagnostic.Kind.ERROR, "Can be applied only to class."); | ||
return true; | ||
} | ||
|
||
String presenterTag = e.getAnnotation(PresenterTag.class).value(); | ||
|
||
MethodSpec getPresenterTagMethod = MethodSpec.methodBuilder("getPresenterTag") | ||
.addModifiers(Modifier.PUBLIC) | ||
.addAnnotation(Override.class) | ||
.returns(String.class) | ||
.addStatement("return $S", presenterTag) | ||
.build(); | ||
|
||
TypeMirror baseActivity = ((TypeElement) e).getSuperclass(); | ||
String baseActivityPath = "com.ne1c.rainbowmvp.base.BaseActivity"; | ||
|
||
if (!((Type.ClassType) baseActivity).asElement().toString().equals(baseActivityPath)) { | ||
messager.printMessage(Diagnostic.Kind.ERROR, | ||
"Can be annotated only classes that inherit com.ne1c.rainbowmvp.base.BaseActivity"); | ||
} | ||
|
||
TypeSpec typeSpec = TypeSpec.classBuilder(e.getSimpleName().toString() + "$$PresenterTagProxy") | ||
.addModifiers(Modifier.PUBLIC) | ||
.addMethod(getPresenterTagMethod) | ||
.superclass(ParameterizedTypeName.get(baseActivity)) | ||
.build(); | ||
|
||
JavaFile javaFile = JavaFile.builder(e.getEnclosingElement().toString(), typeSpec) | ||
.addFileComment("Generated by RainbowMVP processor, don't modify") | ||
.build(); | ||
|
||
try { | ||
javaFile.writeTo(filer); | ||
|
||
JCTree.JCExpression selector = treeMaker.Ident(names.fromString(javaFile.packageName)); | ||
selector = treeMaker.Select(selector, names.fromString(typeSpec.name)); | ||
((JCTree.JCClassDecl) trees.getTree(e)).extending = selector; | ||
} catch (IOException ex) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public Set<String> getSupportedAnnotationTypes() { | ||
Set<String> annotations = new LinkedHashSet<>(); | ||
annotations.add(PresenterTag.class.getCanonicalName()); | ||
return annotations; | ||
} | ||
|
||
@Override | ||
public SourceVersion getSupportedSourceVersion() { | ||
return SourceVersion.latestSupported(); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...wmvp-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor
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 @@ | ||
com.ne1c.rainbowmvp.processor.PresenterTagProcessor |
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
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
4 changes: 4 additions & 0 deletions
4
rainbowmvp/src/main/java/com/ne1c/rainbowmvp/base/BaseView.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,4 @@ | ||
package com.ne1c.rainbowmvp.base; | ||
|
||
public interface BaseView { | ||
} |
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
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
include ':sample', ':rainbowmvp' | ||
include ':sample', ':rainbowmvp', ':rainbowmvp-annotations', ':rainbowmvp-processor' |