|
17 | 17 | package dagger.internal.codegen.binding; |
18 | 18 |
|
19 | 19 | import static com.google.common.collect.Iterables.getOnlyElement; |
20 | | -import static dagger.internal.codegen.extension.DaggerCollectors.onlyElement; |
| 20 | +import static dagger.internal.codegen.extension.DaggerStreams.toImmutableList; |
21 | 21 | import static dagger.internal.codegen.xprocessing.XElements.getSimpleName; |
| 22 | +import static dagger.internal.codegen.xprocessing.XElements.toStableString; |
22 | 23 | import static dagger.internal.codegen.xprocessing.XProcessingEnvs.getUnboundedWildcardType; |
23 | 24 | import static dagger.internal.codegen.xprocessing.XTypes.isAssignableTo; |
24 | 25 | import static dagger.internal.codegen.xprocessing.XTypes.rewrapType; |
25 | 26 |
|
26 | 27 | import androidx.room.compiler.codegen.XTypeName; |
| 28 | +import androidx.room.compiler.processing.XMethodElement; |
27 | 29 | import androidx.room.compiler.processing.XProcessingEnv; |
28 | 30 | import androidx.room.compiler.processing.XType; |
29 | 31 | import androidx.room.compiler.processing.XTypeElement; |
@@ -87,12 +89,26 @@ private XType desiredAssignableType(XType leftHandSide, ContributionType contrib |
87 | 89 | } |
88 | 90 |
|
89 | 91 | private ImmutableList<XType> methodParameterTypes(XType type, String methodName) { |
90 | | - return ImmutableList.copyOf( |
| 92 | + ImmutableList<XMethodElement> methods = |
91 | 93 | XTypeElements.getAllMethods(type.getTypeElement()).stream() |
92 | 94 | .filter(method -> methodName.contentEquals(getSimpleName(method))) |
93 | | - .collect(onlyElement()) |
94 | | - .asMemberOf(type) |
95 | | - .getParameterTypes()); |
| 95 | + .collect(toImmutableList()); |
| 96 | + if (methods.size() != 1) { |
| 97 | + // TODO(bcorso): This check can be removed (and rely on Iterables.getOnlyElement() below) once |
| 98 | + // https://github.com/google/dagger/issues/3450#issuecomment-3108716712 is fixed. For now, we |
| 99 | + // use a more verbose, custom error message with more information to make it easier to debug. |
| 100 | + throw new IllegalStateException( |
| 101 | + "Expected exactly one factory method for " + toStableString(type.getTypeElement()) |
| 102 | + + " but found: " |
| 103 | + + methods.stream() |
| 104 | + .map( |
| 105 | + method -> |
| 106 | + toStableString(method.getEnclosingElement()) |
| 107 | + + "#" |
| 108 | + + toStableString(method)) |
| 109 | + .collect(toImmutableList())); |
| 110 | + } |
| 111 | + return ImmutableList.copyOf(getOnlyElement(methods).asMemberOf(type).getParameterTypes()); |
96 | 112 | } |
97 | 113 |
|
98 | 114 | private XType methodParameterType(XType type, String methodName) { |
|
0 commit comments