From 2e76fd52dbc56745260302a74b04536e85bee9a6 Mon Sep 17 00:00:00 2001 From: aoshiguchen <1052045476@qq.com> Date: Wed, 6 Jul 2022 16:12:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=AD=90=E7=B1=BB=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E9=81=87=E5=88=B0=E6=95=B0=E7=BB=84=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/aop/proxy/AsgcProxyGenerator.java | 12 +++++- .../core/aop/AsgcProxyGeneratorTest.java | 6 +++ .../fun/asgc/neutrino/core/aop/Giraffe.java | 40 +++++++++++++++++++ .../neutrino/core/bean/test1/Launcher.java | 1 + 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 neutrino-core/src/test/java/fun/asgc/neutrino/core/aop/Giraffe.java diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/proxy/AsgcProxyGenerator.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/proxy/AsgcProxyGenerator.java index d2cc4c37..fc21f9d4 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/proxy/AsgcProxyGenerator.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/proxy/AsgcProxyGenerator.java @@ -28,7 +28,6 @@ import lombok.experimental.Accessors; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.VelocityEngine; -import sun.management.MethodInfo; import java.io.StringWriter; import java.lang.reflect.Method; @@ -144,9 +143,18 @@ public class AsgcProxyGenerator { * @param clazz */ private synchronized void appendImport(List> importClasses, Class clazz) { - if (importClasses.contains(clazz) || clazz.getName().startsWith("java.lang.") || TypeUtil.isNormalBasicType(clazz) || clazz == void.class) { + if (importClasses.contains(clazz) || + clazz.getName().startsWith("java.lang.") || + TypeUtil.isNormalBasicType(clazz) || + clazz == void.class + ) { return; } + if (clazz.isArray()) { + appendImport(importClasses, clazz.getComponentType()); + return; + } + importClasses.add(clazz); } diff --git a/neutrino-core/src/test/java/fun/asgc/neutrino/core/aop/AsgcProxyGeneratorTest.java b/neutrino-core/src/test/java/fun/asgc/neutrino/core/aop/AsgcProxyGeneratorTest.java index cebf5f0c..2f7465cf 100644 --- a/neutrino-core/src/test/java/fun/asgc/neutrino/core/aop/AsgcProxyGeneratorTest.java +++ b/neutrino-core/src/test/java/fun/asgc/neutrino/core/aop/AsgcProxyGeneratorTest.java @@ -37,4 +37,10 @@ public class AsgcProxyGeneratorTest { System.out.println(result); } + @Test + public void test2() { + String result = AsgcProxyGenerator.getInstance().generator("A", Giraffe.class); + System.out.println(result); + } + } diff --git a/neutrino-core/src/test/java/fun/asgc/neutrino/core/aop/Giraffe.java b/neutrino-core/src/test/java/fun/asgc/neutrino/core/aop/Giraffe.java new file mode 100644 index 00000000..6afb98e7 --- /dev/null +++ b/neutrino-core/src/test/java/fun/asgc/neutrino/core/aop/Giraffe.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.aop; + + +import java.util.Arrays; + +/** + * + * @author: aoshiguchen + * @date: 2022/7/6 + */ +public class Giraffe { + public void run(String[] args) { + System.out.println("运行:" + Arrays.toString(args)); + } + + public Dog getDog() { + return new Dog(); + } +} diff --git a/neutrino-core/src/test/java/fun/asgc/neutrino/core/bean/test1/Launcher.java b/neutrino-core/src/test/java/fun/asgc/neutrino/core/bean/test1/Launcher.java index 845a4950..2e1a2dfd 100644 --- a/neutrino-core/src/test/java/fun/asgc/neutrino/core/bean/test1/Launcher.java +++ b/neutrino-core/src/test/java/fun/asgc/neutrino/core/bean/test1/Launcher.java @@ -34,6 +34,7 @@ import java.util.Set; * @author: aoshiguchen * @date: 2022/7/4 */ +@NonIntercept(false) @NeutrinoApplication public class Launcher {