Feedback from cgruber.
diff --git a/generator/src/main/java/com/google/autofactory/AbstractGenerator.java b/generator/src/main/java/com/google/autofactory/AbstractGenerator.java
deleted file mode 100644
index 8bbbfad..0000000
--- a/generator/src/main/java/com/google/autofactory/AbstractGenerator.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2013 Google, Inc.
- * Copyright (C) 2013 Square, 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.autofactory;
-
-import com.squareup.java.JavaWriter;
-import java.io.IOException;
-import javax.annotation.processing.ProcessingEnvironment;
-import javax.lang.model.element.Element;
-import javax.lang.model.element.TypeElement;
-import javax.tools.Diagnostic;
-import javax.tools.JavaFileObject;
-
-public abstract class AbstractGenerator {
-
- private final ProcessingEnvironment env;
-
- protected AbstractGenerator(ProcessingEnvironment env) {
- this.env = env;
- }
-
- protected JavaWriter newWriter(String adapterName, TypeElement type) throws IOException {
- JavaFileObject sourceFile = env.getFiler().createSourceFile(adapterName, type);
- return new JavaWriter(sourceFile.openWriter());
- }
-
- protected void error(String format, Object... args) {
- env.getMessager().printMessage(Diagnostic.Kind.ERROR, String.format(format, args));
- }
-
- protected void warn(String format, Object... args) {
- env.getMessager().printMessage(Diagnostic.Kind.WARNING, String.format(format, args));
- }
-
- static String fieldName(boolean disambiguateFields, Element field) {
- return (disambiguateFields ? "field_" : "") + field.getSimpleName().toString();
- }
-
- static String parameterName(boolean disambiguateFields, Element parameter) {
- return (disambiguateFields ? "parameter_" : "") + parameter.getSimpleName().toString();
- }
-
-}
\ No newline at end of file
diff --git a/generator/src/main/java/com/google/autofactory/AutoFactory.java b/generator/src/main/java/com/google/autofactory/AutoFactory.java
index 853d9a9..6853da6 100644
--- a/generator/src/main/java/com/google/autofactory/AutoFactory.java
+++ b/generator/src/main/java/com/google/autofactory/AutoFactory.java
@@ -19,12 +19,29 @@
import static java.lang.annotation.ElementType.TYPE;
import java.lang.annotation.Target;
+import java.util.Formatter;
/**
+ * An annotation to be applied to elements for which a factory should be automatically generated.
+ *
+ * @author Gregory Kick
*/
@Target({ TYPE, CONSTRUCTOR })
public @interface AutoFactory {
+ /**
+ * The pattern for the fully qualified name of the factory implementation. The pattern syntax is
+ * that of {@link Formatter}. There are two arguments passed to the pattern: the package and the
+ * simple name of the type enclosing the target of the annotation.
+ */
String named() default "%s.%sFactory";
+
+ /**
+ * A list of interfaces that the generated factory is required to implement.
+ */
Class<?>[] implementing() default { };
+
+ /**
+ * The type that the generated factory is require to extend.
+ */
Class<?> extending() default Object.class;
}
diff --git a/generator/src/main/java/com/google/autofactory/AutoFactoryDeclaration.java b/generator/src/main/java/com/google/autofactory/AutoFactoryDeclaration.java
index 35c7610..a59d3de 100644
--- a/generator/src/main/java/com/google/autofactory/AutoFactoryDeclaration.java
+++ b/generator/src/main/java/com/google/autofactory/AutoFactoryDeclaration.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2013 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.autofactory;
import static com.google.common.base.Preconditions.checkArgument;
@@ -18,6 +33,11 @@
import com.google.common.collect.ImmutableSet;
+/**
+ * This is a value object that mirrors the static declaration of an {@link AutoFactory} annotation.
+ *
+ * @author Gregory Kick
+ */
final class AutoFactoryDeclaration {
private final String namePattern;
private final String extendingQualifiedName;
diff --git a/generator/src/main/java/com/google/autofactory/AutoFactoryProcessor.java b/generator/src/main/java/com/google/autofactory/AutoFactoryProcessor.java
index f604265..0dfefaa 100644
--- a/generator/src/main/java/com/google/autofactory/AutoFactoryProcessor.java
+++ b/generator/src/main/java/com/google/autofactory/AutoFactoryProcessor.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2013 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.autofactory;
import java.io.IOException;
@@ -19,6 +34,11 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimaps;
+/**
+ * The annotation processor that generates factories for {@link AutoFactory} annotations.
+ *
+ * @author Gregory Kick
+ */
public final class AutoFactoryProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
@@ -50,7 +70,6 @@
implementing.addAll(methodDescriptor.declaration().implementingQualifiedNames());
}
try {
-
factoryWriter.writeFactory(
new FactoryDescriptor(
entry.getKey(),
diff --git a/generator/src/main/java/com/google/autofactory/Elements2.java b/generator/src/main/java/com/google/autofactory/Elements2.java
index 284863a..f001b68 100644
--- a/generator/src/main/java/com/google/autofactory/Elements2.java
+++ b/generator/src/main/java/com/google/autofactory/Elements2.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2013 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.autofactory;
import static com.google.common.base.Preconditions.checkArgument;
diff --git a/generator/src/main/java/com/google/autofactory/FactoryDescriptor.java b/generator/src/main/java/com/google/autofactory/FactoryDescriptor.java
index c35ac3f..1e40429 100644
--- a/generator/src/main/java/com/google/autofactory/FactoryDescriptor.java
+++ b/generator/src/main/java/com/google/autofactory/FactoryDescriptor.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2013 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.autofactory;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -11,6 +26,11 @@
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Iterables;
+/**
+ * A value object representing a factory to be generated.
+ *
+ * @author Gregory Kick
+ */
final class FactoryDescriptor {
private static final CharMatcher identifierMatcher = new CharMatcher() {
@Override
@@ -31,14 +51,14 @@
this.extendingType = checkNotNull(extendingType);
this.implementingTypes = checkNotNull(implementingTypes);
this.methodDescriptors = checkNotNull(methodDescriptors);
- ImmutableSetMultimap.Builder<Key, String> builder = ImmutableSetMultimap.builder();
+ ImmutableSetMultimap.Builder<Key, String> providerNamesBuilder = ImmutableSetMultimap.builder();
for (FactoryMethodDescriptor descriptor : methodDescriptors) {
for (Parameter parameter : descriptor.providedParameters()) {
- builder.putAll(parameter.asKey(), parameter.name());
+ providerNamesBuilder.putAll(parameter.asKey(), parameter.name());
}
}
ImmutableMap.Builder<Key, String> providersBuilder = ImmutableMap.builder();
- for (Entry<Key, Collection<String>> entry : builder.build().asMap().entrySet()) {
+ for (Entry<Key, Collection<String>> entry : providerNamesBuilder.build().asMap().entrySet()) {
Key key = entry.getKey();
switch (entry.getValue().size()) {
case 0:
diff --git a/generator/src/main/java/com/google/autofactory/FactoryDescriptorGenerator.java b/generator/src/main/java/com/google/autofactory/FactoryDescriptorGenerator.java
index 635a3be..a6a43ff 100644
--- a/generator/src/main/java/com/google/autofactory/FactoryDescriptorGenerator.java
+++ b/generator/src/main/java/com/google/autofactory/FactoryDescriptorGenerator.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2013 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.autofactory;
import static com.google.common.base.Preconditions.checkArgument;
@@ -28,6 +43,11 @@
import com.google.common.collect.Multimaps;
import com.google.common.collect.Sets;
+/**
+ * A service that traverses an element and returns the set of factory methods defined therein.
+ *
+ * @author Gregory Kick
+ */
final class FactoryDescriptorGenerator {
private final Messager messager;
private final Elements elements;
@@ -54,15 +74,7 @@
// applied to the type to be created
ImmutableSet<ExecutableElement> constructors = Elements2.getConstructors(type);
if (constructors.isEmpty()) {
- return ImmutableSet.of(new FactoryMethodDescriptor.Builder(declaration)
- .factoryName(declaration.getFactoryName(
- elements.getPackageOf(type).getQualifiedName(), type.getSimpleName()))
- .name("create")
- .returnType(type.getQualifiedName().toString())
- .passedParameters(ImmutableSet.<Parameter>of())
- .creationParameters(ImmutableSet.<Parameter>of())
- .providedParameters(ImmutableSet.<Parameter>of())
- .build());
+ return generateDescriptorForDefaultConstructor(declaration, type);
} else {
return FluentIterable.from(constructors)
.transform(new Function<ExecutableElement, FactoryMethodDescriptor>() {
@@ -132,7 +144,7 @@
.build();
}
- @SuppressWarnings("unused")
+ @SuppressWarnings("unused") // not used yet
private void generateDescriptorForFactoryMethodDeclaration(final ExecutableElement e,
Optional<TypeElement> referenceType) {
String returnType = e.getReturnType().toString();
@@ -168,4 +180,17 @@
break;
}
}
+
+ private ImmutableSet<FactoryMethodDescriptor> generateDescriptorForDefaultConstructor(
+ AutoFactoryDeclaration declaration, TypeElement type) {
+ return ImmutableSet.of(new FactoryMethodDescriptor.Builder(declaration)
+ .factoryName(declaration.getFactoryName(
+ elements.getPackageOf(type).getQualifiedName(), type.getSimpleName()))
+ .name("create")
+ .returnType(type.getQualifiedName().toString())
+ .passedParameters(ImmutableSet.<Parameter>of())
+ .creationParameters(ImmutableSet.<Parameter>of())
+ .providedParameters(ImmutableSet.<Parameter>of())
+ .build());
+ }
}
diff --git a/generator/src/main/java/com/google/autofactory/FactoryMethodDescriptor.java b/generator/src/main/java/com/google/autofactory/FactoryMethodDescriptor.java
index e7fd182..30e4410 100644
--- a/generator/src/main/java/com/google/autofactory/FactoryMethodDescriptor.java
+++ b/generator/src/main/java/com/google/autofactory/FactoryMethodDescriptor.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2013 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.autofactory;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -11,6 +26,11 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
+/**
+ * A value object representing a factory method to be generated.
+ *
+ * @author Gregory Kick
+ */
final class FactoryMethodDescriptor {
private final AutoFactoryDeclaration declaration;
private final String factoryName;
diff --git a/generator/src/main/java/com/google/autofactory/FactoryWriter.java b/generator/src/main/java/com/google/autofactory/FactoryWriter.java
index d6718d2..11539af 100644
--- a/generator/src/main/java/com/google/autofactory/FactoryWriter.java
+++ b/generator/src/main/java/com/google/autofactory/FactoryWriter.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2013 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.autofactory;
import java.io.IOException;
@@ -35,7 +50,7 @@
throws IOException {
JavaFileObject sourceFile = filer.createSourceFile(descriptor.name(), originatingElement);
JavaWriter writer = new JavaWriter(sourceFile.openWriter());
- String packageName = Names.getPackage(descriptor.name()).toString();
+ String packageName = getPackage(descriptor.name()).toString();
writer.emitPackage(packageName)
.emitImports("javax.annotation.Generated");
@@ -45,7 +60,7 @@
}
for (String implementingType : descriptor.implementingTypes()) {
- String implementingPackageName = Names.getPackage(implementingType).toString();
+ String implementingPackageName = getPackage(implementingType).toString();
if (!"java.lang".equals(implementingPackageName)
&& !packageName.equals(implementingPackageName)) {
writer.emitImports(implementingType);
@@ -55,15 +70,16 @@
String[] implementedClasses = FluentIterable.from(descriptor.implementingTypes())
.transform(new Function<String, String>() {
@Override public String apply(String implemetingClass) {
- return Names.getSimpleName(implemetingClass).toString();
+ return getSimpleName(implemetingClass).toString();
}
})
.toSortedSet(Ordering.natural())
.toArray(new String[0]);
- String factoryName = Names.getSimpleName(descriptor.name()).toString();
- writer.emitAnnotation(Generated.class, ImmutableMap.of("value", "\"auto-factory\""))
- .beginType(factoryName, "class", Modifier.FINAL, null, implementedClasses);
+ String factoryName = getSimpleName(descriptor.name()).toString();
+ writer.emitAnnotation(Generated.class,
+ ImmutableMap.of("value", "\"" + AutoFactoryProcessor.class.getName() + "\""))
+ .beginType(factoryName, "class", Modifier.FINAL, null, implementedClasses);
ImmutableList.Builder<String> constructorTokens = ImmutableList.builder();
for (Entry<Key, String> entry : descriptor.providerNames().entrySet()) {
@@ -116,4 +132,23 @@
}
return parameterTokens.toArray(new String[0]);
}
+
+ private static CharSequence getSimpleName(CharSequence fullyQualifiedName) {
+ int lastDot = lastIndexOf(fullyQualifiedName, '.');
+ return fullyQualifiedName.subSequence(lastDot + 1, fullyQualifiedName.length());
+ }
+
+ private static CharSequence getPackage(CharSequence fullyQualifiedName) {
+ int lastDot = lastIndexOf(fullyQualifiedName, '.');
+ return fullyQualifiedName.subSequence(0, lastDot);
+ }
+
+ private static int lastIndexOf(CharSequence charSequence, char c) {
+ for (int i = charSequence.length() - 1; i >= 0; i--) {
+ if (charSequence.charAt(i) == c) {
+ return i;
+ }
+ }
+ return -1;
+ }
}
diff --git a/generator/src/main/java/com/google/autofactory/Key.java b/generator/src/main/java/com/google/autofactory/Key.java
index 06353d3..a3db9b8 100644
--- a/generator/src/main/java/com/google/autofactory/Key.java
+++ b/generator/src/main/java/com/google/autofactory/Key.java
@@ -1,8 +1,28 @@
+/*
+ * Copyright (C) 2013 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.autofactory;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
+/**
+ * A value object for types and qualifiers.
+ *
+ * @author Gregory Kick
+ */
final class Key {
private final String type;
private final Optional<String> qualifier;
diff --git a/generator/src/main/java/com/google/autofactory/Mirrors.java b/generator/src/main/java/com/google/autofactory/Mirrors.java
index e4e0c45..bfae82e 100644
--- a/generator/src/main/java/com/google/autofactory/Mirrors.java
+++ b/generator/src/main/java/com/google/autofactory/Mirrors.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2013 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.autofactory;
import java.lang.annotation.Annotation;
diff --git a/generator/src/main/java/com/google/autofactory/Names.java b/generator/src/main/java/com/google/autofactory/Names.java
deleted file mode 100644
index f432e71..0000000
--- a/generator/src/main/java/com/google/autofactory/Names.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.google.autofactory;
-
-
-final class Names {
- private Names() { }
-
- static CharSequence getSimpleName(CharSequence fullyQualifiedName) {
- int lastDot = lastIndexOf(fullyQualifiedName, '.');
- return fullyQualifiedName.subSequence(lastDot + 1, fullyQualifiedName.length());
- }
-
- static CharSequence getPackage(CharSequence fullyQualifiedName) {
- int lastDot = lastIndexOf(fullyQualifiedName, '.');
- return fullyQualifiedName.subSequence(0, lastDot);
- }
-
- private static int lastIndexOf(CharSequence charSequence, char c) {
- for (int i = charSequence.length() - 1; i >= 0; i--) {
- if (charSequence.charAt(i) == c) {
- return i;
- }
- }
- return -1;
- }
-}
diff --git a/generator/src/main/java/com/google/autofactory/Parameter.java b/generator/src/main/java/com/google/autofactory/Parameter.java
index da5dbce..6078257 100644
--- a/generator/src/main/java/com/google/autofactory/Parameter.java
+++ b/generator/src/main/java/com/google/autofactory/Parameter.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2013 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.autofactory;
import static com.google.common.base.Preconditions.checkArgument;
diff --git a/generator/src/main/java/com/google/autofactory/Provided.java b/generator/src/main/java/com/google/autofactory/Provided.java
index 40bc545..67ed7a1 100644
--- a/generator/src/main/java/com/google/autofactory/Provided.java
+++ b/generator/src/main/java/com/google/autofactory/Provided.java
@@ -19,5 +19,11 @@
import java.lang.annotation.Target;
+/**
+ * An annotation to be applied to parameters that should be provided by an
+ * {@linkplain javax.inject.Inject injected} {@link javax.inject.Provider} in a generated factory.
+ *
+ * @author Gregory Kick
+ */
@Target(PARAMETER)
public @interface Provided { }
diff --git a/generator/src/main/java/com/google/autofactory/ProvidedChecker.java b/generator/src/main/java/com/google/autofactory/ProvidedChecker.java
index f445c2c..c3fa193 100644
--- a/generator/src/main/java/com/google/autofactory/ProvidedChecker.java
+++ b/generator/src/main/java/com/google/autofactory/ProvidedChecker.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2013 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.autofactory;
import static com.google.common.base.Preconditions.checkArgument;
@@ -18,7 +33,8 @@
}
void checkProvidedParameter(Element element) {
- checkArgument(element.getAnnotation(Provided.class) != null);
+ checkArgument(element.getAnnotation(Provided.class) != null, "%s not annoated with @Provided",
+ element);
element.accept(new ElementKindVisitor6<Void, Void>() {
@Override
protected Void defaultAction(Element e, Void p) {
diff --git a/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor
index bac28a7..935d75b 100644
--- a/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor
+++ b/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor
@@ -1 +1 @@
-com.google.autofactory.FactoryProcessor
+com.google.autofactory.AutoFactoryProcessor
diff --git a/generator/src/test/java/com/google/autofactory/AutoFactoryProcessorTest.java b/generator/src/test/java/com/google/autofactory/AutoFactoryProcessorTest.java
index b068e96..7fdf608 100644
--- a/generator/src/test/java/com/google/autofactory/AutoFactoryProcessorTest.java
+++ b/generator/src/test/java/com/google/autofactory/AutoFactoryProcessorTest.java
@@ -1,9 +1,25 @@
+/*
+ * Copyright (C) 2013 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.autofactory;
import static com.google.auto.factory.gentest.JavaSourceSubjectFactory.JAVA_SOURCE;
import static com.google.common.base.Charsets.UTF_8;
import static javax.tools.StandardLocation.SOURCE_OUTPUT;
import static org.junit.Assert.assertTrue;
+import static org.truth0.Truth.ASSERT;
import java.io.File;
import java.io.IOException;
@@ -22,7 +38,6 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.truth0.Truth;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@@ -72,7 +87,7 @@
assertTrue("file does not exist. files: " + Arrays.toString(outputSources.listFiles()),
actual.exists());
try {
- Truth.ASSERT.about(JAVA_SOURCE).that(expectedOutput)
+ ASSERT.about(JAVA_SOURCE).that(expectedOutput)
.isEquivalentTo(actual);
} catch (AssertionError e) {
throw new ComparisonFailure("", Files.toString(expectedOutput, UTF_8),
diff --git a/generator/src/test/resources/tests/CustomNamedFactory.java b/generator/src/test/resources/tests/CustomNamedFactory.java
index 1178880..bdfb066 100644
--- a/generator/src/test/resources/tests/CustomNamedFactory.java
+++ b/generator/src/test/resources/tests/CustomNamedFactory.java
@@ -1,9 +1,24 @@
+/*
+ * Copyright (C) 2013 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;
-@Generated(value = "auto-factory")
+@Generated(value = "com.google.autofactory.AutoFactoryProcessor")
final class CustomNamedFactory {
@Inject CustomNamedFactory() {}
diff --git a/generator/src/test/resources/tests/ProvidedButNoAutoFactory.java b/generator/src/test/resources/tests/ProvidedButNoAutoFactory.java
index 2d9ce2a..dc026df 100644
--- a/generator/src/test/resources/tests/ProvidedButNoAutoFactory.java
+++ b/generator/src/test/resources/tests/ProvidedButNoAutoFactory.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2013 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.autofactory.Provided;
diff --git a/generator/src/test/resources/tests/SimpleClass.java b/generator/src/test/resources/tests/SimpleClass.java
index e8328b3..7197990 100644
--- a/generator/src/test/resources/tests/SimpleClass.java
+++ b/generator/src/test/resources/tests/SimpleClass.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2013 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.autofactory.AutoFactory;
diff --git a/generator/src/test/resources/tests/SimpleClassCustomName.java b/generator/src/test/resources/tests/SimpleClassCustomName.java
index 637b62e..4ec5ce0 100644
--- a/generator/src/test/resources/tests/SimpleClassCustomName.java
+++ b/generator/src/test/resources/tests/SimpleClassCustomName.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2013 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.autofactory.AutoFactory;
diff --git a/generator/src/test/resources/tests/SimpleClassFactory.java b/generator/src/test/resources/tests/SimpleClassFactory.java
index c83c07b..cf0692d 100644
--- a/generator/src/test/resources/tests/SimpleClassFactory.java
+++ b/generator/src/test/resources/tests/SimpleClassFactory.java
@@ -1,9 +1,24 @@
+/*
+ * Copyright (C) 2013 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;
-@Generated(value = "auto-factory")
+@Generated(value = "com.google.autofactory.AutoFactoryProcessor")
final class SimpleClassFactory {
@Inject SimpleClassFactory() {}
diff --git a/generator/src/test/resources/tests/SimpleClassImplementing.java b/generator/src/test/resources/tests/SimpleClassImplementing.java
index 9235d6d..414a0c8 100644
--- a/generator/src/test/resources/tests/SimpleClassImplementing.java
+++ b/generator/src/test/resources/tests/SimpleClassImplementing.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2013 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.autofactory.AutoFactory;
diff --git a/generator/src/test/resources/tests/SimpleClassImplementingFactory.java b/generator/src/test/resources/tests/SimpleClassImplementingFactory.java
index f33baa3..5220a5b 100644
--- a/generator/src/test/resources/tests/SimpleClassImplementingFactory.java
+++ b/generator/src/test/resources/tests/SimpleClassImplementingFactory.java
@@ -1,10 +1,25 @@
+/*
+ * Copyright (C) 2013 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 com.google.common.base.Supplier;
-@Generated(value = "auto-factory")
+@Generated("com.google.autofactory.AutoFactoryProcessor")
final class SimpleClassImplementingFactory implements Supplier<SimpleClassImplementing> {
@Override public SimpleClassImplementing get() {
return new SimpleClassImplementing();
diff --git a/generator/src/test/resources/tests/SimpleClassMixedDepsFactory.java b/generator/src/test/resources/tests/SimpleClassMixedDepsFactory.java
index 52f1e79..5d61992 100644
--- a/generator/src/test/resources/tests/SimpleClassMixedDepsFactory.java
+++ b/generator/src/test/resources/tests/SimpleClassMixedDepsFactory.java
@@ -1,10 +1,25 @@
+/*
+ * Copyright (C) 2013 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 = "auto-factory")
+@Generated(value = "com.google.autofactory.AutoFactoryProcessor")
final class SimpleClassMixedDepsFactory {
private final Provider<String> providedDepAProvider;
diff --git a/generator/src/test/resources/tests/SimpleClassPassedDepsFactory.java b/generator/src/test/resources/tests/SimpleClassPassedDepsFactory.java
index 17af8c4..df0a302 100644
--- a/generator/src/test/resources/tests/SimpleClassPassedDepsFactory.java
+++ b/generator/src/test/resources/tests/SimpleClassPassedDepsFactory.java
@@ -1,9 +1,24 @@
+/*
+ * Copyright (C) 2013 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;
-@Generated(value = "auto-factory")
+@Generated(value = "com.google.autofactory.AutoFactoryProcessor")
final class SimpleClassPassedDepsFactory {
@Inject SimpleClassPassedDepsFactory() {}
diff --git a/generator/src/test/resources/tests/SimpleClassProvidedDepsFactory.java b/generator/src/test/resources/tests/SimpleClassProvidedDepsFactory.java
index 5a3cad8..1427463 100644
--- a/generator/src/test/resources/tests/SimpleClassProvidedDepsFactory.java
+++ b/generator/src/test/resources/tests/SimpleClassProvidedDepsFactory.java
@@ -1,10 +1,25 @@
+/*
+ * Copyright (C) 2013 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 = "auto-factory")
+@Generated(value = "com.google.autofactory.AutoFactoryProcessor")
final class SimpleClassProvidedDepsFactory {
private final Provider<String> providedDepAProvider;
private final Provider<String> providedDepBProvider;
diff --git a/generator/tests/ConstructorFactoryClassFactory.java b/generator/tests/ConstructorFactoryClassFactory.java
new file mode 100644
index 0000000..1a1d7e0
--- /dev/null
+++ b/generator/tests/ConstructorFactoryClassFactory.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2013 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.Provider;
+
+@Generated("com.google.autofactory.AutoFactoryProcessor")
+final class ConstructorFactoryClassFactory {
+ private final Provider<Object> objProvider;
+
+ ConstructorFactoryClass create() {
+ return new ConstructorFactoryClass();
+ }
+
+ ConstructorFactoryClass create(int i) {
+ return new ConstructorFactoryClass(i);
+ }
+
+ ConstructorFactoryClass create(char c) {
+ return new ConstructorFactoryClass(objProvider.get(), c);
+ }
+
+ ConstructorFactoryClass create(byte b) {
+ return new ConstructorFactoryClass(objProvider.get(), b);
+ }
+}
diff --git a/generator/tests/CustomNamedFactory.java b/generator/tests/CustomNamedFactory.java
index 1178880..bdfb066 100644
--- a/generator/tests/CustomNamedFactory.java
+++ b/generator/tests/CustomNamedFactory.java
@@ -1,9 +1,24 @@
+/*
+ * Copyright (C) 2013 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;
-@Generated(value = "auto-factory")
+@Generated(value = "com.google.autofactory.AutoFactoryProcessor")
final class CustomNamedFactory {
@Inject CustomNamedFactory() {}
diff --git a/generator/tests/SimpleClassFactory.java b/generator/tests/SimpleClassFactory.java
index c83c07b..cf0692d 100644
--- a/generator/tests/SimpleClassFactory.java
+++ b/generator/tests/SimpleClassFactory.java
@@ -1,9 +1,24 @@
+/*
+ * Copyright (C) 2013 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;
-@Generated(value = "auto-factory")
+@Generated(value = "com.google.autofactory.AutoFactoryProcessor")
final class SimpleClassFactory {
@Inject SimpleClassFactory() {}
diff --git a/generator/tests/SimpleClassMixedDepsFactory.java b/generator/tests/SimpleClassMixedDepsFactory.java
index 52f1e79..5d61992 100644
--- a/generator/tests/SimpleClassMixedDepsFactory.java
+++ b/generator/tests/SimpleClassMixedDepsFactory.java
@@ -1,10 +1,25 @@
+/*
+ * Copyright (C) 2013 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 = "auto-factory")
+@Generated(value = "com.google.autofactory.AutoFactoryProcessor")
final class SimpleClassMixedDepsFactory {
private final Provider<String> providedDepAProvider;
diff --git a/generator/tests/SimpleClassPassedDepsFactory.java b/generator/tests/SimpleClassPassedDepsFactory.java
index 17af8c4..df0a302 100644
--- a/generator/tests/SimpleClassPassedDepsFactory.java
+++ b/generator/tests/SimpleClassPassedDepsFactory.java
@@ -1,9 +1,24 @@
+/*
+ * Copyright (C) 2013 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;
-@Generated(value = "auto-factory")
+@Generated(value = "com.google.autofactory.AutoFactoryProcessor")
final class SimpleClassPassedDepsFactory {
@Inject SimpleClassPassedDepsFactory() {}
diff --git a/generator/tests/SimpleClassProvidedDepsFactory.java b/generator/tests/SimpleClassProvidedDepsFactory.java
index 5a3cad8..1427463 100644
--- a/generator/tests/SimpleClassProvidedDepsFactory.java
+++ b/generator/tests/SimpleClassProvidedDepsFactory.java
@@ -1,10 +1,25 @@
+/*
+ * Copyright (C) 2013 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 = "auto-factory")
+@Generated(value = "com.google.autofactory.AutoFactoryProcessor")
final class SimpleClassProvidedDepsFactory {
private final Provider<String> providedDepAProvider;
private final Provider<String> providedDepBProvider;