aboutsummaryrefslogtreecommitdiff
path: root/factory
diff options
context:
space:
mode:
authorcushon <cushon@google.com>2019-06-05 15:28:46 -0700
committerRon Shapiro <shapiro.rd@gmail.com>2019-06-06 11:06:15 -0400
commit1ee934285cabe3f19cb77cc6a7664682f29c0fde (patch)
tree49bc22c1599a0115e07de0fd81599f800de9d986 /factory
parent42433c6048c0a81e7669d3d9e36fece025185487 (diff)
downloadauto-1ee934285cabe3f19cb77cc6a7664682f29c0fde.tar.gz
Don't compare TypeMirrors using Object#equals
RELNOTES=n/a ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=251731604
Diffstat (limited to 'factory')
-rw-r--r--factory/src/main/java/com/google/auto/factory/processor/FactoryDescriptor.java7
-rw-r--r--factory/src/main/java/com/google/auto/factory/processor/FactoryWriter.java9
-rw-r--r--factory/src/main/java/com/google/auto/factory/processor/Parameter.java21
3 files changed, 18 insertions, 19 deletions
diff --git a/factory/src/main/java/com/google/auto/factory/processor/FactoryDescriptor.java b/factory/src/main/java/com/google/auto/factory/processor/FactoryDescriptor.java
index 2ffad953..68ae678d 100644
--- a/factory/src/main/java/com/google/auto/factory/processor/FactoryDescriptor.java
+++ b/factory/src/main/java/com/google/auto/factory/processor/FactoryDescriptor.java
@@ -15,7 +15,6 @@
*/
package com.google.auto.factory.processor;
-import com.google.auto.common.MoreTypes;
import com.google.auto.value.AutoValue;
import com.google.common.base.CharMatcher;
import com.google.common.base.Optional;
@@ -222,8 +221,8 @@ abstract class FactoryDescriptor {
}
// Descriptors are identical if they have the same passed types in the same order.
- return MoreTypes.equivalence().pairwise().equivalent(
- Iterables.transform(factory.passedParameters(), Parameter.TYPE),
- Iterables.transform(implementation.passedParameters(), Parameter.TYPE));
+ return Iterables.elementsEqual(
+ Iterables.transform(factory.passedParameters(), Parameter::type),
+ Iterables.transform(implementation.passedParameters(), Parameter::type));
}
}
diff --git a/factory/src/main/java/com/google/auto/factory/processor/FactoryWriter.java b/factory/src/main/java/com/google/auto/factory/processor/FactoryWriter.java
index 61058470..8037a831 100644
--- a/factory/src/main/java/com/google/auto/factory/processor/FactoryWriter.java
+++ b/factory/src/main/java/com/google/auto/factory/processor/FactoryWriter.java
@@ -16,7 +16,6 @@
package com.google.auto.factory.processor;
import static com.google.auto.common.GeneratedAnnotationSpecs.generatedAnnotationSpec;
-import static com.google.auto.factory.processor.Mirrors.isProvider;
import static com.squareup.javapoet.MethodSpec.constructorBuilder;
import static com.squareup.javapoet.MethodSpec.methodBuilder;
import static com.squareup.javapoet.TypeSpec.classBuilder;
@@ -143,13 +142,13 @@ final class FactoryWriter {
CodeBlock argument;
if (methodDescriptor.passedParameters().contains(parameter)) {
argument = CodeBlock.of(parameter.name());
- if (parameter.type().getKind().isPrimitive()) {
+ if (parameter.isPrimitive()) {
checkNotNull = false;
}
} else {
ProviderField provider = descriptor.providers().get(parameter.key());
argument = CodeBlock.of(provider.name());
- if (isProvider(parameter.type())) {
+ if (parameter.isProvider()) {
// Providers are checked for nullness in the Factory's constructor.
checkNotNull = false;
} else {
@@ -204,7 +203,7 @@ final class FactoryWriter {
ImmutableList.Builder<ParameterSpec> builder = ImmutableList.builder();
for (Parameter parameter : parameters) {
ParameterSpec.Builder parameterBuilder =
- ParameterSpec.builder(TypeName.get(parameter.type()), parameter.name());
+ ParameterSpec.builder(TypeName.get(parameter.type().get()), parameter.name());
for (AnnotationMirror annotation :
Iterables.concat(parameter.nullable().asSet(), parameter.key().qualifier().asSet())) {
parameterBuilder.addAnnotation(AnnotationSpec.get(annotation));
@@ -243,7 +242,7 @@ final class FactoryWriter {
}
for (FactoryMethodDescriptor method : descriptor.methodDescriptors()) {
for (Parameter parameter : method.creationParameters()) {
- if (!parameter.nullable().isPresent() && !parameter.type().getKind().isPrimitive()) {
+ if (!parameter.nullable().isPresent() && !parameter.type().get().getKind().isPrimitive()) {
return true;
}
}
diff --git a/factory/src/main/java/com/google/auto/factory/processor/Parameter.java b/factory/src/main/java/com/google/auto/factory/processor/Parameter.java
index 229e11b7..781225a2 100644
--- a/factory/src/main/java/com/google/auto/factory/processor/Parameter.java
+++ b/factory/src/main/java/com/google/auto/factory/processor/Parameter.java
@@ -21,9 +21,9 @@ import static com.google.common.base.Preconditions.checkArgument;
import com.google.auto.common.AnnotationMirrors;
import com.google.auto.common.MoreElements;
+import com.google.auto.common.MoreTypes;
import com.google.auto.value.AutoValue;
import com.google.common.base.Equivalence;
-import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
@@ -45,18 +45,19 @@ import javax.lang.model.util.Types;
@AutoValue
abstract class Parameter {
- static final Function<Parameter, TypeMirror> TYPE = new Function<Parameter, TypeMirror>() {
- @Override
- public TypeMirror apply(Parameter parameter) {
- return parameter.type();
- }
- };
-
/**
* The original type of the parameter, while {@code key().type()} erases the wrapped {@link
* Provider}, if any.
*/
- abstract TypeMirror type();
+ abstract Equivalence.Wrapper<TypeMirror> type();
+
+ boolean isProvider() {
+ return Mirrors.isProvider(type().get());
+ }
+
+ boolean isPrimitive() {
+ return type().get().getKind().isPrimitive();
+ }
/** The name of the parameter. */
abstract String name();
@@ -82,7 +83,7 @@ abstract class Parameter {
Key key = Key.create(type, annotations, types);
return new AutoValue_Parameter(
- type,
+ MoreTypes.equivalence().wrap(type),
variable.getSimpleName().toString(),
key,
wrapOptionalInEquivalence(AnnotationMirrors.equivalence(), nullable));