Skip to content
Merged
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 @@ -23,7 +23,6 @@
import static dagger.internal.codegen.extension.DaggerStreams.toImmutableSet;
import static dagger.internal.codegen.xprocessing.XElements.getSimpleName;
import static java.util.stream.Collectors.joining;
import static kotlin.streams.jdk8.StreamsKt.asStream;

import androidx.room3.compiler.processing.JavaPoetExtKt;
import androidx.room3.compiler.processing.XAnnotation;
Expand All @@ -37,7 +36,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.squareup.javapoet.AnnotationSpec;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.CodeBlock;
Expand Down Expand Up @@ -269,12 +267,20 @@ static void addInjectionMethods(AndroidEntryPointMetadata metadata, TypeSpec.Bui
/** Returns the nearest super class method for the given method signature. */
static XMethodElement nearestSuperClassMethod(
MethodSignature methodSignature, AndroidEntryPointMetadata metadata) {
ImmutableList<XMethodElement> methodOnBaseElement =
asStream(metadata.baseElement().getAllMethods())
.filter(method -> MethodSignature.of(method).equals(methodSignature))
.collect(toImmutableList());
Preconditions.checkState(methodOnBaseElement.size() >= 1);
return Iterables.getLast(methodOnBaseElement);
// We do a top-down traversal of the class hierarchy, looking for the first matching method.
// We purposely avoid getAllMethods() since it resolves more than we typically need here.
XTypeElement currentClass = metadata.baseElement();
while (currentClass != null) {
for (XMethodElement method : currentClass.getDeclaredMethods()) {
if (MethodSignature.of(method).equals(methodSignature)) {
return method;
}
}
XType superClass = currentClass.getSuperClass();
currentClass = superClass != null ? superClass.getTypeElement() : null;
}

throw new IllegalStateException("Method not found for signature: " + methodSignature);
}

// @Override
Expand Down
Loading