aboutsummaryrefslogtreecommitdiff
path: root/factory
diff options
context:
space:
mode:
authorgsaul <gsaul@google.com>2019-08-13 09:43:57 -0700
committerDavid P. Baker <dpb@google.com>2019-08-19 12:23:56 -0400
commite63019a49c2081c61595c36e499ab244aa82c40b (patch)
tree9786fb11957aca6883480480021ace3df3464bf9 /factory
parent12436ccd31725220fc90fe3775a58e39930508b5 (diff)
downloadauto-e63019a49c2081c61595c36e499ab244aa82c40b.tar.gz
Add support for type parameters to @AutoFactory.
RELNOTES=Add support for generics to @AutoFactory #AutoFactory ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=263154977
Diffstat (limited to 'factory')
-rw-r--r--factory/src/it/functional/pom.xml4
-rw-r--r--factory/src/it/functional/src/main/java/com/google/auto/factory/DaggerModule.java5
-rw-r--r--factory/src/it/functional/src/main/java/com/google/auto/factory/FactoryComponent.java4
-rw-r--r--factory/src/it/functional/src/main/java/com/google/auto/factory/FactoryInterface.java2
-rw-r--r--factory/src/it/functional/src/main/java/com/google/auto/factory/Foo.java (renamed from factory/src/it/functional/src/main/java/com/google/auto/factory/FactoryGenerated.java)6
-rw-r--r--factory/src/it/functional/src/main/java/com/google/auto/factory/GenericFoo.java61
-rw-r--r--factory/src/it/functional/src/main/java/com/google/auto/factory/GuiceModule.java1
-rw-r--r--factory/src/it/functional/src/test/java/com/google/auto/factory/DependencyInjectionIntegrationTest.java72
-rw-r--r--factory/src/main/java/com/google/auto/factory/processor/FactoryDescriptorGenerator.java3
-rw-r--r--factory/src/main/java/com/google/auto/factory/processor/FactoryWriter.java52
-rw-r--r--factory/src/main/java/com/google/auto/factory/processor/TypeVariables.java101
-rw-r--r--factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java10
-rw-r--r--factory/src/test/resources/bad/GenericClass.java21
13 files changed, 289 insertions, 53 deletions
diff --git a/factory/src/it/functional/pom.xml b/factory/src/it/functional/pom.xml
index f38b6031..56e8f6f2 100644
--- a/factory/src/it/functional/pom.xml
+++ b/factory/src/it/functional/pom.xml
@@ -89,8 +89,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
- <source>1.6</source>
- <target>1.6</target>
+ <source>1.8</source>
+ <target>1.8</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
diff --git a/factory/src/it/functional/src/main/java/com/google/auto/factory/DaggerModule.java b/factory/src/it/functional/src/main/java/com/google/auto/factory/DaggerModule.java
index a9bf2de8..be9478fc 100644
--- a/factory/src/it/functional/src/main/java/com/google/auto/factory/DaggerModule.java
+++ b/factory/src/it/functional/src/main/java/com/google/auto/factory/DaggerModule.java
@@ -40,4 +40,9 @@ final class DaggerModule {
int provideQualifiedPrimitive() {
return 2;
}
+
+ @Provides
+ Number provideNumber() {
+ return 3;
+ }
}
diff --git a/factory/src/it/functional/src/main/java/com/google/auto/factory/FactoryComponent.java b/factory/src/it/functional/src/main/java/com/google/auto/factory/FactoryComponent.java
index d2fbe852..7d0a1627 100644
--- a/factory/src/it/functional/src/main/java/com/google/auto/factory/FactoryComponent.java
+++ b/factory/src/it/functional/src/main/java/com/google/auto/factory/FactoryComponent.java
@@ -20,5 +20,7 @@ import dagger.Component;
/** A component to materialize the factory using Dagger 2 */
@Component(modules = DaggerModule.class)
interface FactoryComponent {
- FactoryGeneratedFactory factory();
+ FooFactory factory();
+
+ GenericFooFactory<Number> generatedFactory();
}
diff --git a/factory/src/it/functional/src/main/java/com/google/auto/factory/FactoryInterface.java b/factory/src/it/functional/src/main/java/com/google/auto/factory/FactoryInterface.java
index f0e6738f..5f9d4156 100644
--- a/factory/src/it/functional/src/main/java/com/google/auto/factory/FactoryInterface.java
+++ b/factory/src/it/functional/src/main/java/com/google/auto/factory/FactoryInterface.java
@@ -16,5 +16,5 @@
package com.google.auto.factory;
public interface FactoryInterface {
- FactoryGenerated generate(String name);
+ Foo generate(String name);
}
diff --git a/factory/src/it/functional/src/main/java/com/google/auto/factory/FactoryGenerated.java b/factory/src/it/functional/src/main/java/com/google/auto/factory/Foo.java
index 485e23cf..3cc02d52 100644
--- a/factory/src/it/functional/src/main/java/com/google/auto/factory/FactoryGenerated.java
+++ b/factory/src/it/functional/src/main/java/com/google/auto/factory/Foo.java
@@ -18,14 +18,14 @@ package com.google.auto.factory;
import javax.inject.Provider;
@AutoFactory(implementing = FactoryInterface.class)
-public final class FactoryGenerated {
+public final class Foo {
private final String name;
private final Dependency dependency;
private final Provider<Dependency> dependencyProvider;
private final int primitive;
private final int qualifiedPrimitive;
- FactoryGenerated(
+ Foo(
String name,
@Provided Dependency dependency,
@Provided @Qualifier Provider<Dependency> dependencyProvider,
@@ -40,7 +40,7 @@ public final class FactoryGenerated {
// Generates second factory method with a different name for the Dependency dependency.
// Tests http://b/21632171.
- FactoryGenerated(
+ Foo(
Object name,
@Provided Dependency dependency2,
@Provided @Qualifier Provider<Dependency> dependencyProvider,
diff --git a/factory/src/it/functional/src/main/java/com/google/auto/factory/GenericFoo.java b/factory/src/it/functional/src/main/java/com/google/auto/factory/GenericFoo.java
new file mode 100644
index 00000000..94ee8a5b
--- /dev/null
+++ b/factory/src/it/functional/src/main/java/com/google/auto/factory/GenericFoo.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2019 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.google.auto.factory;
+
+import java.util.List;
+import javax.inject.Provider;
+
+@AutoFactory
+public class GenericFoo<A, B extends List<? extends A>, C> {
+
+ private final A depA;
+ private final B depB;
+ private final IntAccessor depDIntAccessor;
+ private final StringAccessor depDStringAccessor;
+
+ <D extends IntAccessor & StringAccessor> GenericFoo(@Provided Provider<A> depA, B depB, D depD) {
+ this.depA = depA.get();
+ this.depB = depB;
+ this.depDIntAccessor = depD;
+ this.depDStringAccessor = depD;
+ }
+
+ public A getDepA() {
+ return depA;
+ }
+
+ public B getDepB() {
+ return depB;
+ }
+
+ public C passThrough(C value) {
+ return value;
+ }
+
+ public IntAccessor getDepDIntAccessor() {
+ return depDIntAccessor;
+ }
+
+ public StringAccessor getDepDStringAccessor() {
+ return depDStringAccessor;
+ }
+
+ public interface IntAccessor {}
+
+ public interface StringAccessor {}
+
+ public interface IntAndStringAccessor extends IntAccessor, StringAccessor {}
+}
diff --git a/factory/src/it/functional/src/main/java/com/google/auto/factory/GuiceModule.java b/factory/src/it/functional/src/main/java/com/google/auto/factory/GuiceModule.java
index bf6ce71b..45d4d26e 100644
--- a/factory/src/it/functional/src/main/java/com/google/auto/factory/GuiceModule.java
+++ b/factory/src/it/functional/src/main/java/com/google/auto/factory/GuiceModule.java
@@ -23,5 +23,6 @@ public class GuiceModule extends AbstractModule {
bind(Dependency.class).annotatedWith(Qualifier.class).to(QualifiedDependencyImpl.class);
bind(Integer.class).toInstance(1);
bind(Integer.class).annotatedWith(Qualifier.class).toInstance(2);
+ bind(Number.class).toInstance(3);
}
}
diff --git a/factory/src/it/functional/src/test/java/com/google/auto/factory/DependencyInjectionIntegrationTest.java b/factory/src/it/functional/src/test/java/com/google/auto/factory/DependencyInjectionIntegrationTest.java
index ba3af2a1..21ccfbb4 100644
--- a/factory/src/it/functional/src/test/java/com/google/auto/factory/DependencyInjectionIntegrationTest.java
+++ b/factory/src/it/functional/src/test/java/com/google/auto/factory/DependencyInjectionIntegrationTest.java
@@ -2,17 +2,25 @@ package com.google.auto.factory;
import static com.google.common.truth.Truth.assertThat;
+import com.google.auto.factory.GenericFoo.IntAndStringAccessor;
+import com.google.common.collect.ImmutableList;
import com.google.inject.Guice;
+import com.google.inject.Key;
+import com.google.inject.TypeLiteral;
+import java.util.ArrayList;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class DependencyInjectionIntegrationTest {
+
+ private static final IntAndStringAccessor INT_AND_STRING_ACCESSOR = new IntAndStringAccessor() {};
+
@Test public void daggerInjectedFactory() {
- FactoryGeneratedFactory factoryGeneratedFactory = DaggerFactoryComponent.create().factory();
- FactoryGenerated one = factoryGeneratedFactory.create("A");
- FactoryGenerated two = factoryGeneratedFactory.create("B");
+ FooFactory fooFactory = DaggerFactoryComponent.create().factory();
+ Foo one = fooFactory.create("A");
+ Foo two = fooFactory.create("B");
assertThat(one.name()).isEqualTo("A");
assertThat(one.dependency()).isNotNull();
assertThat(one.dependencyProvider()).isNotNull();
@@ -28,12 +36,35 @@ public class DependencyInjectionIntegrationTest {
assertThat(two.qualifiedPrimitive()).isEqualTo(2);
}
+ @Test
+ public void daggerInjectedGenericFactory() {
+ GenericFooFactory<Number> genericFooFactory =
+ DaggerFactoryComponent.create().generatedFactory();
+ GenericFoo<Number, ImmutableList<Long>, String> three =
+ genericFooFactory.create(ImmutableList.of(3L), INT_AND_STRING_ACCESSOR);
+ ArrayList<Double> intAndStringAccessorArrayList = new ArrayList<>();
+ intAndStringAccessorArrayList.add(4.0);
+ GenericFoo<Number, ArrayList<Double>, Long> four =
+ genericFooFactory.create(intAndStringAccessorArrayList, INT_AND_STRING_ACCESSOR);
+ assertThat(three.getDepA()).isEqualTo(3);
+ ImmutableList<Long> unusedLongList = three.getDepB();
+ assertThat(three.getDepB()).containsExactly(3L);
+ assertThat(three.getDepDIntAccessor()).isEqualTo(INT_AND_STRING_ACCESSOR);
+ assertThat(three.getDepDStringAccessor()).isEqualTo(INT_AND_STRING_ACCESSOR);
+ assertThat(three.passThrough("value")).isEqualTo("value");
+ assertThat(four.getDepA()).isEqualTo(3);
+ ArrayList<Double> unusedDoubleList = four.getDepB();
+ assertThat(four.getDepB()).isInstanceOf(ArrayList.class);
+ assertThat(four.getDepB()).containsExactly(4.0);
+ assertThat(four.getDepDIntAccessor()).isEqualTo(INT_AND_STRING_ACCESSOR);
+ assertThat(four.getDepDStringAccessor()).isEqualTo(INT_AND_STRING_ACCESSOR);
+ assertThat(four.passThrough(5L)).isEqualTo(5L);
+ }
+
@Test public void guiceInjectedFactory() {
- FactoryGeneratedFactory factoryGeneratedFactory =
- Guice.createInjector(new GuiceModule())
- .getInstance(FactoryGeneratedFactory.class);
- FactoryGenerated one = factoryGeneratedFactory.create("A");
- FactoryGenerated two = factoryGeneratedFactory.create("B");
+ FooFactory fooFactory = Guice.createInjector(new GuiceModule()).getInstance(FooFactory.class);
+ Foo one = fooFactory.create("A");
+ Foo two = fooFactory.create("B");
assertThat(one.name()).isEqualTo("A");
assertThat(one.dependency()).isNotNull();
assertThat(one.dependencyProvider()).isNotNull();
@@ -48,4 +79,29 @@ public class DependencyInjectionIntegrationTest {
assertThat(two.primitive()).isEqualTo(1);
assertThat(two.qualifiedPrimitive()).isEqualTo(2);
}
+
+ @Test
+ public void guiceInjectedGenericFactory() {
+ GenericFooFactory<Number> genericFooFactory =
+ Guice.createInjector(new GuiceModule())
+ .getInstance(Key.get(new TypeLiteral<GenericFooFactory<Number>>() {}));
+ GenericFoo<Number, ImmutableList<Long>, String> three =
+ genericFooFactory.create(ImmutableList.of(3L), INT_AND_STRING_ACCESSOR);
+ ArrayList<Double> intAndStringAccessorArrayList = new ArrayList<>();
+ intAndStringAccessorArrayList.add(4.0);
+ GenericFoo<Number, ArrayList<Double>, Long> four =
+ genericFooFactory.create(intAndStringAccessorArrayList, INT_AND_STRING_ACCESSOR);
+ assertThat(three.getDepA()).isEqualTo(3);
+ ImmutableList<Long> unusedLongList = three.getDepB();
+ assertThat(three.getDepB()).containsExactly(3L);
+ assertThat(three.getDepDIntAccessor()).isEqualTo(INT_AND_STRING_ACCESSOR);
+ assertThat(three.getDepDStringAccessor()).isEqualTo(INT_AND_STRING_ACCESSOR);
+ assertThat(three.passThrough("value")).isEqualTo("value");
+ assertThat(four.getDepA()).isEqualTo(3);
+ ArrayList<Double> unusedDoubleList = four.getDepB();
+ assertThat(four.getDepB()).containsExactly(4.0);
+ assertThat(four.getDepDIntAccessor()).isEqualTo(INT_AND_STRING_ACCESSOR);
+ assertThat(four.getDepDStringAccessor()).isEqualTo(INT_AND_STRING_ACCESSOR);
+ assertThat(four.passThrough(5L)).isEqualTo(5L);
+ }
}
diff --git a/factory/src/main/java/com/google/auto/factory/processor/FactoryDescriptorGenerator.java b/factory/src/main/java/com/google/auto/factory/processor/FactoryDescriptorGenerator.java
index 8a54173a..d2331f42 100644
--- a/factory/src/main/java/com/google/auto/factory/processor/FactoryDescriptorGenerator.java
+++ b/factory/src/main/java/com/google/auto/factory/processor/FactoryDescriptorGenerator.java
@@ -120,9 +120,6 @@ final class FactoryDescriptorGenerator {
checkNotNull(constructor);
checkArgument(constructor.getKind() == ElementKind.CONSTRUCTOR);
TypeElement classElement = MoreElements.asType(constructor.getEnclosingElement());
- if (!classElement.getTypeParameters().isEmpty()) {
- messager.printMessage(ERROR, "AutoFactory does not support generic types", classElement);
- }
ImmutableListMultimap<Boolean, ? extends VariableElement> parameterMap =
Multimaps.index(constructor.getParameters(), Functions.forPredicate(
new Predicate<VariableElement>() {
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 e084eb0e..3bb68e1c 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
@@ -28,7 +28,9 @@ import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
import com.squareup.javapoet.AnnotationSpec;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.CodeBlock;
@@ -47,6 +49,7 @@ import javax.inject.Provider;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.type.TypeMirror;
+import javax.lang.model.type.TypeVariable;
import javax.lang.model.util.Elements;
final class FactoryWriter {
@@ -87,8 +90,11 @@ final class FactoryWriter {
factory.addSuperinterface(TypeName.get(implementingType));
}
+ ImmutableSet<TypeVariableName> factoryTypeVariables = getFactoryTypeVariables(descriptor);
+
+ addFactoryTypeParameters(factory, factoryTypeVariables);
addConstructorAndProviderFields(factory, descriptor);
- addFactoryMethods(factory, descriptor);
+ addFactoryMethods(factory, descriptor, factoryTypeVariables);
addImplementationMethods(factory, descriptor);
addCheckNotNullMethod(factory, descriptor);
@@ -98,7 +104,12 @@ final class FactoryWriter {
.writeTo(filer);
}
- private void addConstructorAndProviderFields(
+ private static void addFactoryTypeParameters(
+ TypeSpec.Builder factory, ImmutableSet<TypeVariableName> typeVariableNames) {
+ factory.addTypeVariables(typeVariableNames);
+ }
+
+ private static void addConstructorAndProviderFields(
TypeSpec.Builder factory, FactoryDescriptor descriptor) {
MethodSpec.Builder constructor = constructorBuilder().addAnnotation(Inject.class);
if (descriptor.publicType()) {
@@ -121,10 +132,14 @@ final class FactoryWriter {
factory.addMethod(constructor.build());
}
- private void addFactoryMethods(TypeSpec.Builder factory, FactoryDescriptor descriptor) {
+ private static void addFactoryMethods(
+ TypeSpec.Builder factory,
+ FactoryDescriptor descriptor,
+ ImmutableSet<TypeVariableName> factoryTypeVariables) {
for (FactoryMethodDescriptor methodDescriptor : descriptor.methodDescriptors()) {
MethodSpec.Builder method =
MethodSpec.methodBuilder(methodDescriptor.name())
+ .addTypeVariables(getMethodTypeVariables(methodDescriptor, factoryTypeVariables))
.returns(TypeName.get(methodDescriptor.returnType()))
.varargs(methodDescriptor.isVarArgs());
if (methodDescriptor.overridingMethod()) {
@@ -168,7 +183,8 @@ final class FactoryWriter {
}
}
- private void addImplementationMethods(TypeSpec.Builder factory, FactoryDescriptor descriptor) {
+ private static void addImplementationMethods(
+ TypeSpec.Builder factory, FactoryDescriptor descriptor) {
for (ImplementationMethodDescriptor methodDescriptor :
descriptor.implementationMethodDescriptors()) {
MethodSpec.Builder implementationMethod =
@@ -268,4 +284,32 @@ final class FactoryWriter {
}
return -1;
}
+
+ private static ImmutableSet<TypeVariableName> getFactoryTypeVariables(
+ FactoryDescriptor descriptor) {
+ ImmutableSet.Builder<TypeVariableName> typeVariables = ImmutableSet.builder();
+ for (ProviderField provider : descriptor.providers().values()) {
+ typeVariables.addAll(getReferencedTypeParameterNames(provider.key().type().get()));
+ }
+ return typeVariables.build();
+ }
+
+ private static ImmutableSet<TypeVariableName> getMethodTypeVariables(
+ FactoryMethodDescriptor methodDescriptor,
+ ImmutableSet<TypeVariableName> factoryTypeVariables) {
+ ImmutableSet.Builder<TypeVariableName> typeVariables = ImmutableSet.builder();
+ typeVariables.addAll(getReferencedTypeParameterNames(methodDescriptor.returnType()));
+ for (Parameter parameter : methodDescriptor.passedParameters()) {
+ typeVariables.addAll(getReferencedTypeParameterNames(parameter.type().get()));
+ }
+ return Sets.difference(typeVariables.build(), factoryTypeVariables).immutableCopy();
+ }
+
+ private static ImmutableSet<TypeVariableName> getReferencedTypeParameterNames(TypeMirror type) {
+ ImmutableSet.Builder<TypeVariableName> typeVariableNames = ImmutableSet.builder();
+ for (TypeVariable typeVariable : TypeVariables.getReferencedTypeVariables(type)) {
+ typeVariableNames.add(TypeVariableName.get(typeVariable));
+ }
+ return typeVariableNames.build();
+ }
}
diff --git a/factory/src/main/java/com/google/auto/factory/processor/TypeVariables.java b/factory/src/main/java/com/google/auto/factory/processor/TypeVariables.java
new file mode 100644
index 00000000..35206c29
--- /dev/null
+++ b/factory/src/main/java/com/google/auto/factory/processor/TypeVariables.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2019 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.google.auto.factory.processor;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.common.collect.ImmutableSet;
+import javax.lang.model.type.ArrayType;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.IntersectionType;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.type.TypeVariable;
+import javax.lang.model.type.UnionType;
+import javax.lang.model.type.WildcardType;
+import javax.lang.model.util.SimpleTypeVisitor8;
+
+final class TypeVariables {
+ private TypeVariables() {}
+
+ static ImmutableSet<TypeVariable> getReferencedTypeVariables(TypeMirror type) {
+ checkNotNull(type);
+ return type.accept(ReferencedTypeVariables.INSTANCE, null);
+ }
+
+ private static final class ReferencedTypeVariables
+ extends SimpleTypeVisitor8<ImmutableSet<TypeVariable>, Void> {
+ private static final ReferencedTypeVariables INSTANCE = new ReferencedTypeVariables();
+
+ ReferencedTypeVariables() {
+ super(ImmutableSet.of());
+ }
+
+ @Override
+ public ImmutableSet<TypeVariable> visitArray(ArrayType t, Void unused) {
+ return t.getComponentType().accept(this, unused);
+ }
+
+ @Override
+ public ImmutableSet<TypeVariable> visitDeclared(DeclaredType t, Void unused) {
+ ImmutableSet.Builder<TypeVariable> typeVariables = ImmutableSet.builder();
+ for (TypeMirror typeArgument : t.getTypeArguments()) {
+ typeVariables.addAll(typeArgument.accept(this, unused));
+ }
+ return typeVariables.build();
+ }
+
+ @Override
+ public ImmutableSet<TypeVariable> visitTypeVariable(TypeVariable t, Void unused) {
+ ImmutableSet.Builder<TypeVariable> typeVariables = ImmutableSet.builder();
+ typeVariables.add(t);
+ typeVariables.addAll(t.getLowerBound().accept(this, unused));
+ typeVariables.addAll(t.getUpperBound().accept(this, unused));
+ return typeVariables.build();
+ }
+
+ @Override
+ public ImmutableSet<TypeVariable> visitUnion(UnionType t, Void unused) {
+ ImmutableSet.Builder<TypeVariable> typeVariables = ImmutableSet.builder();
+ for (TypeMirror unionType : t.getAlternatives()) {
+ typeVariables.addAll(unionType.accept(this, unused));
+ }
+ return typeVariables.build();
+ }
+
+ @Override
+ public ImmutableSet<TypeVariable> visitIntersection(IntersectionType t, Void unused) {
+ ImmutableSet.Builder<TypeVariable> typeVariables = ImmutableSet.builder();
+ for (TypeMirror intersectionType : t.getBounds()) {
+ typeVariables.addAll(intersectionType.accept(this, unused));
+ }
+ return typeVariables.build();
+ }
+
+ @Override
+ public ImmutableSet<TypeVariable> visitWildcard(WildcardType t, Void unused) {
+ ImmutableSet.Builder<TypeVariable> typeVariables = ImmutableSet.builder();
+ TypeMirror extendsBound = t.getExtendsBound();
+ if (extendsBound != null) {
+ typeVariables.addAll(extendsBound.accept(this, unused));
+ }
+ TypeMirror superBound = t.getSuperBound();
+ if (superBound != null) {
+ typeVariables.addAll(superBound.accept(this, unused));
+ }
+ return typeVariables.build();
+ }
+ }
+}
diff --git a/factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java b/factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java
index 853be12c..3088bb2e 100644
--- a/factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java
+++ b/factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java
@@ -200,16 +200,6 @@ public class AutoFactoryProcessorTest {
.in(file).onLine(27);
}
- @Test public void failsOnGenericClass() {
- JavaFileObject file = JavaFileObjects.forResource("bad/GenericClass.java");
- assertAbout(javaSource())
- .that(file)
- .processedWith(new AutoFactoryProcessor())
- .failsToCompile()
- .withErrorContaining("AutoFactory does not support generic types")
- .in(file).onLine(21).atColumn(14);
- }
-
@Test public void providedButNoAutoFactory() {
JavaFileObject file = JavaFileObjects.forResource("bad/ProvidedButNoAutoFactory.java");
assertAbout(javaSource())
diff --git a/factory/src/test/resources/bad/GenericClass.java b/factory/src/test/resources/bad/GenericClass.java
deleted file mode 100644
index 4542fecd..00000000
--- a/factory/src/test/resources/bad/GenericClass.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright 2013 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests;
-
-import com.google.auto.factory.AutoFactory;
-
-@AutoFactory
-public final class GenericClass<T> {}