├── .github ├── dependabot.yml └── workflows │ └── ci.yml ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── build-pom.xml ├── common ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── google │ │ └── auto │ │ └── common │ │ ├── AnnotationMirrors.java │ │ ├── AnnotationOutput.java │ │ ├── AnnotationValues.java │ │ ├── BasicAnnotationProcessor.java │ │ ├── GeneratedAnnotationSpecs.java │ │ ├── GeneratedAnnotations.java │ │ ├── MoreElements.java │ │ ├── MoreStreams.java │ │ ├── MoreTypes.java │ │ ├── Overrides.java │ │ ├── SimpleAnnotationMirror.java │ │ ├── SimpleTypeAnnotationValue.java │ │ ├── SuperficialValidation.java │ │ ├── Visibility.java │ │ └── package-info.java │ └── test │ └── java │ └── com │ └── google │ └── auto │ └── common │ ├── AnnotationMirrorsTest.java │ ├── AnnotationValuesTest.java │ ├── BasicAnnotationProcessorTest.java │ ├── GeneratedAnnotationsTest.java │ ├── MoreElementsTest.java │ ├── MoreTypesIsTypeOfTest.java │ ├── MoreTypesTest.java │ ├── OverridesTest.java │ ├── SimpleAnnotationMirrorTest.java │ ├── SimpleTypeAnnotationValueTest.java │ ├── SuperficialValidationTest.java │ └── VisibilityTest.java ├── factory ├── README.md ├── pom.xml └── src │ ├── it │ └── functional │ │ ├── pom.xml │ │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── google │ │ │ └── auto │ │ │ └── factory │ │ │ ├── DaggerModule.java │ │ │ ├── Dependency.java │ │ │ ├── DependencyImpl.java │ │ │ ├── FactoryComponent.java │ │ │ ├── FactoryInterface.java │ │ │ ├── Foo.java │ │ │ ├── GenericFoo.java │ │ │ ├── GuiceModule.java │ │ │ ├── QualifiedDependencyImpl.java │ │ │ ├── Qualifier.java │ │ │ ├── ReferencePackage.java │ │ │ └── otherpackage │ │ │ └── OtherPackage.java │ │ └── test │ │ └── java │ │ └── com │ │ └── google │ │ └── auto │ │ └── factory │ │ └── DependencyInjectionIntegrationTest.java │ ├── main │ └── java │ │ └── com │ │ └── google │ │ └── auto │ │ └── factory │ │ ├── AutoFactory.java │ │ ├── Provided.java │ │ ├── package-info.java │ │ └── processor │ │ ├── AnnotationValues.java │ │ ├── AutoFactoryDeclaration.java │ │ ├── AutoFactoryProcessor.java │ │ ├── Elements2.java │ │ ├── FactoryDescriptor.java │ │ ├── FactoryDescriptorGenerator.java │ │ ├── FactoryMethodDescriptor.java │ │ ├── FactoryWriter.java │ │ ├── ImplementationMethodDescriptor.java │ │ ├── InjectApi.java │ │ ├── Key.java │ │ ├── Mirrors.java │ │ ├── PackageAndClass.java │ │ ├── Parameter.java │ │ ├── ProvidedChecker.java │ │ ├── ProviderField.java │ │ ├── TypeVariables.java │ │ └── package-info.java │ └── test │ ├── java │ └── com │ │ └── google │ │ └── auto │ │ └── factory │ │ └── processor │ │ ├── AutoFactoryDeclarationTest.java │ │ ├── AutoFactoryProcessorNegativeTest.java │ │ └── AutoFactoryProcessorTest.java │ └── resources │ ├── bad │ ├── AnnotationsToApplyMultiple.java │ ├── AnnotationsToApplyNotAnnotations.java │ ├── AnnotationsToApplyRepeated.java │ ├── EnumSupertype.java │ ├── FactoryExtendingAbstractClassWithConstructorParams.java │ ├── FinalSupertype.java │ ├── InterfaceSupertype.java │ ├── InvalidCustomName.java │ ├── MixedFinals.java │ ├── ProvidedButNoAutoFactory.java │ └── ProvidedOnMethodParameter.java │ ├── expected │ ├── CheckerFrameworkNullableFactory.java │ ├── ClassUsingQualifierWithArgsFactory.java │ ├── ConstructorAnnotatedFactory.java │ ├── ConstructorAnnotatedNonFinalFactory.java │ ├── ConstructorAnnotatedThrowsFactory.java │ ├── CustomAnnotationsFactory.java │ ├── CustomNamedFactory.java │ ├── CustomNullableFactory.java │ ├── DefaultPackageFactory.java │ ├── FactoryExtendingAbstractClassFactory.java │ ├── FactoryExtendingAbstractClassThrowsFactory.java │ ├── FactoryImplementingCreateMethod_ConcreteClassFactory.java │ ├── FactoryImplementingGenericInterfaceExtensionFactory.java │ ├── Generics_ExplicitFooImplFactory.java │ ├── Generics_FooImplFactory.java │ ├── Generics_FooImplWithClassFactory.java │ ├── MixedDepsImplementingInterfacesFactory.java │ ├── MultipleFactoriesConflictingParameterNamesFactory.java │ ├── MultipleFactoriesImplementingInterface_ClassAFactory.java │ ├── MultipleFactoriesImplementingInterface_ClassBFactory.java │ ├── MultipleProvidedParamsSameKeyFactory.java │ ├── NestedClassCustomNamedFactory.java │ ├── NestedClasses_SimpleNestedClassFactory.java │ ├── OnlyPrimitivesFactory.java │ ├── ParameterAnnotationsFactory.java │ ├── ProviderArgumentToCreateMethodFactory.java │ ├── PublicClassFactory.java │ ├── SimpleClassFactory.java │ ├── SimpleClassImplementingMarkerFactory.java │ ├── SimpleClassImplementingSimpleInterfaceFactory.java │ ├── SimpleClassMixedDepsFactory.java │ ├── SimpleClassNonFinalFactory.java │ ├── SimpleClassNullableParametersFactory.java │ ├── SimpleClassPassedDepsFactory.java │ ├── SimpleClassProvidedDepsFactory.java │ ├── SimpleClassProvidedProviderDepsFactory.java │ ├── SimpleClassThrowsFactory.java │ └── SimpleClassVarargsFactory.java │ ├── good │ ├── CheckerFrameworkNullable.java │ ├── ClassUsingQualifierWithArgs.java │ ├── ConstructorAnnotated.java │ ├── ConstructorAnnotatedNonFinal.java │ ├── ConstructorAnnotatedThrows.java │ ├── CustomAnnotations.java │ ├── CustomNullable.java │ ├── DefaultPackage.java │ ├── FactoryExtendingAbstractClass.java │ ├── FactoryExtendingAbstractClassThrows.java │ ├── FactoryExtendingAbstractClassWithMultipleConstructors.java │ ├── FactoryImplementingCreateMethod.java │ ├── FactoryImplementingGenericInterfaceExtension.java │ ├── Generics.java │ ├── MixedDepsImplementingInterfaces.java │ ├── MultipleFactoriesConflictingParameterNames.java │ ├── MultipleFactoriesImplementingInterface.java │ ├── MultipleProvidedParamsSameKey.java │ ├── NestedClasses.java │ ├── OnlyPrimitives.java │ ├── ParameterAnnotations.java │ ├── ProviderArgumentToCreateMethod.java │ ├── PublicClass.java │ ├── SimpleClass.java │ ├── SimpleClassCustomName.java │ ├── SimpleClassImplementingMarker.java │ ├── SimpleClassImplementingSimpleInterface.java │ ├── SimpleClassMixedDeps.java │ ├── SimpleClassNonFinal.java │ ├── SimpleClassNullableParameters.java │ ├── SimpleClassPassedDeps.java │ ├── SimpleClassProvidedDeps.java │ ├── SimpleClassProvidedProviderDeps.java │ ├── SimpleClassThrows.java │ └── SimpleClassVarargs.java │ └── support │ ├── AQualifier.java │ ├── BQualifier.java │ └── QualifierWithArgs.java ├── service ├── README.md ├── annotations │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── google │ │ └── auto │ │ └── service │ │ └── AutoService.java ├── pom.xml └── processor │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── google │ │ │ └── auto │ │ │ └── service │ │ │ └── processor │ │ │ ├── AutoServiceProcessor.java │ │ │ ├── ServicesFiles.java │ │ │ └── package-info.java │ └── resources │ │ └── META-INF │ │ ├── gradle │ │ └── incremental.annotation.processors │ │ └── services │ │ └── javax.annotation.processing.Processor │ └── test │ ├── java │ └── com │ │ └── google │ │ └── auto │ │ └── service │ │ └── processor │ │ └── AutoServiceProcessorTest.java │ └── resources │ ├── META-INF │ └── services │ │ ├── test.AnotherService │ │ └── test.SomeService │ └── test │ ├── AnotherService.java │ ├── AnotherServiceProvider.java │ ├── AutoServiceOnAbstractClass.java │ ├── AutoServiceOnInterface.java │ ├── DoesNotImplement.java │ ├── DoesNotImplementSuppressed.java │ ├── Enclosing.java │ ├── EnclosingGeneric.java │ ├── GenericService.java │ ├── GenericServiceProvider.java │ ├── GenericServiceProviderSuppressWarnings.java │ ├── GenericServiceProviderWithMissingServiceClass.java │ ├── MultiServiceProvider.java │ ├── NoServices.java │ ├── SomeService.java │ ├── SomeServiceProvider1.java │ └── SomeServiceProvider2.java ├── util ├── generate-latest-docs.sh └── publish-snapshot-on-commit.sh └── value ├── CHANGES.md ├── README.md ├── annotations └── pom.xml ├── pom.xml ├── processor └── pom.xml ├── src ├── it │ ├── functional │ │ ├── invoker.properties │ │ ├── pom.xml │ │ └── src │ │ │ ├── main │ │ │ └── java │ │ │ │ ├── PackagelessNestedValueType.java │ │ │ │ ├── PackagelessValueType.java │ │ │ │ └── com │ │ │ │ └── google │ │ │ │ └── auto │ │ │ │ └── value │ │ │ │ ├── NestedValueType.java │ │ │ │ └── SimpleValueType.java │ │ │ └── test │ │ │ └── java │ │ │ ├── PackagelessValueTypeTest.java │ │ │ └── com │ │ │ └── google │ │ │ └── auto │ │ │ └── value │ │ │ ├── AutoAnnotationDefaultsTest.java │ │ │ ├── AutoAnnotationTest.java │ │ │ ├── AutoBuilderKotlinTest.java │ │ │ ├── AutoBuilderTest.java │ │ │ ├── AutoOneOfJava8Test.java │ │ │ ├── AutoOneOfTest.java │ │ │ ├── AutoValueJava8Test.java │ │ │ ├── AutoValueNotEclipseTest.java │ │ │ ├── AutoValueTest.java │ │ │ ├── CompileWithEclipseTest.java │ │ │ ├── GradleIT.java │ │ │ ├── KotlinData.kt │ │ │ ├── SimpleValueTypeTest.java │ │ │ ├── annotations │ │ │ ├── Empty.java │ │ │ ├── GwtArrays.java │ │ │ ├── StringValues.java │ │ │ └── TestAnnotation.java │ │ │ ├── enums │ │ │ └── MyEnum.java │ │ │ └── gwt │ │ │ ├── CustomFieldSerializerTest.java │ │ │ ├── EmptyExtension.java │ │ │ ├── GwtCompilationTest.java │ │ │ ├── GwtValueType.java │ │ │ ├── GwtValueTypeWithBuilder.java │ │ │ ├── NonSerializableGwtValueType.java │ │ │ └── SerialSignatureTest.java │ └── gwtserializer │ │ ├── invoker.properties │ │ ├── pom.xml │ │ └── src │ │ └── test │ │ └── java │ │ └── com │ │ └── google │ │ └── auto │ │ └── value │ │ ├── GwtSerializerSuite.gwt.xml │ │ ├── GwtSerializerSuite.java │ │ └── client │ │ └── GwtSerializerTest.java ├── main │ └── java │ │ └── com │ │ └── google │ │ └── auto │ │ └── value │ │ ├── AutoAnnotation.java │ │ ├── AutoBuilder.java │ │ ├── AutoOneOf.java │ │ ├── AutoValue.java │ │ ├── extension │ │ ├── AutoValueExtension.java │ │ ├── memoized │ │ │ ├── Memoized.java │ │ │ └── processor │ │ │ │ ├── ClassNames.java │ │ │ │ ├── MemoizeExtension.java │ │ │ │ └── MemoizedValidator.java │ │ ├── serializable │ │ │ ├── SerializableAutoValue.java │ │ │ ├── g3doc │ │ │ │ ├── index.md │ │ │ │ └── serializer-extension.md │ │ │ ├── processor │ │ │ │ ├── ClassNames.java │ │ │ │ ├── PropertyMirror.java │ │ │ │ └── SerializableAutoValueExtension.java │ │ │ └── serializer │ │ │ │ ├── SerializerFactoryLoader.java │ │ │ │ ├── impl │ │ │ │ ├── IdentitySerializerFactory.java │ │ │ │ ├── ImmutableListSerializerExtension.java │ │ │ │ ├── ImmutableMapSerializerExtension.java │ │ │ │ ├── OptionalSerializerExtension.java │ │ │ │ └── SerializerFactoryImpl.java │ │ │ │ ├── interfaces │ │ │ │ ├── Serializer.java │ │ │ │ ├── SerializerExtension.java │ │ │ │ └── SerializerFactory.java │ │ │ │ └── runtime │ │ │ │ └── FunctionWithExceptions.java │ │ └── toprettystring │ │ │ ├── ToPrettyString.java │ │ │ └── processor │ │ │ ├── Annotations.java │ │ │ ├── ClassNames.java │ │ │ ├── ExtensionClassTypeSpecBuilder.java │ │ │ ├── ToPrettyStringExtension.java │ │ │ ├── ToPrettyStringMethods.java │ │ │ └── ToPrettyStringValidator.java │ │ └── processor │ │ ├── AbortProcessingException.java │ │ ├── AnnotatedTypeMirror.java │ │ ├── AnnotationOutput.java │ │ ├── AutoAnnotationProcessor.java │ │ ├── AutoAnnotationTemplateVars.java │ │ ├── AutoBuilderAnnotationTemplateVars.java │ │ ├── AutoBuilderProcessor.java │ │ ├── AutoBuilderTemplateVars.java │ │ ├── AutoOneOfProcessor.java │ │ ├── AutoOneOfTemplateVars.java │ │ ├── AutoValueBuilderProcessor.java │ │ ├── AutoValueOrBuilderTemplateVars.java │ │ ├── AutoValueProcessor.java │ │ ├── AutoValueTemplateVars.java │ │ ├── AutoValueishProcessor.java │ │ ├── AutoValueishTemplateVars.java │ │ ├── BuilderMethodClassifier.java │ │ ├── BuilderMethodClassifierForAutoBuilder.java │ │ ├── BuilderMethodClassifierForAutoValue.java │ │ ├── BuilderRequiredProperties.java │ │ ├── BuilderSpec.java │ │ ├── ClassNames.java │ │ ├── EclipseHack.java │ │ ├── ErrorReporter.java │ │ ├── Executable.java │ │ ├── ExtensionContext.java │ │ ├── ForwardingClassGenerator.java │ │ ├── GwtCompatibility.java │ │ ├── GwtSerialization.java │ │ ├── JavaScanner.java │ │ ├── KotlinMetadata.java │ │ ├── MethodSignature.java │ │ ├── MissingTypes.java │ │ ├── Nullables.java │ │ ├── Optionalish.java │ │ ├── PropertyBuilderClassifier.java │ │ ├── PropertyNames.java │ │ ├── Reformatter.java │ │ ├── SimpleMethod.java │ │ ├── SimpleServiceLoader.java │ │ ├── TemplateVars.java │ │ ├── TypeEncoder.java │ │ ├── TypeMirrorSet.java │ │ ├── TypeSimplifier.java │ │ ├── TypeVariables.java │ │ ├── autoannotation.vm │ │ ├── autobuilder.vm │ │ ├── autobuilderannotation.vm │ │ ├── autooneof.vm │ │ ├── autovalue.vm │ │ ├── builder.vm │ │ ├── equalshashcode.vm │ │ ├── gwtserializer.vm │ │ └── package-info.java └── test │ └── java │ └── com │ └── google │ └── auto │ └── value │ ├── extension │ ├── memoized │ │ ├── MemoizedMethodSubject.java │ │ ├── MemoizedMethodSubjectFactory.java │ │ ├── MemoizedTest.java │ │ └── MemoizedValidationTest.java │ ├── serializable │ │ ├── processor │ │ │ └── SerializableAutoValueExtensionTest.java │ │ └── serializer │ │ │ ├── SerializerFactoryLoaderTest.java │ │ │ ├── impl │ │ │ ├── IdentitySerializerFactoryTest.java │ │ │ ├── ImmutableListSerializerExtensionTest.java │ │ │ ├── ImmutableMapSerializerExtensionTest.java │ │ │ ├── OptionalSerializerExtensionTest.java │ │ │ └── SerializerFactoryImplTest.java │ │ │ └── utils │ │ │ ├── CompilationAbstractTest.java │ │ │ ├── FakeSerializerFactory.java │ │ │ └── TestStringSerializerFactory.java │ └── toprettystring │ │ ├── ToPrettyStringTest.java │ │ └── ToPrettyStringValidatorTest.java │ └── processor │ ├── AutoAnnotationCompilationTest.java │ ├── AutoAnnotationErrorsTest.java │ ├── AutoBuilderCompilationTest.java │ ├── AutoOneOfCompilationTest.java │ ├── AutoValueCompilationTest.java │ ├── BuilderRequiredPropertiesTest.java │ ├── ExtensionTest.java │ ├── ForwardingClassGeneratorTest.java │ ├── GeneratedDoesNotExistTest.java │ ├── GeneratedImport.java │ ├── GuavaCollectionBuildersTest.java │ ├── IncrementalExtensionTest.java │ ├── JavaScannerTest.java │ ├── NullablesTest.java │ ├── PropertyAnnotationsTest.java │ ├── PropertyNamesTest.java │ ├── ReformatterTest.java │ ├── SimpleServiceLoaderTest.java │ ├── SimplifyWithAnnotationsTest.java │ ├── TemplateVarsTest.java │ ├── TypeEncoderTest.java │ ├── TypeSimplifierTest.java │ ├── TypeVariablesTest.java │ └── testclasses │ └── RuntimePermission.java └── userguide ├── autobuilder.md ├── builders-howto.md ├── builders.md ├── design-faq.md ├── extensions.md ├── generated-builder-example.md ├── generated-example.md ├── howto.md ├── index.md ├── performance.md ├── practices.md ├── records.md ├── trouble.md └── why.md /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "maven" 4 | directory: "/common" 5 | schedule: 6 | interval: "weekly" 7 | groups: 8 | dependencies: 9 | applies-to: version-updates 10 | patterns: 11 | - "*" 12 | - package-ecosystem: "maven" 13 | directory: "/factory" 14 | schedule: 15 | interval: "weekly" 16 | groups: 17 | dependencies: 18 | applies-to: version-updates 19 | patterns: 20 | - "*" 21 | - package-ecosystem: "maven" 22 | directory: "/service" 23 | schedule: 24 | interval: "weekly" 25 | groups: 26 | dependencies: 27 | applies-to: version-updates 28 | patterns: 29 | - "*" 30 | - package-ecosystem: "maven" 31 | directory: "/value" 32 | schedule: 33 | interval: "weekly" 34 | groups: 35 | dependencies: 36 | applies-to: version-updates 37 | patterns: 38 | - "*" 39 | - package-ecosystem: "github-actions" 40 | directory: "/" 41 | schedule: 42 | interval: "monthly" 43 | groups: 44 | github-actions: 45 | applies-to: version-updates 46 | patterns: 47 | - "*" 48 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .factorypath 3 | .project 4 | .settings 5 | eclipsebin 6 | 7 | bin 8 | gen 9 | build 10 | out 11 | lib 12 | 13 | target 14 | *.class 15 | pom.xml.* 16 | release.properties 17 | 18 | .idea 19 | *.iml 20 | classes 21 | 22 | obj 23 | 24 | .DS_Store 25 | *~ 26 | dependency-reduced-pom.xml 27 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ============ 3 | 4 | If you would like to contribute code to Auto you can do so through GitHub 5 | by forking the repository and sending a pull request. 6 | 7 | When submitting code, please make every effort to follow existing conventions 8 | and style in order to keep the code as readable as possible. 9 | 10 | Where appropriate, please provide unit tests or integration tests. Unit tests 11 | should be JUnit based tests and can use either standard JUnit assertions or 12 | Truth assertions and be added to `/src/test/java`. Changes to 13 | code generation or other build-time behaviour should go into small maven 14 | projects using the `maven-invoker-plugin`. Examples of this are in 15 | `generator/src/it` and can include bean-shell verification scripts and other 16 | facilities provided by `maven-invoker-plugin`. 17 | 18 | Please make sure your code compiles by running `mvn clean verify` which will 19 | execute both unit and integration test phases. Additionally, consider using 20 | http://travis-ci.org to validate your branches before you even put them into 21 | pull requests. All pull requests will be validated by Travis-ci in any case 22 | and must pass before being merged. 23 | 24 | If you are adding or modifying files you may add your own copyright line, but 25 | please ensure that the form is consistent with the existing files, and please 26 | note that a Google, Inc. copyright line must appear in every copyright notice. 27 | All files are released with the Apache 2.0 license and any new files may only 28 | be accepted under the terms of that license. 29 | 30 | Before your code can be accepted into the project you must sign the 31 | [Individual Contributor License Agreement (CLA)][1]. 32 | 33 | 34 | [1]: https://developers.google.com/open-source/cla/individual 35 | -------------------------------------------------------------------------------- /build-pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | build-only 5 | build-only 6 | NO_VERSION 7 | pom 8 | 9 | common 10 | factory 11 | service 12 | value 13 | 14 | 15 | 16 | sonatype-nexus-staging 17 | Nexus Release Repository 18 | file:///tmp/auto_project_maven_fake_repo/ 19 | 20 | 21 | sonatype-nexus-snapshots 22 | Sonatype Nexus Snapshots 23 | file:///tmp/auto_project_maven_fake_repo/ 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /common/README.md: -------------------------------------------------------------------------------- 1 | # Auto Common Utilities 2 | 3 | ## Overview 4 | 5 | The Auto project has a set of common utilities to help ease use of the 6 | annotation processing environment. 7 | 8 | ## Utility classes of note 9 | 10 | `MoreTypes` 11 | : Utilities and `Equivalence` wrappers for `TypeMirror` and related subtypes 12 | 13 | `MoreElements` 14 | : Utilities for `Element` and related subtypes 15 | 16 | `SuperficialValidation` 17 | : Very simple scanner to ensure an `Element` is valid and free from distortion 18 | from upstream compilation errors 19 | 20 | `Visibility` 21 | : Utilities for working with `Element`s' visibility levels (public, protected, 22 | etc.) 23 | 24 | `BasicAnnotationProcessor`/`Step` 25 | : Simple types that 26 | - implement a validating annotation processor 27 | - defer invalid elements until later 28 | - break processor actions into multiple steps (which may each handle 29 | different annotations) 30 | 31 | ## Usage/Setup 32 | 33 | Auto common utilities have a standard [Maven](http://maven.apache.org) setup 34 | which can also be used from Gradle, Ivy, Ant, or other systems which consume 35 | binary artifacts from the central Maven binary artifact repositories. 36 | 37 | ```xml 38 | 39 | com.google.auto 40 | auto-common 41 | 1.0-SNAPSHOT 42 | 43 | ``` 44 | -------------------------------------------------------------------------------- /common/src/main/java/com/google/auto/common/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | @NullMarked 17 | package com.google.auto.common; 18 | 19 | import org.jspecify.annotations.NullMarked; 20 | -------------------------------------------------------------------------------- /factory/src/it/functional/src/main/java/com/google/auto/factory/DaggerModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.factory; 17 | 18 | import com.google.auto.factory.otherpackage.OtherPackage; 19 | import dagger.Binds; 20 | import dagger.Module; 21 | import dagger.Provides; 22 | 23 | @Module 24 | abstract class DaggerModule { 25 | private DaggerModule() {} // no instances 26 | 27 | @Binds 28 | abstract Dependency provideDependency(DependencyImpl impl); 29 | 30 | @Binds 31 | @Qualifier 32 | abstract Dependency provideQualifiedDependency(QualifiedDependencyImpl impl); 33 | 34 | @Provides 35 | static int providePrimitive() { 36 | return 1; 37 | } 38 | 39 | @Provides 40 | @Qualifier 41 | static int provideQualifiedPrimitive() { 42 | return 2; 43 | } 44 | 45 | @Provides 46 | static Number provideNumber() { 47 | return 3; 48 | } 49 | 50 | @Provides 51 | static ReferencePackage provideReferencePackage(ReferencePackageFactory factory) { 52 | return factory.create(17); 53 | } 54 | 55 | @Provides 56 | static OtherPackage provideOtherPackage() { 57 | return new OtherPackage(null, 23); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /factory/src/it/functional/src/main/java/com/google/auto/factory/Dependency.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.factory; 17 | 18 | public interface Dependency {} 19 | -------------------------------------------------------------------------------- /factory/src/it/functional/src/main/java/com/google/auto/factory/DependencyImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.factory; 17 | 18 | import javax.inject.Inject; 19 | 20 | public class DependencyImpl implements Dependency { 21 | @Inject 22 | DependencyImpl() {} 23 | } 24 | -------------------------------------------------------------------------------- /factory/src/it/functional/src/main/java/com/google/auto/factory/FactoryComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.factory; 17 | 18 | import com.google.auto.factory.otherpackage.OtherPackageFactory; 19 | import dagger.Component; 20 | 21 | /** A component to materialize the factory using Dagger 2 */ 22 | @Component(modules = DaggerModule.class) 23 | interface FactoryComponent { 24 | FooFactory factory(); 25 | 26 | GenericFooFactory generatedFactory(); 27 | 28 | ReferencePackageFactory referencePackageFactory(); 29 | 30 | OtherPackageFactory otherPackageFactory(); 31 | } 32 | -------------------------------------------------------------------------------- /factory/src/it/functional/src/main/java/com/google/auto/factory/FactoryInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.factory; 17 | 18 | public interface FactoryInterface { 19 | Foo generate(String name); 20 | } 21 | -------------------------------------------------------------------------------- /factory/src/it/functional/src/main/java/com/google/auto/factory/GenericFoo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.factory; 17 | 18 | import java.util.List; 19 | import javax.inject.Provider; 20 | 21 | @AutoFactory 22 | public class GenericFoo, C, E extends Enum> { 23 | 24 | private final A depA; 25 | private final B depB; 26 | private final IntAccessor depDIntAccessor; 27 | private final StringAccessor depDStringAccessor; 28 | private final E depE; 29 | 30 | GenericFoo( 31 | @Provided Provider depA, B depB, D depD, E depE) { 32 | this.depA = depA.get(); 33 | this.depB = depB; 34 | this.depDIntAccessor = depD; 35 | this.depDStringAccessor = depD; 36 | this.depE = depE; 37 | } 38 | 39 | public A getDepA() { 40 | return depA; 41 | } 42 | 43 | public B getDepB() { 44 | return depB; 45 | } 46 | 47 | public C passThrough(C value) { 48 | return value; 49 | } 50 | 51 | public IntAccessor getDepDIntAccessor() { 52 | return depDIntAccessor; 53 | } 54 | 55 | public StringAccessor getDepDStringAccessor() { 56 | return depDStringAccessor; 57 | } 58 | 59 | public E getDepE() { 60 | return depE; 61 | } 62 | 63 | public interface IntAccessor {} 64 | 65 | public interface StringAccessor {} 66 | 67 | public interface IntAndStringAccessor extends IntAccessor, StringAccessor {} 68 | 69 | public enum DepE { 70 | VALUE_1, 71 | VALUE_2 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /factory/src/it/functional/src/main/java/com/google/auto/factory/GuiceModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.factory; 17 | 18 | import com.google.inject.AbstractModule; 19 | 20 | public class GuiceModule extends AbstractModule { 21 | @Override 22 | protected void configure() { 23 | bind(Dependency.class).to(DependencyImpl.class); 24 | bind(Dependency.class).annotatedWith(Qualifier.class).to(QualifiedDependencyImpl.class); 25 | bind(Integer.class).toInstance(1); 26 | bind(Integer.class).annotatedWith(Qualifier.class).toInstance(2); 27 | bind(Number.class).toInstance(3); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /factory/src/it/functional/src/main/java/com/google/auto/factory/QualifiedDependencyImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.factory; 17 | 18 | import javax.inject.Inject; 19 | 20 | public class QualifiedDependencyImpl implements Dependency { 21 | @Inject 22 | QualifiedDependencyImpl() {} 23 | } 24 | -------------------------------------------------------------------------------- /factory/src/it/functional/src/main/java/com/google/auto/factory/Qualifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.factory; 17 | 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | 21 | @javax.inject.Qualifier 22 | @Retention(RetentionPolicy.RUNTIME) 23 | @interface Qualifier {} 24 | -------------------------------------------------------------------------------- /factory/src/it/functional/src/main/java/com/google/auto/factory/ReferencePackage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.factory; 17 | 18 | import com.google.auto.factory.otherpackage.OtherPackage; 19 | import com.google.auto.factory.otherpackage.OtherPackageFactory; 20 | import javax.inject.Inject; 21 | 22 | @AutoFactory 23 | public class ReferencePackage { 24 | private final OtherPackageFactory otherPackageFactory; 25 | private final int random; 26 | 27 | @Inject 28 | ReferencePackage(@Provided OtherPackageFactory otherPackageFactory, int random) { 29 | this.otherPackageFactory = otherPackageFactory; 30 | this.random = random; 31 | } 32 | 33 | public OtherPackage otherPackage() { 34 | return otherPackageFactory.create(random); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /factory/src/it/functional/src/main/java/com/google/auto/factory/otherpackage/OtherPackage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.factory.otherpackage; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import com.google.auto.factory.Provided; 20 | import com.google.auto.factory.ReferencePackageFactory; 21 | 22 | @AutoFactory 23 | public class OtherPackage { 24 | private final ReferencePackageFactory referencePackageFactory; 25 | private final int random; 26 | 27 | public OtherPackage(@Provided ReferencePackageFactory referencePackageFactory, int random) { 28 | this.referencePackageFactory = referencePackageFactory; 29 | this.random = random; 30 | } 31 | 32 | public ReferencePackageFactory referencePackageFactory() { 33 | return referencePackageFactory; 34 | } 35 | 36 | public int random() { 37 | return random; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /factory/src/main/java/com/google/auto/factory/Provided.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.factory; 17 | 18 | import static java.lang.annotation.ElementType.PARAMETER; 19 | 20 | import java.lang.annotation.Target; 21 | 22 | /** 23 | * An annotation to be applied to parameters that should be provided by an injected {@code Provider} 24 | * in a generated factory. 25 | * 26 | *

The {@code @Inject} and {@code Provider} classes come from either the legacy package {@code 27 | * javax.inject} or the updated package {@code jakarta.inject}. {@code jakarta.inject} is used if it 28 | * is on the classpath. Compile with {@code -Acom.google.auto.factory.InjectApi=javax} if you want 29 | * to use {@code javax.inject} even when {@code jakarta.inject} is available. 30 | * 31 | * @author Gregory Kick 32 | */ 33 | @Target(PARAMETER) 34 | public @interface Provided {} 35 | -------------------------------------------------------------------------------- /factory/src/main/java/com/google/auto/factory/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | @NullMarked 17 | package com.google.auto.factory; 18 | 19 | import org.jspecify.annotations.NullMarked; 20 | -------------------------------------------------------------------------------- /factory/src/main/java/com/google/auto/factory/processor/ImplementationMethodDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.factory.processor; 17 | 18 | import com.google.auto.value.AutoValue; 19 | import com.google.common.collect.ImmutableSet; 20 | import javax.lang.model.type.TypeMirror; 21 | 22 | @AutoValue 23 | abstract class ImplementationMethodDescriptor { 24 | abstract String name(); 25 | 26 | abstract TypeMirror returnType(); 27 | 28 | abstract boolean publicMethod(); 29 | 30 | abstract ImmutableSet passedParameters(); 31 | 32 | abstract boolean isVarArgs(); 33 | 34 | abstract ImmutableSet exceptions(); 35 | 36 | static Builder builder() { 37 | return new AutoValue_ImplementationMethodDescriptor.Builder(); 38 | } 39 | 40 | @AutoValue.Builder 41 | abstract static class Builder { 42 | abstract Builder name(String name); 43 | 44 | abstract Builder returnType(TypeMirror returnTypeElement); 45 | 46 | abstract Builder publicMethod(boolean publicMethod); 47 | 48 | final Builder publicMethod() { 49 | return publicMethod(true); 50 | } 51 | 52 | abstract Builder passedParameters(Iterable passedParameters); 53 | 54 | abstract Builder isVarArgs(boolean isVarargs); 55 | 56 | abstract Builder exceptions(Iterable exceptions); 57 | 58 | abstract ImplementationMethodDescriptor build(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /factory/src/main/java/com/google/auto/factory/processor/PackageAndClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.factory.processor; 17 | 18 | import com.google.auto.value.AutoValue; 19 | 20 | /** A Java class name, separated into its package part and its class part. */ 21 | @AutoValue 22 | abstract class PackageAndClass { 23 | /** 24 | * The package part of this class name. For {@code java.util.Map.Entry}, it would be {@code 25 | * java.util}. 26 | */ 27 | abstract String packageName(); 28 | 29 | /** 30 | * The class part of this class name. For {@code java.util.Map.Entry}, it would be {@code 31 | * Map.Entry}. 32 | */ 33 | abstract String className(); 34 | 35 | static PackageAndClass of(String packageName, String className) { 36 | return new AutoValue_PackageAndClass(packageName, className); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /factory/src/main/java/com/google/auto/factory/processor/ProviderField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.factory.processor; 17 | 18 | import static com.google.auto.factory.processor.Mirrors.unwrapOptionalEquivalence; 19 | import static com.google.auto.factory.processor.Mirrors.wrapOptionalInEquivalence; 20 | 21 | import com.google.auto.common.AnnotationMirrors; 22 | import com.google.auto.value.AutoValue; 23 | import com.google.common.base.Equivalence; 24 | import java.util.Optional; 25 | import javax.lang.model.element.AnnotationMirror; 26 | 27 | @AutoValue 28 | abstract class ProviderField { 29 | abstract String name(); 30 | 31 | abstract Key key(); 32 | 33 | abstract Optional> nullableWrapper(); 34 | 35 | Optional nullable() { 36 | return unwrapOptionalEquivalence(nullableWrapper()); 37 | } 38 | 39 | static ProviderField create(String name, Key key, Optional nullable) { 40 | return new AutoValue_ProviderField( 41 | name, key, wrapOptionalInEquivalence(AnnotationMirrors.equivalence(), nullable)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /factory/src/main/java/com/google/auto/factory/processor/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | /** 15 | * This package contains the annotation processor that implements the {@link 16 | * com.google.auto.factory.AutoFactory} API. 17 | */ 18 | @NullMarked 19 | package com.google.auto.factory.processor; 20 | 21 | import org.jspecify.annotations.NullMarked; 22 | -------------------------------------------------------------------------------- /factory/src/test/java/com/google/auto/factory/processor/AutoFactoryDeclarationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.factory.processor; 17 | 18 | import static com.google.auto.factory.processor.AutoFactoryDeclaration.Factory.isValidIdentifier; 19 | import static com.google.common.truth.Truth.assertThat; 20 | 21 | import org.junit.Test; 22 | import org.junit.runner.RunWith; 23 | import org.junit.runners.JUnit4; 24 | 25 | @RunWith(JUnit4.class) 26 | public class AutoFactoryDeclarationTest { 27 | @Test 28 | public void identifiers() { 29 | assertThat(isValidIdentifier("String")).isTrue(); 30 | assertThat(isValidIdentifier("9CantStartWithNumber")).isFalse(); 31 | assertThat(isValidIdentifier("enum")).isFalse(); 32 | assertThat(isValidIdentifier("goto")).isFalse(); 33 | assertThat(isValidIdentifier("InvalidCharacter!")).isFalse(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /factory/src/test/resources/bad/AnnotationsToApplyMultiple.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | 20 | @AutoFactory.AnnotationsToApply 21 | @interface This { 22 | SuppressWarnings suppressWarnings() default @SuppressWarnings("Immutable"); 23 | } 24 | 25 | @AutoFactory.AnnotationsToApply 26 | @interface That { 27 | SuppressWarnings suppressWarnings() default @SuppressWarnings("Immutable"); 28 | } 29 | 30 | @This 31 | @That 32 | @AutoFactory 33 | final class AnnotationsToApplyMultiple {} 34 | -------------------------------------------------------------------------------- /factory/src/test/resources/bad/AnnotationsToApplyNotAnnotations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import com.google.errorprone.annotations.Immutable; 20 | 21 | @AutoFactory.AnnotationsToApply 22 | @interface ImmutableAndSuppressWarnings { 23 | Immutable immutable() default @Immutable; 24 | 25 | SuppressWarnings suppressWarnings() default @SuppressWarnings("Immutable"); 26 | 27 | int whatIsThis() default 23; 28 | 29 | Immutable[] andWhatIsThis() default {}; 30 | } 31 | 32 | @ImmutableAndSuppressWarnings(suppressWarnings = @SuppressWarnings({"unchecked", "Immutable"})) 33 | @AutoFactory 34 | final class AnnotationsToApplyNotAnnotations {} 35 | -------------------------------------------------------------------------------- /factory/src/test/resources/bad/AnnotationsToApplyRepeated.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | 20 | @AutoFactory.AnnotationsToApply 21 | @interface ReallySuppressWarnings { 22 | SuppressWarnings suppressWarnings() default @SuppressWarnings("Immutable"); 23 | 24 | SuppressWarnings suppressWarningsSomeMore() default @SuppressWarnings("Immutable"); 25 | } 26 | 27 | @ReallySuppressWarnings 28 | @AutoFactory 29 | final class AnnotationsToApplyMultiple {} 30 | -------------------------------------------------------------------------------- /factory/src/test/resources/bad/EnumSupertype.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import java.util.concurrent.TimeUnit; 20 | 21 | @AutoFactory(extending = TimeUnit.class) 22 | final class InterfaceSupertype {} 23 | -------------------------------------------------------------------------------- /factory/src/test/resources/bad/FactoryExtendingAbstractClassWithConstructorParams.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import tests.FactoryExtendingAbstractClassWithConstructorParams.AbstractFactory; 20 | 21 | @AutoFactory(extending = AbstractFactory.class) 22 | final class FactoryExtendingAbstractClassWithConstructorParams { 23 | abstract static class AbstractFactory { 24 | protected AbstractFactory(Object obj) {} 25 | 26 | abstract FactoryExtendingAbstractClassWithConstructorParams newInstance(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /factory/src/test/resources/bad/FinalSupertype.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | 20 | @AutoFactory(extending = Boolean.class) 21 | final class InterfaceSupertype {} 22 | -------------------------------------------------------------------------------- /factory/src/test/resources/bad/InterfaceSupertype.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | 20 | @AutoFactory(extending = Runnable.class) 21 | final class InterfaceSupertype {} 22 | -------------------------------------------------------------------------------- /factory/src/test/resources/bad/InvalidCustomName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | 20 | @AutoFactory(className = "SillyFactory!") 21 | final class InvalidCustomName {} 22 | -------------------------------------------------------------------------------- /factory/src/test/resources/bad/MixedFinals.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | 20 | final class MixedFinals { 21 | @AutoFactory(allowSubclasses = false) 22 | MixedFinals() {} 23 | 24 | @AutoFactory(allowSubclasses = true) 25 | MixedFinals(String s) {} 26 | 27 | @AutoFactory(allowSubclasses = true) 28 | MixedFinals(String s, Integer i) {} 29 | } 30 | -------------------------------------------------------------------------------- /factory/src/test/resources/bad/ProvidedButNoAutoFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.Provided; 19 | 20 | final class ProvidedButNoAutoFactory { 21 | ProvidedButNoAutoFactory(Object a, @Provided Object b) {} 22 | } 23 | -------------------------------------------------------------------------------- /factory/src/test/resources/bad/ProvidedOnMethodParameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.Provided; 19 | 20 | final class ProvidedOnMethodParameter { 21 | void blah(Object a, @Provided Object b) {} 22 | } 23 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/ClassUsingQualifierWithArgsFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | import javax.inject.Provider; 21 | 22 | @Generated( 23 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 24 | comments = "https://github.com/google/auto/tree/main/factory" 25 | ) 26 | final class ClassUsingQualifierWithArgsFactory { 27 | private final Provider providedDepAProvider; 28 | 29 | @Inject 30 | ClassUsingQualifierWithArgsFactory( 31 | @QualifierWithArgs(name = "Fred", count = 3) Provider providedDepAProvider) { 32 | this.providedDepAProvider = checkNotNull(providedDepAProvider, 1, 1); 33 | } 34 | 35 | ClassUsingQualifierWithArgs create() { 36 | return new ClassUsingQualifierWithArgs(checkNotNull(providedDepAProvider.get(), 1, 1)); 37 | } 38 | 39 | private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { 40 | if (reference == null) { 41 | throw new NullPointerException( 42 | "@AutoFactory method argument is null but is not marked @Nullable. Argument " 43 | + argumentNumber 44 | + " of " 45 | + argumentCount); 46 | } 47 | return reference; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/ConstructorAnnotatedFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | import javax.inject.Provider; 21 | 22 | @Generated( 23 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 24 | comments = "https://github.com/google/auto/tree/main/factory" 25 | ) 26 | final class ConstructorAnnotatedFactory { 27 | private final Provider objProvider; 28 | 29 | @Inject 30 | ConstructorAnnotatedFactory(Provider objProvider) { 31 | this.objProvider = checkNotNull(objProvider, 1, 1); 32 | } 33 | 34 | ConstructorAnnotated create() { 35 | return new ConstructorAnnotated(); 36 | } 37 | 38 | ConstructorAnnotated create(String s) { 39 | return new ConstructorAnnotated(checkNotNull(s, 1, 1)); 40 | } 41 | 42 | ConstructorAnnotated create(int i) { 43 | return new ConstructorAnnotated(checkNotNull(objProvider.get(), 1, 2), i); 44 | } 45 | 46 | ConstructorAnnotated create(char c) { 47 | return new ConstructorAnnotated(checkNotNull(objProvider.get(), 1, 2), c); 48 | } 49 | 50 | private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { 51 | if (reference == null) { 52 | throw new NullPointerException( 53 | "@AutoFactory method argument is null but is not marked @Nullable. Argument " 54 | + argumentNumber 55 | + " of " 56 | + argumentCount); 57 | } 58 | return reference; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/CustomAnnotationsFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.errorprone.annotations.Immutable; 19 | import javax.annotation.processing.Generated; 20 | import javax.inject.Inject; 21 | 22 | @Generated( 23 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 24 | comments = "https://github.com/google/auto/tree/main/factory" 25 | ) 26 | @Immutable 27 | @SuppressWarnings({"unchecked", "Immutable"}) 28 | final class CustomAnnotationsFactory { 29 | @Inject 30 | CustomAnnotationsFactory() {} 31 | 32 | CustomAnnotations create() { 33 | return new CustomAnnotations(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/CustomNamedFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | 21 | @Generated( 22 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 23 | comments = "https://github.com/google/auto/tree/main/factory" 24 | ) 25 | final class CustomNamedFactory { 26 | @Inject 27 | CustomNamedFactory() {} 28 | 29 | SimpleClassCustomName create() { 30 | return new SimpleClassCustomName(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/CustomNullableFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | import javax.inject.Provider; 21 | 22 | @Generated( 23 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 24 | comments = "https://github.com/google/auto/tree/main/factory" 25 | ) 26 | final class CustomNullableFactory { 27 | 28 | private final Provider objectProvider; 29 | 30 | @Inject 31 | CustomNullableFactory(Provider objectProvider) { 32 | this.objectProvider = checkNotNull(objectProvider, 1, 1); 33 | } 34 | 35 | CustomNullable create(@CustomNullable.Nullable String string) { 36 | return new CustomNullable(string, objectProvider.get()); 37 | } 38 | 39 | private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { 40 | if (reference == null) { 41 | throw new NullPointerException( 42 | "@AutoFactory method argument is null but is not marked @Nullable. Argument " 43 | + argumentNumber 44 | + " of " 45 | + argumentCount); 46 | } 47 | return reference; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/DefaultPackageFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import javax.annotation.processing.Generated; 18 | import javax.inject.Inject; 19 | 20 | @Generated( 21 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 22 | comments = "https://github.com/google/auto/tree/main/factory" 23 | ) 24 | public final class DefaultPackageFactory { 25 | @Inject 26 | public DefaultPackageFactory() {} 27 | 28 | public DefaultPackage create() { 29 | return new DefaultPackage(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/FactoryExtendingAbstractClassFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | 21 | @Generated( 22 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 23 | comments = "https://github.com/google/auto/tree/main/factory" 24 | ) 25 | final class FactoryExtendingAbstractClassFactory 26 | extends FactoryExtendingAbstractClass.AbstractFactory { 27 | @Inject 28 | FactoryExtendingAbstractClassFactory() {} 29 | 30 | FactoryExtendingAbstractClass create() { 31 | return new FactoryExtendingAbstractClass(); 32 | } 33 | 34 | @Override 35 | public FactoryExtendingAbstractClass newInstance() { 36 | return create(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/FactoryExtendingAbstractClassThrowsFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import java.io.IOException; 19 | import javax.annotation.processing.Generated; 20 | import javax.inject.Inject; 21 | 22 | @Generated( 23 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 24 | comments = "https://github.com/google/auto/tree/main/factory" 25 | ) 26 | final class FactoryExtendingAbstractClassThrowsFactory 27 | extends FactoryExtendingAbstractClassThrows.AbstractFactory { 28 | @Inject 29 | FactoryExtendingAbstractClassThrowsFactory() {} 30 | 31 | FactoryExtendingAbstractClassThrows create() throws IOException, InterruptedException { 32 | return new FactoryExtendingAbstractClassThrows(); 33 | } 34 | 35 | @Override 36 | public FactoryExtendingAbstractClassThrows newInstance() throws Exception { 37 | return create(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/FactoryImplementingGenericInterfaceExtensionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | import javax.inject.Provider; 21 | 22 | @Generated( 23 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 24 | comments = "https://github.com/google/auto/tree/main/factory" 25 | ) 26 | final class FactoryImplementingGenericInterfaceExtensionFactory 27 | implements FactoryImplementingGenericInterfaceExtension.MyFactory { 28 | private final Provider sProvider; 29 | 30 | @Inject 31 | FactoryImplementingGenericInterfaceExtensionFactory(Provider sProvider) { 32 | this.sProvider = checkNotNull(sProvider, 1, 1); 33 | } 34 | 35 | FactoryImplementingGenericInterfaceExtension create(Integer i) { 36 | return new FactoryImplementingGenericInterfaceExtension( 37 | checkNotNull(sProvider.get(), 1, 2), checkNotNull(i, 2, 2)); 38 | } 39 | 40 | @Override 41 | public FactoryImplementingGenericInterfaceExtension make(Integer arg) { 42 | return create(arg); 43 | } 44 | 45 | private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { 46 | if (reference == null) { 47 | throw new NullPointerException( 48 | "@AutoFactory method argument is null but is not marked @Nullable. Argument " 49 | + argumentNumber 50 | + " of " 51 | + argumentCount); 52 | } 53 | return reference; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/Generics_ExplicitFooImplFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | import javax.inject.Provider; 21 | 22 | @Generated( 23 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 24 | comments = "https://github.com/google/auto/tree/main/factory" 25 | ) 26 | final class Generics_ExplicitFooImplFactory 27 | implements Generics.FooFactory { 28 | private final Provider unusedProvider; 29 | 30 | @Inject 31 | Generics_ExplicitFooImplFactory(Provider unusedProvider) { 32 | this.unusedProvider = checkNotNull(unusedProvider, 1, 1); 33 | } 34 | 35 | @Override 36 | public Generics.ExplicitFooImpl create() { 37 | return new Generics.ExplicitFooImpl(checkNotNull(unusedProvider.get(), 1, 1)); 38 | } 39 | 40 | private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { 41 | if (reference == null) { 42 | throw new NullPointerException( 43 | "@AutoFactory method argument is null but is not marked @Nullable. Argument " 44 | + argumentNumber 45 | + " of " 46 | + argumentCount); 47 | } 48 | return reference; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/Generics_FooImplFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | 21 | @Generated( 22 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 23 | comments = "https://github.com/google/auto/tree/main/factory" 24 | ) 25 | final class Generics_FooImplFactory implements Generics.FooFactory { 26 | @Inject 27 | Generics_FooImplFactory() {} 28 | 29 | @Override 30 | public Generics.FooImpl create() { 31 | return new Generics.FooImpl(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/Generics_FooImplWithClassFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | 21 | @Generated( 22 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 23 | comments = "https://github.com/google/auto/tree/main/factory" 24 | ) 25 | final class Generics_FooImplWithClassFactory 26 | extends Generics.FooFactoryClass { 27 | @Inject 28 | Generics_FooImplWithClassFactory() {} 29 | 30 | @Override 31 | public Generics.FooImplWithClass create() { 32 | return new Generics.FooImplWithClass(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/MultipleFactoriesImplementingInterface_ClassAFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | 21 | @Generated( 22 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 23 | comments = "https://github.com/google/auto/tree/main/factory" 24 | ) 25 | final class MultipleFactoriesImplementingInterface_ClassAFactory 26 | implements MultipleFactoriesImplementingInterface.Base.Factory { 27 | @Inject 28 | MultipleFactoriesImplementingInterface_ClassAFactory() {} 29 | 30 | MultipleFactoriesImplementingInterface.ClassA create() { 31 | return new MultipleFactoriesImplementingInterface.ClassA(); 32 | } 33 | 34 | @Override 35 | public MultipleFactoriesImplementingInterface.ClassA abstractNonDefaultCreate() { 36 | return create(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/MultipleFactoriesImplementingInterface_ClassBFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | 21 | @Generated( 22 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 23 | comments = "https://github.com/google/auto/tree/main/factory" 24 | ) 25 | final class MultipleFactoriesImplementingInterface_ClassBFactory 26 | implements MultipleFactoriesImplementingInterface.Base.Factory { 27 | @Inject 28 | MultipleFactoriesImplementingInterface_ClassBFactory() {} 29 | 30 | MultipleFactoriesImplementingInterface.ClassB create() { 31 | return new MultipleFactoriesImplementingInterface.ClassB(); 32 | } 33 | 34 | @Override 35 | public MultipleFactoriesImplementingInterface.ClassB abstractNonDefaultCreate() { 36 | return create(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/MultipleProvidedParamsSameKeyFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | import javax.inject.Provider; 21 | 22 | @Generated( 23 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 24 | comments = "https://github.com/google/auto/tree/main/factory" 25 | ) 26 | final class MultipleProvidedParamsSameKeyFactory { 27 | private final Provider java_lang_StringProvider; 28 | 29 | @Inject 30 | MultipleProvidedParamsSameKeyFactory(Provider java_lang_StringProvider) { 31 | this.java_lang_StringProvider = checkNotNull(java_lang_StringProvider, 1, 1); 32 | } 33 | 34 | MultipleProvidedParamsSameKey create() { 35 | return new MultipleProvidedParamsSameKey( 36 | checkNotNull(java_lang_StringProvider.get(), 1, 5), 37 | checkNotNull(java_lang_StringProvider.get(), 2, 5), 38 | java_lang_StringProvider.get(), 39 | java_lang_StringProvider, 40 | java_lang_StringProvider); 41 | } 42 | 43 | private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { 44 | if (reference == null) { 45 | throw new NullPointerException( 46 | "@AutoFactory method argument is null but is not marked @Nullable. Argument " 47 | + argumentNumber 48 | + " of " 49 | + argumentCount); 50 | } 51 | return reference; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/NestedClassCustomNamedFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | 21 | @Generated( 22 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 23 | comments = "https://github.com/google/auto/tree/main/factory" 24 | ) 25 | final class NestedClassCustomNamedFactory { 26 | @Inject 27 | NestedClassCustomNamedFactory() {} 28 | 29 | NestedClasses.SimpleNestedClassWithCustomFactory create() { 30 | return new NestedClasses.SimpleNestedClassWithCustomFactory(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/NestedClasses_SimpleNestedClassFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | 21 | @Generated( 22 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 23 | comments = "https://github.com/google/auto/tree/main/factory" 24 | ) 25 | final class NestedClasses_SimpleNestedClassFactory { 26 | @Inject 27 | NestedClasses_SimpleNestedClassFactory() {} 28 | 29 | NestedClasses.SimpleNestedClass create() { 30 | return new NestedClasses.SimpleNestedClass(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/OnlyPrimitivesFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | 21 | @Generated( 22 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 23 | comments = "https://github.com/google/auto/tree/main/factory" 24 | ) 25 | final class OnlyPrimitivesFactory { 26 | @Inject 27 | OnlyPrimitivesFactory() {} 28 | 29 | OnlyPrimitives create(int i, long l) { 30 | return new OnlyPrimitives(i, l); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/ProviderArgumentToCreateMethodFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | import javax.inject.Provider; 21 | 22 | @Generated( 23 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 24 | comments = "https://github.com/google/auto/tree/main/factory" 25 | ) 26 | final class ProviderArgumentToCreateMethodFactory 27 | implements ProviderArgumentToCreateMethod.CustomCreator { 28 | @Inject 29 | ProviderArgumentToCreateMethodFactory() {} 30 | 31 | ProviderArgumentToCreateMethod create(Provider stringProvider) { 32 | return new ProviderArgumentToCreateMethod(checkNotNull(stringProvider, 1, 1)); 33 | } 34 | 35 | @Override 36 | public ProviderArgumentToCreateMethod newInstance(Provider stringProvider) { 37 | return create(stringProvider); 38 | } 39 | 40 | private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { 41 | if (reference == null) { 42 | throw new NullPointerException( 43 | "@AutoFactory method argument is null but is not marked @Nullable. Argument " 44 | + argumentNumber 45 | + " of " 46 | + argumentCount); 47 | } 48 | return reference; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/PublicClassFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | 21 | @Generated( 22 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 23 | comments = "https://github.com/google/auto/tree/main/factory" 24 | ) 25 | public final class PublicClassFactory { 26 | @Inject 27 | public PublicClassFactory() {} 28 | 29 | public PublicClass create() { 30 | return new PublicClass(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/SimpleClassFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | 21 | @Generated( 22 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 23 | comments = "https://github.com/google/auto/tree/main/factory" 24 | ) 25 | final class SimpleClassFactory { 26 | @Inject 27 | SimpleClassFactory() {} 28 | 29 | SimpleClass create() { 30 | return new SimpleClass(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/SimpleClassImplementingMarkerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import java.util.RandomAccess; 19 | import javax.annotation.processing.Generated; 20 | import javax.inject.Inject; 21 | 22 | @Generated( 23 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 24 | comments = "https://github.com/google/auto/tree/main/factory" 25 | ) 26 | final class SimpleClassImplementingMarkerFactory implements RandomAccess { 27 | @Inject 28 | SimpleClassImplementingMarkerFactory() {} 29 | 30 | SimpleClassImplementingMarker create() { 31 | return new SimpleClassImplementingMarker(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/SimpleClassImplementingSimpleInterfaceFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | 21 | @Generated( 22 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 23 | comments = "https://github.com/google/auto/tree/main/factory" 24 | ) 25 | final class SimpleClassImplementingSimpleInterfaceFactory 26 | implements SimpleClassImplementingSimpleInterface.SimpleInterface { 27 | @Inject 28 | SimpleClassImplementingSimpleInterfaceFactory() {} 29 | 30 | SimpleClassImplementingSimpleInterface create() { 31 | return new SimpleClassImplementingSimpleInterface(); 32 | } 33 | 34 | @Override 35 | public SimpleClassImplementingSimpleInterface newInstance() { 36 | return create(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/SimpleClassMixedDepsFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | import javax.inject.Provider; 21 | 22 | @Generated( 23 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 24 | comments = "https://github.com/google/auto/tree/main/factory" 25 | ) 26 | final class SimpleClassMixedDepsFactory { 27 | private final Provider providedDepAProvider; 28 | 29 | @Inject 30 | SimpleClassMixedDepsFactory(@AQualifier Provider providedDepAProvider) { 31 | this.providedDepAProvider = checkNotNull(providedDepAProvider, 1, 1); 32 | } 33 | 34 | SimpleClassMixedDeps create(String depB) { 35 | return new SimpleClassMixedDeps( 36 | checkNotNull(providedDepAProvider.get(), 1, 2), checkNotNull(depB, 2, 2)); 37 | } 38 | 39 | private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { 40 | if (reference == null) { 41 | throw new NullPointerException( 42 | "@AutoFactory method argument is null but is not marked @Nullable. Argument " 43 | + argumentNumber 44 | + " of " 45 | + argumentCount); 46 | } 47 | return reference; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/SimpleClassNonFinalFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | 21 | @Generated( 22 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 23 | comments = "https://github.com/google/auto/tree/main/factory" 24 | ) 25 | class SimpleClassNonFinalFactory { 26 | @Inject 27 | SimpleClassNonFinalFactory() {} 28 | 29 | SimpleClassNonFinal create() { 30 | return new SimpleClassNonFinal(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/SimpleClassPassedDepsFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | 21 | @Generated( 22 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 23 | comments = "https://github.com/google/auto/tree/main/factory" 24 | ) 25 | final class SimpleClassPassedDepsFactory { 26 | @Inject 27 | SimpleClassPassedDepsFactory() {} 28 | 29 | SimpleClassPassedDeps create(String depA, String depB) { 30 | return new SimpleClassPassedDeps(checkNotNull(depA, 1, 2), checkNotNull(depB, 2, 2)); 31 | } 32 | 33 | private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { 34 | if (reference == null) { 35 | throw new NullPointerException( 36 | "@AutoFactory method argument is null but is not marked @Nullable. Argument " 37 | + argumentNumber 38 | + " of " 39 | + argumentCount); 40 | } 41 | return reference; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/SimpleClassProvidedProviderDepsFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | import javax.inject.Provider; 21 | 22 | @Generated( 23 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 24 | comments = "https://github.com/google/auto/tree/main/factory" 25 | ) 26 | final class SimpleClassProvidedProviderDepsFactory { 27 | private final Provider providedDepAProvider; 28 | private final Provider providedDepBProvider; 29 | 30 | @Inject 31 | SimpleClassProvidedProviderDepsFactory( 32 | @AQualifier Provider providedDepAProvider, 33 | @BQualifier Provider providedDepBProvider) { 34 | this.providedDepAProvider = checkNotNull(providedDepAProvider, 1, 2); 35 | this.providedDepBProvider = checkNotNull(providedDepBProvider, 2, 2); 36 | } 37 | 38 | SimpleClassProvidedProviderDeps create() { 39 | return new SimpleClassProvidedProviderDeps(providedDepAProvider, providedDepBProvider); 40 | } 41 | 42 | private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { 43 | if (reference == null) { 44 | throw new NullPointerException( 45 | "@AutoFactory method argument is null but is not marked @Nullable. Argument " 46 | + argumentNumber 47 | + " of " 48 | + argumentCount); 49 | } 50 | return reference; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/SimpleClassThrowsFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import java.io.IOException; 19 | import javax.annotation.processing.Generated; 20 | import javax.inject.Inject; 21 | 22 | @Generated( 23 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 24 | comments = "https://github.com/google/auto/tree/main/factory" 25 | ) 26 | final class SimpleClassThrowsFactory { 27 | @Inject 28 | SimpleClassThrowsFactory() {} 29 | 30 | SimpleClassThrows create() throws IOException, InterruptedException { 31 | return new SimpleClassThrows(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /factory/src/test/resources/expected/SimpleClassVarargsFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import javax.annotation.processing.Generated; 19 | import javax.inject.Inject; 20 | 21 | @Generated( 22 | value = "com.google.auto.factory.processor.AutoFactoryProcessor", 23 | comments = "https://github.com/google/auto/tree/main/factory" 24 | ) 25 | final class SimpleClassVarargsFactory implements SimpleClassVarargs.InterfaceWithVarargs { 26 | @Inject 27 | SimpleClassVarargsFactory() {} 28 | 29 | SimpleClassVarargs create(String... args) { 30 | return new SimpleClassVarargs(checkNotNull(args, 1, 1)); 31 | } 32 | 33 | @Override 34 | public SimpleClassVarargs build(String... args) { 35 | return create(args); 36 | } 37 | 38 | private static T checkNotNull(T reference, int argumentNumber, int argumentCount) { 39 | if (reference == null) { 40 | throw new NullPointerException( 41 | "@AutoFactory method argument is null but is not marked @Nullable. Argument " 42 | + argumentNumber 43 | + " of " 44 | + argumentCount); 45 | } 46 | return reference; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/CheckerFrameworkNullable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import com.google.auto.factory.Provided; 20 | import java.util.Map; 21 | import org.checkerframework.checker.nullness.compatqual.NullableDecl; 22 | import org.checkerframework.checker.nullness.compatqual.NullableType; 23 | 24 | @AutoFactory 25 | final class CheckerFrameworkNullable { 26 | 27 | CheckerFrameworkNullable( 28 | @NullableDecl String nullableDecl, 29 | @Provided @NullableDecl String providedNullableDecl, 30 | @NullableType String nullableType, 31 | @Provided @NullableType String providedNullableType, 32 | Map.@NullableType Entry nestedNullableType, 33 | @Provided Map.@NullableType Entry providedNestedNullableType) {} 34 | } 35 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/ClassUsingQualifierWithArgs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package tests; 15 | 16 | import com.google.auto.factory.AutoFactory; 17 | import com.google.auto.factory.Provided; 18 | 19 | /** 20 | * @author Justine Tunney 21 | */ 22 | @AutoFactory 23 | @SuppressWarnings("unused") 24 | final class ClassUsingQualifierWithArgs { 25 | private final String providedDepA; 26 | 27 | ClassUsingQualifierWithArgs( 28 | @Provided @QualifierWithArgs(name = "Fred", count = 3) String providedDepA) { 29 | this.providedDepA = providedDepA; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/ConstructorAnnotated.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import com.google.auto.factory.Provided; 20 | 21 | final class ConstructorAnnotated { 22 | @AutoFactory 23 | ConstructorAnnotated() {} 24 | 25 | ConstructorAnnotated(Object obj) {} 26 | 27 | @AutoFactory 28 | ConstructorAnnotated(String s) {} 29 | 30 | @AutoFactory 31 | ConstructorAnnotated(@Provided Object obj, int i) {} 32 | 33 | @AutoFactory 34 | ConstructorAnnotated(@Provided Object obj, char c) {} 35 | } 36 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/ConstructorAnnotatedNonFinal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import com.google.auto.factory.Provided; 20 | 21 | final class ConstructorAnnotatedNonFinal { 22 | @AutoFactory(allowSubclasses = true) 23 | ConstructorAnnotatedNonFinal() {} 24 | 25 | ConstructorAnnotatedNonFinal(Object obj) {} 26 | 27 | @AutoFactory(allowSubclasses = true) 28 | ConstructorAnnotatedNonFinal(String s) {} 29 | 30 | @AutoFactory(allowSubclasses = true) 31 | ConstructorAnnotatedNonFinal(@Provided Object obj, int i) {} 32 | 33 | @AutoFactory(allowSubclasses = true) 34 | ConstructorAnnotatedNonFinal(@Provided Object obj, char c) {} 35 | } 36 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/ConstructorAnnotatedThrows.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import com.google.auto.factory.Provided; 20 | import java.io.IOException; 21 | 22 | final class ConstructorAnnotatedThrows { 23 | @AutoFactory 24 | ConstructorAnnotatedThrows() throws IOException, InterruptedException {} 25 | 26 | ConstructorAnnotatedThrows(Object obj) {} 27 | 28 | @AutoFactory 29 | ConstructorAnnotatedThrows(String s) {} 30 | 31 | @AutoFactory 32 | ConstructorAnnotatedThrows(@Provided Object obj, int i) throws IOException {} 33 | 34 | @AutoFactory 35 | ConstructorAnnotatedThrows(@Provided Object obj, char c) throws InterruptedException {} 36 | } 37 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/CustomAnnotations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import com.google.errorprone.annotations.Immutable; 20 | 21 | @AutoFactory.AnnotationsToApply 22 | @interface ImmutableAndSuppressWarnings { 23 | Immutable immutable() default @Immutable; 24 | 25 | SuppressWarnings suppressWarnings() default @SuppressWarnings("Immutable"); 26 | } 27 | 28 | @ImmutableAndSuppressWarnings(suppressWarnings = @SuppressWarnings({"unchecked", "Immutable"})) 29 | @AutoFactory 30 | final class CustomAnnotations {} 31 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/CustomNullable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import com.google.auto.factory.Provided; 20 | 21 | @AutoFactory 22 | final class CustomNullable { 23 | 24 | private final String string; 25 | private final Object object; 26 | 27 | CustomNullable( 28 | @CustomNullable.Nullable String string, @CustomNullable.Nullable @Provided Object object) { 29 | this.string = string; 30 | this.object = object; 31 | } 32 | 33 | @interface Nullable {} 34 | } 35 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/DefaultPackage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import com.google.auto.factory.AutoFactory; 18 | 19 | @AutoFactory 20 | public final class DefaultPackage {} 21 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/FactoryExtendingAbstractClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import tests.FactoryExtendingAbstractClass.AbstractFactory; 20 | 21 | @AutoFactory(extending = AbstractFactory.class) 22 | final class FactoryExtendingAbstractClass { 23 | abstract static class AbstractFactory { 24 | abstract FactoryExtendingAbstractClass newInstance(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/FactoryExtendingAbstractClassThrows.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import java.io.IOException; 20 | import tests.FactoryExtendingAbstractClassThrows.AbstractFactory; 21 | 22 | @AutoFactory(extending = AbstractFactory.class) 23 | final class FactoryExtendingAbstractClassThrows { 24 | FactoryExtendingAbstractClassThrows() throws IOException, InterruptedException {} 25 | 26 | abstract static class AbstractFactory { 27 | abstract FactoryExtendingAbstractClassThrows newInstance() throws Exception; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/FactoryExtendingAbstractClassWithMultipleConstructors.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import tests.FactoryExtendingAbstractClassWithMultipleConstructors.AbstractFactory; 20 | 21 | @AutoFactory(extending = AbstractFactory.class) 22 | final class FactoryExtendingAbstractClassWithMultipleConstructors { 23 | abstract static class AbstractFactory { 24 | protected AbstractFactory(Object obj) {} 25 | 26 | protected AbstractFactory() {} 27 | 28 | abstract FactoryExtendingAbstractClassWithMultipleConstructors newInstance(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/FactoryImplementingCreateMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import java.util.List; 20 | 21 | final class FactoryImplementingCreateMethod { 22 | 23 | interface Interface {} 24 | 25 | interface FactoryInterfaceWithCreateMethod { 26 | Interface create(); 27 | 28 | Interface create(int a); 29 | 30 | Interface create(List generic); 31 | } 32 | 33 | @AutoFactory(implementing = FactoryInterfaceWithCreateMethod.class) 34 | static class ConcreteClass implements Interface { 35 | // Will generate a method with a signature that matches one from the interface. 36 | ConcreteClass() {} 37 | 38 | // Will generate a method with a signature that matches one from the interface. 39 | ConcreteClass(int aDifferentArgumentName) {} 40 | 41 | // Will generate a method with a signature that matches one from the interface. 42 | ConcreteClass(List genericWithDifferentArgumentName) {} 43 | 44 | ConcreteClass(int a, boolean b) {} 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/FactoryImplementingGenericInterfaceExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import com.google.auto.factory.Provided; 20 | 21 | class FactoryImplementingGenericInterfaceExtension { 22 | 23 | @AutoFactory(implementing = MyFactory.class) 24 | FactoryImplementingGenericInterfaceExtension(@Provided String s, Integer i) {} 25 | 26 | interface MyFactory 27 | extends GenericFactory {} 28 | 29 | interface GenericFactory { 30 | T make(S arg); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/Generics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import com.google.auto.factory.Provided; 20 | 21 | class Generics { 22 | interface Bar {} 23 | 24 | interface Foo {} 25 | 26 | interface FooFactory { 27 | Foo create(); 28 | } 29 | 30 | // The generated FooImplFactory should also have an type parameter, so we can 31 | // have FooImplFactory implements FooFactory. 32 | @AutoFactory(implementing = FooFactory.class) 33 | static final class FooImpl implements Foo { 34 | FooImpl() {} 35 | } 36 | 37 | // The generated ExplicitFooImplFactory should have an type parameter, which 38 | // serves both for FooFactory and for Provider in the constructor. 39 | @AutoFactory(implementing = FooFactory.class) 40 | static final class ExplicitFooImpl implements Foo { 41 | ExplicitFooImpl(@Provided M unused) {} 42 | } 43 | 44 | abstract static class FooFactoryClass { 45 | abstract Foo create(); 46 | } 47 | 48 | @AutoFactory(extending = FooFactoryClass.class) 49 | static final class FooImplWithClass implements Foo {} 50 | } 51 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/MixedDepsImplementingInterfaces.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import com.google.auto.factory.Provided; 20 | 21 | /** 22 | * @author Gregory Kick 23 | */ 24 | final class MixedDepsImplementingInterfaces { 25 | @AutoFactory(implementing = {FromInt.class, MarkerA.class}) 26 | MixedDepsImplementingInterfaces(@Provided String s, int i) {} 27 | 28 | @AutoFactory(implementing = {FromObject.class, MarkerB.class}) 29 | MixedDepsImplementingInterfaces(Object o) {} 30 | 31 | interface FromInt { 32 | MixedDepsImplementingInterfaces fromInt(int i); 33 | } 34 | 35 | interface FromObject { 36 | MixedDepsImplementingInterfaces fromObject(Object o); 37 | } 38 | 39 | interface MarkerA {} 40 | 41 | interface MarkerB {} 42 | } 43 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/MultipleFactoriesConflictingParameterNames.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import com.google.auto.factory.Provided; 20 | import javax.inject.Provider; 21 | 22 | class MultipleFactoriesConflictingParameterNames { 23 | 24 | @AutoFactory 25 | MultipleFactoriesConflictingParameterNames( 26 | @Provided String string, 27 | @Provided Object duplicatedKey_nameDoesntMatter, 28 | @Provided Provider duplicatedKeyProvider_nameDoesntMatter, 29 | // used to disambiguate with the second constructor since qualifiers aren't part of the type 30 | // system 31 | Object unused) {} 32 | 33 | @AutoFactory 34 | MultipleFactoriesConflictingParameterNames( 35 | @Provided @AQualifier String string, 36 | @Provided @AQualifier Object qualifiedDuplicatedKey_nameDoesntMatter, 37 | @Provided @AQualifier Provider qualifiedDuplicatedKeyProvider_nameDoesntMatter) {} 38 | } 39 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/MultipleFactoriesImplementingInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | 20 | class MultipleFactoriesImplementingInterface { 21 | static interface Base { 22 | static interface Factory { 23 | public abstract Base abstractNonDefaultCreate(); 24 | } 25 | } 26 | 27 | @AutoFactory(implementing = Base.Factory.class) 28 | static class ClassA implements Base {} 29 | 30 | @AutoFactory(implementing = Base.Factory.class) 31 | static class ClassB implements Base {} 32 | } 33 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/MultipleProvidedParamsSameKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import com.google.auto.factory.Provided; 20 | import javax.annotation.Nullable; 21 | import javax.inject.Provider; 22 | 23 | @AutoFactory 24 | final class MultipleProvidedParamsSameKey { 25 | private final String one; 26 | private final String two; 27 | private final String three; 28 | private final Provider providerOne; 29 | private final Provider providerTwo; 30 | 31 | public MultipleProvidedParamsSameKey( 32 | @Provided String one, 33 | @Provided String two, 34 | @Nullable @Provided String three, 35 | @Provided Provider providerOne, 36 | @Provided Provider providerTwo) { 37 | this.one = one; 38 | this.two = two; 39 | this.three = three; 40 | this.providerOne = providerOne; 41 | this.providerTwo = providerTwo; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/NestedClasses.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | 20 | final class NestedClasses { 21 | 22 | @AutoFactory 23 | static final class SimpleNestedClass {} 24 | 25 | @AutoFactory(className = "NestedClassCustomNamedFactory") 26 | static final class SimpleNestedClassWithCustomFactory {} 27 | } 28 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/OnlyPrimitives.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | 20 | /** 21 | * @author Ron Shapiro 22 | */ 23 | @AutoFactory 24 | final class OnlyPrimitives { 25 | OnlyPrimitives(int i, long l) {} 26 | } 27 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/ParameterAnnotations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import static java.lang.annotation.ElementType.PARAMETER; 19 | import static java.lang.annotation.ElementType.TYPE_USE; 20 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 | 22 | import com.google.auto.factory.AutoFactory; 23 | import com.google.auto.factory.Provided; 24 | import java.lang.annotation.Retention; 25 | import java.lang.annotation.Target; 26 | 27 | @AutoFactory 28 | final class ParameterAnnotations { 29 | @Retention(RUNTIME) 30 | @Target(PARAMETER) 31 | @interface NullableParameter {} 32 | 33 | // We have special treatment of @Nullable; make sure it doesn't get copied twice. 34 | @Retention(RUNTIME) 35 | @Target(PARAMETER) 36 | @interface Nullable {} 37 | 38 | @Retention(RUNTIME) 39 | @Target(TYPE_USE) 40 | @interface NullableType {} 41 | 42 | @Retention(RUNTIME) 43 | @Target({PARAMETER, TYPE_USE}) 44 | @interface NullableParameterAndType {} 45 | 46 | ParameterAnnotations( 47 | @Provided @NullableParameter @NullableType String foo, 48 | @NullableParameter Integer bar, 49 | @Nullable Long baz, 50 | @NullableType Thread buh, 51 | @NullableParameterAndType String quux) {} 52 | } 53 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/ProviderArgumentToCreateMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import javax.inject.Provider; 20 | 21 | @AutoFactory(implementing = ProviderArgumentToCreateMethod.CustomCreator.class) 22 | final class ProviderArgumentToCreateMethod { 23 | private final Provider stringProvider; 24 | 25 | ProviderArgumentToCreateMethod(Provider stringProvider) { 26 | this.stringProvider = stringProvider; 27 | } 28 | 29 | interface CustomCreator { 30 | ProviderArgumentToCreateMethod newInstance(Provider stringProvider); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/PublicClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | 20 | @AutoFactory 21 | public final class PublicClass {} 22 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/SimpleClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | 20 | @AutoFactory 21 | final class SimpleClass {} 22 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/SimpleClassCustomName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | 20 | @AutoFactory(className = "CustomNamedFactory") 21 | final class SimpleClassCustomName {} 22 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/SimpleClassImplementingMarker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package tests; 15 | 16 | import com.google.auto.factory.AutoFactory; 17 | import java.util.RandomAccess; 18 | 19 | @AutoFactory(implementing = RandomAccess.class) 20 | class SimpleClassImplementingMarker {} 21 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/SimpleClassImplementingSimpleInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import tests.SimpleClassImplementingSimpleInterface.SimpleInterface; 20 | 21 | @AutoFactory(implementing = SimpleInterface.class) 22 | final class SimpleClassImplementingSimpleInterface { 23 | interface SimpleInterface { 24 | SimpleClassImplementingSimpleInterface newInstance(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/SimpleClassMixedDeps.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import com.google.auto.factory.Provided; 20 | 21 | /** 22 | * @author Gregory Kick 23 | */ 24 | @AutoFactory 25 | @SuppressWarnings("unused") 26 | final class SimpleClassMixedDeps { 27 | private final String providedDepA; 28 | private final String depB; 29 | 30 | SimpleClassMixedDeps(@Provided @AQualifier String providedDepA, String depB) { 31 | this.providedDepA = providedDepA; 32 | this.depB = depB; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/SimpleClassNonFinal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | 20 | @AutoFactory(allowSubclasses = true) 21 | final class SimpleClassNonFinal {} 22 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/SimpleClassNullableParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import com.google.auto.factory.Provided; 20 | import javax.annotation.Nullable; 21 | 22 | @AutoFactory 23 | @SuppressWarnings("unused") 24 | final class SimpleClassNullableParameters { 25 | @Nullable private final String nullable; 26 | @Nullable private final String qualifiedNullable; 27 | @Nullable private final String providedNullable; 28 | @Nullable private final String providedQualifiedNullable; 29 | 30 | // TODO(ronshapiro): with Java 8, test Provider<@Nullable String> parameters and provider fields 31 | SimpleClassNullableParameters( 32 | @Nullable String nullable, 33 | @Nullable @AQualifier String qualifiedNullable, 34 | @Nullable @Provided String providedNullable, 35 | @Nullable @Provided @BQualifier String providedQualifiedNullable) { 36 | this.nullable = nullable; 37 | this.qualifiedNullable = qualifiedNullable; 38 | this.providedNullable = providedNullable; 39 | this.providedQualifiedNullable = providedQualifiedNullable; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/SimpleClassPassedDeps.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | 20 | /** 21 | * @author Gregory Kick 22 | */ 23 | @AutoFactory 24 | @SuppressWarnings("unused") 25 | final class SimpleClassPassedDeps { 26 | private final String depA; 27 | private final String depB; 28 | 29 | SimpleClassPassedDeps(String depA, String depB) { 30 | this.depA = depA; 31 | this.depB = depB; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/SimpleClassProvidedDeps.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package tests; 15 | 16 | import com.google.auto.factory.AutoFactory; 17 | import com.google.auto.factory.Provided; 18 | 19 | /** 20 | * @author Gregory Kick 21 | */ 22 | @AutoFactory 23 | @SuppressWarnings("unused") 24 | final class SimpleClassProvidedDeps { 25 | private final int providedPrimitiveA; 26 | private final int providedPrimitiveB; 27 | private final String providedDepA; 28 | private final String providedDepB; 29 | 30 | SimpleClassProvidedDeps( 31 | @Provided @AQualifier int providedPrimitiveA, 32 | @Provided @BQualifier int providedPrimitiveB, 33 | @Provided @AQualifier String providedDepA, 34 | @Provided @BQualifier String providedDepB) { 35 | this.providedPrimitiveA = providedPrimitiveA; 36 | this.providedPrimitiveB = providedPrimitiveB; 37 | this.providedDepA = providedDepA; 38 | this.providedDepB = providedDepB; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/SimpleClassProvidedProviderDeps.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package tests; 15 | 16 | import com.google.auto.factory.AutoFactory; 17 | import com.google.auto.factory.Provided; 18 | import javax.inject.Provider; 19 | 20 | /** 21 | * @author Gregory Kick 22 | */ 23 | @AutoFactory 24 | @SuppressWarnings("unused") 25 | final class SimpleClassProvidedProviderDeps { 26 | private final Provider providedDepA; 27 | private final Provider providedDepB; 28 | 29 | SimpleClassProvidedProviderDeps( 30 | @Provided @AQualifier Provider providedDepA, 31 | @Provided @BQualifier Provider providedDepB) { 32 | this.providedDepA = providedDepA; 33 | this.providedDepB = providedDepB; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/SimpleClassThrows.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | import java.io.IOException; 20 | 21 | @AutoFactory 22 | final class SimpleClassThrows { 23 | SimpleClassThrows() throws IOException, InterruptedException {} 24 | } 25 | -------------------------------------------------------------------------------- /factory/src/test/resources/good/SimpleClassVarargs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import com.google.auto.factory.AutoFactory; 19 | 20 | @AutoFactory(implementing = SimpleClassVarargs.InterfaceWithVarargs.class) 21 | final class SimpleClassVarargs { 22 | private final String[] args; 23 | 24 | SimpleClassVarargs(String... args) { 25 | this.args = args; 26 | } 27 | 28 | interface InterfaceWithVarargs { 29 | SimpleClassVarargs build(String... args); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /factory/src/test/resources/support/AQualifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 19 | 20 | import java.lang.annotation.Documented; 21 | import java.lang.annotation.Retention; 22 | import javax.inject.Qualifier; 23 | 24 | /** 25 | * @author Gregory Kick 26 | */ 27 | @Documented 28 | @Qualifier 29 | @Retention(RUNTIME) 30 | @interface AQualifier {} 31 | -------------------------------------------------------------------------------- /factory/src/test/resources/support/BQualifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 19 | 20 | import java.lang.annotation.Documented; 21 | import java.lang.annotation.Retention; 22 | import javax.inject.Qualifier; 23 | 24 | /** 25 | * @author Gregory Kick 26 | */ 27 | @Documented 28 | @Qualifier 29 | @Retention(RUNTIME) 30 | @interface BQualifier {} 31 | -------------------------------------------------------------------------------- /factory/src/test/resources/support/QualifierWithArgs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package tests; 17 | 18 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 19 | 20 | import java.lang.annotation.Documented; 21 | import java.lang.annotation.Retention; 22 | import javax.inject.Qualifier; 23 | 24 | /** 25 | * @author Justine Tunney 26 | */ 27 | @Documented 28 | @Qualifier 29 | @Retention(RUNTIME) 30 | @interface QualifierWithArgs { 31 | String name(); 32 | 33 | int count(); 34 | } 35 | -------------------------------------------------------------------------------- /service/annotations/src/main/java/com/google/auto/service/AutoService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.service; 17 | 18 | import static java.lang.annotation.ElementType.TYPE; 19 | import static java.lang.annotation.RetentionPolicy.CLASS; 20 | 21 | import java.lang.annotation.Documented; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * An annotation for service providers as described in {@link java.util.ServiceLoader}. The 27 | * annotation processor generates the configuration files that allow the annotated class to be 28 | * loaded with {@link java.util.ServiceLoader#load(Class)}. 29 | * 30 | *

The annotated class must conform to the service provider specification. Specifically, it must: 31 | * 32 | *

    33 | *
  • be a non-inner, non-anonymous, concrete class 34 | *
  • have a publicly accessible no-arg constructor 35 | *
  • implement the interface type returned by {@code value()} 36 | *
37 | */ 38 | @Documented 39 | @Retention(CLASS) 40 | @Target(TYPE) 41 | public @interface AutoService { 42 | /** Returns the interfaces implemented by this service provider. */ 43 | Class[] value(); 44 | } 45 | -------------------------------------------------------------------------------- /service/processor/src/main/java/com/google/auto/service/processor/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | /** 15 | * This package contains the annotation processor that implements the {@link 16 | * com.google.auto.service.AutoService} API. 17 | */ 18 | package com.google.auto.service.processor; 19 | -------------------------------------------------------------------------------- /service/processor/src/main/resources/META-INF/gradle/incremental.annotation.processors: -------------------------------------------------------------------------------- 1 | com.google.auto.service.processor.AutoServiceProcessor,AGGREGATING 2 | -------------------------------------------------------------------------------- /service/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor: -------------------------------------------------------------------------------- 1 | com.google.auto.service.processor.AutoServiceProcessor 2 | -------------------------------------------------------------------------------- /service/processor/src/test/resources/META-INF/services/test.AnotherService: -------------------------------------------------------------------------------- 1 | test.AnotherServiceProvider 2 | -------------------------------------------------------------------------------- /service/processor/src/test/resources/META-INF/services/test.SomeService: -------------------------------------------------------------------------------- 1 | test.Enclosing$NestedSomeServiceProvider 2 | test.SomeServiceProvider1 3 | test.SomeServiceProvider2 4 | -------------------------------------------------------------------------------- /service/processor/src/test/resources/test/AnotherService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package test; 17 | 18 | interface AnotherService {} 19 | -------------------------------------------------------------------------------- /service/processor/src/test/resources/test/AnotherServiceProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package test; 17 | 18 | import com.google.auto.service.AutoService; 19 | 20 | @AutoService(AnotherService.class) 21 | public class AnotherServiceProvider implements AnotherService {} 22 | -------------------------------------------------------------------------------- /service/processor/src/test/resources/test/AutoServiceOnAbstractClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package test; 17 | 18 | import com.google.auto.service.AutoService; 19 | 20 | @AutoService(SomeService.class) 21 | public abstract class AutoServiceOnAbstractClass implements SomeService {} 22 | -------------------------------------------------------------------------------- /service/processor/src/test/resources/test/AutoServiceOnInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package test; 17 | 18 | import com.google.auto.service.AutoService; 19 | 20 | @AutoService(SomeService.class) 21 | public interface AutoServiceOnInterface extends SomeService {} 22 | -------------------------------------------------------------------------------- /service/processor/src/test/resources/test/DoesNotImplement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package test; 17 | 18 | import com.google.auto.service.AutoService; 19 | 20 | @AutoService(SomeService.class) 21 | public class DoesNotImplement {} 22 | -------------------------------------------------------------------------------- /service/processor/src/test/resources/test/DoesNotImplementSuppressed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package test; 17 | 18 | import com.google.auto.service.AutoService; 19 | 20 | @AutoService(SomeService.class) 21 | @SuppressWarnings("AutoService") 22 | public class DoesNotImplementSuppressed {} 23 | -------------------------------------------------------------------------------- /service/processor/src/test/resources/test/Enclosing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package test; 17 | 18 | import com.google.auto.service.AutoService; 19 | 20 | public class Enclosing { 21 | @AutoService(SomeService.class) 22 | public static class NestedSomeServiceProvider implements SomeService {} 23 | } 24 | -------------------------------------------------------------------------------- /service/processor/src/test/resources/test/EnclosingGeneric.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package test; 17 | 18 | import com.google.auto.service.AutoService; 19 | 20 | /** Test for suppressing warnings about raw types on nested {@code @AutoService} classes. */ 21 | @SuppressWarnings("rawtypes") 22 | public final class EnclosingGeneric { 23 | /** 24 | * This is technically a raw class reference, but should be suppressed by the 25 | * {@code @SuppressWarnings} on the enclosing class. 26 | */ 27 | @AutoService(GenericService.class) 28 | public class GenericServiceProvider implements GenericService {} 29 | 30 | private EnclosingGeneric() {} 31 | } 32 | -------------------------------------------------------------------------------- /service/processor/src/test/resources/test/GenericService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package test; 17 | 18 | /** 19 | * An interface with a type parameter, which by default will produce a warning with 20 | * {@code @AutoService} if you compile with {@code -Averify=true}. 21 | */ 22 | public interface GenericService {} 23 | -------------------------------------------------------------------------------- /service/processor/src/test/resources/test/GenericServiceProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package test; 17 | 18 | import com.google.auto.service.AutoService; 19 | 20 | /** 21 | * An implementation of a service with a type parameter, which by default will produce a warning if 22 | * you compile with {@code -Averify=true}. 23 | */ 24 | @AutoService(GenericService.class) 25 | public class GenericServiceProvider implements GenericService {} 26 | -------------------------------------------------------------------------------- /service/processor/src/test/resources/test/GenericServiceProviderSuppressWarnings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package test; 17 | 18 | import com.google.auto.service.AutoService; 19 | 20 | /** 21 | * An implementation of a service with a type parameter, which will not produce a warning even if 22 | * compiled with {@code -Averify=true}, because of the {@code @SuppressWarnings}. 23 | */ 24 | @AutoService(GenericService.class) 25 | @SuppressWarnings("rawtypes") 26 | public class GenericServiceProviderSuppressWarnings implements GenericService {} 27 | -------------------------------------------------------------------------------- /service/processor/src/test/resources/test/GenericServiceProviderWithMissingServiceClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package test; 17 | 18 | import com.google.auto.service.AutoService; 19 | 20 | /** 21 | * A service that references a missing class. This is useful for testing that the processor behaves 22 | * correctly. 23 | */ 24 | @AutoService(MissingServiceClass.class) 25 | public class GenericServiceProviderWithMissingServiceClass implements MissingServiceClass {} 26 | -------------------------------------------------------------------------------- /service/processor/src/test/resources/test/MultiServiceProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package test; 17 | 18 | import com.google.auto.service.AutoService; 19 | 20 | @AutoService({SomeService.class, AnotherService.class}) 21 | public class MultiServiceProvider implements SomeService, AnotherService {} 22 | -------------------------------------------------------------------------------- /service/processor/src/test/resources/test/NoServices.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package test; 17 | 18 | import com.google.auto.service.AutoService; 19 | 20 | @AutoService({}) 21 | public class NoServices {} 22 | -------------------------------------------------------------------------------- /service/processor/src/test/resources/test/SomeService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package test; 17 | 18 | interface SomeService {} 19 | -------------------------------------------------------------------------------- /service/processor/src/test/resources/test/SomeServiceProvider1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package test; 17 | 18 | import com.google.auto.service.AutoService; 19 | 20 | @AutoService(SomeService.class) 21 | public class SomeServiceProvider1 implements SomeService {} 22 | -------------------------------------------------------------------------------- /service/processor/src/test/resources/test/SomeServiceProvider2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package test; 17 | 18 | import com.google.auto.service.AutoService; 19 | 20 | @AutoService(SomeService.class) 21 | public class SomeServiceProvider2 implements SomeService {} 22 | -------------------------------------------------------------------------------- /util/generate-latest-docs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Run by GitHub Actions (see .github/workflows/ci.yml) 4 | 5 | set -e 6 | 7 | echo -e "Publishing javadoc...\n" 8 | 9 | mvn -f build-pom.xml javadoc:aggregate 10 | TARGET="$(pwd)/target" 11 | 12 | cd $HOME 13 | git clone --quiet --branch=gh-pages "https://x-access-token:${GITHUB_TOKEN}@github.com/google/auto" gh-pages > /dev/null 14 | 15 | cd gh-pages 16 | git config --global user.name "$GITHUB_ACTOR" 17 | git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com" 18 | git rm -rf api/latest 19 | mkdir -p api # Just to make mv work if the directory is missing 20 | mv ${TARGET}/reports/apidocs api/latest 21 | git add -A -f api/latest 22 | git commit -m "Latest javadoc on successful CI build auto-pushed to gh-pages" 23 | git push -fq origin gh-pages > /dev/null 24 | 25 | echo -e "Published Javadoc to gh-pages.\n" 26 | -------------------------------------------------------------------------------- /util/publish-snapshot-on-commit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | mvn -B dependency:go-offline test clean -U --quiet --fail-never -DskipTests=true -f build-pom.xml 6 | mvn -B -U source:jar deploy -DskipTests=true -f build-pom.xml 7 | -------------------------------------------------------------------------------- /value/README.md: -------------------------------------------------------------------------------- 1 | # AutoValue 2 | 3 | *Generated immutable value classes for Java 8+*
4 | ***Kevin Bourrillion, Éamonn McManus***
5 | **Google, Inc.** 6 | 7 | **Value classes** are extremely common in Java projects. These are classes for 8 | which you want to treat any two instances with suitably equal field values as 9 | interchangeable. That's right: we're talking about those classes where you wind 10 | up implementing `equals`, `hashCode` and `toString` in a bloated, repetitive, 11 | formulaic yet error-prone fashion. 12 | 13 | Writing these methods the first time is not too bad, with the aid of a few 14 | helper methods and IDE templates. But once written they continue to burden 15 | reviewers, editors and future readers. Their wide expanses of boilerplate 16 | sharply decrease the signal-to-noise ratio of your code... and they love to 17 | harbor hard-to-spot bugs. 18 | 19 | AutoValue provides an easier way to create immutable value classes, with a lot 20 | less code and less room for error, while **not restricting your freedom** to 21 | code almost any aspect of your class exactly the way you want it. 22 | 23 | For more information, consult the [detailed documentation]. 24 | 25 | **Note:** If you are using Kotlin then its 26 | [data classes](https://kotlinlang.org/docs/data-classes.html) are usually more 27 | appropriate than AutoValue. Likewise, if you are using a version of Java that 28 | has [records] then those are usually more appropriate. You can still 29 | use [AutoBuilder] to make builders for data classes or records. 30 | 31 | [detailed documentation]: userguide/index.md 32 | [records]: userguide/records.md 33 | [AutoBuilder]: userguide/autobuilder.md 34 | -------------------------------------------------------------------------------- /value/src/it/functional/invoker.properties: -------------------------------------------------------------------------------- 1 | invoker.goals = clean verify 2 | 3 | invoker.profiles.1 = 4 | invoker.profiles.2 = eclipse -------------------------------------------------------------------------------- /value/src/it/functional/src/main/java/PackagelessNestedValueType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import com.google.auto.value.AutoValue; 18 | import java.util.Map; 19 | 20 | /** 21 | * @author emcmanus@google.com (Éamonn McManus) 22 | */ 23 | @SuppressWarnings("DefaultPackage") 24 | public class PackagelessNestedValueType { 25 | @AutoValue 26 | public abstract static class Nested { 27 | abstract Map numberNames(); 28 | 29 | public static Nested create(Map numberNames) { 30 | return new AutoValue_PackagelessNestedValueType_Nested(numberNames); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /value/src/it/functional/src/main/java/PackagelessValueType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import com.google.auto.value.AutoValue; 18 | import java.util.Map; 19 | import javax.annotation.Nullable; 20 | 21 | /** 22 | * Simple package-less value type for tests. 23 | * 24 | * @author emcmanus@google.com (Éamonn McManus) 25 | */ 26 | @SuppressWarnings("DefaultPackage") 27 | @AutoValue 28 | public abstract class PackagelessValueType { 29 | // The getters here are formatted as an illustration of what getters typically look in real 30 | // classes. In particular they have doc comments. 31 | 32 | /** 33 | * @return A string that is a nullable string. 34 | */ 35 | @Nullable 36 | public abstract String string(); 37 | 38 | /** 39 | * @return An integer that is an integer. 40 | */ 41 | public abstract int integer(); 42 | 43 | /** 44 | * @return A non-null map where the keys are strings and the values are longs. 45 | */ 46 | public abstract Map map(); 47 | 48 | public static PackagelessValueType create( 49 | @Nullable String string, int integer, Map map) { 50 | // The subclass AutoValue_PackagelessValueType is created by the annotation processor that is 51 | // triggered by the presence of the @AutoValue annotation. It has a constructor for each 52 | // of the abstract getter methods here, in order. The constructor stashes the values here 53 | // in private final fields, and each method is implemented to return the value of the 54 | // corresponding field. 55 | return new AutoValue_PackagelessValueType(string, integer, map); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /value/src/it/functional/src/main/java/com/google/auto/value/NestedValueType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value; 17 | 18 | import java.util.Map; 19 | 20 | /** 21 | * @author emcmanus@google.com (Éamonn McManus) 22 | */ 23 | public class NestedValueType { 24 | @AutoValue 25 | public abstract static class Nested { 26 | abstract Map numberNames(); 27 | 28 | public static Nested create(Map numberNames) { 29 | return new AutoValue_NestedValueType_Nested(numberNames); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /value/src/it/functional/src/main/java/com/google/auto/value/SimpleValueType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value; 17 | 18 | import java.util.Map; 19 | import javax.annotation.Nullable; 20 | 21 | /** 22 | * Simple value type for tests. 23 | * 24 | * @author emcmanus@google.com (Éamonn McManus) 25 | */ 26 | @AutoValue 27 | public abstract class SimpleValueType { 28 | // The getters here are formatted as an illustration of what getters typically look in real 29 | // classes. In particular they have doc comments. 30 | 31 | /** Returns a string that is a nullable string. */ 32 | @Nullable 33 | public abstract String string(); 34 | 35 | /** Returns an integer that is an integer. */ 36 | public abstract int integer(); 37 | 38 | /** Returns a non-null map where the keys are strings and the values are longs. */ 39 | public abstract Map map(); 40 | 41 | public static SimpleValueType create( 42 | @Nullable String string, int integer, Map map) { 43 | // The subclass AutoValue_SimpleValueType is created by the annotation processor that is 44 | // triggered by the presence of the @AutoValue annotation. It has a constructor for each 45 | // of the abstract getter methods here, in order. The constructor stashes the values here 46 | // in private final fields, and each method is implemented to return the value of the 47 | // corresponding field. 48 | return new AutoValue_SimpleValueType(string, integer, map); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /value/src/it/functional/src/test/java/com/google/auto/value/annotations/Empty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.annotations; 17 | 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | 21 | /** 22 | * An annotation with no members, for tests, and runtime retention so it can be accessed through 23 | * reflection. 24 | * 25 | * @author emcmanus@google.com (Éamonn McManus) 26 | */ 27 | @Retention(RetentionPolicy.RUNTIME) 28 | public @interface Empty {} 29 | -------------------------------------------------------------------------------- /value/src/it/functional/src/test/java/com/google/auto/value/annotations/GwtArrays.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.annotations; 17 | 18 | import com.google.common.annotations.GwtCompatible; 19 | 20 | /** 21 | * An annotation that is marked {@code @GwtCompatible} and that contains an array member. 22 | * 23 | * @author emcmanus@google.com (Éamonn McManus) 24 | */ 25 | @GwtCompatible 26 | public @interface GwtArrays { 27 | String[] strings(); 28 | 29 | int[] ints(); 30 | } 31 | -------------------------------------------------------------------------------- /value/src/it/functional/src/test/java/com/google/auto/value/annotations/StringValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.annotations; 17 | 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | 21 | /** 22 | * An annotation with one member, an array of strings with the default name {@code value}, and 23 | * runtime retention so it can be accessed through reflection. 24 | * 25 | * @author emcmanus@google.com (Éamonn McManus) 26 | */ 27 | @Retention(RetentionPolicy.RUNTIME) 28 | public @interface StringValues { 29 | String[] value(); 30 | } 31 | -------------------------------------------------------------------------------- /value/src/it/functional/src/test/java/com/google/auto/value/annotations/TestAnnotation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.annotations; 17 | 18 | /** Test annotation for AutoAnnotation and Kotlin. */ 19 | public @interface TestAnnotation { 20 | String value() default "default"; 21 | 22 | int integer() default 23; 23 | 24 | String[] values() default {}; 25 | } 26 | -------------------------------------------------------------------------------- /value/src/it/functional/src/test/java/com/google/auto/value/enums/MyEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.enums; 17 | 18 | /** 19 | * @author emcmanus@google.com (Éamonn McManus) 20 | */ 21 | public enum MyEnum { 22 | ONE, 23 | TWO, 24 | BUCKLE_MY_SHOE 25 | } 26 | -------------------------------------------------------------------------------- /value/src/it/functional/src/test/java/com/google/auto/value/gwt/GwtValueType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.gwt; 17 | 18 | import com.google.auto.value.AutoValue; 19 | import com.google.common.annotations.GwtCompatible; 20 | import java.io.Serializable; 21 | import java.util.Collections; 22 | import java.util.List; 23 | import javax.annotation.Nullable; 24 | 25 | /** 26 | * A class that is serializable with both Java and GWT serialization. 27 | * 28 | * @author emcmanus@google.com (Éamonn McManus) 29 | */ 30 | @AutoValue 31 | @GwtCompatible(serializable = true) 32 | abstract class GwtValueType implements Serializable { 33 | abstract String string(); 34 | 35 | abstract int integer(); 36 | 37 | @Nullable 38 | abstract GwtValueType other(); 39 | 40 | abstract List others(); 41 | 42 | static GwtValueType create(String string, int integer, @Nullable GwtValueType other) { 43 | return create(string, integer, other, Collections.emptyList()); 44 | } 45 | 46 | static GwtValueType create( 47 | String string, int integer, @Nullable GwtValueType other, List others) { 48 | return new AutoValue_GwtValueType(string, integer, other, others); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /value/src/it/functional/src/test/java/com/google/auto/value/gwt/NonSerializableGwtValueType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.gwt; 17 | 18 | import com.google.auto.value.AutoValue; 19 | import com.google.common.annotations.GwtCompatible; 20 | import java.io.Serializable; 21 | 22 | /** 23 | * A class that is serializable with native Java serialization but not with GWT serialization. 24 | * 25 | * @author emcmanus@google.com (Éamonn McManus) 26 | */ 27 | @AutoValue 28 | @GwtCompatible 29 | abstract class NonSerializableGwtValueType implements Serializable { 30 | abstract String string(); 31 | 32 | abstract int integer(); 33 | 34 | static NonSerializableGwtValueType create(String string, int integer) { 35 | return new AutoValue_NonSerializableGwtValueType(string, integer); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /value/src/it/gwtserializer/invoker.properties: -------------------------------------------------------------------------------- 1 | invoker.goals = clean verify 2 | -------------------------------------------------------------------------------- /value/src/it/gwtserializer/src/test/java/com/google/auto/value/GwtSerializerSuite.gwt.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /value/src/it/gwtserializer/src/test/java/com/google/auto/value/GwtSerializerSuite.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value; 17 | 18 | import com.google.auto.value.client.GwtSerializerTest; 19 | import com.google.gwt.junit.tools.GWTTestSuite; 20 | import junit.framework.Test; 21 | 22 | public class GwtSerializerSuite { 23 | public static Test suite() { 24 | GWTTestSuite suite = new GWTTestSuite(); 25 | 26 | suite.addTestSuite(GwtSerializerTest.class); 27 | 28 | return suite; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /value/src/main/java/com/google/auto/value/extension/memoized/processor/ClassNames.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.extension.memoized.processor; 17 | 18 | /** Names of classes that are referenced in the processor/extension. */ 19 | final class ClassNames { 20 | static final String MEMOIZED_NAME = "com.google.auto.value.extension.memoized.Memoized"; 21 | } 22 | -------------------------------------------------------------------------------- /value/src/main/java/com/google/auto/value/extension/serializable/SerializableAutoValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.extension.serializable; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * Annotates {@link com.google.auto.value.AutoValue @AutoValue} classes that implement {@link 25 | * java.io.Serializable}. A serializable subclass is generated for classes with normally 26 | * un-serializable fields like {@link java.util.Optional}. 27 | */ 28 | @Retention(RetentionPolicy.SOURCE) 29 | @Target(ElementType.TYPE) 30 | public @interface SerializableAutoValue {} 31 | -------------------------------------------------------------------------------- /value/src/main/java/com/google/auto/value/extension/serializable/processor/ClassNames.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.extension.serializable.processor; 17 | 18 | /** Names of classes that are referenced in /processor. */ 19 | final class ClassNames { 20 | static final String SERIALIZABLE_AUTO_VALUE_NAME = 21 | "com.google.auto.value.extension.serializable.SerializableAutoValue"; 22 | 23 | private ClassNames() {} 24 | } 25 | -------------------------------------------------------------------------------- /value/src/main/java/com/google/auto/value/extension/serializable/processor/PropertyMirror.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.extension.serializable.processor; 17 | 18 | import javax.lang.model.type.TypeMirror; 19 | 20 | /** 21 | * A POJO containing information about an AutoValue's property. 22 | * 23 | *

For example, given this AutoValue property: abstract T getX(); 24 | * 25 | *

    26 | *
  1. The type would be T. 27 | *
  2. The name would be x. 28 | *
  3. The method would be getX. 29 | */ 30 | final class PropertyMirror { 31 | 32 | private final TypeMirror type; 33 | private final String name; 34 | private final String method; 35 | 36 | PropertyMirror(TypeMirror type, String name, String method) { 37 | this.type = type; 38 | this.name = name; 39 | this.method = method; 40 | } 41 | 42 | /** Gets the AutoValue property's type. */ 43 | TypeMirror getType() { 44 | return type; 45 | } 46 | 47 | /** Gets the AutoValue property's name. */ 48 | String getName() { 49 | return name; 50 | } 51 | 52 | /** Gets the AutoValue property accessor method. */ 53 | String getMethod() { 54 | return method; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /value/src/main/java/com/google/auto/value/extension/serializable/serializer/impl/IdentitySerializerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.extension.serializable.serializer.impl; 17 | 18 | import com.google.auto.value.extension.serializable.serializer.interfaces.Serializer; 19 | import com.squareup.javapoet.CodeBlock; 20 | import javax.lang.model.type.TypeMirror; 21 | 22 | /** Creates identity {@link Serializer} instances. */ 23 | public final class IdentitySerializerFactory { 24 | 25 | /** Returns a {@link Serializer} that leaves the type as is. */ 26 | public static Serializer getSerializer(TypeMirror typeMirror) { 27 | return new IdentitySerializer(typeMirror); 28 | } 29 | 30 | private static class IdentitySerializer implements Serializer { 31 | 32 | private final TypeMirror typeMirror; 33 | 34 | IdentitySerializer(TypeMirror typeMirror) { 35 | this.typeMirror = typeMirror; 36 | } 37 | 38 | @Override 39 | public TypeMirror proxyFieldType() { 40 | return typeMirror; 41 | } 42 | 43 | @Override 44 | public CodeBlock toProxy(CodeBlock expression) { 45 | return expression; 46 | } 47 | 48 | @Override 49 | public CodeBlock fromProxy(CodeBlock expression) { 50 | return expression; 51 | } 52 | 53 | @Override 54 | public boolean isIdentity() { 55 | return true; 56 | } 57 | } 58 | 59 | private IdentitySerializerFactory() {} 60 | } 61 | -------------------------------------------------------------------------------- /value/src/main/java/com/google/auto/value/extension/serializable/serializer/interfaces/Serializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.extension.serializable.serializer.interfaces; 17 | 18 | import com.squareup.javapoet.CodeBlock; 19 | import javax.lang.model.type.TypeMirror; 20 | 21 | /** 22 | * A Serializer, at compile time, generates code to map an unserializable type to a serializable 23 | * type. It also generates the reverse code to re-create the original type. 24 | */ 25 | public interface Serializer { 26 | 27 | /** The proxy type the original unserializable type will be mapped to. */ 28 | TypeMirror proxyFieldType(); 29 | 30 | /** Creates an expression that converts the original type to the proxy type. */ 31 | CodeBlock toProxy(CodeBlock expression); 32 | 33 | /** Creates an expression that converts the proxy type back to the original type. */ 34 | CodeBlock fromProxy(CodeBlock expression); 35 | 36 | /** Returns true if this is an identity {@link Serializer}. */ 37 | default boolean isIdentity() { 38 | return false; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /value/src/main/java/com/google/auto/value/extension/serializable/serializer/interfaces/SerializerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.extension.serializable.serializer.interfaces; 17 | 18 | import com.squareup.javapoet.CodeBlock; 19 | import javax.lang.model.type.TypeMirror; 20 | 21 | /** 22 | * A factory that returns a {@link Serializer} for any given {@link TypeMirror}. 23 | * 24 | *

    Defaults to an identity serializer if no SerializerExtensions are suitable. 25 | */ 26 | public interface SerializerFactory { 27 | 28 | /** Returns a {@link Serializer} for the given {@link TypeMirror}. */ 29 | Serializer getSerializer(TypeMirror type); 30 | 31 | /** 32 | * Returns an identifier beginning with the given prefix and that is distinct from any identifier 33 | * returned by another call to this method. The returned identifier will contain a {@code $}, 34 | * which should also mean it is distinct from identifiers in user code that are in scope. 35 | * 36 | *

    The default implementation of this method throws {@link UnsupportedOperationException} for 37 | * compatibility reasons. 38 | */ 39 | default CodeBlock newIdentifier(String prefix) { 40 | throw new UnsupportedOperationException(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /value/src/main/java/com/google/auto/value/extension/serializable/serializer/runtime/FunctionWithExceptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.extension.serializable.serializer.runtime; 17 | 18 | import java.util.function.Function; 19 | 20 | /** A utility for lambdas that throw exceptions. */ 21 | public final class FunctionWithExceptions { 22 | 23 | /** Creates a wrapper for lambdas that converts checked exceptions to runtime exceptions. */ 24 | public static Function wrapper(FunctionWithException fe) { 25 | return arg -> { 26 | try { 27 | return fe.apply(arg); 28 | } catch (Exception e) { 29 | throw new RuntimeException(e); 30 | } 31 | }; 32 | } 33 | 34 | /** A function that can throw an exception. */ 35 | @FunctionalInterface 36 | public interface FunctionWithException { 37 | O apply(I i) throws Exception; 38 | } 39 | 40 | private FunctionWithExceptions() {} 41 | } 42 | -------------------------------------------------------------------------------- /value/src/main/java/com/google/auto/value/extension/toprettystring/processor/Annotations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.auto.value.extension.toprettystring.processor; 18 | 19 | import static com.google.auto.value.extension.toprettystring.processor.ClassNames.TO_PRETTY_STRING_NAME; 20 | 21 | import com.google.auto.common.MoreTypes; 22 | import java.util.Optional; 23 | import javax.lang.model.element.AnnotationMirror; 24 | import javax.lang.model.element.Element; 25 | import javax.lang.model.element.TypeElement; 26 | 27 | /** Extension methods for working with {@link AnnotationMirror}. */ 28 | final class Annotations { 29 | static Optional getAnnotationMirror(Element element, String annotationName) { 30 | for (AnnotationMirror annotation : element.getAnnotationMirrors()) { 31 | TypeElement annotationElement = MoreTypes.asTypeElement(annotation.getAnnotationType()); 32 | if (annotationElement.getQualifiedName().contentEquals(annotationName)) { 33 | return Optional.of(annotation); 34 | } 35 | } 36 | return Optional.empty(); 37 | } 38 | 39 | static Optional toPrettyStringAnnotation(Element element) { 40 | return getAnnotationMirror(element, TO_PRETTY_STRING_NAME); 41 | } 42 | 43 | private Annotations() {} 44 | } 45 | -------------------------------------------------------------------------------- /value/src/main/java/com/google/auto/value/extension/toprettystring/processor/ClassNames.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.auto.value.extension.toprettystring.processor; 18 | 19 | /** Names of classes that are referenced in the processor/extension. */ 20 | final class ClassNames { 21 | static final String TO_PRETTY_STRING_NAME = 22 | "com.google.auto.value.extension.toprettystring.ToPrettyString"; 23 | 24 | private ClassNames() {} 25 | } 26 | -------------------------------------------------------------------------------- /value/src/main/java/com/google/auto/value/processor/AbortProcessingException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.processor; 17 | 18 | /** 19 | * Exception thrown when annotation processing should be aborted for the current class. Processing 20 | * can continue on other classes. Throwing this exception does not cause a compiler error, so either 21 | * one should explicitly be emitted or it should be clear that the compiler will be producing its 22 | * own error for other reasons. 23 | * 24 | * @author emcmanus@google.com (Éamonn McManus) 25 | */ 26 | @SuppressWarnings("serial") 27 | class AbortProcessingException extends RuntimeException {} 28 | -------------------------------------------------------------------------------- /value/src/main/java/com/google/auto/value/processor/AutoBuilderAnnotationTemplateVars.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.processor; 17 | 18 | import com.google.auto.value.processor.AutoValueishProcessor.Property; 19 | import com.google.common.collect.ImmutableSet; 20 | import com.google.escapevelocity.Template; 21 | 22 | /** The variables to substitute into the autobuilderannotation.vm template. */ 23 | class AutoBuilderAnnotationTemplateVars extends TemplateVars { 24 | private static final Template TEMPLATE = parsedTemplateForResource("autobuilderannotation.vm"); 25 | 26 | /** Package of generated class. */ 27 | String pkg; 28 | 29 | /** The encoding of the {@code Generated} class. Empty if the class is not available. */ 30 | String generated; 31 | 32 | /** The name of the class to generate. */ 33 | String className; 34 | 35 | /** 36 | * The {@linkplain TypeEncoder#encode encoded} name of the annotation type that the generated code 37 | * will build. 38 | */ 39 | String annotationType; 40 | 41 | /** 42 | * The {@linkplain TypeEncoder#encode encoded} name of the {@code @AutoBuilder} type that users 43 | * will call to build this annotation. 44 | */ 45 | String autoBuilderType; 46 | 47 | /** 48 | * The "properties" that the builder will build. These are really just names and types, being the 49 | * names and types of the annotation elements. 50 | */ 51 | ImmutableSet props; 52 | 53 | @Override 54 | Template parsedTemplate() { 55 | return TEMPLATE; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /value/src/main/java/com/google/auto/value/processor/AutoBuilderTemplateVars.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.processor; 17 | 18 | import com.google.escapevelocity.Template; 19 | 20 | class AutoBuilderTemplateVars extends AutoValueOrBuilderTemplateVars { 21 | private static final Template TEMPLATE = parsedTemplateForResource("autobuilder.vm"); 22 | 23 | @Override 24 | Template parsedTemplate() { 25 | return TEMPLATE; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /value/src/main/java/com/google/auto/value/processor/AutoOneOfTemplateVars.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.processor; 17 | 18 | import com.google.common.collect.ImmutableSet; 19 | import com.google.escapevelocity.Template; 20 | import java.util.Map; 21 | 22 | /** 23 | * The variables to substitute into the autooneof.vm template. 24 | * 25 | * @author emcmanus@google.com (Éamonn McManus) 26 | */ 27 | @SuppressWarnings("unused") // the fields in this class are only read via reflection 28 | class AutoOneOfTemplateVars extends AutoValueishTemplateVars { 29 | /** 30 | * The properties defined by the parent class's abstract methods. The elements of this set are in 31 | * the same order as the original abstract method declarations in the AutoOneOf class. 32 | */ 33 | ImmutableSet props; 34 | 35 | /** The simple name of the generated class. */ 36 | String generatedClass; 37 | 38 | /** The encoded name of the "kind" enum class. */ 39 | String kindType; 40 | 41 | /** The name of the method that gets the kind of the current {@code @AutoOneOf} instance. */ 42 | String kindGetter; 43 | 44 | /** Maps property names like {@code dog} to enum constants like {@code DOG}. */ 45 | Map propertyToKind; 46 | 47 | /** True if this {@code @AutoOneOf} class is Serializable. */ 48 | Boolean serializable; 49 | 50 | private static final Template TEMPLATE = parsedTemplateForResource("autooneof.vm"); 51 | 52 | @Override 53 | Template parsedTemplate() { 54 | return TEMPLATE; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /value/src/main/java/com/google/auto/value/processor/ClassNames.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.processor; 17 | 18 | /** 19 | * Names of classes that are referenced in the processors. 20 | * 21 | * @author emcmanus@google.com (Éamonn McManus) 22 | */ 23 | final class ClassNames { 24 | private ClassNames() {} 25 | 26 | static final String AUTO_VALUE_PACKAGE_NAME = "com.google.auto.value."; 27 | static final String AUTO_ANNOTATION_NAME = AUTO_VALUE_PACKAGE_NAME + "AutoAnnotation"; 28 | static final String AUTO_ONE_OF_NAME = AUTO_VALUE_PACKAGE_NAME + "AutoOneOf"; 29 | static final String AUTO_VALUE_NAME = AUTO_VALUE_PACKAGE_NAME + "AutoValue"; 30 | static final String AUTO_VALUE_BUILDER_NAME = AUTO_VALUE_NAME + ".Builder"; 31 | static final String AUTO_BUILDER_NAME = AUTO_VALUE_PACKAGE_NAME + "AutoBuilder"; 32 | static final String COPY_ANNOTATIONS_NAME = AUTO_VALUE_NAME + ".CopyAnnotations"; 33 | static final String KOTLIN_METADATA_NAME = "kot".concat("lin.Metadata"); // defeat shading 34 | } 35 | -------------------------------------------------------------------------------- /value/src/main/java/com/google/auto/value/processor/GwtCompatibility.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.processor; 17 | 18 | import java.util.List; 19 | import java.util.Optional; 20 | import javax.lang.model.element.AnnotationMirror; 21 | import javax.lang.model.element.Name; 22 | import javax.lang.model.element.TypeElement; 23 | 24 | class GwtCompatibility { 25 | private final Optional gwtCompatibleAnnotation; 26 | 27 | GwtCompatibility(TypeElement type) { 28 | Optional gwtCompatibleAnnotation = Optional.empty(); 29 | List annotations = type.getAnnotationMirrors(); 30 | for (AnnotationMirror annotation : annotations) { 31 | Name name = annotation.getAnnotationType().asElement().getSimpleName(); 32 | if (name.contentEquals("GwtCompatible")) { 33 | gwtCompatibleAnnotation = Optional.of(annotation); 34 | } 35 | } 36 | this.gwtCompatibleAnnotation = gwtCompatibleAnnotation; 37 | } 38 | 39 | Optional gwtCompatibleAnnotation() { 40 | return gwtCompatibleAnnotation; 41 | } 42 | 43 | String gwtCompatibleAnnotationString() { 44 | return gwtCompatibleAnnotation.map(AnnotationOutput::sourceFormForAnnotation).orElse(""); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /value/src/main/java/com/google/auto/value/processor/autobuilder.vm: -------------------------------------------------------------------------------- 1 | ## Copyright 2014 Google LLC 2 | ## 3 | ## Licensed under the Apache License, Version 2.0 (the "License"); 4 | ## you may not use this file except in compliance with the License. 5 | ## You may obtain a copy of the License at 6 | ## 7 | ## http://www.apache.org/licenses/LICENSE-2.0 8 | ## 9 | ## Unless required by applicable law or agreed to in writing, software 10 | ## distributed under the License is distributed on an "AS IS" BASIS, 11 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | ## See the License for the specific language governing permissions and 13 | ## limitations under the License. 14 | 15 | ## Template for each generated AutoBuilder_Foo class. 16 | ## This template uses the Apache Velocity Template Language (VTL). 17 | ## The variables ($pkg, $props, and so on) are defined by the fields of AutoBuilderTemplateVars. 18 | ## 19 | ## Comments, like this one, begin with ##. The comment text extends up to and including the newline 20 | ## character at the end of the line. So comments also serve to join a line to the next one. 21 | ## Velocity deletes a newline after a directive (#if, #foreach, #end etc) so ## is not needed there. 22 | ## That does mean that we sometimes need an extra blank line after such a directive. 23 | ## 24 | ## Post-processing will remove unwanted spaces and blank lines, but will not join two lines. 25 | ## It will also replace classes spelled as (e.g.) `java.util.Arrays`, with the backquotes, to 26 | ## use just Arrays if that class can be imported unambiguously, or java.util.Arrays if not. 27 | 28 | #if (!$pkg.empty) 29 | package $pkg; 30 | #end 31 | 32 | ## The following line will be replaced by the required imports during post-processing. 33 | `import` 34 | 35 | #if (!$generated.empty) 36 | @${generated}("com.google.auto.value.processor.AutoBuilderProcessor") 37 | #else 38 | // Generated by com.google.auto.value.processor.AutoBuilderProcessor 39 | #end 40 | #set($autoBuilder = true) 41 | #parse("builder.vm") 42 | -------------------------------------------------------------------------------- /value/src/main/java/com/google/auto/value/processor/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | /** 15 | * This package contains the annotation processor that implements the {@link 16 | * com.google.auto.value.AutoValue} API. 17 | */ 18 | package com.google.auto.value.processor; 19 | -------------------------------------------------------------------------------- /value/src/test/java/com/google/auto/value/extension/memoized/MemoizedMethodSubjectFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.auto.value.extension.memoized; 18 | 19 | import static com.google.common.truth.Truth.assertAbout; 20 | 21 | import com.google.common.truth.FailureMetadata; 22 | import com.google.common.truth.Subject; 23 | 24 | final class MemoizedMethodSubjectFactory implements Subject.Factory { 25 | 26 | static MemoizedMethodSubjectFactory memoizeMethod() { 27 | return new MemoizedMethodSubjectFactory(); 28 | } 29 | 30 | static MemoizedMethodSubject assertThatMemoizeMethod(String method) { 31 | return assertAbout(memoizeMethod()).that(method); 32 | } 33 | 34 | @Override 35 | public MemoizedMethodSubject createSubject(FailureMetadata failureMetadata, String that) { 36 | return new MemoizedMethodSubject(failureMetadata, that); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /value/src/test/java/com/google/auto/value/extension/serializable/serializer/SerializerFactoryLoaderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.extension.serializable.serializer; 17 | 18 | import static com.google.common.truth.Truth.assertThat; 19 | 20 | import com.google.auto.value.extension.serializable.serializer.interfaces.Serializer; 21 | import com.google.auto.value.extension.serializable.serializer.interfaces.SerializerFactory; 22 | import com.google.auto.value.extension.serializable.serializer.utils.CompilationAbstractTest; 23 | import org.junit.Test; 24 | import org.junit.runner.RunWith; 25 | import org.junit.runners.JUnit4; 26 | 27 | @RunWith(JUnit4.class) 28 | public final class SerializerFactoryLoaderTest extends CompilationAbstractTest { 29 | 30 | @Test 31 | public void getFactory_extensionsLoaded() throws Exception { 32 | SerializerFactory factory = SerializerFactoryLoader.getFactory(mockProcessingEnvironment); 33 | 34 | Serializer actualSerializer = factory.getSerializer(typeMirrorOf(String.class)); 35 | 36 | assertThat(actualSerializer.getClass().getName()) 37 | .contains("TestStringSerializerFactory$TestStringSerializer"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /value/src/test/java/com/google/auto/value/processor/GeneratedImport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.processor; 17 | 18 | import javax.lang.model.SourceVersion; 19 | 20 | /** 21 | * Utility methods for compile-testing tests to know which {@code @Generated} annotation is 22 | * available. 23 | */ 24 | final class GeneratedImport { 25 | 26 | /** 27 | * Returns the qualified name of the {@code @Generated} annotation available during a compilation 28 | * task. 29 | */ 30 | static String generatedAnnotationType() { 31 | return SourceVersion.latestSupported().compareTo(SourceVersion.RELEASE_8) > 0 32 | ? "javax.annotation.processing.Generated" 33 | : "javax.annotation.Generated"; 34 | } 35 | 36 | /** 37 | * Returns an {@code import} statement that imports the {@code @Generated} annotation {@linkplain 38 | * #generatedAnnotationType() available during a compilation task}. 39 | */ 40 | static String importGeneratedAnnotationType() { 41 | return "import " + generatedAnnotationType() + ";"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /value/src/test/java/com/google/auto/value/processor/testclasses/RuntimePermission.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.auto.value.processor.testclasses; 17 | 18 | /** 19 | * This class just exists to test import behaviour when referencing a class which has the same name 20 | * as a class in java.lang. 21 | * 22 | * @author emcmanus@google.com (Éamonn McManus) 23 | */ 24 | public class RuntimePermission {} 25 | -------------------------------------------------------------------------------- /value/userguide/design-faq.md: -------------------------------------------------------------------------------- 1 | # Design FAQ 2 | 3 | 4 | TODO. This page will contain various explanations of *why* AutoValue's features 5 | were designed as they are. 6 | -------------------------------------------------------------------------------- /value/userguide/extensions.md: -------------------------------------------------------------------------------- 1 | # Extensions 2 | 3 | 4 | AutoValue can be extended to implement new features for classes annotated with 5 | `@AutoValue`. 6 | 7 | ## Using extensions 8 | 9 | Each extension is a class. If that class is on the `processorpath` when you 10 | compile your `@AutoValue` class, the extension can run. 11 | 12 | Some extensions are triggered by their own annotations, which you add to your 13 | class; others may be triggered in other ways. Consult the extension's 14 | documentation for usage instructions. 15 | 16 | ## Writing an extension 17 | 18 | To add a feature, write a class that extends [`AutoValueExtension`], and put 19 | that class on the `processorpath` along with `AutoValueProcessor`. 20 | 21 | `AutoValueExtension` uses the [`ServiceLoader`] mechanism, which means: 22 | 23 | * Your class must be public and have a public no-argument constructor. 24 | * Its fully-qualified name must appear in a file called 25 | `META-INF/services/com.google.auto.value.extension.AutoValueExtension` in a 26 | JAR that is on the compiler's `classpath` or `processorpath`. 27 | 28 | You can use [AutoService] to make implementing the `ServiceLoader` pattern easy. 29 | 30 | Without extensions, AutoValue generates a subclass of the `@AutoValue` class. 31 | Extensions can work by generating a chain of subclasses, each of which alters 32 | behavior by overriding or implementing new methods. 33 | 34 | ## TODO 35 | 36 | * How to distribute extensions. 37 | * List of known extensions. 38 | 39 | [AutoService]: https://github.com/google/auto/tree/main/service 40 | [`AutoValueExtension`]: https://github.com/google/auto/blob/main/value/src/main/java/com/google/auto/value/extension/AutoValueExtension.java 41 | [`ServiceLoader`]: http://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html 42 | -------------------------------------------------------------------------------- /value/userguide/generated-example.md: -------------------------------------------------------------------------------- 1 | # Generated example 2 | 3 | 4 | For the code shown in the [introduction](index.md), the following is typical 5 | code AutoValue might generate: 6 | 7 | ```java 8 | import javax.annotation.Generated; 9 | 10 | @Generated("com.google.auto.value.processor.AutoValueProcessor") 11 | final class AutoValue_Animal extends Animal { 12 | private final String name; 13 | private final int numberOfLegs; 14 | 15 | AutoValue_Animal(String name, int numberOfLegs) { 16 | if (name == null) { 17 | throw new NullPointerException("Null name"); 18 | } 19 | this.name = name; 20 | this.numberOfLegs = numberOfLegs; 21 | } 22 | 23 | @Override 24 | String name() { 25 | return name; 26 | } 27 | 28 | @Override 29 | int numberOfLegs() { 30 | return numberOfLegs; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "Animal{" 36 | + "name=" + name + ", " 37 | + "numberOfLegs=" + numberOfLegs + "}"; 38 | } 39 | 40 | @Override 41 | public boolean equals(Object o) { 42 | if (o == this) { 43 | return true; 44 | } 45 | if (o instanceof Animal) { 46 | Animal that = (Animal) o; 47 | return this.name.equals(that.name()) 48 | && this.numberOfLegs == that.numberOfLegs(); 49 | } 50 | return false; 51 | } 52 | 53 | @Override 54 | public int hashCode() { 55 | int h = 1; 56 | h *= 1000003; 57 | h ^= this.name.hashCode(); 58 | h *= 1000003; 59 | h ^= this.numberOfLegs; 60 | return h; 61 | } 62 | } 63 | ``` 64 | -------------------------------------------------------------------------------- /value/userguide/performance.md: -------------------------------------------------------------------------------- 1 | # Performance notes 2 | 3 | 4 | TODO: write a real page 5 | 6 | * should perform like a hand-written class after HotSpot compiles it 7 | (generated accessors can be inlined) 8 | * what does proguard do with it 9 | * hash codes are not cached 10 | -------------------------------------------------------------------------------- /value/userguide/trouble.md: -------------------------------------------------------------------------------- 1 | # Troubleshooting 2 | 3 | 4 | TODO 5 | 6 | ## `equals()` is not returning what I expect 7 | 8 | This is usually a sign that one of your field types is not implementing `equals` 9 | as you expect. A typical offending class is [`JSONObject`] 10 | (https://developer.android.com/reference/org/json/JSONObject.html), which 11 | doesn't override `Object.equals()` and thus compromises your class's `equals` 12 | behavior as well. 13 | -------------------------------------------------------------------------------- /value/userguide/why.md: -------------------------------------------------------------------------------- 1 | # Why use AutoValue? 2 | 3 | 4 | In versions of Java preceding 5 | [records](https://docs.oracle.com/en/java/javase/16/language/records.html), 6 | AutoValue is the only solution to the value class problem having all of the 7 | following characteristics: 8 | 9 | * **API-invisible** (callers cannot become dependent on your choice to use it) 10 | * No runtime dependencies 11 | * Negligible cost to performance 12 | * Very few limitations on what your class can do 13 | * Extralinguistic "magic" kept to an absolute minimum (uses only standard Java 14 | platform technologies, in the manner they were intended) 15 | 16 | This 17 | [slide presentation] compares AutoValue to numerous alternatives and explains 18 | why we think it is better. 19 | 20 | [slide presentation]: https://docs.google.com/presentation/d/14u_h-lMn7f1rXE1nDiLX0azS3IkgjGl5uxp5jGJ75RE/edit 21 | --------------------------------------------------------------------------------