From ffdbe55df9c6da4f720063cd819978b914ec5def Mon Sep 17 00:00:00 2001 From: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Sun, 27 Oct 2024 14:22:23 -0400 Subject: [PATCH 1/2] cease reading supertypes for `java.lang` --- .../inject/generator/TypeExtendsReader.java | 38 +++++++++---------- .../java/io/avaje/inject/spi/DBeanMap.java | 6 ++- 2 files changed, 21 insertions(+), 23 deletions(-) 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 e743566c3..91ffa936c 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 @@ -22,9 +22,6 @@ final class TypeExtendsReader { private static final Set ROUTE_TYPES = Set.of( "io.avaje.http.api.AvajeJavalinPlugin", "io.helidon.webserver.http.HttpFeature"); - - private static final String JAVA_LANG_OBJECT = "java.lang.Object"; - private static final String JAVA_LANG_RECORD = "java.lang.Record"; private final UType baseUType; private final TypeElement baseType; private final TypeExtendsInjection extendsInjection; @@ -203,7 +200,7 @@ private String initProvidesAspect() { private void addSuperType(TypeElement element, TypeMirror mirror, boolean proxyBean) { readInterfaces(element); final String fullName = mirror.toString(); - if (!JAVA_LANG_OBJECT.equals(fullName) && !JAVA_LANG_RECORD.equals(fullName)) { + if (Util.notJavaLang(fullName)) { final String type = Util.unwrapProvider(fullName); if (proxyBean || isPublic(element)) { @@ -226,38 +223,37 @@ private void addSuperType(TypeElement element, TypeMirror mirror, boolean proxyB } private void readInterfaces(TypeElement type) { - for (final TypeMirror anInterface : type.getInterfaces()) { - if (isPublic(asElement(anInterface))) { - readInterfacesOf(anInterface); + if (Util.notJavaLang(type.getQualifiedName().toString())) { + for (final TypeMirror anInterface : type.getInterfaces()) { + if (isPublic(asElement(anInterface))) { + readInterfacesOf(anInterface); + } } } } private void readInterfacesOf(TypeMirror anInterface) { - final String rawType = Util.unwrapProvider(anInterface.toString()); - final UType rawUType = Util.unwrapProvider(anInterface); - if (JAVA_LANG_OBJECT.equals(rawType)) { - // we can stop - return; - } - if (rawType.indexOf('.') == -1) { - logWarn("skip when no package on interface " + rawType); - } else if (Constants.AUTO_CLOSEABLE.equals(rawType) || Constants.IO_CLOSEABLE.equals(rawType)) { + final String rawType = Util.unwrapProvider(anInterface.toString()); + final UType rawUType = Util.unwrapProvider(anInterface); + if (Constants.AUTO_CLOSEABLE.equals(rawType) || Constants.IO_CLOSEABLE.equals(rawType)) { closeable = true; + } else if (!Util.notJavaLang(rawType)) { + // return + } else if (rawType.indexOf('.') == -1) { + logWarn("skip when no package on interface " + rawType); } else { if (qualifierName == null) { final String mainType = rawUType.mainType(); final String iShortName = Util.shortName(mainType); if (beanSimpleName.endsWith(iShortName)) { // derived qualifier name based on prefix to interface short name - qualifierName = beanSimpleName.substring(0, beanSimpleName.length() - iShortName.length()); + qualifierName = + beanSimpleName.substring(0, beanSimpleName.length() - iShortName.length()); } } interfaceTypes.add(rawUType); - if (Util.notJavaLang(rawType)) { - for (final TypeMirror supertype : types().directSupertypes(anInterface)) { - readInterfacesOf(supertype); - } + for (final TypeMirror supertype : types().directSupertypes(anInterface)) { + readInterfacesOf(supertype); } } } diff --git a/inject/src/main/java/io/avaje/inject/spi/DBeanMap.java b/inject/src/main/java/io/avaje/inject/spi/DBeanMap.java index 6e534b239..15710b965 100644 --- a/inject/src/main/java/io/avaje/inject/spi/DBeanMap.java +++ b/inject/src/main/java/io/avaje/inject/spi/DBeanMap.java @@ -62,8 +62,10 @@ private void addSuppliedBean(SuppliedBean supplied) { qualifiers.add(supplied.name()); DContextEntryBean entryBean = DContextEntryBean.supplied(supplied.source(), supplied.name(), supplied.priority()); beans.computeIfAbsent(suppliedType.getTypeName(), s -> new DContextEntry()).add(entryBean); - for (Class anInterface : supplied.interfaces()) { - beans.computeIfAbsent(anInterface.getTypeName(), s -> new DContextEntry()).add(entryBean); + if (!suppliedType.getTypeName().startsWith("java.lang")) { + for (Class anInterface : supplied.interfaces()) { + beans.computeIfAbsent(anInterface.getTypeName(), s -> new DContextEntry()).add(entryBean); + } } } From 5f3a5003e252a63d2f8d09a0ed9f88e574ac3a8a Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Mon, 28 Oct 2024 20:49:01 +1300 Subject: [PATCH 2/2] Format only --- .../java/io/avaje/inject/generator/TypeExtendsReader.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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 91ffa936c..d32605af0 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 @@ -244,11 +244,10 @@ private void readInterfacesOf(TypeMirror anInterface) { } else { if (qualifierName == null) { final String mainType = rawUType.mainType(); - final String iShortName = Util.shortName(mainType); - if (beanSimpleName.endsWith(iShortName)) { + final String shortName = Util.shortName(mainType); + if (beanSimpleName.endsWith(shortName)) { // derived qualifier name based on prefix to interface short name - qualifierName = - beanSimpleName.substring(0, beanSimpleName.length() - iShortName.length()); + qualifierName = beanSimpleName.substring(0, beanSimpleName.length() - shortName.length()); } } interfaceTypes.add(rawUType);