From 3abc18d0e3c059975f4428589313111c486b8034 Mon Sep 17 00:00:00 2001 From: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Mon, 30 Jan 2023 20:26:03 -0500 Subject: [PATCH 1/3] use aspect provider --- .../avaje/inject/generator/AspectMethod.java | 5 ++-- .../io/avaje/inject/generator/AspectPair.java | 2 +- .../avaje/inject/generator/BeanAspects.java | 25 +++++++++---------- .../generator/SimpleBeanProxyWriter.java | 10 ++++---- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/AspectMethod.java b/inject-generator/src/main/java/io/avaje/inject/generator/AspectMethod.java index 26d800786..ab7d35834 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/AspectMethod.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/AspectMethod.java @@ -41,7 +41,7 @@ List initParams(List parame void addTargets(Set targets) { for (AspectPair aspectPair : aspectPairs) { - targets.add(aspectPair.target()); + targets.add(aspectPair.annotationShortName()); } } @@ -123,8 +123,7 @@ void writeSetupForMethods(Append writer, String shortName) { } writer.append(");").eol(); for (AspectPair aspect : aspectPairs) { - String target = aspect.target(); - String name = aspectTargetShortName(target); + String name = Util.initLower(aspect.annotationShortName()); String sn = aspect.annotationShortName(); writer.append(" %s%s = %s.interceptor(%s, %s.getAnnotation(%s.class));", localName, sn, name, localName, localName, sn).eol(); } diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/AspectPair.java b/inject-generator/src/main/java/io/avaje/inject/generator/AspectPair.java index 6c34349bd..61e113c8d 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/AspectPair.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/AspectPair.java @@ -21,7 +21,7 @@ String target() { } void addImports(ImportTypeMap importTypes) { - importTypes.add(target); + importTypes.add("io.avaje.inject.aop.AspectProvider"); importTypes.add(annotationFullName); } diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/BeanAspects.java b/inject-generator/src/main/java/io/avaje/inject/generator/BeanAspects.java index 80df5fdad..7593bdfa4 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/BeanAspects.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/BeanAspects.java @@ -10,44 +10,44 @@ final class BeanAspects { static final BeanAspects EMPTY = new BeanAspects(); private final List aspectMethods; - private final Set targets; + private final Set aspectNames; private BeanAspects() { this.aspectMethods = Collections.emptyList(); - this.targets = Collections.emptySet(); + this.aspectNames = Collections.emptySet(); } BeanAspects(List aspectMethods) { this.aspectMethods = aspectMethods; - this.targets = initTargets(); + this.aspectNames = initAspectNames(); } boolean hasAspects() { return !aspectMethods.isEmpty(); } - Set targets() { - return targets; + Set aspectNames() { + return aspectNames; } void extraImports(ImportTypeMap importTypes) { - for (AspectMethod aspectMethod : aspectMethods) { + for (final AspectMethod aspectMethod : aspectMethods) { aspectMethod.addImports(importTypes); } } - Set initTargets() { - Set targets = new LinkedHashSet<>(); - for (AspectMethod aspectMethod : aspectMethods) { + Set initAspectNames() { + final Set targets = new LinkedHashSet<>(); + for (final AspectMethod aspectMethod : aspectMethods) { aspectMethod.addTargets(targets); } return targets; } void writeFields(Append writer) { - for (String target : targets) { - String type = Util.shortName(target); - String name = Util.initLower(type); + for (final String aspectName : aspectNames) { + final var type = "AspectProvider<" + aspectName + ">"; + final var name = Util.initLower(aspectName); writer.append(" private final %s %s;", type, name).eol(); } writer.eol(); @@ -56,5 +56,4 @@ void writeFields(Append writer) { List methods() { return aspectMethods; } - } diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/SimpleBeanProxyWriter.java b/inject-generator/src/main/java/io/avaje/inject/generator/SimpleBeanProxyWriter.java index 006026871..7d0ceb9ab 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/SimpleBeanProxyWriter.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/SimpleBeanProxyWriter.java @@ -57,19 +57,19 @@ private void writeFields() { private void writeConstructor() { writer.append(" public %s%s(", shortName, suffix); int count = 0; - for (String target : aspects.targets()) { + for (final String aspectName : aspects.aspectNames()) { if (count++ > 0) { writer.append(", "); } - final String type = Util.shortName(target); - String name = Util.initLower(type); + final var type = "AspectProvider<" + aspectName + ">"; + final var name = Util.initLower(aspectName); writer.append(type).append(" ").append(name); } beanReader.writeConstructorParams(writer); writer.append(") {").eol(); beanReader.writeConstructorInit(writer); - for (String target : aspects.targets()) { - String name = AspectMethod.aspectTargetShortName(target); + for (final String target : aspects.aspectNames()) { + final var name = Util.initLower(target); writer.append(" this.%s = %s;", name, name).eol(); } writeSetupForMethods(); From a926e2f876ed9a34cd1649e0df8f46e23fa95144 Mon Sep 17 00:00:00 2001 From: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Mon, 30 Jan 2023 20:34:12 -0500 Subject: [PATCH 2/3] fields are not used --- .../main/java/io/avaje/inject/generator/BeanAspects.java | 9 --------- .../io/avaje/inject/generator/SimpleBeanProxyWriter.java | 5 ----- 2 files changed, 14 deletions(-) diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/BeanAspects.java b/inject-generator/src/main/java/io/avaje/inject/generator/BeanAspects.java index 7593bdfa4..0c3430cb7 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/BeanAspects.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/BeanAspects.java @@ -44,15 +44,6 @@ Set initAspectNames() { return targets; } - void writeFields(Append writer) { - for (final String aspectName : aspectNames) { - final var type = "AspectProvider<" + aspectName + ">"; - final var name = Util.initLower(aspectName); - writer.append(" private final %s %s;", type, name).eol(); - } - writer.eol(); - } - List methods() { return aspectMethods; } diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/SimpleBeanProxyWriter.java b/inject-generator/src/main/java/io/avaje/inject/generator/SimpleBeanProxyWriter.java index 7d0ceb9ab..2046678ae 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/SimpleBeanProxyWriter.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/SimpleBeanProxyWriter.java @@ -47,7 +47,6 @@ private void writeMethods() { } private void writeFields() { - aspects.writeFields(writer); for (AspectMethod method : aspects.methods()) { method.writeSetupFields(writer); } @@ -68,10 +67,6 @@ private void writeConstructor() { beanReader.writeConstructorParams(writer); writer.append(") {").eol(); beanReader.writeConstructorInit(writer); - for (final String target : aspects.aspectNames()) { - final var name = Util.initLower(target); - writer.append(" this.%s = %s;", name, name).eol(); - } writeSetupForMethods(); writer.append(" }").eol(); } From 9b32648b1a74e2dfdcc05a09ffa35801ed17731a Mon Sep 17 00:00:00 2001 From: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Mon, 30 Jan 2023 20:38:05 -0500 Subject: [PATCH 3/3] Update Aspect.java --- inject/src/main/java/io/avaje/inject/aop/Aspect.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inject/src/main/java/io/avaje/inject/aop/Aspect.java b/inject/src/main/java/io/avaje/inject/aop/Aspect.java index 0b580c4aa..99469726f 100644 --- a/inject/src/main/java/io/avaje/inject/aop/Aspect.java +++ b/inject/src/main/java/io/avaje/inject/aop/Aspect.java @@ -20,7 +20,7 @@ /** * Specify the {@link AspectProvider} for this aspect. */ - Class target(); + Class target(); /** * Specify the priority ordering when multiple aspects are on a method.