Skip to content

Commit

Permalink
Make ContributionBinding.contributesPrimitiveType() return an Optiona…
Browse files Browse the repository at this point in the history
…l so that callers can easily get at the actual primitive type.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=172789243
  • Loading branch information
netdpb authored and ronshapiro committed Oct 24, 2017
1 parent 5b60471 commit 2c6d3da
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
15 changes: 5 additions & 10 deletions java/dagger/internal/codegen/ContributionBinding.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,11 @@ boolean requiresModuleInstance() {
return !modifiers.contains(ABSTRACT) && !modifiers.contains(STATIC);
}

/**
* Returns {@code true} if {@link #bindingElement()} is present and is a method that returns a
* primitive type.
*/
boolean contributesPrimitiveType() {
return bindingElement().isPresent()
&& MoreElements.asExecutable(bindingElement().get())
.getReturnType()
.getKind()
.isPrimitive();
/** If {@link #bindingElement()} is a method that returns a primitive type, returns that type. */
Optional<TypeMirror> contributedPrimitiveType() {
return bindingElement()
.map(bindingElement -> MoreElements.asExecutable(bindingElement).getReturnType())
.filter(type -> type.getKind().isPrimitive());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package dagger.internal.codegen;

import static com.google.auto.common.MoreElements.asExecutable;
import static com.google.common.base.CaseFormat.LOWER_CAMEL;
import static com.google.common.base.CaseFormat.UPPER_CAMEL;
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
Expand Down Expand Up @@ -173,9 +172,11 @@ private void createMethod(String name, DependencyRequest.Kind requestKind) {

/** Returns the return type for the dependency request. */
private TypeMirror returnType(DependencyRequest.Kind requestKind) {
return binding.contributesPrimitiveType() && requestKind.equals(DependencyRequest.Kind.INSTANCE)
? asExecutable(binding.bindingElement().get()).getReturnType()
: accessibleType(requestKind.type(binding.contributedType(), types));
if (requestKind.equals(DependencyRequest.Kind.INSTANCE)
&& binding.contributedPrimitiveType().isPresent()) {
return binding.contributedPrimitiveType().get();
}
return accessibleType(requestKind.type(binding.contributedType(), types));
}

/** Returns the method body for the dependency request. */
Expand Down
2 changes: 1 addition & 1 deletion java/dagger/internal/codegen/ProvisionBinding.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private static Builder builder() {
abstract Builder toBuilder();

boolean shouldCheckForNull(CompilerOptions compilerOptions) {
return !contributesPrimitiveType()
return !contributedPrimitiveType().isPresent()
&& !nullableType().isPresent()
&& compilerOptions.doCheckForNulls();
}
Expand Down

0 comments on commit 2c6d3da

Please sign in to comment.