aboutsummaryrefslogtreecommitdiff
path: root/factory
diff options
context:
space:
mode:
authorjmittleman <jmittleman@google.com>2016-06-19 14:23:19 -0700
committerÉamonn McManus <eamonn@mcmanus.net>2016-08-29 17:12:34 -0700
commitc64bf47d43c548126ae0f2cd6a21e909641e5d99 (patch)
tree24e263145b70228d787dbf8da09c4e84ffbb8d5a /factory
parent994ba302617596b4f8efc2ec1305a092609f01f3 (diff)
downloadauto-c64bf47d43c548126ae0f2cd6a21e909641e5d99.tar.gz
Automated g4 rollback of changelist 125191485.
*** Reason for rollback *** Breaks []. The bug is present in [] but not in able or baker, so I assume this didn't make it into a [] cut and I don't have to ship this if I get it in by Monday morning. *** Original change description *** Support @Nullable parameters for @AutoFactory FYI This is a rollforward of [] *** ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=125289392
Diffstat (limited to 'factory')
-rw-r--r--factory/pom.xml17
-rw-r--r--factory/src/it/functional/pom.xml15
-rw-r--r--factory/src/main/java/com/google/auto/factory/internal/Preconditions.java39
-rw-r--r--factory/src/main/java/com/google/auto/factory/processor/AutoFactoryProcessor.java28
-rw-r--r--factory/src/main/java/com/google/auto/factory/processor/FactoryDescriptor.java36
-rw-r--r--factory/src/main/java/com/google/auto/factory/processor/FactoryWriter.java141
-rw-r--r--factory/src/main/java/com/google/auto/factory/processor/Key.java54
-rw-r--r--factory/src/main/java/com/google/auto/factory/processor/Mirrors.java24
-rw-r--r--factory/src/main/java/com/google/auto/factory/processor/Parameter.java23
-rw-r--r--factory/src/main/java/com/google/auto/factory/processor/ProviderField.java41
-rw-r--r--factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java29
-rw-r--r--factory/src/test/resources/expected/ClassUsingQualifierWithArgsFactory.java8
-rw-r--r--factory/src/test/resources/expected/ConstructorAnnotatedFactory.java12
-rw-r--r--factory/src/test/resources/expected/ConstructorAnnotatedNonFinalFactory.java12
-rw-r--r--factory/src/test/resources/expected/CustomNamedFactory.java4
-rw-r--r--factory/src/test/resources/expected/CustomNullableFactory.java38
-rw-r--r--factory/src/test/resources/expected/FactoryExtendingAbstractClassFactory.java7
-rw-r--r--factory/src/test/resources/expected/FactoryImplementingCreateMethod_ConcreteClassFactory.java8
-rw-r--r--factory/src/test/resources/expected/FactoryImplementingGenericInterfaceExtension.java9
-rw-r--r--factory/src/test/resources/expected/MixedDepsImplementingInterfacesFactory.java10
-rw-r--r--factory/src/test/resources/expected/MultipleFactoriesImplementingInterface_ClassAFactory.java4
-rw-r--r--factory/src/test/resources/expected/MultipleFactoriesImplementingInterface_ClassBFactory.java4
-rw-r--r--factory/src/test/resources/expected/MultipleProvidedParamsSameKeyFactory.java42
-rw-r--r--factory/src/test/resources/expected/NestedClasses_CustomNamedFactory.java4
-rw-r--r--factory/src/test/resources/expected/NestedClasses_SimpleNestedClassFactory.java4
-rw-r--r--factory/src/test/resources/expected/PublicClassFactory.java4
-rw-r--r--factory/src/test/resources/expected/SimpleClassFactory.java4
-rw-r--r--factory/src/test/resources/expected/SimpleClassImplementingMarkerFactory.java4
-rw-r--r--factory/src/test/resources/expected/SimpleClassImplementingSimpleInterfaceFactory.java4
-rw-r--r--factory/src/test/resources/expected/SimpleClassMixedDepsFactory.java9
-rw-r--r--factory/src/test/resources/expected/SimpleClassNonFinalFactory.java4
-rw-r--r--factory/src/test/resources/expected/SimpleClassNullableParametersFactory.java49
-rw-r--r--factory/src/test/resources/expected/SimpleClassPassedDepsFactory.java9
-rw-r--r--factory/src/test/resources/expected/SimpleClassProvidedDepsFactory.java14
-rw-r--r--factory/src/test/resources/expected/SimpleClassProvidedProviderDepsFactory.java10
-rw-r--r--factory/src/test/resources/good/ConstructorAnnotated.java2
-rw-r--r--factory/src/test/resources/good/CustomNullable.java34
-rw-r--r--factory/src/test/resources/good/MultipleProvidedParamsSameKey.java36
-rw-r--r--factory/src/test/resources/good/SimpleClassNullableParameters.java41
39 files changed, 183 insertions, 654 deletions
diff --git a/factory/pom.xml b/factory/pom.xml
index 722b3474..28a8d545 100644
--- a/factory/pom.xml
+++ b/factory/pom.xml
@@ -44,7 +44,7 @@
<dependency>
<groupId>com.google.auto</groupId>
<artifactId>auto-common</artifactId>
- <version>0.6</version>
+ <version>0.5</version>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
@@ -58,11 +58,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>com.google.googlejavaformat</groupId>
- <artifactId>google-java-format</artifactId>
- <version>1.0</version>
- </dependency>
- <dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
@@ -81,7 +76,7 @@
<dependency>
<groupId>com.google.testing.compile</groupId>
<artifactId>compile-testing</artifactId>
- <version>0.9</version>
+ <version>0.8</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -93,13 +88,7 @@
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
- <version>0.28</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.google.code.findbugs</groupId>
- <artifactId>jsr305</artifactId>
- <version>1.3.9</version>
+ <version>0.25</version>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/factory/src/it/functional/pom.xml b/factory/src/it/functional/pom.xml
index 4352a4a5..30cfce2d 100644
--- a/factory/src/it/functional/pom.xml
+++ b/factory/src/it/functional/pom.xml
@@ -35,14 +35,9 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- <version>19.0</version>
- </dependency>
- <dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
- <version>4.0</version>
+ <version>4.0-beta</version>
</dependency>
<dependency>
<groupId>com.google.dagger</groupId>
@@ -64,7 +59,13 @@
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
- <version>0.28</version>
+ <version>0.25</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava-testlib</artifactId>
+ <version>19.0</version>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/factory/src/main/java/com/google/auto/factory/internal/Preconditions.java b/factory/src/main/java/com/google/auto/factory/internal/Preconditions.java
deleted file mode 100644
index 263d7101..00000000
--- a/factory/src/main/java/com/google/auto/factory/internal/Preconditions.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2016 Google, Inc.
- *
- * 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.internal;
-
-/**
- * An adaptation of Guava's {@code com.google.common.base.Preconditions} that is specially tailored
- * to support checks applied in AutoFactory's generated code.
- */
-public final class Preconditions {
-
- /**
- * Ensures that an object reference passed as a parameter to the calling method is not null.
- *
- * @param reference an object reference
- * @return the non-null reference that was validated
- * @throws NullPointerException if {@code reference} is null
- */
- public static <T> T checkNotNull(T reference) {
- if (reference == null) {
- throw new NullPointerException();
- }
- return reference;
- }
-
- private Preconditions() {}
-}
diff --git a/factory/src/main/java/com/google/auto/factory/processor/AutoFactoryProcessor.java b/factory/src/main/java/com/google/auto/factory/processor/AutoFactoryProcessor.java
index 99607127..3df7d375 100644
--- a/factory/src/main/java/com/google/auto/factory/processor/AutoFactoryProcessor.java
+++ b/factory/src/main/java/com/google/auto/factory/processor/AutoFactoryProcessor.java
@@ -15,6 +15,7 @@
*/
package com.google.auto.factory.processor;
+import com.google.auto.common.MoreElements;
import com.google.auto.common.MoreTypes;
import com.google.auto.factory.AutoFactory;
import com.google.auto.factory.Provided;
@@ -26,6 +27,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSetMultimap;
+import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimaps;
@@ -150,9 +152,12 @@ public final class AutoFactoryProcessor extends AbstractProcessor {
ImmutableSet<FactoryMethodDescriptor> descriptors =
factoryDescriptorGenerator.generateDescriptor(element);
- for (FactoryMethodDescriptor descriptor : descriptors) {
- indexedMethods.put(descriptor.factoryName(), descriptor);
- }
+ indexedMethods.putAll(
+ Multimaps.index(descriptors, new Function<FactoryMethodDescriptor, String>() {
+ @Override public String apply(FactoryMethodDescriptor descriptor) {
+ return descriptor.factoryName();
+ }
+ }));
}
ImmutableSetMultimap<String, ImplementationMethodDescriptor>
@@ -162,15 +167,14 @@ public final class AutoFactoryProcessor extends AbstractProcessor {
: indexedMethods.build().asMap().entrySet()) {
ImmutableSet.Builder<TypeMirror> extending = ImmutableSet.builder();
ImmutableSortedSet.Builder<TypeMirror> implementing =
- ImmutableSortedSet.orderedBy(
- new Comparator<TypeMirror>() {
- @Override
- public int compare(TypeMirror first, TypeMirror second) {
- String firstName = MoreTypes.asTypeElement(first).getQualifiedName().toString();
- String secondName = MoreTypes.asTypeElement(second).getQualifiedName().toString();
- return firstName.compareTo(secondName);
- }
- });
+ ImmutableSortedSet.orderedBy(new Comparator<TypeMirror>() {
+ @Override
+ public int compare(TypeMirror first, TypeMirror second) {
+ String firstName = MoreTypes.asTypeElement(first).getQualifiedName().toString();
+ String secondName = MoreTypes.asTypeElement(second).getQualifiedName().toString();
+ return firstName.compareTo(secondName);
+ }
+ });
boolean publicType = false;
Boolean allowSubclasses = null;
boolean skipCreation = false;
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 e6d30025..f60431fa 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,12 +15,9 @@
*/
package com.google.auto.factory.processor;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import com.google.auto.common.MoreTypes;
import com.google.auto.value.AutoValue;
import com.google.common.base.CharMatcher;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@@ -31,7 +28,6 @@ import com.google.common.collect.Sets;
import java.util.Collection;
import java.util.Map.Entry;
-import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.type.TypeMirror;
/**
@@ -56,7 +52,7 @@ abstract class FactoryDescriptor {
abstract ImmutableSet<FactoryMethodDescriptor> methodDescriptors();
abstract ImmutableSet<ImplementationMethodDescriptor> implementationMethodDescriptors();
abstract boolean allowSubclasses();
- abstract ImmutableMap<Key, ProviderField> providers();
+ abstract ImmutableMap<Key, String> providerNames();
static FactoryDescriptor create(
String name,
@@ -66,36 +62,24 @@ abstract class FactoryDescriptor {
ImmutableSet<FactoryMethodDescriptor> methodDescriptors,
ImmutableSet<ImplementationMethodDescriptor> implementationMethodDescriptors,
boolean allowSubclasses) {
- ImmutableSetMultimap.Builder<Key, Parameter> parametersForProviders =
- ImmutableSetMultimap.builder();
+ ImmutableSetMultimap.Builder<Key, String> providerNamesBuilder = ImmutableSetMultimap.builder();
for (FactoryMethodDescriptor descriptor : methodDescriptors) {
for (Parameter parameter : descriptor.providedParameters()) {
- parametersForProviders.put(parameter.key(), parameter);
+ providerNamesBuilder.put(parameter.key(), parameter.name());
}
}
- ImmutableMap.Builder<Key, ProviderField> providersBuilder = ImmutableMap.builder();
- for (Entry<Key, Collection<Parameter>> entry :
- parametersForProviders.build().asMap().entrySet()) {
+ ImmutableMap.Builder<Key, String> providersBuilder = ImmutableMap.builder();
+ for (Entry<Key, Collection<String>> entry : providerNamesBuilder.build().asMap().entrySet()) {
Key key = entry.getKey();
switch (entry.getValue().size()) {
case 0:
throw new AssertionError();
case 1:
- Parameter parameter = Iterables.getOnlyElement(entry.getValue());
- providersBuilder.put(
- key, ProviderField.create(parameter.name() + "Provider", key, parameter.nullable()));
+ providersBuilder.put(key, Iterables.getOnlyElement(entry.getValue()) + "Provider");
break;
default:
- String providerName =
- invalidIdentifierCharacters.replaceFrom(key.toString(), '_') + "Provider";
- TypeMirror type = null;
- Optional<AnnotationMirror> nullable = Optional.absent();
- for (Parameter param : entry.getValue()) {
- type = param.type();
- nullable = nullable.or(param.nullable());
- }
- checkNotNull(type);
- providersBuilder.put(key, ProviderField.create(providerName, key, nullable));
+ providersBuilder.put(
+ key, invalidIdentifierCharacters.replaceFrom(key.toString(), '_') + "Provider");
break;
}
}
@@ -202,7 +186,7 @@ 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));
+ Iterables.transform(factory.passedParameters(), Parameter.parameterToType),
+ Iterables.transform(implementation.passedParameters(), Parameter.parameterToType));
}
}
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 89c6b6d4..6d4d8f8e 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
@@ -22,22 +22,15 @@ import static javax.lang.model.element.Modifier.FINAL;
import static javax.lang.model.element.Modifier.PRIVATE;
import static javax.lang.model.element.Modifier.PUBLIC;
-import com.google.auto.factory.internal.Preconditions;
import com.google.auto.common.MoreElements;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
-import com.google.common.base.Throwables;
+import com.google.common.base.Optional;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import com.google.common.io.CharSink;
-import com.google.common.io.CharSource;
-import com.google.googlejavaformat.java.Formatter;
-import com.google.googlejavaformat.java.FormatterException;
import com.squareup.javapoet.AnnotationSpec;
import com.squareup.javapoet.ClassName;
-import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.ParameterSpec;
@@ -46,20 +39,16 @@ import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;
import java.io.IOException;
+import java.util.Map.Entry;
-import java.io.Writer;
-import java.util.Iterator;
import javax.annotation.Generated;
import javax.annotation.processing.Filer;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.lang.model.element.AnnotationMirror;
-import javax.lang.model.element.Element;
import javax.lang.model.type.ErrorType;
-import javax.lang.model.type.PrimitiveType;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.SimpleTypeVisitor7;
-import javax.tools.JavaFileObject;
final class FactoryWriter {
private final Filer filer;
@@ -96,16 +85,19 @@ final class FactoryWriter {
if (descriptor.publicType()) {
constructor.addModifiers(PUBLIC);
}
- for (ProviderField provider : descriptor.providers().values()) {
- TypeName typeName = typeName(provider.key().type()).box();
- TypeName providerType = ParameterizedTypeName.get(ClassName.get(Provider.class), typeName);
- factory.addField(providerType, provider.name(), PRIVATE, FINAL);
- if (provider.key().qualifier().isPresent()) {
- // only qualify the constructor parameter
- providerType = providerType.annotated(AnnotationSpec.get(provider.key().qualifier().get()));
- }
- constructor.addParameter(providerType, provider.name());
- constructor.addStatement("this.$1L = $1L", provider.name());
+ for (Entry<Key, String> entry : descriptor.providerNames().entrySet()) {
+ Key key = entry.getKey();
+ String providerName = entry.getValue();
+ Optional<AnnotationMirror> qualifier = key.getQualifier();
+
+ TypeName providerType =
+ ParameterizedTypeName.get(ClassName.get(Provider.class), typeName(key.type()));
+ factory.addField(providerType, providerName, PRIVATE, FINAL);
+ constructor.addParameter(annotateIfPresent(providerType, qualifier), providerName);
+ }
+
+ for (String providerName : descriptor.providerNames().values()) {
+ constructor.addStatement("this.$1L = $1L", providerName);
}
factory.addMethod(constructor.build());
@@ -120,33 +112,26 @@ final class FactoryWriter {
if (methodDescriptor.publicMethod()) {
method.addModifiers(PUBLIC);
}
- CodeBlock.Builder args = CodeBlock.builder();
method.addParameters(parameters(methodDescriptor.passedParameters()));
- Iterator<Parameter> parameters = methodDescriptor.creationParameters().iterator();
- while (parameters.hasNext()) {
- Parameter parameter = parameters.next();
- boolean nullableArgument;
- CodeBlock argument;
- if (methodDescriptor.passedParameters().contains(parameter)) {
- argument = codeBlock(parameter.name());
- nullableArgument = parameter.nullable().isPresent() || isPrimitive(parameter.type());
- } else {
- ProviderField provider = descriptor.providers().get(parameter.key());
- argument = codeBlock(provider.name());
- if (!parameter.providerOfType()) {
- argument = codeBlock("$L.get()", argument);
- }
- nullableArgument = parameter.nullable().isPresent();
- }
- if (!nullableArgument) {
- argument = codeBlock("$T.checkNotNull($L)", Preconditions.class, argument);
- }
- args.add(argument);
- if (parameters.hasNext()) {
- args.add(", ");
- }
- }
- method.addStatement("return new $T($L)", methodDescriptor.returnType(), args.build());
+ FluentIterable<String> creationParameterNames =
+ FluentIterable.from(methodDescriptor.creationParameters())
+ .transform(
+ new Function<Parameter, String>() {
+ @Override
+ public String apply(Parameter parameter) {
+ if (methodDescriptor.passedParameters().contains(parameter)) {
+ return parameter.name();
+ } else if (parameter.providerOfType()) {
+ return descriptor.providerNames().get(parameter.key());
+ } else {
+ return descriptor.providerNames().get(parameter.key()) + ".get()";
+ }
+ }
+ });
+ method.addStatement(
+ "return new $T($L)",
+ methodDescriptor.returnType(),
+ argumentJoiner.join(creationParameterNames));
factory.addMethod(method.build());
}
@@ -172,34 +157,17 @@ final class FactoryWriter {
factory.addMethod(implementationMethod.build());
}
- JavaFile javaFile =
- JavaFile.builder(getPackage(descriptor.name()), factory.build())
- .skipJavaLangImports(true)
- .build();
-
- final JavaFileObject sourceFile = filer.createSourceFile(
- ClassName.get(javaFile.packageName, javaFile.typeSpec.name).toString(),
- Iterables.toArray(javaFile.typeSpec.originatingElements, Element.class));
- try {
- new Formatter().formatSource(
- CharSource.wrap(javaFile.toString()),
- new CharSink() {
- @Override public Writer openStream() throws IOException {
- return sourceFile.openWriter();
- }
- });
- } catch (FormatterException e) {
- Throwables.propagate(e);
- }
+ JavaFile.builder(getPackage(descriptor.name()), factory.build())
+ .skipJavaLangImports(true)
+ .build()
+ .writeTo(filer);
}
private static Iterable<ParameterSpec> parameters(Iterable<Parameter> parameters) {
ImmutableList.Builder<ParameterSpec> builder = ImmutableList.builder();
for (Parameter parameter : parameters) {
- Iterable<AnnotationMirror> annotations =
- Iterables.concat(parameter.nullable().asSet(), parameter.key().qualifier().asSet());
- TypeName type = annotate(TypeName.get(parameter.type()), annotations);
- builder.add(ParameterSpec.builder(type, parameter.name()).build());
+ builder.add(
+ ParameterSpec.builder(TypeName.get(parameter.type()), parameter.name()).build());
}
return builder.build();
}
@@ -223,31 +191,12 @@ final class FactoryWriter {
return -1;
}
- private static TypeName annotate(TypeName type, Iterable<AnnotationMirror> annotations) {
- // TODO(ronshapiro): multiple calls to TypeName.annotated() will be fixed in JavaPoet 1.6
- ImmutableList.Builder<AnnotationSpec> specs = ImmutableList.builder();
- for (AnnotationMirror annotation : annotations) {
- specs.add(AnnotationSpec.get(annotation));
+ private static TypeName annotateIfPresent(
+ TypeName typeName, Optional<AnnotationMirror> annotation) {
+ if (annotation.isPresent()) {
+ return typeName.annotated(AnnotationSpec.get(annotation.get()));
}
- return type.annotated(specs.build());
- }
-
- private static CodeBlock codeBlock(String format, Object... args) {
- return CodeBlock.builder().add(format, args).build();
- }
-
- private static boolean isPrimitive(TypeMirror type) {
- return type.accept(new SimpleTypeVisitor7<Boolean, Void>(){
- @Override
- public Boolean visitPrimitive(PrimitiveType t, Void aVoid) {
- return true;
- }
-
- @Override
- protected Boolean defaultAction(TypeMirror e, Void aVoid) {
- return false;
- }
- }, null);
+ return typeName;
}
/**
diff --git a/factory/src/main/java/com/google/auto/factory/processor/Key.java b/factory/src/main/java/com/google/auto/factory/processor/Key.java
index ff25f7b7..3883da30 100644
--- a/factory/src/main/java/com/google/auto/factory/processor/Key.java
+++ b/factory/src/main/java/com/google/auto/factory/processor/Key.java
@@ -15,41 +15,55 @@
*/
package com.google.auto.factory.processor;
-import com.google.auto.common.AnnotationMirrors;
-import com.google.auto.common.MoreTypes;
-import com.google.auto.value.AutoValue;
-import com.google.common.base.Equivalence;
+import com.google.common.base.Objects;
import com.google.common.base.Optional;
+
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.type.TypeMirror;
-import static com.google.auto.factory.processor.Mirrors.unwrapOptionalEquivalence;
-import static com.google.auto.factory.processor.Mirrors.wrapOptionalInEquivalence;
-
/**
* A value object for types and qualifiers.
*
* @author Gregory Kick
*/
-@AutoValue
-abstract class Key {
- abstract TypeMirror type();
- abstract Optional<Equivalence.Wrapper<AnnotationMirror>> qualifierWrapper();
+final class Key {
+ private final TypeMirror type;
+ private final Optional<AnnotationMirror> qualifier;
+
+ Key(Optional<AnnotationMirror> qualifier, TypeMirror type) {
+ this.qualifier = qualifier;
+ this.type = type;
+ }
+
+ Optional<AnnotationMirror> getQualifier() {
+ return qualifier;
+ }
- Optional<AnnotationMirror> qualifier() {
- return unwrapOptionalEquivalence(qualifierWrapper());
+ TypeMirror type() {
+ return type;
}
- static Key create(Optional<AnnotationMirror> qualifier, TypeMirror type) {
- return new AutoValue_Key(
- type, wrapOptionalInEquivalence(AnnotationMirrors.equivalence(), qualifier));
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ } else if (obj instanceof Key) {
+ Key that = (Key) obj;
+ return this.type.equals(that.type)
+ && this.qualifier.toString().equals(that.qualifier.toString());
+ }
+ return super.equals(obj);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(qualifier.toString(), type);
}
@Override
public String toString() {
- String typeQualifiedName = MoreTypes.asTypeElement(type()).toString();
- return qualifier().isPresent()
- ? qualifier().get() + "/" + typeQualifiedName
- : typeQualifiedName;
+ return qualifier.isPresent()
+ ? qualifier.get().toString() + '/' + type
+ : type.toString();
}
}
diff --git a/factory/src/main/java/com/google/auto/factory/processor/Mirrors.java b/factory/src/main/java/com/google/auto/factory/processor/Mirrors.java
index c0f1867b..c68543b0 100644
--- a/factory/src/main/java/com/google/auto/factory/processor/Mirrors.java
+++ b/factory/src/main/java/com/google/auto/factory/processor/Mirrors.java
@@ -15,7 +15,6 @@
*/
package com.google.auto.factory.processor;
-import com.google.common.base.Equivalence;
import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.Map.Entry;
@@ -77,27 +76,4 @@ final class Mirrors {
}
return Optional.absent();
}
-
- /**
- * Wraps an {@link Optional} of a type in an {@code Optional} of a {@link Equivalence.Wrapper} for
- * that type.
- */
- // TODO(ronshapiro): this is used in AutoFactory and Dagger, consider moving it into auto-common.
- static <T> Optional<Equivalence.Wrapper<T>> wrapOptionalInEquivalence(
- Equivalence<T> equivalence, Optional<T> optional) {
- return optional.isPresent()
- ? Optional.of(equivalence.wrap(optional.get()))
- : Optional.<Equivalence.Wrapper<T>>absent();
- }
-
- /**
- * Unwraps an {@link Optional} of a {@link Equivalence.Wrapper} into an {@code Optional} of the
- * underlying type.
- */
- static <T> Optional<T> unwrapOptionalEquivalence(
- Optional<Equivalence.Wrapper<T>> wrappedOptional) {
- return wrappedOptional.isPresent()
- ? Optional.of(wrappedOptional.get().get())
- : Optional.<T>absent();
- }
}
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 38087c45..8e59f852 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
@@ -16,15 +16,11 @@
package com.google.auto.factory.processor;
import static com.google.auto.common.MoreElements.isAnnotationPresent;
-import static com.google.auto.factory.processor.Mirrors.unwrapOptionalEquivalence;
-import static com.google.auto.factory.processor.Mirrors.wrapOptionalInEquivalence;
import static com.google.common.base.Preconditions.checkArgument;
-import com.google.auto.common.AnnotationMirrors;
import com.google.auto.common.MoreTypes;
import com.google.auto.value.AutoValue;
import com.google.common.base.Function;
-import com.google.common.base.Equivalence;
import com.google.common.base.Optional;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet;
@@ -45,7 +41,7 @@ import javax.lang.model.util.Types;
@AutoValue
abstract class Parameter {
- static final Function<Parameter, TypeMirror> TYPE = new Function<Parameter, TypeMirror>() {
+ static Function<Parameter, TypeMirror> parameterToType = new Function<Parameter, TypeMirror>() {
@Override
public TypeMirror apply(Parameter parameter) {
return parameter.type();
@@ -56,21 +52,13 @@ abstract class Parameter {
abstract String name();
abstract boolean providerOfType();
abstract Key key();
- abstract Optional<Equivalence.Wrapper<AnnotationMirror>> nullableWrapper();
-
- Optional<AnnotationMirror> nullable() {
- return unwrapOptionalEquivalence(nullableWrapper());
- }
static Parameter forVariableElement(VariableElement variable, TypeMirror type, Types types) {
ImmutableSet.Builder<AnnotationMirror> qualifiers = ImmutableSet.builder();
- Optional<AnnotationMirror> nullable = Optional.absent();
for (AnnotationMirror annotationMirror : variable.getAnnotationMirrors()) {
DeclaredType annotationType = annotationMirror.getAnnotationType();
if (isAnnotationPresent(annotationType.asElement(), Qualifier.class)) {
qualifiers.add(annotationMirror);
- } else if (annotationType.asElement().getSimpleName().contentEquals("Nullable")) {
- nullable = nullable.or(Optional.of(annotationMirror));
}
}
@@ -80,13 +68,10 @@ abstract class Parameter {
// TODO(gak): check for only one qualifier rather than using the first
Optional<AnnotationMirror> qualifier = FluentIterable.from(qualifiers.build()).first();
- Key key = Key.create(qualifier, boxedType(providedType, types));
+ Key key = new Key(qualifier, boxedType(providedType, types));
+
return new AutoValue_Parameter(
- providedType,
- variable.getSimpleName().toString(),
- provider,
- key,
- wrapOptionalInEquivalence(AnnotationMirrors.equivalence(), nullable));
+ providedType, variable.getSimpleName().toString(), provider, key);
}
/**
diff --git a/factory/src/main/java/com/google/auto/factory/processor/ProviderField.java b/factory/src/main/java/com/google/auto/factory/processor/ProviderField.java
deleted file mode 100644
index 21eb56d5..00000000
--- a/factory/src/main/java/com/google/auto/factory/processor/ProviderField.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2016 Google, Inc.
- *
- * 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 com.google.auto.common.AnnotationMirrors;
-import com.google.auto.value.AutoValue;
-import com.google.common.base.Equivalence;
-import com.google.common.base.Optional;
-import javax.lang.model.element.AnnotationMirror;
-
-import static com.google.auto.factory.processor.Mirrors.unwrapOptionalEquivalence;
-import static com.google.auto.factory.processor.Mirrors.wrapOptionalInEquivalence;
-
-@AutoValue
-abstract class ProviderField {
- abstract String name();
- abstract Key key();
- abstract Optional<Equivalence.Wrapper<AnnotationMirror>> nullableWrapper();
-
- Optional<AnnotationMirror> nullable() {
- return unwrapOptionalEquivalence(nullableWrapper());
- }
-
- static ProviderField create(String name, Key key, Optional<AnnotationMirror> nullable) {
- return new AutoValue_ProviderField(
- name, key, wrapOptionalInEquivalence(AnnotationMirrors.equivalence(), nullable));
- }
-}
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 3bfca975..0b5a966c 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
@@ -337,33 +337,4 @@ public class AutoFactoryProcessorTest {
JavaFileObjects.forResource(
"expected/FactoryImplementingCreateMethod_ConcreteClassFactory.java"));
}
-
- @Test public void nullableParams() {
- assertAbout(javaSources())
- .that(ImmutableSet.of(
- JavaFileObjects.forResource("good/SimpleClassNullableParameters.java"),
- JavaFileObjects.forResource("support/AQualifier.java"),
- JavaFileObjects.forResource("support/BQualifier.java")))
- .processedWith(new AutoFactoryProcessor())
- .compilesWithoutError()
- .and().generatesSources(
- JavaFileObjects.forResource("expected/SimpleClassNullableParametersFactory.java"));
- }
-
- @Test public void customNullableType() {
- assertAbout(javaSource())
- .that(JavaFileObjects.forResource("good/CustomNullable.java"))
- .processedWith(new AutoFactoryProcessor())
- .compilesWithoutError()
- .and().generatesSources(JavaFileObjects.forResource("expected/CustomNullableFactory.java"));
- }
-
- @Test public void multipleProvidedParamsWithSameKey() {
- assertAbout(javaSource())
- .that(JavaFileObjects.forResource("good/MultipleProvidedParamsSameKey.java"))
- .processedWith(new AutoFactoryProcessor())
- .compilesWithoutError()
- .and().generatesSources(
- JavaFileObjects.forResource("expected/MultipleProvidedParamsSameKeyFactory.java"));
- }
}
diff --git a/factory/src/test/resources/expected/ClassUsingQualifierWithArgsFactory.java b/factory/src/test/resources/expected/ClassUsingQualifierWithArgsFactory.java
index 832012a4..870992ea 100644
--- a/factory/src/test/resources/expected/ClassUsingQualifierWithArgsFactory.java
+++ b/factory/src/test/resources/expected/ClassUsingQualifierWithArgsFactory.java
@@ -15,15 +15,13 @@
*/
package tests;
-import com.google.auto.factory.internal.Preconditions;
-
import javax.annotation.Generated;
import javax.inject.Inject;
import javax.inject.Provider;
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
final class ClassUsingQualifierWithArgsFactory {
private final Provider<String> providedDepAProvider;
@@ -34,6 +32,6 @@ final class ClassUsingQualifierWithArgsFactory {
}
ClassUsingQualifierWithArgs create() {
- return new ClassUsingQualifierWithArgs(Preconditions.checkNotNull(providedDepAProvider.get()));
+ return new ClassUsingQualifierWithArgs(providedDepAProvider.get());
}
}
diff --git a/factory/src/test/resources/expected/ConstructorAnnotatedFactory.java b/factory/src/test/resources/expected/ConstructorAnnotatedFactory.java
index fa258624..3c393bd7 100644
--- a/factory/src/test/resources/expected/ConstructorAnnotatedFactory.java
+++ b/factory/src/test/resources/expected/ConstructorAnnotatedFactory.java
@@ -15,15 +15,13 @@
*/
package tests;
-import com.google.auto.factory.internal.Preconditions;
-
import javax.annotation.Generated;
import javax.inject.Inject;
import javax.inject.Provider;
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
final class ConstructorAnnotatedFactory {
private final Provider<Object> objProvider;
@@ -37,14 +35,14 @@ final class ConstructorAnnotatedFactory {
}
ConstructorAnnotated create(String s) {
- return new ConstructorAnnotated(Preconditions.checkNotNull(s));
+ return new ConstructorAnnotated(s);
}
ConstructorAnnotated create(int i) {
- return new ConstructorAnnotated(Preconditions.checkNotNull(objProvider.get()), i);
+ return new ConstructorAnnotated(objProvider.get(), i);
}
ConstructorAnnotated create(char c) {
- return new ConstructorAnnotated(Preconditions.checkNotNull(objProvider.get()), c);
+ return new ConstructorAnnotated(objProvider.get(), c);
}
}
diff --git a/factory/src/test/resources/expected/ConstructorAnnotatedNonFinalFactory.java b/factory/src/test/resources/expected/ConstructorAnnotatedNonFinalFactory.java
index d83d8dc4..bcbfdd54 100644
--- a/factory/src/test/resources/expected/ConstructorAnnotatedNonFinalFactory.java
+++ b/factory/src/test/resources/expected/ConstructorAnnotatedNonFinalFactory.java
@@ -15,15 +15,13 @@
*/
package tests;
-import com.google.auto.factory.internal.Preconditions;
-
import javax.annotation.Generated;
import javax.inject.Inject;
import javax.inject.Provider;
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
class ConstructorAnnotatedNonFinalFactory {
private final Provider<Object> objProvider;
@@ -37,14 +35,14 @@ class ConstructorAnnotatedNonFinalFactory {
}
ConstructorAnnotatedNonFinal create(String s) {
- return new ConstructorAnnotatedNonFinal(Preconditions.checkNotNull(s));
+ return new ConstructorAnnotatedNonFinal(s);
}
ConstructorAnnotatedNonFinal create(int i) {
- return new ConstructorAnnotatedNonFinal(Preconditions.checkNotNull(objProvider.get()), i);
+ return new ConstructorAnnotatedNonFinal(objProvider.get(), i);
}
ConstructorAnnotatedNonFinal create(char c) {
- return new ConstructorAnnotatedNonFinal(Preconditions.checkNotNull(objProvider.get()), c);
+ return new ConstructorAnnotatedNonFinal(objProvider.get(), c);
}
}
diff --git a/factory/src/test/resources/expected/CustomNamedFactory.java b/factory/src/test/resources/expected/CustomNamedFactory.java
index 91c7e61c..965bfb1b 100644
--- a/factory/src/test/resources/expected/CustomNamedFactory.java
+++ b/factory/src/test/resources/expected/CustomNamedFactory.java
@@ -19,8 +19,8 @@ import javax.annotation.Generated;
import javax.inject.Inject;
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
final class CustomNamedFactory {
@Inject CustomNamedFactory() {}
diff --git a/factory/src/test/resources/expected/CustomNullableFactory.java b/factory/src/test/resources/expected/CustomNullableFactory.java
deleted file mode 100644
index 29ab465d..00000000
--- a/factory/src/test/resources/expected/CustomNullableFactory.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2016 Google, Inc.
- *
- * 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 javax.annotation.Generated;
-import javax.inject.Inject;
-import javax.inject.Provider;
-
-@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
-)
-final class CustomNullableFactory {
-
- private final Provider<Object> objectProvider;
-
- @Inject
- CustomNullableFactory(Provider<Object> objectProvider) {
- this.objectProvider = objectProvider;
- }
-
- CustomNullable create(@CustomNullable.Nullable String string) {
- return new CustomNullable(string, objectProvider.get());
- }
-}
diff --git a/factory/src/test/resources/expected/FactoryExtendingAbstractClassFactory.java b/factory/src/test/resources/expected/FactoryExtendingAbstractClassFactory.java
index 171fcb30..899abcd5 100644
--- a/factory/src/test/resources/expected/FactoryExtendingAbstractClassFactory.java
+++ b/factory/src/test/resources/expected/FactoryExtendingAbstractClassFactory.java
@@ -19,11 +19,10 @@ import javax.annotation.Generated;
import javax.inject.Inject;
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
-final class FactoryExtendingAbstractClassFactory
- extends FactoryExtendingAbstractClass.AbstractFactory {
+final class FactoryExtendingAbstractClassFactory extends FactoryExtendingAbstractClass.AbstractFactory {
@Inject FactoryExtendingAbstractClassFactory() {}
FactoryExtendingAbstractClass create() {
diff --git a/factory/src/test/resources/expected/FactoryImplementingCreateMethod_ConcreteClassFactory.java b/factory/src/test/resources/expected/FactoryImplementingCreateMethod_ConcreteClassFactory.java
index 0c466b0d..616e52e4 100644
--- a/factory/src/test/resources/expected/FactoryImplementingCreateMethod_ConcreteClassFactory.java
+++ b/factory/src/test/resources/expected/FactoryImplementingCreateMethod_ConcreteClassFactory.java
@@ -15,14 +15,13 @@
*/
package tests;
-import com.google.auto.factory.internal.Preconditions;
import java.util.List;
import javax.annotation.Generated;
import javax.inject.Inject;
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
final class FactoryImplementingCreateMethod_ConcreteClassFactory
implements FactoryImplementingCreateMethod.FactoryInterfaceWithCreateMethod {
@@ -42,8 +41,7 @@ final class FactoryImplementingCreateMethod_ConcreteClassFactory
@Override
public FactoryImplementingCreateMethod.ConcreteClass create(List<Integer> genericWithDifferentArgumentName) {
- return new FactoryImplementingCreateMethod.ConcreteClass(
- Preconditions.checkNotNull(genericWithDifferentArgumentName));
+ return new FactoryImplementingCreateMethod.ConcreteClass(genericWithDifferentArgumentName);
}
FactoryImplementingCreateMethod.ConcreteClass create(int a, boolean b) {
diff --git a/factory/src/test/resources/expected/FactoryImplementingGenericInterfaceExtension.java b/factory/src/test/resources/expected/FactoryImplementingGenericInterfaceExtension.java
index 0f9a12de..50b5aa9d 100644
--- a/factory/src/test/resources/expected/FactoryImplementingGenericInterfaceExtension.java
+++ b/factory/src/test/resources/expected/FactoryImplementingGenericInterfaceExtension.java
@@ -15,15 +15,13 @@
*/
package tests;
-import com.google.auto.factory.internal.Preconditions;
-
import javax.annotation.Generated;
import javax.inject.Inject;
import javax.inject.Provider;
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
final class FactoryImplementingGenericInterfaceExtensionFactory
implements FactoryImplementingGenericInterfaceExtension.MyFactory {
@@ -33,8 +31,7 @@ final class FactoryImplementingGenericInterfaceExtensionFactory
this.sProvider = sProvider;
}
FactoryImplementingGenericInterfaceExtension create(Integer i) {
- return new FactoryImplementingGenericInterfaceExtension(
- Preconditions.checkNotNull(sProvider.get()), Preconditions.checkNotNull(i));
+ return new FactoryImplementingGenericInterfaceExtension(sProvider.get(), i);
}
@Override
public FactoryImplementingGenericInterfaceExtension make(Integer arg) {
diff --git a/factory/src/test/resources/expected/MixedDepsImplementingInterfacesFactory.java b/factory/src/test/resources/expected/MixedDepsImplementingInterfacesFactory.java
index 0f8b7fe6..82a9297b 100644
--- a/factory/src/test/resources/expected/MixedDepsImplementingInterfacesFactory.java
+++ b/factory/src/test/resources/expected/MixedDepsImplementingInterfacesFactory.java
@@ -15,8 +15,6 @@
*/
package tests;
-import com.google.auto.factory.internal.Preconditions;
-
import javax.annotation.Generated;
import javax.inject.Inject;
import javax.inject.Provider;
@@ -25,8 +23,8 @@ import javax.inject.Provider;
* @author Gregory Kick
*/
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
final class MixedDepsImplementingInterfacesFactory
implements MixedDepsImplementingInterfaces.FromInt, MixedDepsImplementingInterfaces.FromObject,
@@ -38,11 +36,11 @@ final class MixedDepsImplementingInterfacesFactory
}
MixedDepsImplementingInterfaces create(int i) {
- return new MixedDepsImplementingInterfaces(Preconditions.checkNotNull(sProvider.get()), i);
+ return new MixedDepsImplementingInterfaces(sProvider.get(), i);
}
MixedDepsImplementingInterfaces create(Object o) {
- return new MixedDepsImplementingInterfaces(Preconditions.checkNotNull(o));
+ return new MixedDepsImplementingInterfaces(o);
}
@Override public MixedDepsImplementingInterfaces fromInt(int i) {
diff --git a/factory/src/test/resources/expected/MultipleFactoriesImplementingInterface_ClassAFactory.java b/factory/src/test/resources/expected/MultipleFactoriesImplementingInterface_ClassAFactory.java
index 6e0610e2..ceb450b5 100644
--- a/factory/src/test/resources/expected/MultipleFactoriesImplementingInterface_ClassAFactory.java
+++ b/factory/src/test/resources/expected/MultipleFactoriesImplementingInterface_ClassAFactory.java
@@ -19,8 +19,8 @@ import javax.annotation.Generated;
import javax.inject.Inject;
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
final class MultipleFactoriesImplementingInterface_ClassAFactory
implements MultipleFactoriesImplementingInterface.Base.Factory {
diff --git a/factory/src/test/resources/expected/MultipleFactoriesImplementingInterface_ClassBFactory.java b/factory/src/test/resources/expected/MultipleFactoriesImplementingInterface_ClassBFactory.java
index 0c4fd912..ed20a912 100644
--- a/factory/src/test/resources/expected/MultipleFactoriesImplementingInterface_ClassBFactory.java
+++ b/factory/src/test/resources/expected/MultipleFactoriesImplementingInterface_ClassBFactory.java
@@ -19,8 +19,8 @@ import javax.annotation.Generated;
import javax.inject.Inject;
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
final class MultipleFactoriesImplementingInterface_ClassBFactory
implements MultipleFactoriesImplementingInterface.Base.Factory {
diff --git a/factory/src/test/resources/expected/MultipleProvidedParamsSameKeyFactory.java b/factory/src/test/resources/expected/MultipleProvidedParamsSameKeyFactory.java
deleted file mode 100644
index 3a728d4d..00000000
--- a/factory/src/test/resources/expected/MultipleProvidedParamsSameKeyFactory.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2016 Google, Inc.
- *
- * 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.internal.Preconditions;
-
-import javax.annotation.Generated;
-import javax.inject.Inject;
-import javax.inject.Provider;
-
-@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
-)
-final class MultipleProvidedParamsSameKeyFactory {
- private final Provider<String> java_lang_StringProvider;
-
- @Inject
- MultipleProvidedParamsSameKeyFactory(Provider<String> java_lang_StringProvider) {
- this.java_lang_StringProvider = java_lang_StringProvider;
- }
-
- MultipleProvidedParamsSameKey create() {
- return new MultipleProvidedParamsSameKey(
- Preconditions.checkNotNull(java_lang_StringProvider.get()),
- Preconditions.checkNotNull(java_lang_StringProvider.get()),
- java_lang_StringProvider.get());
- }
-}
diff --git a/factory/src/test/resources/expected/NestedClasses_CustomNamedFactory.java b/factory/src/test/resources/expected/NestedClasses_CustomNamedFactory.java
index 145cdc35..0859e2c8 100644
--- a/factory/src/test/resources/expected/NestedClasses_CustomNamedFactory.java
+++ b/factory/src/test/resources/expected/NestedClasses_CustomNamedFactory.java
@@ -19,8 +19,8 @@ import javax.annotation.Generated;
import javax.inject.Inject;
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
final class NestedClasses_CustomNamedFactory {
@Inject NestedClasses_CustomNamedFactory() {}
diff --git a/factory/src/test/resources/expected/NestedClasses_SimpleNestedClassFactory.java b/factory/src/test/resources/expected/NestedClasses_SimpleNestedClassFactory.java
index 4f1a0ce1..2c2b5340 100644
--- a/factory/src/test/resources/expected/NestedClasses_SimpleNestedClassFactory.java
+++ b/factory/src/test/resources/expected/NestedClasses_SimpleNestedClassFactory.java
@@ -19,8 +19,8 @@ import javax.annotation.Generated;
import javax.inject.Inject;
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
final class NestedClasses_SimpleNestedClassFactory {
@Inject NestedClasses_SimpleNestedClassFactory() {}
diff --git a/factory/src/test/resources/expected/PublicClassFactory.java b/factory/src/test/resources/expected/PublicClassFactory.java
index 16a37206..a2e091bd 100644
--- a/factory/src/test/resources/expected/PublicClassFactory.java
+++ b/factory/src/test/resources/expected/PublicClassFactory.java
@@ -19,8 +19,8 @@ import javax.annotation.Generated;
import javax.inject.Inject;
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
public final class PublicClassFactory {
@Inject public PublicClassFactory() {}
diff --git a/factory/src/test/resources/expected/SimpleClassFactory.java b/factory/src/test/resources/expected/SimpleClassFactory.java
index 4bea0dc2..7900935c 100644
--- a/factory/src/test/resources/expected/SimpleClassFactory.java
+++ b/factory/src/test/resources/expected/SimpleClassFactory.java
@@ -19,8 +19,8 @@ import javax.annotation.Generated;
import javax.inject.Inject;
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
final class SimpleClassFactory {
@Inject SimpleClassFactory() {}
diff --git a/factory/src/test/resources/expected/SimpleClassImplementingMarkerFactory.java b/factory/src/test/resources/expected/SimpleClassImplementingMarkerFactory.java
index 7a59d748..8029e7ff 100644
--- a/factory/src/test/resources/expected/SimpleClassImplementingMarkerFactory.java
+++ b/factory/src/test/resources/expected/SimpleClassImplementingMarkerFactory.java
@@ -20,8 +20,8 @@ import javax.annotation.Generated;
import javax.inject.Inject;
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
final class SimpleClassImplementingMarkerFactory implements RandomAccess {
@Inject SimpleClassImplementingMarkerFactory() {}
diff --git a/factory/src/test/resources/expected/SimpleClassImplementingSimpleInterfaceFactory.java b/factory/src/test/resources/expected/SimpleClassImplementingSimpleInterfaceFactory.java
index 04028e1f..26ace62f 100644
--- a/factory/src/test/resources/expected/SimpleClassImplementingSimpleInterfaceFactory.java
+++ b/factory/src/test/resources/expected/SimpleClassImplementingSimpleInterfaceFactory.java
@@ -19,8 +19,8 @@ import javax.annotation.Generated;
import javax.inject.Inject;
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
final class SimpleClassImplementingSimpleInterfaceFactory
implements SimpleClassImplementingSimpleInterface.SimpleInterface {
diff --git a/factory/src/test/resources/expected/SimpleClassMixedDepsFactory.java b/factory/src/test/resources/expected/SimpleClassMixedDepsFactory.java
index accada9d..5d84d024 100644
--- a/factory/src/test/resources/expected/SimpleClassMixedDepsFactory.java
+++ b/factory/src/test/resources/expected/SimpleClassMixedDepsFactory.java
@@ -15,15 +15,13 @@
*/
package tests;
-import com.google.auto.factory.internal.Preconditions;
-
import javax.annotation.Generated;
import javax.inject.Inject;
import javax.inject.Provider;
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
final class SimpleClassMixedDepsFactory {
private final Provider<String> providedDepAProvider;
@@ -34,7 +32,6 @@ final class SimpleClassMixedDepsFactory {
}
SimpleClassMixedDeps create(String depB) {
- return new SimpleClassMixedDeps(
- Preconditions.checkNotNull(providedDepAProvider.get()), Preconditions.checkNotNull(depB));
+ return new SimpleClassMixedDeps(providedDepAProvider.get(), depB);
}
}
diff --git a/factory/src/test/resources/expected/SimpleClassNonFinalFactory.java b/factory/src/test/resources/expected/SimpleClassNonFinalFactory.java
index 8fd543cf..853382ff 100644
--- a/factory/src/test/resources/expected/SimpleClassNonFinalFactory.java
+++ b/factory/src/test/resources/expected/SimpleClassNonFinalFactory.java
@@ -19,8 +19,8 @@ import javax.annotation.Generated;
import javax.inject.Inject;
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
class SimpleClassNonFinalFactory {
@Inject SimpleClassNonFinalFactory() {}
diff --git a/factory/src/test/resources/expected/SimpleClassNullableParametersFactory.java b/factory/src/test/resources/expected/SimpleClassNullableParametersFactory.java
deleted file mode 100644
index 227fb547..00000000
--- a/factory/src/test/resources/expected/SimpleClassNullableParametersFactory.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2016 Google, Inc.
- *
- * 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 javax.annotation.Generated;
-import javax.annotation.Nullable;
-import javax.inject.Inject;
-import javax.inject.Provider;
-
-@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
-)
-final class SimpleClassNullableParametersFactory {
- private final Provider<String> providedNullableProvider;
-
- private final Provider<String> providedQualifiedNullableProvider;
-
- @Inject
- SimpleClassNullableParametersFactory(
- Provider<String> providedNullableProvider,
- @BQualifier Provider<String> providedQualifiedNullableProvider) {
- this.providedNullableProvider = providedNullableProvider;
- this.providedQualifiedNullableProvider = providedQualifiedNullableProvider;
- }
-
- SimpleClassNullableParameters create(
- @Nullable String nullable,
- @Nullable @AQualifier String qualifiedNullable) {
- return new SimpleClassNullableParameters(
- nullable,
- qualifiedNullable,
- providedNullableProvider.get(),
- providedQualifiedNullableProvider.get());
- }
-}
diff --git a/factory/src/test/resources/expected/SimpleClassPassedDepsFactory.java b/factory/src/test/resources/expected/SimpleClassPassedDepsFactory.java
index 443f61fd..b944fd5e 100644
--- a/factory/src/test/resources/expected/SimpleClassPassedDepsFactory.java
+++ b/factory/src/test/resources/expected/SimpleClassPassedDepsFactory.java
@@ -15,20 +15,17 @@
*/
package tests;
-import com.google.auto.factory.internal.Preconditions;
-
import javax.annotation.Generated;
import javax.inject.Inject;
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
final class SimpleClassPassedDepsFactory {
@Inject SimpleClassPassedDepsFactory() {}
SimpleClassPassedDeps create(String depA, String depB) {
- return new SimpleClassPassedDeps(
- Preconditions.checkNotNull(depA), Preconditions.checkNotNull(depB));
+ return new SimpleClassPassedDeps(depA, depB);
}
}
diff --git a/factory/src/test/resources/expected/SimpleClassProvidedDepsFactory.java b/factory/src/test/resources/expected/SimpleClassProvidedDepsFactory.java
index 195e0491..d2959657 100644
--- a/factory/src/test/resources/expected/SimpleClassProvidedDepsFactory.java
+++ b/factory/src/test/resources/expected/SimpleClassProvidedDepsFactory.java
@@ -15,15 +15,13 @@
*/
package tests;
-import com.google.auto.factory.internal.Preconditions;
-
import javax.annotation.Generated;
import javax.inject.Inject;
import javax.inject.Provider;
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
final class SimpleClassProvidedDepsFactory {
private final Provider<Integer> providedPrimitiveAProvider;
@@ -45,9 +43,9 @@ final class SimpleClassProvidedDepsFactory {
SimpleClassProvidedDeps create() {
return new SimpleClassProvidedDeps(
- Preconditions.checkNotNull(providedPrimitiveAProvider.get()),
- Preconditions.checkNotNull(providedPrimitiveBProvider.get()),
- Preconditions.checkNotNull(providedDepAProvider.get()),
- Preconditions.checkNotNull(providedDepBProvider.get()));
+ providedPrimitiveAProvider.get(),
+ providedPrimitiveBProvider.get(),
+ providedDepAProvider.get(),
+ providedDepBProvider.get());
}
}
diff --git a/factory/src/test/resources/expected/SimpleClassProvidedProviderDepsFactory.java b/factory/src/test/resources/expected/SimpleClassProvidedProviderDepsFactory.java
index abb34989..5e83d15d 100644
--- a/factory/src/test/resources/expected/SimpleClassProvidedProviderDepsFactory.java
+++ b/factory/src/test/resources/expected/SimpleClassProvidedProviderDepsFactory.java
@@ -15,15 +15,13 @@
*/
package tests;
-import com.google.auto.factory.internal.Preconditions;
-
import javax.annotation.Generated;
import javax.inject.Inject;
import javax.inject.Provider;
@Generated(
- value = "com.google.auto.factory.processor.AutoFactoryProcessor",
- comments = "https://github.com/google/auto/tree/master/factory"
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
)
final class SimpleClassProvidedProviderDepsFactory {
private final Provider<String> providedDepAProvider;
@@ -38,8 +36,6 @@ final class SimpleClassProvidedProviderDepsFactory {
}
SimpleClassProvidedProviderDeps create() {
- return new SimpleClassProvidedProviderDeps(
- Preconditions.checkNotNull(providedDepAProvider),
- Preconditions.checkNotNull(providedDepBProvider));
+ return new SimpleClassProvidedProviderDeps(providedDepAProvider, providedDepBProvider);
}
}
diff --git a/factory/src/test/resources/good/ConstructorAnnotated.java b/factory/src/test/resources/good/ConstructorAnnotated.java
index 475ac7f9..59e4f0ea 100644
--- a/factory/src/test/resources/good/ConstructorAnnotated.java
+++ b/factory/src/test/resources/good/ConstructorAnnotated.java
@@ -15,6 +15,8 @@
*/
package tests;
+import javax.annotation.Generated;
+
import com.google.auto.factory.AutoFactory;
import com.google.auto.factory.Provided;
diff --git a/factory/src/test/resources/good/CustomNullable.java b/factory/src/test/resources/good/CustomNullable.java
deleted file mode 100644
index ef3b0329..00000000
--- a/factory/src/test/resources/good/CustomNullable.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2016 Google, Inc.
- *
- * 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;
-import com.google.auto.factory.Provided;
-
-@AutoFactory
-final class CustomNullable {
-
- private final String string;
- private final Object object;
-
- CustomNullable(
- @CustomNullable.Nullable String string, @CustomNullable.Nullable @Provided Object object) {
- this.string = string;
- this.object = object;
- }
-
- @interface Nullable {}
-}
diff --git a/factory/src/test/resources/good/MultipleProvidedParamsSameKey.java b/factory/src/test/resources/good/MultipleProvidedParamsSameKey.java
deleted file mode 100644
index 8592dac1..00000000
--- a/factory/src/test/resources/good/MultipleProvidedParamsSameKey.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2016 Google, Inc.
- *
- * 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;
-import com.google.auto.factory.Provided;
-import javax.annotation.Nullable;
-
-@AutoFactory
-final class MultipleProvidedParamsSameKey {
- private final String one;
- private final String two;
- private final String three;
-
- public MultipleProvidedParamsSameKey(
- @Provided String one,
- @Provided String two,
- @Nullable @Provided String three) {
- this.one = one;
- this.two = two;
- this.three = three;
- }
-}
diff --git a/factory/src/test/resources/good/SimpleClassNullableParameters.java b/factory/src/test/resources/good/SimpleClassNullableParameters.java
deleted file mode 100644
index 9e2cc46b..00000000
--- a/factory/src/test/resources/good/SimpleClassNullableParameters.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2016 Google, Inc.
- *
- * 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;
-import com.google.auto.factory.Provided;
-import javax.annotation.Nullable;
-
-@AutoFactory
-@SuppressWarnings("unused")
-final class SimpleClassNullableParameters {
- @Nullable private final String nullable;
- @Nullable private final String qualifiedNullable;
- @Nullable private final String providedNullable;
- @Nullable private final String providedQualifiedNullable;
-
- // TODO(ronshapiro): with Java 8, test Provider<@Nullable String> parameters and provider fields
- SimpleClassNullableParameters(
- @Nullable String nullable,
- @Nullable @AQualifier String qualifiedNullable,
- @Nullable @Provided String providedNullable,
- @Nullable @Provided @BQualifier String providedQualifiedNullable) {
- this.nullable = nullable;
- this.qualifiedNullable = qualifiedNullable;
- this.providedNullable = providedNullable;
- this.providedQualifiedNullable = providedQualifiedNullable;
- }
-}