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 4891fd8c27..02a6507a31 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 @@ -29,6 +29,7 @@ import static javax.lang.model.element.Modifier.STATIC; import com.google.auto.common.MoreTypes; +import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSetMultimap; @@ -45,7 +46,6 @@ import com.squareup.javapoet.TypeSpec; import com.squareup.javapoet.TypeVariableName; import java.io.IOException; -import java.util.Iterator; import java.util.List; import javax.annotation.processing.Filer; import javax.annotation.processing.ProcessingEnvironment; @@ -121,9 +121,10 @@ private void addConstructorAndProviderFields( if (descriptor.publicType()) { constructor.addModifiers(PUBLIC); } - Iterator providerFields = descriptor.providers().values().iterator(); - for (int argumentIndex = 1; providerFields.hasNext(); argumentIndex++) { - ProviderField provider = providerFields.next(); + ImmutableCollection providerFields = descriptor.providers().values(); + int argumentNumber = 0; + for (ProviderField provider : providerFields) { + ++argumentNumber; TypeName typeName = resolveTypeName(provider.key().type().get()).box(); TypeName providerType = ParameterizedTypeName.get(ClassName.get(Provider.class), typeName); factory.addField(providerType, provider.name(), PRIVATE, FINAL); @@ -132,7 +133,11 @@ private void addConstructorAndProviderFields( providerType = providerType.annotated(AnnotationSpec.get(provider.key().qualifier().get())); } constructor.addParameter(providerType, provider.name()); - constructor.addStatement("this.$1L = checkNotNull($1L, $2L)", provider.name(), argumentIndex); + constructor.addStatement( + "this.$1L = checkNotNull($1L, $2L, $3L)", + provider.name(), + argumentNumber, + providerFields.size()); } factory.addMethod(constructor.build()); @@ -158,9 +163,13 @@ private void addFactoryMethods( methodDescriptor.exceptions().stream().map(TypeName::get).collect(toList())); CodeBlock.Builder args = CodeBlock.builder(); method.addParameters(parameters(methodDescriptor.passedParameters())); - Iterator parameters = methodDescriptor.creationParameters().iterator(); - for (int argumentIndex = 1; parameters.hasNext(); argumentIndex++) { - Parameter parameter = parameters.next(); + ImmutableSet parameters = methodDescriptor.creationParameters(); + int argumentNumber = 0; + String sep = ""; + for (Parameter parameter : parameters) { + ++argumentNumber; + args.add(sep); + sep = ", "; boolean checkNotNull = !parameter.nullable().isPresent(); CodeBlock argument; if (methodDescriptor.passedParameters().contains(parameter)) { @@ -179,12 +188,10 @@ private void addFactoryMethods( } } if (checkNotNull) { - argument = CodeBlock.of("checkNotNull($L, $L)", argument, argumentIndex); + argument = + CodeBlock.of("checkNotNull($L, $L, $L)", argument, argumentNumber, parameters.size()); } args.add(argument); - if (parameters.hasNext()) { - args.add(", "); - } } method.addStatement("return new $T($L)", methodDescriptor.returnType(), args.build()); factory.addMethod(method.build()); @@ -221,9 +228,7 @@ private ImmutableList parameters(Iterable parameters) for (Parameter parameter : parameters) { TypeName type = resolveTypeName(parameter.type().get()); ImmutableList annotations = - parameter.annotations().stream() - .map(AnnotationSpec::get) - .collect(toImmutableList()); + parameter.annotations().stream().map(AnnotationSpec::get).collect(toImmutableList()); ParameterSpec parameterSpec = ParameterSpec.builder(type, parameter.name()).addAnnotations(annotations).build(); builder.add(parameterSpec); @@ -241,13 +246,14 @@ private static void addCheckNotNullMethod( .addTypeVariable(typeVariable) .returns(typeVariable) .addParameter(typeVariable, "reference") - .addParameter(TypeName.INT, "argumentIndex") + .addParameter(TypeName.INT, "argumentNumber") + .addParameter(TypeName.INT, "argumentCount") .beginControlFlow("if (reference == null)") .addStatement( - "throw new $T($S + argumentIndex)", + "throw new $T($S + argumentNumber + $S + argumentCount)", NullPointerException.class, - "@AutoFactory method argument is null but is not marked @Nullable. Argument " - + "index: ") + "@AutoFactory method argument is null but is not marked @Nullable. Argument ", + " of ") .endControlFlow() .addStatement("return reference") .build()); @@ -269,15 +275,14 @@ private static boolean shouldGenerateCheckNotNull(FactoryDescriptor descriptor) } /** - * Returns an appropriate {@code TypeName} for the given type. If the type is an - * {@code ErrorType}, and if it is a simple-name reference to one of the {@code *Factory} - * classes that we are going to generate, then we return its fully-qualified name. In every other - * case we just return {@code TypeName.get(type)}. Specifically, if it is an {@code ErrorType} - * referencing some other type, or referencing one of the classes we are going to generate but - * using its fully-qualified name, then we leave it as-is. JavaPoet treats {@code TypeName.get(t)} - * the same for {@code ErrorType} as for {@code DeclaredType}, which means that if this is a name - * that will eventually be generated then the code we write that references the type will in fact - * compile. + * Returns an appropriate {@code TypeName} for the given type. If the type is an {@code + * ErrorType}, and if it is a simple-name reference to one of the {@code *Factory} classes that we + * are going to generate, then we return its fully-qualified name. In every other case we just + * return {@code TypeName.get(type)}. Specifically, if it is an {@code ErrorType} referencing some + * other type, or referencing one of the classes we are going to generate but using its + * fully-qualified name, then we leave it as-is. JavaPoet treats {@code TypeName.get(t)} the same + * for {@code ErrorType} as for {@code DeclaredType}, which means that if this is a name that will + * eventually be generated then the code we write that references the type will in fact compile. * *

A simpler alternative would be to defer processing to a later round if we find an * {@code @AutoFactory} class that references undefined types, under the assumption that something diff --git a/factory/src/test/resources/expected/CheckerFrameworkNullableFactory.java b/factory/src/test/resources/expected/CheckerFrameworkNullableFactory.java index 5a08020ef5..775bda076f 100644 --- a/factory/src/test/resources/expected/CheckerFrameworkNullableFactory.java +++ b/factory/src/test/resources/expected/CheckerFrameworkNullableFactory.java @@ -36,8 +36,9 @@ final class CheckerFrameworkNullableFactory { CheckerFrameworkNullableFactory( Provider java_lang_StringProvider, Provider> providedNestedNullableTypeProvider) { - this.java_lang_StringProvider = checkNotNull(java_lang_StringProvider, 1); - this.providedNestedNullableTypeProvider = checkNotNull(providedNestedNullableTypeProvider, 2); + this.java_lang_StringProvider = checkNotNull(java_lang_StringProvider, 1, 2); + this.providedNestedNullableTypeProvider = + checkNotNull(providedNestedNullableTypeProvider, 2, 2); } CheckerFrameworkNullable create( @@ -53,11 +54,13 @@ CheckerFrameworkNullable create( providedNestedNullableTypeProvider.get()); } - private static T checkNotNull(T reference, int argumentIndex) { + private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { if (reference == null) { throw new NullPointerException( - "@AutoFactory method argument is null but is not marked @Nullable. Argument index: " - + argumentIndex); + "@AutoFactory method argument is null but is not marked @Nullable. Argument " + + argumentNumber + + " of " + + argumentCount); } return reference; } diff --git a/factory/src/test/resources/expected/ClassUsingQualifierWithArgsFactory.java b/factory/src/test/resources/expected/ClassUsingQualifierWithArgsFactory.java index 7f29996959..4d9cc805e4 100644 --- a/factory/src/test/resources/expected/ClassUsingQualifierWithArgsFactory.java +++ b/factory/src/test/resources/expected/ClassUsingQualifierWithArgsFactory.java @@ -29,18 +29,20 @@ final class ClassUsingQualifierWithArgsFactory { @Inject ClassUsingQualifierWithArgsFactory( @QualifierWithArgs(name = "Fred", count = 3) Provider providedDepAProvider) { - this.providedDepAProvider = checkNotNull(providedDepAProvider, 1); + this.providedDepAProvider = checkNotNull(providedDepAProvider, 1, 1); } ClassUsingQualifierWithArgs create() { - return new ClassUsingQualifierWithArgs(checkNotNull(providedDepAProvider.get(), 1)); + return new ClassUsingQualifierWithArgs(checkNotNull(providedDepAProvider.get(), 1, 1)); } - private static T checkNotNull(T reference, int argumentIndex) { + private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { if (reference == null) { throw new NullPointerException( - "@AutoFactory method argument is null but is not marked @Nullable. Argument index: " - + argumentIndex); + "@AutoFactory method argument is null but is not marked @Nullable. Argument " + + argumentNumber + + " of " + + argumentCount); } return reference; } diff --git a/factory/src/test/resources/expected/ConstructorAnnotatedFactory.java b/factory/src/test/resources/expected/ConstructorAnnotatedFactory.java index 8f1715186f..aa8730c573 100644 --- a/factory/src/test/resources/expected/ConstructorAnnotatedFactory.java +++ b/factory/src/test/resources/expected/ConstructorAnnotatedFactory.java @@ -28,7 +28,7 @@ final class ConstructorAnnotatedFactory { @Inject ConstructorAnnotatedFactory(Provider objProvider) { - this.objProvider = checkNotNull(objProvider, 1); + this.objProvider = checkNotNull(objProvider, 1, 1); } ConstructorAnnotated create() { @@ -36,22 +36,24 @@ ConstructorAnnotated create() { } ConstructorAnnotated create(String s) { - return new ConstructorAnnotated(checkNotNull(s, 1)); + return new ConstructorAnnotated(checkNotNull(s, 1, 1)); } ConstructorAnnotated create(int i) { - return new ConstructorAnnotated(checkNotNull(objProvider.get(), 1), i); + return new ConstructorAnnotated(checkNotNull(objProvider.get(), 1, 2), i); } ConstructorAnnotated create(char c) { - return new ConstructorAnnotated(checkNotNull(objProvider.get(), 1), c); + return new ConstructorAnnotated(checkNotNull(objProvider.get(), 1, 2), c); } - private static T checkNotNull(T reference, int argumentIndex) { + private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { if (reference == null) { throw new NullPointerException( - "@AutoFactory method argument is null but is not marked @Nullable. Argument index: " - + argumentIndex); + "@AutoFactory method argument is null but is not marked @Nullable. Argument " + + argumentNumber + + " of " + + argumentCount); } return reference; } diff --git a/factory/src/test/resources/expected/ConstructorAnnotatedNonFinalFactory.java b/factory/src/test/resources/expected/ConstructorAnnotatedNonFinalFactory.java index 9678e40f05..6866ab35ae 100644 --- a/factory/src/test/resources/expected/ConstructorAnnotatedNonFinalFactory.java +++ b/factory/src/test/resources/expected/ConstructorAnnotatedNonFinalFactory.java @@ -28,7 +28,7 @@ class ConstructorAnnotatedNonFinalFactory { @Inject ConstructorAnnotatedNonFinalFactory(Provider objProvider) { - this.objProvider = checkNotNull(objProvider, 1); + this.objProvider = checkNotNull(objProvider, 1, 1); } ConstructorAnnotatedNonFinal create() { @@ -36,22 +36,24 @@ ConstructorAnnotatedNonFinal create() { } ConstructorAnnotatedNonFinal create(String s) { - return new ConstructorAnnotatedNonFinal(checkNotNull(s, 1)); + return new ConstructorAnnotatedNonFinal(checkNotNull(s, 1, 1)); } ConstructorAnnotatedNonFinal create(int i) { - return new ConstructorAnnotatedNonFinal(checkNotNull(objProvider.get(), 1), i); + return new ConstructorAnnotatedNonFinal(checkNotNull(objProvider.get(), 1, 2), i); } ConstructorAnnotatedNonFinal create(char c) { - return new ConstructorAnnotatedNonFinal(checkNotNull(objProvider.get(), 1), c); + return new ConstructorAnnotatedNonFinal(checkNotNull(objProvider.get(), 1, 2), c); } - private static T checkNotNull(T reference, int argumentIndex) { + private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { if (reference == null) { throw new NullPointerException( - "@AutoFactory method argument is null but is not marked @Nullable. Argument index: " - + argumentIndex); + "@AutoFactory method argument is null but is not marked @Nullable. Argument " + + argumentNumber + + " of " + + argumentCount); } return reference; } diff --git a/factory/src/test/resources/expected/ConstructorAnnotatedThrowsFactory.java b/factory/src/test/resources/expected/ConstructorAnnotatedThrowsFactory.java index c3718e648c..e84ff2fbdf 100644 --- a/factory/src/test/resources/expected/ConstructorAnnotatedThrowsFactory.java +++ b/factory/src/test/resources/expected/ConstructorAnnotatedThrowsFactory.java @@ -29,7 +29,7 @@ final class ConstructorAnnotatedThrowsFactory { @Inject ConstructorAnnotatedThrowsFactory(Provider objProvider) { - this.objProvider = checkNotNull(objProvider, 1); + this.objProvider = checkNotNull(objProvider, 1, 1); } ConstructorAnnotatedThrows create() throws IOException, InterruptedException { @@ -37,22 +37,24 @@ ConstructorAnnotatedThrows create() throws IOException, InterruptedException { } ConstructorAnnotatedThrows create(String s) { - return new ConstructorAnnotatedThrows(checkNotNull(s, 1)); + return new ConstructorAnnotatedThrows(checkNotNull(s, 1, 1)); } ConstructorAnnotatedThrows create(int i) throws IOException { - return new ConstructorAnnotatedThrows(checkNotNull(objProvider.get(), 1), i); + return new ConstructorAnnotatedThrows(checkNotNull(objProvider.get(), 1, 2), i); } ConstructorAnnotatedThrows create(char c) throws InterruptedException { - return new ConstructorAnnotatedThrows(checkNotNull(objProvider.get(), 1), c); + return new ConstructorAnnotatedThrows(checkNotNull(objProvider.get(), 1, 2), c); } - private static T checkNotNull(T reference, int argumentIndex) { + private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { if (reference == null) { throw new NullPointerException( - "@AutoFactory method argument is null but is not marked @Nullable. Argument index: " - + argumentIndex); + "@AutoFactory method argument is null but is not marked @Nullable. Argument " + + argumentNumber + + " of " + + argumentCount); } return reference; } diff --git a/factory/src/test/resources/expected/CustomNullableFactory.java b/factory/src/test/resources/expected/CustomNullableFactory.java index 343b27d6b4..964e9861ea 100644 --- a/factory/src/test/resources/expected/CustomNullableFactory.java +++ b/factory/src/test/resources/expected/CustomNullableFactory.java @@ -29,18 +29,20 @@ final class CustomNullableFactory { @Inject CustomNullableFactory(Provider objectProvider) { - this.objectProvider = checkNotNull(objectProvider, 1); + this.objectProvider = checkNotNull(objectProvider, 1, 1); } CustomNullable create(@CustomNullable.Nullable String string) { return new CustomNullable(string, objectProvider.get()); } - private static T checkNotNull(T reference, int argumentIndex) { + private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { if (reference == null) { throw new NullPointerException( - "@AutoFactory method argument is null but is not marked @Nullable. Argument index: " - + argumentIndex); + "@AutoFactory method argument is null but is not marked @Nullable. Argument " + + argumentNumber + + " of " + + argumentCount); } return reference; } diff --git a/factory/src/test/resources/expected/FactoryImplementingCreateMethod_ConcreteClassFactory.java b/factory/src/test/resources/expected/FactoryImplementingCreateMethod_ConcreteClassFactory.java index 3d6fbb9777..ecd41ab1f5 100644 --- a/factory/src/test/resources/expected/FactoryImplementingCreateMethod_ConcreteClassFactory.java +++ b/factory/src/test/resources/expected/FactoryImplementingCreateMethod_ConcreteClassFactory.java @@ -43,18 +43,20 @@ public FactoryImplementingCreateMethod.ConcreteClass create(int aDifferentArgume public FactoryImplementingCreateMethod.ConcreteClass create( List genericWithDifferentArgumentName) { return new FactoryImplementingCreateMethod.ConcreteClass( - checkNotNull(genericWithDifferentArgumentName, 1)); + checkNotNull(genericWithDifferentArgumentName, 1, 1)); } FactoryImplementingCreateMethod.ConcreteClass create(int a, boolean b) { return new FactoryImplementingCreateMethod.ConcreteClass(a, b); } - private static T checkNotNull(T reference, int argumentIndex) { + private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { if (reference == null) { throw new NullPointerException( - "@AutoFactory method argument is null but is not marked @Nullable. Argument index: " - + argumentIndex); + "@AutoFactory method argument is null but is not marked @Nullable. Argument " + + argumentNumber + + " of " + + argumentCount); } return reference; } diff --git a/factory/src/test/resources/expected/FactoryImplementingGenericInterfaceExtensionFactory.java b/factory/src/test/resources/expected/FactoryImplementingGenericInterfaceExtensionFactory.java index fdc21e8f35..5379bbdb0e 100644 --- a/factory/src/test/resources/expected/FactoryImplementingGenericInterfaceExtensionFactory.java +++ b/factory/src/test/resources/expected/FactoryImplementingGenericInterfaceExtensionFactory.java @@ -29,12 +29,12 @@ final class FactoryImplementingGenericInterfaceExtensionFactory @Inject FactoryImplementingGenericInterfaceExtensionFactory(Provider sProvider) { - this.sProvider = checkNotNull(sProvider, 1); + this.sProvider = checkNotNull(sProvider, 1, 1); } FactoryImplementingGenericInterfaceExtension create(Integer i) { return new FactoryImplementingGenericInterfaceExtension( - checkNotNull(sProvider.get(), 1), checkNotNull(i, 2)); + checkNotNull(sProvider.get(), 1, 2), checkNotNull(i, 2, 2)); } @Override @@ -42,11 +42,13 @@ public FactoryImplementingGenericInterfaceExtension make(Integer arg) { return create(arg); } - private static T checkNotNull(T reference, int argumentIndex) { + private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { if (reference == null) { throw new NullPointerException( - "@AutoFactory method argument is null but is not marked @Nullable. Argument index: " - + argumentIndex); + "@AutoFactory method argument is null but is not marked @Nullable. Argument " + + argumentNumber + + " of " + + argumentCount); } return reference; } diff --git a/factory/src/test/resources/expected/Generics_ExplicitFooImplFactory.java b/factory/src/test/resources/expected/Generics_ExplicitFooImplFactory.java index 77f2bef56d..69b0df34b2 100644 --- a/factory/src/test/resources/expected/Generics_ExplicitFooImplFactory.java +++ b/factory/src/test/resources/expected/Generics_ExplicitFooImplFactory.java @@ -29,19 +29,21 @@ final class Generics_ExplicitFooImplFactory @Inject Generics_ExplicitFooImplFactory(Provider unusedProvider) { - this.unusedProvider = checkNotNull(unusedProvider, 1); + this.unusedProvider = checkNotNull(unusedProvider, 1, 1); } @Override public Generics.ExplicitFooImpl create() { - return new Generics.ExplicitFooImpl(checkNotNull(unusedProvider.get(), 1)); + return new Generics.ExplicitFooImpl(checkNotNull(unusedProvider.get(), 1, 1)); } - private static T checkNotNull(T reference, int argumentIndex) { + private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { if (reference == null) { throw new NullPointerException( - "@AutoFactory method argument is null but is not marked @Nullable. Argument index: " - + argumentIndex); + "@AutoFactory method argument is null but is not marked @Nullable. Argument " + + argumentNumber + + " of " + + argumentCount); } return reference; } diff --git a/factory/src/test/resources/expected/MixedDepsImplementingInterfacesFactory.java b/factory/src/test/resources/expected/MixedDepsImplementingInterfacesFactory.java index 231fc1f897..12102bb1a6 100644 --- a/factory/src/test/resources/expected/MixedDepsImplementingInterfacesFactory.java +++ b/factory/src/test/resources/expected/MixedDepsImplementingInterfacesFactory.java @@ -35,15 +35,15 @@ final class MixedDepsImplementingInterfacesFactory @Inject MixedDepsImplementingInterfacesFactory(Provider sProvider) { - this.sProvider = checkNotNull(sProvider, 1); + this.sProvider = checkNotNull(sProvider, 1, 1); } MixedDepsImplementingInterfaces create(int i) { - return new MixedDepsImplementingInterfaces(checkNotNull(sProvider.get(), 1), i); + return new MixedDepsImplementingInterfaces(checkNotNull(sProvider.get(), 1, 2), i); } MixedDepsImplementingInterfaces create(Object o) { - return new MixedDepsImplementingInterfaces(checkNotNull(o, 1)); + return new MixedDepsImplementingInterfaces(checkNotNull(o, 1, 1)); } @Override @@ -56,11 +56,13 @@ public MixedDepsImplementingInterfaces fromObject(Object o) { return create(o); } - private static T checkNotNull(T reference, int argumentIndex) { + private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { if (reference == null) { throw new NullPointerException( - "@AutoFactory method argument is null but is not marked @Nullable. Argument index: " - + argumentIndex); + "@AutoFactory method argument is null but is not marked @Nullable. Argument " + + argumentNumber + + " of " + + argumentCount); } return reference; } diff --git a/factory/src/test/resources/expected/MultipleFactoriesConflictingParameterNamesFactory.java b/factory/src/test/resources/expected/MultipleFactoriesConflictingParameterNamesFactory.java index 39a203d9a5..529684ed16 100644 --- a/factory/src/test/resources/expected/MultipleFactoriesConflictingParameterNamesFactory.java +++ b/factory/src/test/resources/expected/MultipleFactoriesConflictingParameterNamesFactory.java @@ -36,33 +36,35 @@ final class MultipleFactoriesConflictingParameterNamesFactory { Provider java_lang_ObjectProvider, @AQualifier Provider stringProvider2, @AQualifier Provider _tests_AQualifier_java_lang_ObjectProvider) { - this.stringProvider = checkNotNull(stringProvider, 1); - this.java_lang_ObjectProvider = checkNotNull(java_lang_ObjectProvider, 2); - this.stringProvider2 = checkNotNull(stringProvider2, 3); + this.stringProvider = checkNotNull(stringProvider, 1, 4); + this.java_lang_ObjectProvider = checkNotNull(java_lang_ObjectProvider, 2, 4); + this.stringProvider2 = checkNotNull(stringProvider2, 3, 4); this._tests_AQualifier_java_lang_ObjectProvider = - checkNotNull(_tests_AQualifier_java_lang_ObjectProvider, 4); + checkNotNull(_tests_AQualifier_java_lang_ObjectProvider, 4, 4); } MultipleFactoriesConflictingParameterNames create(Object unused) { return new MultipleFactoriesConflictingParameterNames( - checkNotNull(stringProvider.get(), 1), - checkNotNull(java_lang_ObjectProvider.get(), 2), + checkNotNull(stringProvider.get(), 1, 4), + checkNotNull(java_lang_ObjectProvider.get(), 2, 4), java_lang_ObjectProvider, - checkNotNull(unused, 4)); + checkNotNull(unused, 4, 4)); } MultipleFactoriesConflictingParameterNames create() { return new MultipleFactoriesConflictingParameterNames( - checkNotNull(stringProvider2.get(), 1), - checkNotNull(_tests_AQualifier_java_lang_ObjectProvider.get(), 2), + checkNotNull(stringProvider2.get(), 1, 3), + checkNotNull(_tests_AQualifier_java_lang_ObjectProvider.get(), 2, 3), _tests_AQualifier_java_lang_ObjectProvider); } - private static T checkNotNull(T reference, int argumentIndex) { + private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { if (reference == null) { throw new NullPointerException( - "@AutoFactory method argument is null but is not marked @Nullable. Argument index: " - + argumentIndex); + "@AutoFactory method argument is null but is not marked @Nullable. Argument " + + argumentNumber + + " of " + + argumentCount); } return reference; } diff --git a/factory/src/test/resources/expected/MultipleProvidedParamsSameKeyFactory.java b/factory/src/test/resources/expected/MultipleProvidedParamsSameKeyFactory.java index daf273bbbe..7a8eb97c6e 100644 --- a/factory/src/test/resources/expected/MultipleProvidedParamsSameKeyFactory.java +++ b/factory/src/test/resources/expected/MultipleProvidedParamsSameKeyFactory.java @@ -28,23 +28,25 @@ final class MultipleProvidedParamsSameKeyFactory { @Inject MultipleProvidedParamsSameKeyFactory(Provider java_lang_StringProvider) { - this.java_lang_StringProvider = checkNotNull(java_lang_StringProvider, 1); + this.java_lang_StringProvider = checkNotNull(java_lang_StringProvider, 1, 1); } MultipleProvidedParamsSameKey create() { return new MultipleProvidedParamsSameKey( - checkNotNull(java_lang_StringProvider.get(), 1), - checkNotNull(java_lang_StringProvider.get(), 2), + checkNotNull(java_lang_StringProvider.get(), 1, 5), + checkNotNull(java_lang_StringProvider.get(), 2, 5), java_lang_StringProvider.get(), java_lang_StringProvider, java_lang_StringProvider); } - private static T checkNotNull(T reference, int argumentIndex) { + private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { if (reference == null) { throw new NullPointerException( - "@AutoFactory method argument is null but is not marked @Nullable. Argument index: " - + argumentIndex); + "@AutoFactory method argument is null but is not marked @Nullable. Argument " + + argumentNumber + + " of " + + argumentCount); } return reference; } diff --git a/factory/src/test/resources/expected/ParameterAnnotationsFactory.java b/factory/src/test/resources/expected/ParameterAnnotationsFactory.java index a2e251b7ff..a238a9d287 100644 --- a/factory/src/test/resources/expected/ParameterAnnotationsFactory.java +++ b/factory/src/test/resources/expected/ParameterAnnotationsFactory.java @@ -28,7 +28,7 @@ final class ParameterAnnotationsFactory { @Inject ParameterAnnotationsFactory(Provider<@ParameterAnnotations.NullableType String> fooProvider) { - this.fooProvider = checkNotNull(fooProvider, 1); + this.fooProvider = checkNotNull(fooProvider, 1, 1); } ParameterAnnotations create( @@ -37,18 +37,20 @@ ParameterAnnotations create( @ParameterAnnotations.NullableType Thread buh, @ParameterAnnotations.NullableParameterAndType String quux) { return new ParameterAnnotations( - checkNotNull(fooProvider.get(), 1), - checkNotNull(bar, 2), + checkNotNull(fooProvider.get(), 1, 5), + checkNotNull(bar, 2, 5), baz, - checkNotNull(buh, 4), - checkNotNull(quux, 5)); + checkNotNull(buh, 4, 5), + checkNotNull(quux, 5, 5)); } - private static T checkNotNull(T reference, int argumentIndex) { + private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { if (reference == null) { throw new NullPointerException( - "@AutoFactory method argument is null but is not marked @Nullable. Argument index: " - + argumentIndex); + "@AutoFactory method argument is null but is not marked @Nullable. Argument " + + argumentNumber + + " of " + + argumentCount); } return reference; } diff --git a/factory/src/test/resources/expected/ProviderArgumentToCreateMethodFactory.java b/factory/src/test/resources/expected/ProviderArgumentToCreateMethodFactory.java index 4a74b1320e..224e38d00a 100644 --- a/factory/src/test/resources/expected/ProviderArgumentToCreateMethodFactory.java +++ b/factory/src/test/resources/expected/ProviderArgumentToCreateMethodFactory.java @@ -29,7 +29,7 @@ final class ProviderArgumentToCreateMethodFactory ProviderArgumentToCreateMethodFactory() {} ProviderArgumentToCreateMethod create(Provider stringProvider) { - return new ProviderArgumentToCreateMethod(checkNotNull(stringProvider, 1)); + return new ProviderArgumentToCreateMethod(checkNotNull(stringProvider, 1, 1)); } @Override @@ -37,11 +37,13 @@ public ProviderArgumentToCreateMethod newInstance(Provider stringProvide return create(stringProvider); } - private static T checkNotNull(T reference, int argumentIndex) { + private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { if (reference == null) { throw new NullPointerException( - "@AutoFactory method argument is null but is not marked @Nullable. Argument index: " - + argumentIndex); + "@AutoFactory method argument is null but is not marked @Nullable. Argument " + + argumentNumber + + " of " + + argumentCount); } return reference; } diff --git a/factory/src/test/resources/expected/SimpleClassMixedDepsFactory.java b/factory/src/test/resources/expected/SimpleClassMixedDepsFactory.java index 64b5c82782..3e00e55088 100644 --- a/factory/src/test/resources/expected/SimpleClassMixedDepsFactory.java +++ b/factory/src/test/resources/expected/SimpleClassMixedDepsFactory.java @@ -28,19 +28,21 @@ final class SimpleClassMixedDepsFactory { @Inject SimpleClassMixedDepsFactory(@AQualifier Provider providedDepAProvider) { - this.providedDepAProvider = checkNotNull(providedDepAProvider, 1); + this.providedDepAProvider = checkNotNull(providedDepAProvider, 1, 1); } SimpleClassMixedDeps create(String depB) { return new SimpleClassMixedDeps( - checkNotNull(providedDepAProvider.get(), 1), checkNotNull(depB, 2)); + checkNotNull(providedDepAProvider.get(), 1, 2), checkNotNull(depB, 2, 2)); } - private static T checkNotNull(T reference, int argumentIndex) { + private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { if (reference == null) { throw new NullPointerException( - "@AutoFactory method argument is null but is not marked @Nullable. Argument index: " - + argumentIndex); + "@AutoFactory method argument is null but is not marked @Nullable. Argument " + + argumentNumber + + " of " + + argumentCount); } return reference; } diff --git a/factory/src/test/resources/expected/SimpleClassNullableParametersFactory.java b/factory/src/test/resources/expected/SimpleClassNullableParametersFactory.java index 4bf0677428..b200daa1e9 100644 --- a/factory/src/test/resources/expected/SimpleClassNullableParametersFactory.java +++ b/factory/src/test/resources/expected/SimpleClassNullableParametersFactory.java @@ -33,8 +33,8 @@ final class SimpleClassNullableParametersFactory { SimpleClassNullableParametersFactory( Provider providedNullableProvider, @BQualifier Provider providedQualifiedNullableProvider) { - this.providedNullableProvider = checkNotNull(providedNullableProvider, 1); - this.providedQualifiedNullableProvider = checkNotNull(providedQualifiedNullableProvider, 2); + this.providedNullableProvider = checkNotNull(providedNullableProvider, 1, 2); + this.providedQualifiedNullableProvider = checkNotNull(providedQualifiedNullableProvider, 2, 2); } SimpleClassNullableParameters create( @@ -46,11 +46,13 @@ SimpleClassNullableParameters create( providedQualifiedNullableProvider.get()); } - private static T checkNotNull(T reference, int argumentIndex) { + private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { if (reference == null) { throw new NullPointerException( - "@AutoFactory method argument is null but is not marked @Nullable. Argument index: " - + argumentIndex); + "@AutoFactory method argument is null but is not marked @Nullable. Argument " + + argumentNumber + + " of " + + argumentCount); } return reference; } diff --git a/factory/src/test/resources/expected/SimpleClassPassedDepsFactory.java b/factory/src/test/resources/expected/SimpleClassPassedDepsFactory.java index f00aa8b2ea..abc922308b 100644 --- a/factory/src/test/resources/expected/SimpleClassPassedDepsFactory.java +++ b/factory/src/test/resources/expected/SimpleClassPassedDepsFactory.java @@ -27,14 +27,16 @@ final class SimpleClassPassedDepsFactory { SimpleClassPassedDepsFactory() {} SimpleClassPassedDeps create(String depA, String depB) { - return new SimpleClassPassedDeps(checkNotNull(depA, 1), checkNotNull(depB, 2)); + return new SimpleClassPassedDeps(checkNotNull(depA, 1, 2), checkNotNull(depB, 2, 2)); } - private static T checkNotNull(T reference, int argumentIndex) { + private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { if (reference == null) { throw new NullPointerException( - "@AutoFactory method argument is null but is not marked @Nullable. Argument index: " - + argumentIndex); + "@AutoFactory method argument is null but is not marked @Nullable. Argument " + + argumentNumber + + " of " + + argumentCount); } return reference; } diff --git a/factory/src/test/resources/expected/SimpleClassProvidedDepsFactory.java b/factory/src/test/resources/expected/SimpleClassProvidedDepsFactory.java index 766689d6bd..31a21aade3 100644 --- a/factory/src/test/resources/expected/SimpleClassProvidedDepsFactory.java +++ b/factory/src/test/resources/expected/SimpleClassProvidedDepsFactory.java @@ -35,25 +35,27 @@ final class SimpleClassProvidedDepsFactory { @BQualifier Provider providedPrimitiveBProvider, @AQualifier Provider providedDepAProvider, @BQualifier Provider providedDepBProvider) { - this.providedPrimitiveAProvider = checkNotNull(providedPrimitiveAProvider, 1); - this.providedPrimitiveBProvider = checkNotNull(providedPrimitiveBProvider, 2); - this.providedDepAProvider = checkNotNull(providedDepAProvider, 3); - this.providedDepBProvider = checkNotNull(providedDepBProvider, 4); + this.providedPrimitiveAProvider = checkNotNull(providedPrimitiveAProvider, 1, 4); + this.providedPrimitiveBProvider = checkNotNull(providedPrimitiveBProvider, 2, 4); + this.providedDepAProvider = checkNotNull(providedDepAProvider, 3, 4); + this.providedDepBProvider = checkNotNull(providedDepBProvider, 4, 4); } SimpleClassProvidedDeps create() { return new SimpleClassProvidedDeps( - checkNotNull(providedPrimitiveAProvider.get(), 1), - checkNotNull(providedPrimitiveBProvider.get(), 2), - checkNotNull(providedDepAProvider.get(), 3), - checkNotNull(providedDepBProvider.get(), 4)); + checkNotNull(providedPrimitiveAProvider.get(), 1, 4), + checkNotNull(providedPrimitiveBProvider.get(), 2, 4), + checkNotNull(providedDepAProvider.get(), 3, 4), + checkNotNull(providedDepBProvider.get(), 4, 4)); } - private static T checkNotNull(T reference, int argumentIndex) { + private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { if (reference == null) { throw new NullPointerException( - "@AutoFactory method argument is null but is not marked @Nullable. Argument index: " - + argumentIndex); + "@AutoFactory method argument is null but is not marked @Nullable. Argument " + + argumentNumber + + " of " + + argumentCount); } return reference; } diff --git a/factory/src/test/resources/expected/SimpleClassProvidedProviderDepsFactory.java b/factory/src/test/resources/expected/SimpleClassProvidedProviderDepsFactory.java index e0f990afd2..aec94301d2 100644 --- a/factory/src/test/resources/expected/SimpleClassProvidedProviderDepsFactory.java +++ b/factory/src/test/resources/expected/SimpleClassProvidedProviderDepsFactory.java @@ -31,19 +31,21 @@ final class SimpleClassProvidedProviderDepsFactory { SimpleClassProvidedProviderDepsFactory( @AQualifier Provider providedDepAProvider, @BQualifier Provider providedDepBProvider) { - this.providedDepAProvider = checkNotNull(providedDepAProvider, 1); - this.providedDepBProvider = checkNotNull(providedDepBProvider, 2); + this.providedDepAProvider = checkNotNull(providedDepAProvider, 1, 2); + this.providedDepBProvider = checkNotNull(providedDepBProvider, 2, 2); } SimpleClassProvidedProviderDeps create() { return new SimpleClassProvidedProviderDeps(providedDepAProvider, providedDepBProvider); } - private static T checkNotNull(T reference, int argumentIndex) { + private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { if (reference == null) { throw new NullPointerException( - "@AutoFactory method argument is null but is not marked @Nullable. Argument index: " - + argumentIndex); + "@AutoFactory method argument is null but is not marked @Nullable. Argument " + + argumentNumber + + " of " + + argumentCount); } return reference; } diff --git a/factory/src/test/resources/expected/SimpleClassVarargsFactory.java b/factory/src/test/resources/expected/SimpleClassVarargsFactory.java index 3303f7f110..99deab31fc 100644 --- a/factory/src/test/resources/expected/SimpleClassVarargsFactory.java +++ b/factory/src/test/resources/expected/SimpleClassVarargsFactory.java @@ -27,7 +27,7 @@ final class SimpleClassVarargsFactory implements SimpleClassVarargs.InterfaceWit SimpleClassVarargsFactory() {} SimpleClassVarargs create(String... args) { - return new SimpleClassVarargs(checkNotNull(args, 1)); + return new SimpleClassVarargs(checkNotNull(args, 1, 1)); } @Override @@ -35,11 +35,13 @@ public SimpleClassVarargs build(String... args) { return create(args); } - private static T checkNotNull(T reference, int argumentIndex) { + private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { if (reference == null) { throw new NullPointerException( - "@AutoFactory method argument is null but is not marked @Nullable. Argument index: " - + argumentIndex); + "@AutoFactory method argument is null but is not marked @Nullable. Argument " + + argumentNumber + + " of " + + argumentCount); } return reference; }