From f907dd62299f69f1db30649d1304b1260d987d42 Mon Sep 17 00:00:00 2001 From: xiaojinzi Date: Sat, 5 Dec 2020 10:35:59 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E7=9A=84=E6=97=B6=E5=80=99,=20=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8A=A0=E8=BD=BD=E4=B8=8D=E6=88=90=E5=8A=9F=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xiaojinzi/component/impl/RouterCenter.java | 4 +++- .../component/impl/RouterDegradeCenter.java | 4 +++- .../component/impl/application/ModuleManager.java | 4 +++- .../component/impl/fragment/FragmentCenter.java | 4 +++- .../impl/interceptor/InterceptorCenter.java | 4 +++- .../component/impl/service/ServiceCenter.java | 4 +++- .../com/xiaojinzi/component/support/ASMUtil.java | 12 ++++++------ 7 files changed, 24 insertions(+), 12 deletions(-) diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterCenter.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterCenter.java index 204c7bdb..50e11807 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterCenter.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterCenter.java @@ -407,7 +407,9 @@ public void unregister(@NonNull String host) { public IComponentHostRouter findUiRouter(String host) { try { if (Component.getConfig().isOptimizeInit()) { - return ASMUtil.findModuleRouterAsmImpl(host); + return ASMUtil.findModuleRouterAsmImpl( + ComponentUtil.transformHostForClass(host) + ); } else { Class clazz = null; String className = ComponentUtil.genHostRouterClassName(host); diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterDegradeCenter.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterDegradeCenter.java index e188569d..27de37f9 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterDegradeCenter.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterDegradeCenter.java @@ -147,7 +147,9 @@ public void unregister(@NonNull String host) { public IComponentHostRouterDegrade findModuleRouterDegrade(String host) { try { if (Component.getConfig().isOptimizeInit()) { - return ASMUtil.findModuleRouterDegradeAsmImpl(host); + return ASMUtil.findModuleRouterDegradeAsmImpl( + ComponentUtil.transformHostForClass(host) + ); } else { Class clazz = null; String className = ComponentUtil.genHostRouterDegradeClassName(host); diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/application/ModuleManager.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/application/ModuleManager.java index 7c5d5162..cc3fe39f 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/application/ModuleManager.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/application/ModuleManager.java @@ -141,7 +141,9 @@ public static IComponentHostApplication findModuleApplication(@NonNull String ho IComponentHostApplication result = null; if (Component.getConfig().isOptimizeInit()) { LogUtil.log("\"" + host + "\" will try to load by bytecode"); - result = ASMUtil.findModuleApplicationAsmImpl(host); + result = ASMUtil.findModuleApplicationAsmImpl( + ComponentUtil.transformHostForClass(host) + ); } else { LogUtil.log("\"" + host + "\" will try to load by reflection"); if (result == null) { diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/fragment/FragmentCenter.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/fragment/FragmentCenter.java index a107efd8..34cb25c9 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/fragment/FragmentCenter.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/fragment/FragmentCenter.java @@ -82,7 +82,9 @@ public void unregister(@NonNull String host) { public IComponentHostFragment findModuleService(String host) { try { if (Component.getConfig().isOptimizeInit()) { - return ASMUtil.findModuleFragmentAsmImpl(host); + return ASMUtil.findModuleFragmentAsmImpl( + ComponentUtil.transformHostForClass(host) + ); } else { Class clazz = null; String className = ComponentUtil.genHostFragmentClassName(host); diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/interceptor/InterceptorCenter.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/interceptor/InterceptorCenter.java index cbb12019..1ea35b46 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/interceptor/InterceptorCenter.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/interceptor/InterceptorCenter.java @@ -171,7 +171,9 @@ public IComponentHostInterceptor findModuleInterceptor(String host) { Utils.checkMainThread(); try { if (Component.getConfig().isOptimizeInit()) { - return ASMUtil.findModuleInterceptorAsmImpl(host); + return ASMUtil.findModuleInterceptorAsmImpl( + ComponentUtil.transformHostForClass(host) + ); } else { Class clazz = null; String className = ComponentUtil.genHostInterceptorClassName(host); diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/service/ServiceCenter.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/service/ServiceCenter.java index 083c1c11..19fd3d67 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/service/ServiceCenter.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/service/ServiceCenter.java @@ -80,7 +80,9 @@ public void unregister(@NonNull String host) { public IComponentHostService findModuleService(@NonNull String host) { try { if (Component.getConfig().isOptimizeInit()) { - return ASMUtil.findModuleServiceAsmImpl(host); + return ASMUtil.findModuleServiceAsmImpl( + ComponentUtil.transformHostForClass(host) + ); } else { Class clazz = null; String className = ComponentUtil.genHostServiceClassName(host); diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/ASMUtil.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/ASMUtil.java index 1726c0bf..846da513 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/ASMUtil.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/ASMUtil.java @@ -87,7 +87,7 @@ public static List getModuleNames() { * @return 返回对应模块的 Application {@link IComponentHostApplication} */ @Nullable - public static IComponentHostApplication findModuleApplicationAsmImpl(String host) { + public static IComponentHostApplication findModuleApplicationAsmImpl(@NonNull String host) { return null; } @@ -98,7 +98,7 @@ public static IComponentHostApplication findModuleApplicationAsmImpl(String host * @return 返回对应模块的 Application {@link IComponentHostInterceptor} */ @Nullable - public static IComponentHostInterceptor findModuleInterceptorAsmImpl(String host) { + public static IComponentHostInterceptor findModuleInterceptorAsmImpl(@NonNull String host) { return null; } @@ -109,7 +109,7 @@ public static IComponentHostInterceptor findModuleInterceptorAsmImpl(String host * @return 返回对应模块的 {@link IComponentHostRouter} */ @Nullable - public static IComponentHostRouter findModuleRouterAsmImpl(String host) { + public static IComponentHostRouter findModuleRouterAsmImpl(@NonNull String host) { return null; } @@ -120,7 +120,7 @@ public static IComponentHostRouter findModuleRouterAsmImpl(String host) { * @return 返回对应模块的 {@link IComponentHostRouterDegrade} */ @Nullable - public static IComponentHostRouterDegrade findModuleRouterDegradeAsmImpl(String host) { + public static IComponentHostRouterDegrade findModuleRouterDegradeAsmImpl(@NonNull String host) { return null; } @@ -131,7 +131,7 @@ public static IComponentHostRouterDegrade findModuleRouterDegradeAsmImpl(String * @return 返回对应模块的 {@link IComponentHostService} */ @Nullable - public static IComponentHostService findModuleServiceAsmImpl(String host) { + public static IComponentHostService findModuleServiceAsmImpl(@NonNull String host) { return null; } @@ -142,7 +142,7 @@ public static IComponentHostService findModuleServiceAsmImpl(String host) { * @return 返回对应模块的 {@link IComponentHostFragment} */ @Nullable - public static IComponentHostFragment findModuleFragmentAsmImpl(String host) { + public static IComponentHostFragment findModuleFragmentAsmImpl(@NonNull String host) { return null; } From 02e767a8163de26178b1fda36ca429f7c0bf3af0 Mon Sep 17 00:00:00 2001 From: xiaojinzi Date: Sat, 5 Dec 2020 10:38:38 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B3=A8=E8=A7=A3=E9=A9=B1=E5=8A=A8?= =?UTF-8?q?=E5=99=A8=E4=B8=AD=E5=BD=93=E6=89=BE=E4=B8=8D=E5=88=B0=20@Keep?= =?UTF-8?q?=20=E5=92=8C=20@NonNull=20=E6=B3=A8=E8=A7=A3=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E5=80=99=E7=9A=84=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/xiaojinzi/component/BaseProcessor.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ComponentCompiler/src/main/java/com/xiaojinzi/component/BaseProcessor.java b/ComponentCompiler/src/main/java/com/xiaojinzi/component/BaseProcessor.java index 73d1d87e..8792210e 100644 --- a/ComponentCompiler/src/main/java/com/xiaojinzi/component/BaseProcessor.java +++ b/ComponentCompiler/src/main/java/com/xiaojinzi/component/BaseProcessor.java @@ -122,9 +122,12 @@ public synchronized void init(ProcessingEnvironment processingEnvironment) { mTypeNameString = TypeName.get(mTypeElementString.asType()); + TypeElement keepTypeElement = mElements.getTypeElement(ComponentConstants.ANDROID_ANNOTATION_KEEP); + TypeElement nonNullTypeElement = mElements.getTypeElement(ComponentConstants.ANDROID_ANNOTATION_NONNULL); + // androidx 和 非 androidx 的两个注解 - mClassNameKeep = ClassName.get(mElements.getTypeElement(ComponentConstants.ANDROID_ANNOTATION_KEEP)); - mClassNameNonNull = ClassName.get(mElements.getTypeElement(ComponentConstants.ANDROID_ANNOTATION_NONNULL)); + mClassNameKeep = ClassName.get(keepTypeElement); + mClassNameNonNull = ClassName.get(nonNullTypeElement); if (mClassNameKeep == null || mClassNameNonNull == null) { String addDependencyTip = getAddDependencyTip(Arrays.asList( From da34b001b98a191aba6748a29fab8bdb7988e512 Mon Sep 17 00:00:00 2001 From: xiaojinzi Date: Sat, 5 Dec 2020 10:39:02 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=B3=A8=E8=A7=A3=E9=A9=B1=E5=8A=A8?= =?UTF-8?q?=E5=99=A8=E4=B8=AD=E5=BD=93=E6=89=BE=E4=B8=8D=E5=88=B0=20@Keep?= =?UTF-8?q?=20=E5=92=8C=20@NonNull=20=E6=B3=A8=E8=A7=A3=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E5=80=99=E7=9A=84=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/xiaojinzi/component/BaseProcessor.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ComponentCompiler/src/main/java/com/xiaojinzi/component/BaseProcessor.java b/ComponentCompiler/src/main/java/com/xiaojinzi/component/BaseProcessor.java index 8792210e..d9414724 100644 --- a/ComponentCompiler/src/main/java/com/xiaojinzi/component/BaseProcessor.java +++ b/ComponentCompiler/src/main/java/com/xiaojinzi/component/BaseProcessor.java @@ -125,11 +125,7 @@ public synchronized void init(ProcessingEnvironment processingEnvironment) { TypeElement keepTypeElement = mElements.getTypeElement(ComponentConstants.ANDROID_ANNOTATION_KEEP); TypeElement nonNullTypeElement = mElements.getTypeElement(ComponentConstants.ANDROID_ANNOTATION_NONNULL); - // androidx 和 非 androidx 的两个注解 - mClassNameKeep = ClassName.get(keepTypeElement); - mClassNameNonNull = ClassName.get(nonNullTypeElement); - - if (mClassNameKeep == null || mClassNameNonNull == null) { + if (keepTypeElement == null || nonNullTypeElement == null) { String addDependencyTip = getAddDependencyTip(Arrays.asList( ComponentConstants.ANDROID_ANNOTATION_KEEP, ComponentConstants.ANDROID_ANNOTATION_NONNULL @@ -139,6 +135,10 @@ public synchronized void init(ProcessingEnvironment processingEnvironment) { "\n else see https://github.com/xiaojinzi123/Component/wiki/%E4%BE%9D%E8%B5%96%E5%92%8C%E9%85%8D%E7%BD%AE"); } + // androidx 和 非 androidx 的两个注解 + mClassNameKeep = ClassName.get(keepTypeElement); + mClassNameNonNull = ClassName.get(nonNullTypeElement); + } protected String getAddDependencyTip(List classPathList, boolean isOr) {