From 064d8be4c47daeb51c4bbc5c03e1aed1f07e5403 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Thu, 9 Feb 2023 21:24:22 +1300 Subject: [PATCH] Squashed commit of the following: commit 2b20e1b24f85cc3e75f79ae91bff790cb1e0f4d1 Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Wed Feb 8 18:45:55 2023 -0500 order constants commit 80dcb5c40d099e54e763d3d028894df4303e665b Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Wed Feb 8 18:35:12 2023 -0500 Update pom.xml commit a4e0de9b44120f6940a9231606e1915b5d8ebcdc Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Wed Feb 8 17:47:57 2023 -0500 use avaje prism (it works, but is not deployed) commit e0518065ad3e14946db938f54d9d4bcb15d43003 Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Tue Feb 7 19:04:25 2023 -0500 Update module-info.java commit df99f4bd07bd3e76487a39f8705c58473dbbf841 Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Tue Feb 7 19:04:09 2023 -0500 Update module-info.java commit ce72b23da50bb0a5db0ff23848fcdb687aaa8913 Merge: ad3f269 df12d0c Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Tue Feb 7 18:57:45 2023 -0500 Merge branch 'prism' of https://github.com/SentryMan/avaje-inject into prism commit ad3f269c4b992550e552d8b3db2c7f05c76b90b9 Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Tue Feb 7 18:57:29 2023 -0500 static inject commit df12d0c24875c4db0351110f05046a865e9ba83f Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Tue Feb 7 18:48:12 2023 -0500 static requires commit d09c0e210eb459bc50c7b1e2863cef111d521ca0 Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Tue Feb 7 18:14:25 2023 -0500 don't need prism module commit b23e7f03d9fb1bc5c33b47f3020cdde178b9803b Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Tue Feb 7 18:04:34 2023 -0500 Update ExternalProvider.java commit 84da34b63fe09395a1e1ea2ab7f7c7018ddbe627 Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Tue Feb 7 17:57:38 2023 -0500 fix module commit 2e9008e91088818613b32145d5dd75a149dd5824 Merge: 6e65622 91c5da2 Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Tue Feb 7 17:55:29 2023 -0500 Merge branch 'prism2' into prism commit 91c5da2d101f74dbf94bc72a9d6e7a16942c5729 Merge: 2ee8553 2b0f8d4 Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Tue Feb 7 17:55:04 2023 -0500 Merge pull request #3 from agentgt/prism Switch to generating module-info for prisms commit 6e65622d5a6f1110fa029979312f701efca85aa6 Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Tue Feb 7 17:47:15 2023 -0500 rc5 commit 2b0f8d4f6e586e10f89201fcfd9f79fac0b1609a Author: Adam Gent Date: Tue Feb 7 17:30:33 2023 -0500 Switch to generating module-info for prisms commit ca6c9e5f37ea5c4120a10935e495d4ac5055aaac Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Tue Feb 7 17:01:32 2023 -0500 minor stuff commit 6f896d79e27907092a6ed84004ba6186dbccff21 Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Tue Feb 7 16:52:31 2023 -0500 fix test commit 5f8b4bff47083282e678c9d47ba52fe230c7f66a Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Tue Feb 7 16:45:17 2023 -0500 compiles commit e7577ca2e382245b2b0afa8eb43ab88689a5ee57 Merge: b932fd8 2ee8553 Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Tue Feb 7 15:42:27 2023 -0500 Merge remote-tracking branch 'origin/prism2' into prism commit 2ee8553a39c1fae41cb4d34e7490cb3cd5b6182b Merge: 8258618 a121495 Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Tue Feb 7 15:34:49 2023 -0500 Merge pull request #2 from agentgt/prism Merge prism changes commit b932fd8c19e099a63590f8d83fb7eb5c7d2fec01 Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Tue Feb 7 15:01:46 2023 -0500 Update pom.xml commit 585e707f53127737ced3870a241cc356e203e9f4 Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Tue Feb 7 15:01:29 2023 -0500 Update pom.xml commit f876306deeba981973301d90547bc8ca3cbd88ca Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Tue Feb 7 14:49:31 2023 -0500 external commit a12149516fc11972062911c40c3e3afd85caf759 Author: Adam Gent Date: Tue Feb 7 14:53:57 2023 -0500 Move prisms to new module commit 13c83007c130ff31e64524d3eb91f7cfdb611955 Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Tue Feb 7 13:21:45 2023 -0500 working commit 65c022e8fcfc8f95e4207ae35cafa65331173bbb Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Mon Feb 6 21:48:57 2023 -0500 Update pom.xml commit 264d51db31bd28e4bb8e464a5642537f808af821 Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Mon Feb 6 21:47:12 2023 -0500 sorta work commit 825861879b9d50f82c0b19c1b589b8d9b7ca85b2 Merge: 244360d 12eba7f Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Mon Feb 6 09:56:59 2023 -0500 Merge remote-tracking branch 'upstream/master' commit 244360dbefd924383d5ed39743f51ea3ce4176c3 Author: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Thu Feb 2 18:17:12 2023 -0500 Update pom.xml --- blackbox-aspect/pom.xml | 2 +- blackbox-other/pom.xml | 2 +- blackbox-test-inject/pom.xml | 2 +- inject-generator/pom.xml | 30 ++- .../io/avaje/inject/generator/AllScopes.java | 10 +- .../generator/AspectAnnotationReader.java | 4 +- .../io/avaje/inject/generator/BeanReader.java | 21 ++- .../io/avaje/inject/generator/Constants.java | 15 +- .../inject/generator/ExternalProvider.java | 51 ++++-- .../inject/generator/GenericTypeParser.java | 5 +- .../io/avaje/inject/generator/MetaData.java | 17 +- .../avaje/inject/generator/MethodReader.java | 21 +-- .../inject/generator/ProcessingContext.java | 41 +++-- .../io/avaje/inject/generator/Processor.java | 171 +++++++----------- .../io/avaje/inject/generator/ScopeInfo.java | 37 ++-- .../io/avaje/inject/generator/ScopeUtil.java | 60 +----- .../generator/TypeAnnotationReader.java | 5 +- .../generator/TypeExtendsInjection.java | 13 +- .../inject/generator/TypeExtendsReader.java | 16 +- .../io/avaje/inject/generator/TypeReader.java | 4 +- .../java/io/avaje/inject/generator/Util.java | 6 +- .../avaje/inject/generator/package-info.java | 36 ++++ .../src/main/java/module-info.java | 1 + .../generator/IncludeAnnotationsTest.java | 20 +- inject-maven-plugin/pom.xml | 2 +- inject-test/pom.xml | 4 +- inject/pom.xml | 2 +- pom.xml | 3 +- 28 files changed, 297 insertions(+), 304 deletions(-) create mode 100644 inject-generator/src/main/java/io/avaje/inject/generator/package-info.java diff --git a/blackbox-aspect/pom.xml b/blackbox-aspect/pom.xml index dff5f6a05..336bc7598 100644 --- a/blackbox-aspect/pom.xml +++ b/blackbox-aspect/pom.xml @@ -5,7 +5,7 @@ avaje-inject-parent io.avaje - 8.12-RC4 + 8.12-RC5 4.0.0 diff --git a/blackbox-other/pom.xml b/blackbox-other/pom.xml index c176bb089..71bf0baa2 100644 --- a/blackbox-other/pom.xml +++ b/blackbox-other/pom.xml @@ -6,7 +6,7 @@ avaje-inject-parent io.avaje - 8.12-RC4 + 8.12-RC5 blackbox-other diff --git a/blackbox-test-inject/pom.xml b/blackbox-test-inject/pom.xml index 0d282319e..61b773ab1 100644 --- a/blackbox-test-inject/pom.xml +++ b/blackbox-test-inject/pom.xml @@ -5,7 +5,7 @@ avaje-inject-parent io.avaje - 8.12-RC4 + 8.12-RC5 4.0.0 diff --git a/inject-generator/pom.xml b/inject-generator/pom.xml index 99d4ab4fa..2700b4d75 100644 --- a/inject-generator/pom.xml +++ b/inject-generator/pom.xml @@ -1,22 +1,33 @@ - + 4.0.0 io.avaje avaje-inject-parent - 8.12-RC4 + 8.12-RC5 avaje-inject-generator avaje inject generator annotation processor generating di as source code - io.avaje avaje-inject - 8.12-RC4 + ${project.version} + true + provided + + + + io.avaje + avaje-prisms + 1.0 + true + provided @@ -40,8 +51,13 @@ 11 11 - - -proc:none + + + io.avaje + avaje-prisms + 1.0 + + @@ -54,8 +70,6 @@ - - diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/AllScopes.java b/inject-generator/src/main/java/io/avaje/inject/generator/AllScopes.java index 5500e9e85..91f5e7a0a 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/AllScopes.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/AllScopes.java @@ -1,13 +1,13 @@ package io.avaje.inject.generator; -import io.avaje.inject.InjectModule; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import javax.annotation.processing.RoundEnvironment; import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; -import java.util.HashMap; -import java.util.List; -import java.util.Map; + final class AllScopes { @@ -59,7 +59,7 @@ void readModules(List customScopeModules) { for (String customScopeModule : customScopeModules) { final TypeElement module = context.element(customScopeModule); if (module != null) { - final InjectModule injectModule = module.getAnnotation(InjectModule.class); + InjectModulePrism injectModule = InjectModulePrism.getInstanceOn(module); if (injectModule != null) { final String customScopeType = injectModule.customScopeType(); final TypeElement scopeType = context.element(customScopeType); diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/AspectAnnotationReader.java b/inject-generator/src/main/java/io/avaje/inject/generator/AspectAnnotationReader.java index 206792c14..c79643ba4 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/AspectAnnotationReader.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/AspectAnnotationReader.java @@ -1,8 +1,8 @@ package io.avaje.inject.generator; -import io.avaje.inject.aop.Aspect; import javax.lang.model.element.*; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -27,7 +27,7 @@ List read() { List aspects = new ArrayList<>(); for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) { Element anElement = annotationMirror.getAnnotationType().asElement(); - Aspect aspect = anElement.getAnnotation(Aspect.class); + AspectPrism aspect = AspectPrism.getInstanceOn(anElement); if (aspect != null) { Meta meta = readTarget(anElement); if (meta != null) { diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/BeanReader.java b/inject-generator/src/main/java/io/avaje/inject/generator/BeanReader.java index 9195778e7..9f62e0d2e 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/BeanReader.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/BeanReader.java @@ -1,13 +1,14 @@ package io.avaje.inject.generator; -import io.avaje.inject.Primary; -import io.avaje.inject.Prototype; -import io.avaje.inject.Secondary; -import io.avaje.inject.spi.Proxy; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; -import java.util.*; + final class BeanReader { @@ -40,10 +41,10 @@ final class BeanReader { this.beanType = beanType; this.type = beanType.getQualifiedName().toString(); this.shortName = shortName(beanType); - this.prototype = (beanType.getAnnotation(Prototype.class) != null); - this.primary = (beanType.getAnnotation(Primary.class) != null); - this.secondary = !primary && (beanType.getAnnotation(Secondary.class) != null); - this.proxy = (beanType.getAnnotation(Proxy.class) != null); + this.prototype = (PrototypePrism.getInstanceOn(beanType) != null); + this.primary = (PrimaryPrism.getInstanceOn(beanType) != null); + this.secondary = !primary && (SecondaryPrism.getInstanceOn(beanType) != null); + this.proxy = (ProxyPrism.getInstanceOn(beanType) != null); this.typeReader = new TypeReader(GenericType.parse(type), beanType, context, importTypes, factory); typeReader.process(); this.requestParams = new BeanRequestParams(type); @@ -319,7 +320,7 @@ boolean isRequestScopedController() { } String suffix() { - return isRequestScopedController() ? Constants.FACTORY : Constants.DI; + return isRequestScopedController() ? Constants.DOLLAR_FACTORY : Constants.DI; } /** diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/Constants.java b/inject-generator/src/main/java/io/avaje/inject/generator/Constants.java index a167a02cd..b6f54a355 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/Constants.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/Constants.java @@ -4,7 +4,7 @@ final class Constants { static final int ORDERING_DEFAULT = 1000; - static final String FACTORY = "$Factory"; + static final String DOLLAR_FACTORY = "$Factory"; static final String DI = "$DI"; static final String IO_CLOSEABLE = "java.io.Closeable"; static final String AUTO_CLOSEABLE = "java.lang.AutoCloseable"; @@ -12,9 +12,11 @@ final class Constants { static final String KOTLIN_METADATA = "kotlin.Metadata"; static final String TYPE = "java.lang.reflect.Type"; - static final String PROVIDER = "jakarta.inject.Provider"; static final String SINGLETON = "jakarta.inject.Singleton"; static final String INJECT = "jakarta.inject.Inject"; + static final String SCOPE = "jakarta.inject.Scope"; + static final String QUALIFIER = "jakarta.inject.Qualifier"; + static final String NAMED = "jakarta.inject.Named"; static final String PATH = "io.avaje.http.api.Path"; static final String CONTROLLER = "io.avaje.http.api.Controller"; @@ -30,10 +32,16 @@ final class Constants { static final String BEANSCOPE = "io.avaje.inject.BeanScope"; static final String INJECTMODULE = "io.avaje.inject.InjectModule"; static final String TESTSCOPE = "io.avaje.inject.test.TestScope"; + static final String PRIMARY = "io.avaje.inject.Primary"; + static final String SECONDARY = "io.avaje.inject.Secondary"; + static final String PROTOTYPE = "io.avaje.inject.Prototype"; + static final String COMPONENT = "io.avaje.inject.Component"; + static final String FACTORY = "io.avaje.inject.Factory"; + static final String BEAN = "io.avaje.inject.Bean"; static final String REFLECT_METHOD = "java.lang.reflect.Method"; static final String ASPECT = "io.avaje.inject.aop.Aspect"; - static final String ASPECT_PROVIDER ="io.avaje.inject.aop.AspectProvider"; + static final String ASPECT_PROVIDER = "io.avaje.inject.aop.AspectProvider"; static final String INVOCATION = "io.avaje.inject.aop.Invocation"; static final String INVOCATION_EXCEPTION = "io.avaje.inject.aop.InvocationException"; static final String METHOD_INTERCEPTOR = "io.avaje.inject.aop.MethodInterceptor"; @@ -46,5 +54,4 @@ final class Constants { static final String DEPENDENCYMETA = "io.avaje.inject.spi.DependencyMeta"; static final String MODULE = "io.avaje.inject.spi.Module"; static final String GENERICTYPE = "io.avaje.inject.spi.GenericType"; - } diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/ExternalProvider.java b/inject-generator/src/main/java/io/avaje/inject/generator/ExternalProvider.java index 60c91af8a..ccd9552bd 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/ExternalProvider.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/ExternalProvider.java @@ -1,8 +1,12 @@ package io.avaje.inject.generator; -import io.avaje.inject.spi.Module; +import java.util.Iterator; +import java.util.ServiceConfigurationError; +import java.util.ServiceLoader; +import java.util.Set; -import java.util.*; +import io.avaje.inject.spi.Module; +import io.avaje.inject.spi.Plugin; /** * The types provided by other modules in the classpath at compile time. @@ -11,13 +15,29 @@ */ final class ExternalProvider { - private final Set providedTypes = new HashSet<>(); + private static final boolean injectAvailable = moduleCP(); + + private ExternalProvider() {} + + private static boolean moduleCP() { + try { + Class.forName(Constants.MODULE); + return true; + } catch (final ClassNotFoundException e) { + + return false; + } + } + + public static void registerModuleProvidedTypes(Set providedTypes) { + + if (!injectAvailable) return; + + Iterator iterator = + ServiceLoader.load(Module.class, ExternalProvider.class.getClassLoader()).iterator(); - void init(Set moduleFileProvided) { - providedTypes.addAll(moduleFileProvided); - ServiceLoader load = ServiceLoader.load(Module.class, ExternalProvider.class.getClassLoader()); - Iterator iterator = load.iterator(); while (iterator.hasNext()) { + try { Module module = iterator.next(); for (final Class provide : module.provides()) { @@ -36,10 +56,19 @@ void init(Set moduleFileProvided) { } /** - * Return true if this type is provided by another module in the classpath. We will add it to - * autoRequires(). + * Register types provided by the plugin so no compiler error when we have a dependency on these + * types and the only thing providing them is the plugin. + * + * @param defaultScope */ - boolean provides(String type) { - return providedTypes.contains(type); + public static void registerPluginProvidedTypes(ScopeInfo defaultScope) { + + if (!injectAvailable) return; + + for (final Plugin plugin : ServiceLoader.load(Plugin.class, Processor.class.getClassLoader())) { + for (final Class provide : plugin.provides()) { + defaultScope.pluginProvided(provide.getCanonicalName()); + } + } } } diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/GenericTypeParser.java b/inject-generator/src/main/java/io/avaje/inject/generator/GenericTypeParser.java index 93450ed6a..f2e437385 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/GenericTypeParser.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/GenericTypeParser.java @@ -1,12 +1,13 @@ package io.avaje.inject.generator; -import java.util.Stack; +import java.util.ArrayDeque; +import java.util.Deque; final class GenericTypeParser { private final String raw; private StringBuilder buf = new StringBuilder(); - private final Stack stack = new Stack<>(); + private final Deque stack = new ArrayDeque<>(); GenericTypeParser(String raw) { this.raw = raw; diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/MetaData.java b/inject-generator/src/main/java/io/avaje/inject/generator/MetaData.java index a6a1bcb96..7ddc366de 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/MetaData.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/MetaData.java @@ -1,13 +1,11 @@ package io.avaje.inject.generator; -import io.avaje.inject.spi.DependencyMeta; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import java.util.stream.Stream; + /** * Holds the data as per @DependencyMeta @@ -41,14 +39,14 @@ final class MetaData { private boolean usesExternalDependency; private String externalDependency; - MetaData(DependencyMeta meta) { + MetaData(DependencyMetaPrism meta) { this.type = meta.type(); this.name = trimName(meta.name()); this.shortType = Util.shortName(type); this.method = meta.method(); this.providesAspect = meta.providesAspect(); - this.provides = asList(meta.provides()); - this.dependsOn = Stream.of(meta.dependsOn()).map(Dependency::new).collect(Collectors.toList()); + this.provides = meta.provides(); + this.dependsOn = meta.dependsOn().stream().map(Dependency::new).collect(Collectors.toList()); this.autoProvides = meta.autoProvides(); } @@ -113,13 +111,6 @@ void setWired() { this.wired = true; } - private List asList(String[] content) { - if (content == null || content.length == 0) { - return new ArrayList<>(); - } - return Arrays.asList(content); - } - void update(BeanReader beanReader) { this.provides = beanReader.provides(); this.dependsOn = beanReader.dependsOn(); diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/MethodReader.java b/inject-generator/src/main/java/io/avaje/inject/generator/MethodReader.java index 2dd3cfcda..33cf7e951 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/MethodReader.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/MethodReader.java @@ -1,19 +1,16 @@ package io.avaje.inject.generator; -import io.avaje.inject.Bean; -import io.avaje.inject.Primary; -import io.avaje.inject.Prototype; -import io.avaje.inject.Secondary; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.TypeMirror; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; + final class MethodReader { @@ -42,13 +39,13 @@ final class MethodReader { this(context, element, beanType, null, null, importTypes); } - MethodReader(ProcessingContext context, ExecutableElement element, TypeElement beanType, Bean bean, String qualifierName, ImportTypeMap importTypes) { + MethodReader(ProcessingContext context, ExecutableElement element, TypeElement beanType, BeanPrism bean, String qualifierName, ImportTypeMap importTypes) { this.isFactory = bean != null; this.element = element; if (isFactory) { - prototype = element.getAnnotation(Prototype.class) != null; - primary = element.getAnnotation(Primary.class) != null; - secondary = element.getAnnotation(Secondary.class) != null; + prototype = PrototypePrism.getInstanceOn(element) != null; + primary = PrimaryPrism.getInstanceOn(element) != null; + secondary = SecondaryPrism.getInstanceOn(element) != null; } else { prototype = false; primary = false; diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/ProcessingContext.java b/inject-generator/src/main/java/io/avaje/inject/generator/ProcessingContext.java index 48a8f0cab..e1b3d060b 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/ProcessingContext.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/ProcessingContext.java @@ -1,5 +1,15 @@ package io.avaje.inject.generator; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.LineNumberReader; +import java.nio.file.NoSuchFileException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import javax.annotation.processing.Filer; import javax.annotation.processing.FilerException; import javax.annotation.processing.Messager; @@ -13,12 +23,6 @@ import javax.tools.FileObject; import javax.tools.JavaFileObject; import javax.tools.StandardLocation; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.LineNumberReader; -import java.io.Reader; -import java.nio.file.NoSuchFileException; -import java.util.*; final class ProcessingContext { @@ -28,7 +32,7 @@ final class ProcessingContext { private final Elements elementUtils; private final Types typeUtils; private final Set uniqueModuleNames = new HashSet<>(); - private final ExternalProvider externalProvide = new ExternalProvider(); + private final Set providedTypes = new HashSet<>(); ProcessingContext(ProcessingEnvironment processingEnv, Set moduleFileProvided) { this.processingEnv = processingEnv; @@ -36,7 +40,10 @@ final class ProcessingContext { this.filer = processingEnv.getFiler(); this.elementUtils = processingEnv.getElementUtils(); this.typeUtils = processingEnv.getTypeUtils(); - externalProvide.init(moduleFileProvided); + + ExternalProvider.registerModuleProvidedTypes(providedTypes); + + providedTypes.addAll(moduleFileProvided); } /** @@ -59,7 +66,7 @@ void logDebug(String msg, Object... args) { } String loadMetaInfServices() { - final List lines = loadMetaInf(Constants.META_INF_MODULE); + final var lines = loadMetaInf(Constants.META_INF_MODULE); return lines.isEmpty() ? null : lines.get(0); } @@ -69,11 +76,11 @@ List loadMetaInfCustom() { private List loadMetaInf(String fullName) { try { - FileObject fileObject = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", fullName); + final var fileObject = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", fullName); if (fileObject != null) { - List lines = new ArrayList<>(); - Reader reader = fileObject.openReader(true); - LineNumberReader lineReader = new LineNumberReader(reader); + final List lines = new ArrayList<>(); + final var reader = fileObject.openReader(true); + final var lineReader = new LineNumberReader(reader); String line; while ((line = lineReader.readLine()) != null) { line = line.trim(); @@ -87,10 +94,10 @@ private List loadMetaInf(String fullName) { } catch (FileNotFoundException | NoSuchFileException e) { // logDebug("no services file yet"); - } catch (FilerException e) { + } catch (final FilerException e) { logDebug("FilerException reading services file"); - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); logWarn("Error reading services file: " + e.getMessage()); } @@ -105,7 +112,7 @@ JavaFileObject createWriter(String cls) throws IOException { } FileObject createMetaInfWriter(ScopeInfo.Type scopeType) throws IOException { - String serviceName = scopeType == ScopeInfo.Type.DEFAULT ? Constants.META_INF_MODULE : Constants.META_INF_TESTMODULE; + final var serviceName = scopeType == ScopeInfo.Type.DEFAULT ? Constants.META_INF_MODULE : Constants.META_INF_TESTMODULE; return createMetaInfWriterFor(serviceName); } @@ -144,6 +151,6 @@ boolean isDuplicateModule(String moduleFullName) { } boolean externallyProvided(String type) { - return externalProvide.provides(type); + return providedTypes.contains(type); } } diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/Processor.java b/inject-generator/src/main/java/io/avaje/inject/generator/Processor.java index 45e607b8a..eae312ba9 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/Processor.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/Processor.java @@ -1,18 +1,20 @@ package io.avaje.inject.generator; -import io.avaje.inject.Component; -import io.avaje.inject.Factory; -import io.avaje.inject.InjectModule; -import io.avaje.inject.Prototype; -import io.avaje.inject.spi.Plugin; -import io.avaje.inject.spi.Proxy; -import jakarta.inject.Scope; -import jakarta.inject.Singleton; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.Filer; import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; import javax.lang.model.SourceVersion; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; @@ -20,14 +22,18 @@ import javax.lang.model.element.TypeElement; import javax.lang.model.util.Elements; import javax.tools.StandardLocation; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.URL; -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; + +@SupportedAnnotationTypes({ + Constants.INJECTMODULE, + Constants.FACTORY, + Constants.SINGLETON, + Constants.COMPONENT, + Constants.PROTOTYPE, + Constants.SCOPE, + Constants.TESTSCOPE, + Constants.CONTROLLER, +}) public final class Processor extends AbstractProcessor { private ProcessingContext context; @@ -51,25 +57,22 @@ public synchronized void init(ProcessingEnvironment processingEnv) { this.elementUtils = processingEnv.getElementUtils(); this.allScopes = new AllScopes(context); this.defaultScope = allScopes.defaultScope(); - registerPluginProvidedTypes(); + ExternalProvider.registerPluginProvidedTypes(defaultScope); + pluginFileProvided.forEach(defaultScope::pluginProvided); } - /** - * Loads provider files generated by avaje-inject-maven-plugin - */ + /** Loads provider files generated by avaje-inject-maven-plugin */ void loadProvidedFiles(Filer filer) { - targetProvidesLines(filer, "target/avaje-plugin-provides.txt") - .forEach(pluginFileProvided::add); + targetProvidesLines(filer, "target/avaje-plugin-provides.txt").forEach(pluginFileProvided::add); - targetProvidesLines(filer, "target/avaje-module-provides.txt") - .forEach(moduleFileProvided::add); + targetProvidesLines(filer, "target/avaje-module-provides.txt").forEach(moduleFileProvided::add); } private static List targetProvidesLines(Filer filer, String relativeName) { try { - final String resource = targetProvides(filer, relativeName); + final var resource = targetProvides(filer, relativeName); try (var inputStream = new URL(resource).openStream(); - var reader = new BufferedReader(new InputStreamReader(inputStream))) { + var reader = new BufferedReader(new InputStreamReader(inputStream))) { return reader.lines().collect(Collectors.toList()); } } catch (final IOException e) { @@ -79,54 +82,31 @@ private static List targetProvidesLines(Filer filer, String relativeName private static String targetProvides(Filer filer, String relativeName) throws IOException { return filer - .getResource(StandardLocation.CLASS_OUTPUT, "", relativeName) - .toUri() - .toString() - .replace("/target/classes", ""); - } - - /** - * Register types provided by the plugin so no compiler error when we have a dependency - * on these types and the only thing providing them is the plugin. - */ - private void registerPluginProvidedTypes() { - for (final Plugin plugin : ServiceLoader.load(Plugin.class, Processor.class.getClassLoader())) { - for (final Class provide : plugin.provides()) { - defaultScope.pluginProvided(provide.getCanonicalName()); - } - } - pluginFileProvided.forEach(defaultScope::pluginProvided); - } - - @Override - public Set getSupportedAnnotationTypes() { - Set annotations = new LinkedHashSet<>(); - annotations.add(InjectModule.class.getCanonicalName()); - annotations.add(Factory.class.getCanonicalName()); - annotations.add(Singleton.class.getCanonicalName()); - annotations.add(Component.class.getCanonicalName()); - annotations.add(Prototype.class.getCanonicalName()); - annotations.add(Scope.class.getCanonicalName()); - annotations.add(Constants.TESTSCOPE); - annotations.add(Constants.CONTROLLER); - return annotations; + .getResource(StandardLocation.CLASS_OUTPUT, "", relativeName) + .toUri() + .toString() + .replace("/target/classes", ""); } @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { readModule(roundEnv); - readScopes(roundEnv.getElementsAnnotatedWith(Scope.class)); - readChangedBeans(roundEnv.getElementsAnnotatedWith(Factory.class), true); + readScopes(roundEnv.getElementsAnnotatedWith(context.element(Constants.SCOPE))); + readChangedBeans( + roundEnv.getElementsAnnotatedWith(context.element(Constants.FACTORY)), true); if (defaultScope.includeSingleton()) { - readChangedBeans(roundEnv.getElementsAnnotatedWith(Singleton.class), false); + readChangedBeans( + roundEnv.getElementsAnnotatedWith(context.element(Constants.SINGLETON)), false); } - readChangedBeans(roundEnv.getElementsAnnotatedWith(Component.class), false); - readChangedBeans(roundEnv.getElementsAnnotatedWith(Prototype.class), false); - TypeElement typeElement = elementUtils.getTypeElement(Constants.CONTROLLER); + readChangedBeans( + roundEnv.getElementsAnnotatedWith(context.element(Constants.COMPONENT)), false); + readChangedBeans( + roundEnv.getElementsAnnotatedWith(context.element(Constants.PROTOTYPE)), false); + final var typeElement = elementUtils.getTypeElement(Constants.CONTROLLER); if (typeElement != null) { readChangedBeans(roundEnv.getElementsAnnotatedWith(typeElement), false); } - readChangedBeans(roundEnv.getElementsAnnotatedWith(Proxy.class), false); + readChangedBeans(roundEnv.getElementsAnnotatedWith(context.element(Constants.PROXY)), false); allScopes.readBeans(roundEnv); defaultScope.write(roundEnv.processingOver()); allScopes.write(roundEnv.processingOver()); @@ -134,59 +114,49 @@ public boolean process(Set annotations, RoundEnvironment } private void readScopes(Set scopes) { - for (Element element : scopes) { - if (element.getKind() == ElementKind.ANNOTATION_TYPE) { - if (element instanceof TypeElement) { - TypeElement type = (TypeElement) element; - allScopes.addScopeAnnotation(type); - } + for (final Element element : scopes) { + if ((element.getKind() == ElementKind.ANNOTATION_TYPE) && (element instanceof TypeElement)) { + final var type = (TypeElement) element; + allScopes.addScopeAnnotation(type); } } addTestScope(); } - /** - * Add built-in test scope for @TestScope if available. - */ + /** Add built-in test scope for @TestScope if available. */ private void addTestScope() { - TypeElement testScopeType = elementUtils.getTypeElement(Constants.TESTSCOPE); + final var testScopeType = elementUtils.getTypeElement(Constants.TESTSCOPE); if (testScopeType != null) { allScopes.addScopeAnnotation(testScopeType); } } - /** - * Read the beans that have changed. - */ + /** Read the beans that have changed. */ private void readChangedBeans(Set beans, boolean factory) { - for (Element element : beans) { + for (final Element element : beans) { // ignore methods (e.g. factory methods with @Prototype on them) if (element instanceof TypeElement) { - TypeElement typeElement = (TypeElement) element; - final ScopeInfo scope = findScope(typeElement); + final var typeElement = (TypeElement) element; + final var scope = findScope(typeElement); if (!factory) { // will be found via custom scope so effectively ignore additional @Singleton if (scope == null) { defaultScope.read(typeElement, false); } + } else if (scope != null) { + // context.logWarn("Adding factory to custom scope "+element+" scope: "+scope); + scope.read(typeElement, true); } else { - if (scope != null) { - // context.logWarn("Adding factory to custom scope "+element+" scope: "+scope); - scope.read(typeElement, true); - } else { - defaultScope.read(typeElement, true); - } + defaultScope.read(typeElement, true); } } } } - /** - * Find the scope if the Factory has a scope annotation. - */ + /** Find the scope if the Factory has a scope annotation. */ private ScopeInfo findScope(Element element) { - for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) { - final ScopeInfo scopeInfo = allScopes.get(annotationMirror.getAnnotationType().toString()); + for (final AnnotationMirror annotationMirror : element.getAnnotationMirrors()) { + final var scopeInfo = allScopes.get(annotationMirror.getAnnotationType().toString()); if (scopeInfo != null) { return scopeInfo; } @@ -194,18 +164,16 @@ private ScopeInfo findScope(Element element) { return null; } - /** - * Read the existing meta data from InjectModule (if found) and the factory bean (if exists). - */ + /** Read the existing meta data from InjectModule (if found) and the factory bean (if exists). */ private void readModule(RoundEnvironment roundEnv) { if (readModuleInfo) { // only read the module meta data once return; } readModuleInfo = true; - String factory = context.loadMetaInfServices(); + final var factory = context.loadMetaInfServices(); if (factory != null) { - TypeElement moduleType = elementUtils.getTypeElement(factory); + final var moduleType = elementUtils.getTypeElement(factory); if (moduleType != null) { defaultScope.readModuleMetaData(moduleType); } @@ -214,21 +182,20 @@ private void readModule(RoundEnvironment roundEnv) { readInjectModule(roundEnv); } - /** - * Read InjectModule for things like package-info etc (not for custom scopes) - */ + /** Read InjectModule for things like package-info etc (not for custom scopes) */ private void readInjectModule(RoundEnvironment roundEnv) { // read other that are annotated with InjectModule - for (Element element : roundEnv.getElementsAnnotatedWith(InjectModule.class)) { - Scope scope = element.getAnnotation(Scope.class); + for (final Element element : roundEnv.getElementsAnnotatedWith(context.element(Constants.INJECTMODULE))) { + + final var scope = ScopePrism.getInstanceOn(element); if (scope == null) { // it it not a custom scope annotation - InjectModule annotation = element.getAnnotation(InjectModule.class); + + final var annotation = InjectModulePrism.getInstanceOn(element); if (annotation != null) { defaultScope.details(annotation.name(), element); } } } } - } diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/ScopeInfo.java b/inject-generator/src/main/java/io/avaje/inject/generator/ScopeInfo.java index ab3bd3324..403ade2ac 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/ScopeInfo.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/ScopeInfo.java @@ -1,7 +1,14 @@ package io.avaje.inject.generator; -import io.avaje.inject.InjectModule; -import io.avaje.inject.spi.DependencyMeta; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import javax.annotation.processing.FilerException; import javax.lang.model.element.Element; @@ -9,8 +16,7 @@ import javax.lang.model.element.Name; import javax.lang.model.element.TypeElement; import javax.tools.JavaFileObject; -import java.io.IOException; -import java.util.*; + final class ScopeInfo { @@ -110,13 +116,20 @@ void details(String name, Element contextElement) { } private void read(Element element) { - ignoreSingleton = ScopeUtil.readIgnoreSingleton(element); - requires(ScopeUtil.readRequires(element)); - provides(ScopeUtil.readProvides(element)); - for (String require : ScopeUtil.readRequiresPackages(element)) { - requiresPackages.add(require); - requirePkg.add(Util.packageOf(require) + "."); + final var injectModule = InjectModulePrism.getInstanceOn(element); + if (injectModule == null) { + return; } + ignoreSingleton = injectModule.ignoreSingleton(); + injectModule.requires().stream().map(Object::toString).forEach(requires::add); + injectModule.provides().stream().map(Object::toString).forEach(provides::add); + injectModule.requiresPackages().stream() + .map(Object::toString) + .forEach( + require -> { + requiresPackages.add(require); + requirePkg.add(Util.packageOf(require) + "."); + }); } private String initName(String topPackage) { @@ -304,7 +317,7 @@ void readBuildMethodDependencyMeta(Element element) { Name simpleName = element.getSimpleName(); if (simpleName.toString().startsWith("build_")) { // read a build method - DependencyMeta - DependencyMeta meta = element.getAnnotation(DependencyMeta.class); + DependencyMetaPrism meta = DependencyMetaPrism.getInstanceOn(element); if (meta == null) { context.logError("Missing @DependencyMeta on method " + simpleName); } else { @@ -422,7 +435,7 @@ void buildAutoRequiresAspects(Append writer, Set autoRequires) { } void readModuleMetaData(TypeElement moduleType) { - InjectModule module = moduleType.getAnnotation(InjectModule.class); + InjectModulePrism module = InjectModulePrism.getInstanceOn(moduleType); details(module.name(), moduleType); readFactoryMetaData(moduleType); } diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/ScopeUtil.java b/inject-generator/src/main/java/io/avaje/inject/generator/ScopeUtil.java index 03d55f5cd..aefdb320d 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/ScopeUtil.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/ScopeUtil.java @@ -1,68 +1,10 @@ package io.avaje.inject.generator; -import javax.lang.model.element.*; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - final class ScopeUtil { - private static final String INJECT_MODULE = "io.avaje.inject.InjectModule"; - - static boolean readIgnoreSingleton(Element element) { - if (element == null) { - return false; - } - for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) { - if (INJECT_MODULE.equals(annotationMirror.getAnnotationType().toString())) { - for (Map.Entry entry : annotationMirror.getElementValues().entrySet()) { - if (entry.getKey().toString().startsWith("ignoreSingleton(")) { - Object value = entry.getValue().getValue(); - return "true".equalsIgnoreCase(value.toString()); - } - } - } - } - return false; - } - - static List readProvides(Element element) { - return readClasses(element, "provides("); - } - - static List readRequires(Element element) { - return readClasses(element, "requires("); - } - - static List readRequiresPackages(Element element) { - return readClasses(element, "requiresPackages("); - } - - static List readClasses(Element element, String attributeName) { - if (element == null) { - return Collections.emptyList(); - } - List requiresList = new ArrayList<>(); - for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) { - if (INJECT_MODULE.equals(annotationMirror.getAnnotationType().toString())) { - for (Map.Entry entry : annotationMirror.getElementValues().entrySet()) { - if (entry.getKey().toString().startsWith(attributeName)) { - for (Object requiresType : (List) entry.getValue().getValue()) { - String fullName = requiresType.toString(); - fullName = fullName.substring(0, fullName.length() - 6); - requiresList.add(fullName); - } - } - } - } - } - return requiresList; - } - static String initName(String name) { name = name(name); - return name.equals("Inject") ? "DInject" : name; + return "Inject".equals(name) ? "DInject" : name; } static String name(String name) { diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/TypeAnnotationReader.java b/inject-generator/src/main/java/io/avaje/inject/generator/TypeAnnotationReader.java index 5a3f1c243..ca048d475 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/TypeAnnotationReader.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/TypeAnnotationReader.java @@ -1,10 +1,11 @@ package io.avaje.inject.generator; -import jakarta.inject.Qualifier; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.TypeElement; import javax.lang.model.type.DeclaredType; + + import java.util.ArrayList; import java.util.List; @@ -38,7 +39,7 @@ String qualifierName() { void process() { for (AnnotationMirror annotationMirror : beanType.getAnnotationMirrors()) { DeclaredType annotationType = annotationMirror.getAnnotationType(); - Qualifier qualifier = annotationType.asElement().getAnnotation(Qualifier.class); + QualifierPrism qualifier = QualifierPrism.getInstanceOn(annotationType.asElement()); String annType = annotationType.toString(); if (qualifier != null) { qualifierName = Util.shortName(annType).toLowerCase(); diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/TypeExtendsInjection.java b/inject-generator/src/main/java/io/avaje/inject/generator/TypeExtendsInjection.java index 4ba423cc8..314198217 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/TypeExtendsInjection.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/TypeExtendsInjection.java @@ -1,8 +1,5 @@ package io.avaje.inject.generator; -import io.avaje.inject.Bean; -import jakarta.inject.Inject; - import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; @@ -59,7 +56,7 @@ void read(TypeElement type) { } private void readField(Element element) { - Inject inject = element.getAnnotation(Inject.class); + InjectPrism inject = InjectPrism.getInstanceOn(element); if (inject != null) { injectFields.add(new FieldReader(element)); } @@ -73,7 +70,7 @@ private void readConstructor(Element element, TypeElement type) { ExecutableElement ex = (ExecutableElement) element; MethodReader methodReader = new MethodReader(context, ex, baseType, importTypes).read(); - Inject inject = element.getAnnotation(Inject.class); + InjectPrism inject = InjectPrism.getInstanceOn(element); if (inject != null) { injectConstructor = methodReader; } else { @@ -87,13 +84,13 @@ private void readMethod(Element element, TypeElement type) { boolean checkAspect = true; ExecutableElement methodElement = (ExecutableElement) element; if (factory) { - Bean bean = element.getAnnotation(Bean.class); + BeanPrism bean = BeanPrism.getInstanceOn(element); if (bean != null) { addFactoryMethod(methodElement, bean); checkAspect = false; } } - Inject inject = element.getAnnotation(Inject.class); + InjectPrism inject = InjectPrism.getInstanceOn(element); final String methodKey = methodElement.getSimpleName().toString(); if (inject != null && !notInjectMethods.contains(methodKey)) { if (!injectMethods.containsKey(methodKey)) { @@ -145,7 +142,7 @@ private void checkForAspect(ExecutableElement methodElement) { } - private void addFactoryMethod(ExecutableElement methodElement, Bean bean) { + private void addFactoryMethod(ExecutableElement methodElement, BeanPrism bean) { String qualifierName = Util.getNamed(methodElement); factoryMethods.add(new MethodReader(context, methodElement, baseType, bean, qualifierName, importTypes).read()); } diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/TypeExtendsReader.java b/inject-generator/src/main/java/io/avaje/inject/generator/TypeExtendsReader.java index 92a8569a4..cdd06f83f 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/TypeExtendsReader.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/TypeExtendsReader.java @@ -1,17 +1,15 @@ package io.avaje.inject.generator; -import io.avaje.inject.Factory; -import io.avaje.inject.spi.Generated; -import io.avaje.inject.spi.Proxy; + +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.List; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; import javax.lang.model.type.TypeMirror; -import java.lang.annotation.Annotation; -import java.util.ArrayList; -import java.util.List; /** * Read the inheritance types for a given bean type. @@ -53,9 +51,9 @@ final class TypeExtendsReader { private boolean autoProvide() { return publicAccess - && baseType.getAnnotation(Factory.class) == null - && baseType.getAnnotation(Proxy.class) == null - && baseType.getAnnotation(Generated.class) == null + && FactoryPrism.getInstanceOn(baseType) == null + && ProxyPrism.getInstanceOn(baseType) == null + && GeneratedPrism.getInstanceOn(baseType) == null && !isController(); } diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/TypeReader.java b/inject-generator/src/main/java/io/avaje/inject/generator/TypeReader.java index e7fad39cd..b2d719c68 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/TypeReader.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/TypeReader.java @@ -1,9 +1,9 @@ package io.avaje.inject.generator; -import jakarta.inject.Named; import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; + import java.util.List; import java.util.Set; @@ -94,7 +94,7 @@ void process() { } String name() { - Named named = beanType.getAnnotation(Named.class); + NamedPrism named = NamedPrism.getInstanceOn(beanType); if (named != null) { return named.value().toLowerCase(); } diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/Util.java b/inject-generator/src/main/java/io/avaje/inject/generator/Util.java index fed690b48..77c9fc25e 100644 --- a/inject-generator/src/main/java/io/avaje/inject/generator/Util.java +++ b/inject-generator/src/main/java/io/avaje/inject/generator/Util.java @@ -1,7 +1,5 @@ package io.avaje.inject.generator; -import jakarta.inject.Named; -import jakarta.inject.Qualifier; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; import javax.lang.model.type.DeclaredType; @@ -190,13 +188,13 @@ static String commonParent(String currentTop, String aPackage) { * Return the name via @Named or a Qualifier annotation. */ public static String getNamed(Element p) { - Named named = p.getAnnotation(Named.class); + NamedPrism named = NamedPrism.getInstanceOn(p); if (named != null) { return named.value().toLowerCase(); } for (AnnotationMirror annotationMirror : p.getAnnotationMirrors()) { DeclaredType annotationType = annotationMirror.getAnnotationType(); - Qualifier qualifier = annotationType.asElement().getAnnotation(Qualifier.class); + QualifierPrism qualifier = QualifierPrism.getInstanceOn(annotationType.asElement()); if (qualifier != null) { return Util.shortName(annotationType.toString()).toLowerCase(); } diff --git a/inject-generator/src/main/java/io/avaje/inject/generator/package-info.java b/inject-generator/src/main/java/io/avaje/inject/generator/package-info.java new file mode 100644 index 000000000..64d5af830 --- /dev/null +++ b/inject-generator/src/main/java/io/avaje/inject/generator/package-info.java @@ -0,0 +1,36 @@ +@io.avaje.prism.GeneratePrisms({ + @GeneratePrism(value = InjectModule.class), + @GeneratePrism(value = Factory.class), + @GeneratePrism(value = Singleton.class), + @GeneratePrism(value = Component.class), + @GeneratePrism(value = Prototype.class), + @GeneratePrism(value = Scope.class), + @GeneratePrism(value = Qualifier.class), + @GeneratePrism(value = Named.class), + @GeneratePrism(value = Inject.class), + @GeneratePrism(value = Aspect.class), + @GeneratePrism(value = Primary.class), + @GeneratePrism(value = Secondary.class), + @GeneratePrism(value = Proxy.class), + @GeneratePrism(value = DependencyMeta.class), + @GeneratePrism(value = Bean.class), + @GeneratePrism(value = io.avaje.inject.spi.Generated.class), +}) +package io.avaje.inject.generator; + +import io.avaje.inject.Bean; +import io.avaje.inject.Component; +import io.avaje.inject.Factory; +import io.avaje.inject.InjectModule; +import io.avaje.inject.Primary; +import io.avaje.inject.Prototype; +import io.avaje.inject.Secondary; +import io.avaje.inject.aop.Aspect; +import io.avaje.inject.spi.DependencyMeta; +import io.avaje.inject.spi.Proxy; +import io.avaje.prism.GeneratePrism; +import jakarta.inject.Inject; +import jakarta.inject.Named; +import jakarta.inject.Qualifier; +import jakarta.inject.Scope; +import jakarta.inject.Singleton; diff --git a/inject-generator/src/main/java/module-info.java b/inject-generator/src/main/java/module-info.java index 016c0f79b..ef1d96284 100644 --- a/inject-generator/src/main/java/module-info.java +++ b/inject-generator/src/main/java/module-info.java @@ -2,6 +2,7 @@ requires java.compiler; requires io.avaje.inject; + requires static io.avaje.prism; uses io.avaje.inject.spi.Plugin; uses io.avaje.inject.spi.Module; diff --git a/inject-generator/src/test/java/io/avaje/inject/generator/IncludeAnnotationsTest.java b/inject-generator/src/test/java/io/avaje/inject/generator/IncludeAnnotationsTest.java index d86800247..5ebf901ba 100644 --- a/inject-generator/src/test/java/io/avaje/inject/generator/IncludeAnnotationsTest.java +++ b/inject-generator/src/test/java/io/avaje/inject/generator/IncludeAnnotationsTest.java @@ -1,17 +1,11 @@ package io.avaje.inject.generator; -import io.avaje.inject.Factory; -import io.avaje.inject.Primary; -import io.avaje.inject.Secondary; -import org.junit.jupiter.api.Test; - -import jakarta.inject.Named; -import jakarta.inject.Singleton; - import static io.avaje.inject.generator.IncludeAnnotations.include; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; + public class IncludeAnnotationsTest { @Test @@ -35,11 +29,11 @@ public void exclude_kotlinMetaData() { public void exclude_di_annotations() { assertFalse(include("javax.annotation.Generated")); assertFalse(include("foo.Generated")); - assertFalse(include(Singleton.class.getName())); - assertFalse(include(Named.class.getName())); - assertFalse(include(Factory.class.getName())); - assertFalse(include(Primary.class.getName())); - assertFalse(include(Secondary.class.getName())); + assertFalse(include(Constants.SINGLETON)); + assertFalse(include(Constants.NAMED)); + assertFalse(include(Constants.FACTORY)); + assertFalse(include(Constants.PRIMARY)); + assertFalse(include(Constants.SECONDARY)); assertFalse(include(Constants.PATH)); } diff --git a/inject-maven-plugin/pom.xml b/inject-maven-plugin/pom.xml index 29a48a7a8..12a8822ac 100644 --- a/inject-maven-plugin/pom.xml +++ b/inject-maven-plugin/pom.xml @@ -29,7 +29,7 @@ io.avaje avaje-inject - 8.12-RC3 + 8.12-RC4 diff --git a/inject-test/pom.xml b/inject-test/pom.xml index 1d39f907b..a3a8bd5d0 100644 --- a/inject-test/pom.xml +++ b/inject-test/pom.xml @@ -4,7 +4,7 @@ io.avaje avaje-inject-parent - 8.12-RC4 + 8.12-RC5 avaje-inject-test @@ -124,7 +124,7 @@ io.avaje avaje-inject-generator - 8.12-RC4 + ${project.version} diff --git a/inject/pom.xml b/inject/pom.xml index 333bd9e7a..572bc9ed9 100644 --- a/inject/pom.xml +++ b/inject/pom.xml @@ -4,7 +4,7 @@ io.avaje avaje-inject-parent - 8.12-RC4 + 8.12-RC5 avaje-inject diff --git a/pom.xml b/pom.xml index bea0b7606..3b531a0b0 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ io.avaje avaje-inject-parent - 8.12-RC4 + 8.12-RC5 pom avaje inject parent parent pom for avaje inject library @@ -48,4 +48,3 @@ -