Merge branch 'v_3.0' of https://github.com/AriaLyy/Aria into v_3.0

pull/330/head
AriaLyy 8 years ago
commit dc13be2264
  1. 3
      Aria/build.gradle
  2. 1
      AriaAnnotations/.gitignore
  3. 12
      AriaAnnotations/build.gradle
  4. 42
      AriaAnnotations/src/main/java/com/arialyy/annotations/Download.java
  5. 12
      AriaAnnotations/src/main/java/com/arialyy/annotations/Test.java
  6. 1
      AriaCompiler/.gitignore
  7. 18
      AriaCompiler/build.gradle
  8. 54
      AriaCompiler/src/main/java/com/arialyy/compiler/AriaProcessor.java
  9. 70
      AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandle.java
  10. 55
      AriaCompiler/src/main/java/com/arialyy/compiler/PrintLog.java
  11. 11
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  12. 1
      build.gradle
  13. 2
      settings.gradle

@ -19,8 +19,9 @@ android {
} }
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':AriaCompiler')
} }
apply from: 'jcenter.gradle' apply from: 'jcenter.gradle'

@ -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);
}
}

@ -33,6 +33,8 @@ import android.widget.RadioGroup;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import butterknife.Bind; import butterknife.Bind;
import com.arialyy.annotations.Download;
import com.arialyy.annotations.Test;
import com.arialyy.aria.core.download.DownloadTarget; import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
@ -132,6 +134,15 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
} }
}; };
@Download.onPre private void hehe(String str, DownloadTask task) {
}
@Test
public void gg(){
}
/** /**
* 设置start stop 按钮状态 * 设置start stop 按钮状态
*/ */

@ -9,6 +9,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:2.2.2' classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
} }

@ -1 +1 @@
include ':app', ':Aria' include ':app', ':Aria', ':AriaAnnotations', ':AriaCompiler'

Loading…
Cancel
Save