diff --git a/factory/src/main/java/com/google/auto/factory/processor/FactoryDescriptorGenerator.java b/factory/src/main/java/com/google/auto/factory/processor/FactoryDescriptorGenerator.java index 1b728cc6fe..b44ad3b9c1 100644 --- a/factory/src/main/java/com/google/auto/factory/processor/FactoryDescriptorGenerator.java +++ b/factory/src/main/java/com/google/auto/factory/processor/FactoryDescriptorGenerator.java @@ -139,6 +139,7 @@ public boolean apply(VariableElement parameter) { .name("create") .returnType(classElement.asType()) .publicMethod(classElement.getModifiers().contains(PUBLIC)) + .isVarargs(constructor.isVarArgs()) .providedParameters(providedParameters) .passedParameters(passedParameters) .creationParameters(Parameter.forParameterList(constructor.getParameters(), types)) diff --git a/factory/src/main/java/com/google/auto/factory/processor/FactoryMethodDescriptor.java b/factory/src/main/java/com/google/auto/factory/processor/FactoryMethodDescriptor.java index 15bd7301c6..447865b68a 100644 --- a/factory/src/main/java/com/google/auto/factory/processor/FactoryMethodDescriptor.java +++ b/factory/src/main/java/com/google/auto/factory/processor/FactoryMethodDescriptor.java @@ -36,6 +36,7 @@ abstract class FactoryMethodDescriptor { abstract TypeMirror returnType(); abstract boolean publicMethod(); abstract boolean overridingMethod(); + abstract boolean isVarargs(); abstract ImmutableSet passedParameters(); abstract ImmutableSet providedParameters(); abstract ImmutableSet creationParameters(); @@ -49,7 +50,8 @@ static Builder builder(AutoFactoryDeclaration declaration) { return new AutoValue_FactoryMethodDescriptor.Builder() .declaration(checkNotNull(declaration)) .publicMethod(false) - .overridingMethod(false); + .overridingMethod(false) + .isVarargs(false); } @AutoValue.Builder @@ -59,6 +61,7 @@ static abstract class Builder { abstract Builder returnType(TypeMirror returnType); abstract Builder publicMethod(boolean publicMethod); abstract Builder overridingMethod(boolean overridingMethod); + abstract Builder isVarargs(boolean varargs); abstract Builder passedParameters(Iterable passedParameters); abstract Builder providedParameters(Iterable providedParameters); abstract Builder creationParameters(Iterable creationParameters); 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 6d4d8f8efc..142ae09370 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 @@ -132,6 +132,7 @@ public String apply(Parameter parameter) { "return new $T($L)", methodDescriptor.returnType(), argumentJoiner.join(creationParameterNames)); + method.varargs(methodDescriptor.isVarargs()); factory.addMethod(method.build()); } diff --git a/factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java b/factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java index 0b5a966c81..2694c96579 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 @@ -95,6 +95,15 @@ public void nestedClasses() { .and().generatesSources( JavaFileObjects.forResource("expected/SimpleClassPassedDepsFactory.java")); } + + @Test public void simpleClassVarargsDeps() { + assertAbout(javaSource()) + .that(JavaFileObjects.forResource("good/SimpleClassVarargsDeps.java")) + .processedWith(new AutoFactoryProcessor()) + .compilesWithoutError() + .and().generatesSources( + JavaFileObjects.forResource("expected/SimpleClassVarargsDepsFactory.java")); + } @Test public void simpleClassProvidedDeps() { assertAbout(javaSources()) diff --git a/factory/src/test/resources/expected/SimpleClassVarargsDepsFactory.java b/factory/src/test/resources/expected/SimpleClassVarargsDepsFactory.java new file mode 100644 index 0000000000..6d51d802d0 --- /dev/null +++ b/factory/src/test/resources/expected/SimpleClassVarargsDepsFactory.java @@ -0,0 +1,33 @@ +/* + * 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 = "com.google.auto.factory.processor.AutoFactoryProcessor", + comments = "https://github.com/google/auto/tree/master/factory" +) +final class SimpleClassVarargsDepsFactory { + @Inject + SimpleClassVarargsDepsFactory() { + } + + SimpleClassVarargsDeps create(String... deps) { + return new SimpleClassVarargsDeps(deps); + } +} diff --git a/factory/src/test/resources/good/SimpleClassVarargsDeps.java b/factory/src/test/resources/good/SimpleClassVarargsDeps.java new file mode 100644 index 0000000000..8dffd308bc --- /dev/null +++ b/factory/src/test/resources/good/SimpleClassVarargsDeps.java @@ -0,0 +1,27 @@ +/* + * 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.auto.factory.AutoFactory; + +/** + * @author Matthias Muth + */ +@AutoFactory +class SimpleClassVarargsDeps{ + public SimpleClassVarargsDeps(String... deps) { + } +}