Merge branch 'v_3.0' of https://github.com/AriaLyy/Aria into v_3.0
commit
dc13be2264
@ -0,0 +1 @@ |
||||
/build |
@ -0,0 +1,12 @@ |
||||
apply plugin: 'java' |
||||
|
||||
tasks.withType(JavaCompile) { |
||||
options.encoding = "UTF-8" |
||||
} |
||||
|
||||
dependencies { |
||||
compile fileTree(dir: 'libs', include: ['*.jar']) |
||||
|
||||
sourceCompatibility = "1.7" |
||||
targetCompatibility = "1.7" |
||||
} |
@ -0,0 +1,42 @@ |
||||
package com.arialyy.annotations; |
||||
|
||||
import java.lang.annotation.ElementType; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
/** |
||||
* Created by Aria.Lao on 2017/6/6. |
||||
*/ |
||||
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface Download { |
||||
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onPre { |
||||
} |
||||
|
||||
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskPre { |
||||
} |
||||
|
||||
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskResume { |
||||
} |
||||
|
||||
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskStart { |
||||
} |
||||
|
||||
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskStop { |
||||
} |
||||
|
||||
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskCancel { |
||||
} |
||||
|
||||
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskFail { |
||||
} |
||||
|
||||
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskComplete { |
||||
} |
||||
|
||||
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskRunning { |
||||
} |
||||
|
||||
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) |
||||
public @interface onNoSupportBreakPoint { |
||||
} |
||||
} |
@ -0,0 +1,12 @@ |
||||
package com.arialyy.annotations; |
||||
|
||||
import java.lang.annotation.ElementType; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
/** |
||||
* Created by Aria.Lao on 2017/6/6. |
||||
*/ |
||||
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface Test { |
||||
} |
@ -0,0 +1 @@ |
||||
/build |
@ -0,0 +1,18 @@ |
||||
apply plugin: 'java' |
||||
|
||||
tasks.withType(JavaCompile) { |
||||
options.encoding = "UTF-8" |
||||
} |
||||
|
||||
dependencies { |
||||
compile fileTree(include: ['*.jar'], dir: 'libs') |
||||
compile 'com.google.auto:auto-common:0.6' |
||||
compile 'com.google.auto.service:auto-service:1.0-rc2' |
||||
compile 'com.squareup:javapoet:1.7.0' |
||||
compile project(':AriaAnnotations') |
||||
|
||||
sourceCompatibility = "1.7" |
||||
targetCompatibility = "1.7" |
||||
} |
||||
|
||||
|
@ -0,0 +1,54 @@ |
||||
package com.arialyy.compiler; |
||||
|
||||
import com.arialyy.annotations.Download; |
||||
import com.arialyy.annotations.Test; |
||||
import com.google.auto.service.AutoService; |
||||
import java.util.LinkedHashSet; |
||||
import java.util.Set; |
||||
import javax.annotation.processing.AbstractProcessor; |
||||
import javax.annotation.processing.ProcessingEnvironment; |
||||
import javax.annotation.processing.Processor; |
||||
import javax.annotation.processing.RoundEnvironment; |
||||
import javax.lang.model.SourceVersion; |
||||
import javax.lang.model.element.TypeElement; |
||||
|
||||
/** |
||||
* Created by lyy on 2017/6/6. |
||||
* 事件注解扫描器 |
||||
*/ |
||||
@AutoService(Processor.class) public class AriaProcessor extends AbstractProcessor { |
||||
ElementHandle mHandler; |
||||
|
||||
@Override public synchronized void init(ProcessingEnvironment processingEnv) { |
||||
super.init(processingEnv); |
||||
PrintLog.init(processingEnv.getMessager()); |
||||
mHandler = new ElementHandle(processingEnv.getFiler()); |
||||
} |
||||
|
||||
@Override public Set<String> getSupportedAnnotationTypes() { |
||||
Set<String> annotataions = new LinkedHashSet<>(); |
||||
annotataions.add(Download.onPre.class.getCanonicalName()); |
||||
annotataions.add(Download.onNoSupportBreakPoint.class.getCanonicalName()); |
||||
annotataions.add(Download.onTaskCancel.class.getCanonicalName()); |
||||
annotataions.add(Download.onTaskComplete.class.getCanonicalName()); |
||||
annotataions.add(Download.onTaskFail.class.getCanonicalName()); |
||||
annotataions.add(Download.onTaskPre.class.getCanonicalName()); |
||||
annotataions.add(Download.onTaskResume.class.getCanonicalName()); |
||||
annotataions.add(Download.onTaskRunning.class.getCanonicalName()); |
||||
annotataions.add(Download.onTaskStart.class.getCanonicalName()); |
||||
annotataions.add(Download.onTaskStop.class.getCanonicalName()); |
||||
annotataions.add(Test.class.getCanonicalName()); |
||||
return annotataions; |
||||
} |
||||
|
||||
@Override public SourceVersion getSupportedSourceVersion() { |
||||
return SourceVersion.latestSupported(); |
||||
} |
||||
|
||||
@Override |
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
||||
PrintLog.getInstance().info("开始扫描"); |
||||
mHandler.handle(roundEnv); |
||||
return true; |
||||
} |
||||
} |
@ -0,0 +1,70 @@ |
||||
package com.arialyy.compiler; |
||||
|
||||
import com.arialyy.annotations.Download; |
||||
import java.util.Set; |
||||
import javax.annotation.processing.Filer; |
||||
import javax.annotation.processing.RoundEnvironment; |
||||
import javax.lang.model.element.Element; |
||||
import javax.lang.model.element.ElementKind; |
||||
import javax.lang.model.element.ExecutableElement; |
||||
import javax.lang.model.element.Modifier; |
||||
import javax.lang.model.element.TypeElement; |
||||
import javax.lang.model.element.TypeParameterElement; |
||||
import javax.lang.model.element.VariableElement; |
||||
import javax.lang.model.type.TypeMirror; |
||||
|
||||
/** |
||||
* Created by lyy on 2017/6/6. |
||||
* 元素处理 |
||||
*/ |
||||
class ElementHandle { |
||||
|
||||
private Filer mFiler; |
||||
|
||||
ElementHandle(Filer filer) { |
||||
mFiler = filer; |
||||
} |
||||
|
||||
/** |
||||
* VariableElement 一般代表成员变量 |
||||
* ExecutableElement 一般代表类中的方法 |
||||
* TypeElement 一般代表代表类 |
||||
* PackageElement 一般代表Package |
||||
*/ |
||||
void handle(RoundEnvironment roundEnv) { |
||||
handlePre(roundEnv); |
||||
} |
||||
|
||||
/** |
||||
* 处理{@link Download.onTaskPre}注解 |
||||
*/ |
||||
private void handlePre(RoundEnvironment roundEnv) { |
||||
for (Element element : roundEnv.getElementsAnnotatedWith(Download.onPre.class)) { |
||||
ElementKind kind = element.getKind(); |
||||
if (kind == ElementKind.METHOD) { |
||||
ExecutableElement method = (ExecutableElement) element; |
||||
String methodName = method.getSimpleName().toString(); |
||||
String className = method.getEnclosingElement().toString(); |
||||
Set<Modifier> modifiers = method.getModifiers(); |
||||
if (modifiers.contains(Modifier.PRIVATE)){ |
||||
PrintLog.getInstance().info("私有方法"); |
||||
} |
||||
PrintLog.getInstance().info("注解的方法:" + methodName); |
||||
PrintLog.getInstance().info("所在类:" + className); |
||||
for (VariableElement te : method.getParameters()) { |
||||
TypeMirror paramType = te.asType(); |
||||
PrintLog.getInstance() |
||||
.info("参数名:" + te.getSimpleName().toString() + ",参数类型:" + paramType.toString()); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
private void handleNoSupportBreakPoint(RoundEnvironment roundEnv) { |
||||
|
||||
} |
||||
|
||||
private void handleTaskCancel(RoundEnvironment roundEnv) { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,55 @@ |
||||
package com.arialyy.compiler; |
||||
|
||||
import javax.annotation.processing.Messager; |
||||
import javax.lang.model.element.Element; |
||||
import javax.tools.Diagnostic; |
||||
|
||||
/** |
||||
* Created by Aria.Lao on 2017/6/6. |
||||
*/ |
||||
|
||||
public class PrintLog { |
||||
|
||||
private volatile static PrintLog INSTANCE = null; |
||||
private Messager mMessager; |
||||
|
||||
public static PrintLog init(Messager msg) { |
||||
if (INSTANCE == null) { |
||||
synchronized (PrintLog.class) { |
||||
INSTANCE = new PrintLog(msg); |
||||
} |
||||
} |
||||
return INSTANCE; |
||||
} |
||||
|
||||
public static PrintLog getInstance() { |
||||
return INSTANCE; |
||||
} |
||||
|
||||
private PrintLog() { |
||||
} |
||||
|
||||
private PrintLog(Messager msg) { |
||||
mMessager = msg; |
||||
} |
||||
|
||||
public void error(Element e, String msg, Object... args) { |
||||
mMessager.printMessage(Diagnostic.Kind.ERROR, String.format(msg, args), e); |
||||
} |
||||
|
||||
public void error(String msg, Object... args) { |
||||
mMessager.printMessage(Diagnostic.Kind.ERROR, String.format(msg, args)); |
||||
} |
||||
|
||||
private void warning(String msg) { |
||||
mMessager.printMessage(Diagnostic.Kind.WARNING, msg); |
||||
} |
||||
|
||||
public void error(String msg) { |
||||
mMessager.printMessage(Diagnostic.Kind.ERROR, msg); |
||||
} |
||||
|
||||
public void info(String str) { |
||||
mMessager.printMessage(Diagnostic.Kind.NOTE, str); |
||||
} |
||||
} |
@ -1 +1 @@ |
||||
include ':app', ':Aria' |
||||
include ':app', ':Aria', ':AriaAnnotations', ':AriaCompiler' |
||||
|
Loading…
Reference in new issue