Skip to content

Cease reading supertypes for java.lang #712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ final class TypeExtendsReader {
private static final Set<String> 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;
Expand Down Expand Up @@ -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)) {
Expand All @@ -226,38 +223,36 @@ 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)) {
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);
if (Util.notJavaLang(rawType)) {
for (final TypeMirror supertype : types().directSupertypes(anInterface)) {
readInterfacesOf(supertype);
}
for (final TypeMirror supertype : types().directSupertypes(anInterface)) {
readInterfacesOf(supertype);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions inject/src/main/java/io/avaje/inject/spi/DBeanMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down