Skip to content

Commit

Permalink
Fix an issue where @BindsInstance on a Builder setter method's parame…
Browse files Browse the repository at this point in the history
…ter caused a failure in codegen if the parameter had a different name than the setter method.

Fixes #1464

RELNOTES=Fixed an issue where `@BindsInstance` on a Builder setter method's parameter caused a failure in codegen if the parameter had a different name than the method itself (#1464).

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=241596307
  • Loading branch information
cgdecker committed Apr 2, 2019
1 parent dc3bf5c commit 8051d28
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
17 changes: 8 additions & 9 deletions java/dagger/internal/codegen/ComponentCreatorDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ static ComponentCreatorDescriptor create(
VariableElement parameter = getOnlyElement(method.getParameters());
TypeMirror parameterType = getOnlyElement(resolvedMethodType.getParameterTypes());
setterMethods.put(
requirement(method, parameter, parameterType, dependencyRequestFactory), method);
requirement(method, parameter, parameterType, dependencyRequestFactory, method),
method);
}
}
verify(factoryMethod != null); // validation should have ensured this.
Expand All @@ -187,7 +188,7 @@ static ComponentCreatorDescriptor create(
VariableElement parameter = parameters.get(i);
TypeMirror parameterType = parameterTypes.get(i);
factoryParameters.put(
requirement(factoryMethod, parameter, parameterType, dependencyRequestFactory),
requirement(factoryMethod, parameter, parameterType, dependencyRequestFactory, parameter),
parameter);
}

Expand All @@ -201,15 +202,13 @@ private static ComponentRequirement requirement(
ExecutableElement method,
VariableElement parameter,
TypeMirror type,
DependencyRequestFactory dependencyRequestFactory) {
Element bindsInstanceElement =
isAnnotationPresent(method, BindsInstance.class)
? method
: (isAnnotationPresent(parameter, BindsInstance.class) ? parameter : null);
if (bindsInstanceElement != null) {
DependencyRequestFactory dependencyRequestFactory,
Element elementForVariableName) {
if (isAnnotationPresent(method, BindsInstance.class)
|| isAnnotationPresent(parameter, BindsInstance.class)) {
DependencyRequest request =
dependencyRequestFactory.forRequiredResolvedVariable(parameter, type);
String variableName = bindsInstanceElement.getSimpleName().toString();
String variableName = elementForVariableName.getSimpleName().toString();
return ComponentRequirement.forBoundInstance(
request.key(), request.isNullable(), variableName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ interface TestComponent {

@Component.Builder
interface Builder {
Builder s(@BindsInstance String s);
// https://github.com/google/dagger/issues/1464
Builder s(@BindsInstance String notTheSameNameAsMethod);

Builder i(@BindsInstance int i);

Expand Down

0 comments on commit 8051d28

Please sign in to comment.