From 2709b365ccb75f0f7e34d0837f89ab6c07fbb837 Mon Sep 17 00:00:00 2001 From: Milk <1871357815@qq.com> Date: Wed, 16 Feb 2022 11:41:34 +0800 Subject: [PATCH] rename annotation --- README.md | 8 +++---- .../blackreflection/ref/ActivityThread.java | 6 ++--- .../BlackReflectionProcessor.java | 8 +++---- .../proxy/BlackReflectionInterfaceProxy.java | 11 +++++----- .../blackreflection/BlackReflection.java | 22 +++++++++---------- .../{BStrClass.java => BClassName.java} | 2 +- ...Process.java => BClassNameNotProcess.java} | 2 +- ...trParamClass.java => BParamClassName.java} | 2 +- 8 files changed, 30 insertions(+), 31 deletions(-) rename core/src/main/java/top/niunaijun/blackreflection/annotation/{BStrClass.java => BClassName.java} (93%) rename core/src/main/java/top/niunaijun/blackreflection/annotation/{BStrClassNotProcess.java => BClassNameNotProcess.java} (91%) rename core/src/main/java/top/niunaijun/blackreflection/annotation/{BStrParamClass.java => BParamClassName.java} (92%) diff --git a/README.md b/README.md index ba78b42..4be9275 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ annotationProcessor 'com.github.CodingGay.BlackReflection:compiler:1.0.0' ### Demo #### 1. 如果你需要反射 android.app.ActivityThread 中的各种方法,参考:[ActivityThread.java](https://github.com/CodingGay/BlackReflection/blob/main/app/src/main/java/top/niunaijun/blackreflection/ref/ActivityThread.java) ```java -@BStrClass("android.app.ActivityThread") +@BClassName("android.app.ActivityThread") public interface ActivityThread { @BStaticMethod @@ -42,7 +42,7 @@ public interface ActivityThread { @BMethod void sendActivityResult(@BParamClass(IBinder.class) IBinder token, String id, int requestCode, int resultCode, Intent data); - @BStrClass("android.app.ActivityThread$H") + @BClassName("android.app.ActivityThread$H") interface H { @BStaticField int CREATE_SERVICE(); @@ -67,13 +67,13 @@ BRActivityThread是程序自动生成的类,生成规则是BR + ClassName 注解 | 注解方式 | 解释 ---|---|--- @BClass | Class | 指定需要反射的类 -@BStrClass | Class | 指定需要反射的类 +@BClassName | Class | 指定需要反射的类 @BStaticMethod | Method | 注明是静态方法 @BMethod | Method | 注明是非静态方法 @BStaticField | Method | 注明是静态变量 @BField | Method | 注明是非静态变量 @BParamClass | Parameter | 注明该参数的Class,用于反射时寻找方法 -@BStrParamClass | Parameter | 注明该参数的Class,用于反射时寻找方法 +@BParamClassName | Parameter | 注明该参数的Class,用于反射时寻找方法 ### License diff --git a/app/src/main/java/top/niunaijun/blackreflection/ref/ActivityThread.java b/app/src/main/java/top/niunaijun/blackreflection/ref/ActivityThread.java index 98989eb..c53e38b 100644 --- a/app/src/main/java/top/niunaijun/blackreflection/ref/ActivityThread.java +++ b/app/src/main/java/top/niunaijun/blackreflection/ref/ActivityThread.java @@ -6,7 +6,7 @@ import top.niunaijun.blackreflection.annotation.BMethod; import top.niunaijun.blackreflection.annotation.BParamClass; import top.niunaijun.blackreflection.annotation.BStaticField; -import top.niunaijun.blackreflection.annotation.BStrClass; +import top.niunaijun.blackreflection.annotation.BClassName; import top.niunaijun.blackreflection.annotation.BStaticMethod; /** @@ -17,7 +17,7 @@ * しーJ * 此处无Bug */ -@BStrClass("android.app.ActivityThread") +@BClassName("android.app.ActivityThread") public interface ActivityThread { @BStaticMethod @@ -32,7 +32,7 @@ public interface ActivityThread { @BMethod void sendActivityResult(@BParamClass(IBinder.class) IBinder token, String id, int requestCode, int resultCode, Intent data); - @BStrClass("android.app.ActivityThread$H") + @BClassName("android.app.ActivityThread$H") interface H { @BStaticField int CREATE_SERVICE(); diff --git a/compiler/src/main/java/top/niunaijun/blackreflection/BlackReflectionProcessor.java b/compiler/src/main/java/top/niunaijun/blackreflection/BlackReflectionProcessor.java index a9b9b2a..1075c19 100644 --- a/compiler/src/main/java/top/niunaijun/blackreflection/BlackReflectionProcessor.java +++ b/compiler/src/main/java/top/niunaijun/blackreflection/BlackReflectionProcessor.java @@ -29,7 +29,7 @@ import top.niunaijun.blackreflection.annotation.BMethod; import top.niunaijun.blackreflection.annotation.BStaticField; import top.niunaijun.blackreflection.annotation.BStaticMethod; -import top.niunaijun.blackreflection.annotation.BStrClass; +import top.niunaijun.blackreflection.annotation.BClassName; import top.niunaijun.blackreflection.proxy.BlackReflectionInterfaceProxy; import top.niunaijun.blackreflection.proxy.BlackReflectionProxy; @@ -67,7 +67,7 @@ public synchronized void init(ProcessingEnvironment processingEnv) { public Set getSupportedAnnotationTypes() { HashSet supportTypes = new LinkedHashSet<>(); supportTypes.add(BClass.class.getCanonicalName()); - supportTypes.add(BStrClass.class.getCanonicalName()); + supportTypes.add(BClassName.class.getCanonicalName()); supportTypes.add(BField.class.getCanonicalName()); supportTypes.add(BStaticField.class.getCanonicalName()); @@ -88,8 +88,8 @@ public boolean process(Set annotations, RoundEnvironment mBlackReflectionInterfaceProxies.clear(); mRealMaps.clear(); - for (Element element : roundEnv.getElementsAnnotatedWith(BStrClass.class)) { - BStrClass annotation = element.getAnnotation(BStrClass.class); + for (Element element : roundEnv.getElementsAnnotatedWith(BClassName.class)) { + BClassName annotation = element.getAnnotation(BClassName.class); doProcess(element, annotation.value()); } diff --git a/compiler/src/main/java/top/niunaijun/blackreflection/proxy/BlackReflectionInterfaceProxy.java b/compiler/src/main/java/top/niunaijun/blackreflection/proxy/BlackReflectionInterfaceProxy.java index f4c7321..11cba77 100644 --- a/compiler/src/main/java/top/niunaijun/blackreflection/proxy/BlackReflectionInterfaceProxy.java +++ b/compiler/src/main/java/top/niunaijun/blackreflection/proxy/BlackReflectionInterfaceProxy.java @@ -21,9 +21,8 @@ import top.niunaijun.blackreflection.annotation.BFieldNotProcess; import top.niunaijun.blackreflection.annotation.BFieldSetNotProcess; import top.niunaijun.blackreflection.annotation.BParamClass; -import top.niunaijun.blackreflection.annotation.BStrClassNotProcess; -import top.niunaijun.blackreflection.annotation.BStrParamClass; -import top.niunaijun.blackreflection.utils.ClassUtils; +import top.niunaijun.blackreflection.annotation.BClassNameNotProcess; +import top.niunaijun.blackreflection.annotation.BParamClassName; /** * Created by sunwanquan on 2020/1/8. @@ -54,7 +53,7 @@ public JavaFile generateInterfaceCode() { String finalClass = mClassName .replace(mPackageName + ".", "") .replace(".", ""); - AnnotationSpec annotationSpec = AnnotationSpec.builder(BStrClassNotProcess.class) + AnnotationSpec annotationSpec = AnnotationSpec.builder(BClassNameNotProcess.class) .addMember("value","$S", realMaps.get(mOrigClassName)) .build(); @@ -69,8 +68,8 @@ public JavaFile generateInterfaceCode() { for (VariableElement typeParameter : reflection.getExecutableElement().getParameters()) { ParameterSpec.Builder builder = ParameterSpec.builder(ClassName.get(typeParameter.asType()), typeParameter.getSimpleName().toString()); - if (typeParameter.getAnnotation(BStrParamClass.class) != null) { - BStrParamClass annotation = typeParameter.getAnnotation(BStrParamClass.class); + if (typeParameter.getAnnotation(BParamClassName.class) != null) { + BParamClassName annotation = typeParameter.getAnnotation(BParamClassName.class); builder.addAnnotation(AnnotationSpec.get(annotation)); } if (typeParameter.getAnnotation(BParamClass.class) != null) { diff --git a/core/src/main/java/top/niunaijun/blackreflection/BlackReflection.java b/core/src/main/java/top/niunaijun/blackreflection/BlackReflection.java index fa5ffb4..e0cffa2 100644 --- a/core/src/main/java/top/niunaijun/blackreflection/BlackReflection.java +++ b/core/src/main/java/top/niunaijun/blackreflection/BlackReflection.java @@ -14,9 +14,9 @@ import top.niunaijun.blackreflection.annotation.BFieldNotProcess; import top.niunaijun.blackreflection.annotation.BFieldSetNotProcess; import top.niunaijun.blackreflection.annotation.BParamClass; -import top.niunaijun.blackreflection.annotation.BStrClass; -import top.niunaijun.blackreflection.annotation.BStrClassNotProcess; -import top.niunaijun.blackreflection.annotation.BStrParamClass; +import top.niunaijun.blackreflection.annotation.BClassName; +import top.niunaijun.blackreflection.annotation.BClassNameNotProcess; +import top.niunaijun.blackreflection.annotation.BParamClassName; import top.niunaijun.blackreflection.utils.Reflector; /** @@ -150,9 +150,9 @@ private static Class[] getParamClass(Method method) throws Throwable { Annotation[] parameterAnnotation = parameterAnnotations[i]; boolean found = false; for (Annotation annotation : parameterAnnotation) { - if (annotation instanceof BStrParamClass) { + if (annotation instanceof BParamClassName) { found = true; - param[i] = Class.forName(((BStrParamClass) annotation).value()); + param[i] = Class.forName(((BParamClassName) annotation).value()); break; } else if (annotation instanceof BParamClass) { found = true; @@ -170,18 +170,18 @@ private static Class[] getParamClass(Method method) throws Throwable { private static Class getClassNameByBlackClass(Class clazz) throws ClassNotFoundException { BClass bClass = clazz.getAnnotation(BClass.class); - BStrClass bStrClass = clazz.getAnnotation(BStrClass.class); - BStrClassNotProcess bStrClassNotProcess = clazz.getAnnotation(BStrClassNotProcess.class); - if (bClass == null && bStrClass == null && bStrClassNotProcess == null) { + BClassName bClassName = clazz.getAnnotation(BClassName.class); + BClassNameNotProcess bClassNameNotProcess = clazz.getAnnotation(BClassNameNotProcess.class); + if (bClass == null && bClassName == null && bClassNameNotProcess == null) { throw new RuntimeException("Not found @BlackClass or @BlackStrClass"); } if (bClass != null) { return bClass.value(); - } else if (bStrClass != null) { - return Class.forName(bStrClass.value()); + } else if (bClassName != null) { + return Class.forName(bClassName.value()); } else { - return Class.forName(bStrClassNotProcess.value()); + return Class.forName(bClassNameNotProcess.value()); } } } diff --git a/core/src/main/java/top/niunaijun/blackreflection/annotation/BStrClass.java b/core/src/main/java/top/niunaijun/blackreflection/annotation/BClassName.java similarity index 93% rename from core/src/main/java/top/niunaijun/blackreflection/annotation/BStrClass.java rename to core/src/main/java/top/niunaijun/blackreflection/annotation/BClassName.java index ee7906b..03daa76 100644 --- a/core/src/main/java/top/niunaijun/blackreflection/annotation/BStrClass.java +++ b/core/src/main/java/top/niunaijun/blackreflection/annotation/BClassName.java @@ -16,6 +16,6 @@ */ @Retention(RUNTIME) @Target({TYPE}) -public @interface BStrClass { +public @interface BClassName { String value(); } diff --git a/core/src/main/java/top/niunaijun/blackreflection/annotation/BStrClassNotProcess.java b/core/src/main/java/top/niunaijun/blackreflection/annotation/BClassNameNotProcess.java similarity index 91% rename from core/src/main/java/top/niunaijun/blackreflection/annotation/BStrClassNotProcess.java rename to core/src/main/java/top/niunaijun/blackreflection/annotation/BClassNameNotProcess.java index 5527782..8149543 100644 --- a/core/src/main/java/top/niunaijun/blackreflection/annotation/BStrClassNotProcess.java +++ b/core/src/main/java/top/niunaijun/blackreflection/annotation/BClassNameNotProcess.java @@ -16,6 +16,6 @@ */ @Retention(RUNTIME) @Target({TYPE}) -public @interface BStrClassNotProcess { +public @interface BClassNameNotProcess { String value(); } diff --git a/core/src/main/java/top/niunaijun/blackreflection/annotation/BStrParamClass.java b/core/src/main/java/top/niunaijun/blackreflection/annotation/BParamClassName.java similarity index 92% rename from core/src/main/java/top/niunaijun/blackreflection/annotation/BStrParamClass.java rename to core/src/main/java/top/niunaijun/blackreflection/annotation/BParamClassName.java index 4df2fe7..3e5fedb 100644 --- a/core/src/main/java/top/niunaijun/blackreflection/annotation/BStrParamClass.java +++ b/core/src/main/java/top/niunaijun/blackreflection/annotation/BParamClassName.java @@ -16,6 +16,6 @@ */ @Retention(RUNTIME) @Target({PARAMETER}) -public @interface BStrParamClass { +public @interface BParamClassName { String value(); }