1AutoFactory 2====== 3 4A source code generator for JSR-330-compatible factories. 5 6AutoWhat‽ 7------------- 8 9[Java][java] is full of [factories](http://en.wikipedia.org/wiki/Factory_method_pattern). They're mechanical, repetitive, typically untested and sometimes the source of subtle bugs. _Sounds like a job for robots!_ 10 11AutoFactory generates factories that can be used on their own or with [JSR-330](http://jcp.org/en/jsr/detail?id=330)-compatible [dependency injectors](http://en.wikipedia.org/wiki/Dependency_injection) from a simple annotation. Any combination of parameters can either be passed through factory methods or provided to the factory at construction time. They can implement interfaces or extend abstract classes. They're what you would have written, but without the bugs. 12 13Save time. Save code. Save sanity. 14 15Example 16------- 17 18Say you have: 19 20```java 21@AutoFactory 22final class SomeClass { 23 private final String providedDepA; 24 private final String depB; 25 26 SomeClass(@Provided @AQualifier String providedDepA, String depB) { 27 this.providedDepA = providedDepA; 28 this.depB = depB; 29 } 30 31 // … 32} 33``` 34 35AutoFactory will generate: 36 37```java 38import javax.annotation.Generated; 39import javax.inject.Inject; 40import javax.inject.Provider; 41 42@Generated(value = "com.google.auto.factory.processor.AutoFactoryProcessor") 43final class SomeClassFactory { 44 private final Provider<String> providedDepAProvider; 45 46 @Inject SomeClassFactory( 47 @AQualifier Provider<String> providedDepAProvider) { 48 this.providedDepAProvider = providedDepAProvider; 49 } 50 51 SomeClass create(String depB) { 52 return new SomeClass(providedDepAProvider.get(), depB); 53 } 54} 55``` 56 57> NOTE: AutoFactory only supports JSR-330 @Qualifier annotations. Older, 58> framework-specific annotations from Guice, Spring, etc are not 59> supported (though these all support JSR-330) 60 61Download 62-------- 63 64In order to activate code generation you will need to 65include `auto-factory-${version}.jar` in your build at 66compile time. 67 68In a Maven project, one would include the `auto-factory` 69artifact as an "optional" dependency: 70 71```xml 72<dependencies> 73 <dependency> 74 <groupId>com.google.auto.factory</groupId> 75 <artifactId>auto-factory</artifactId> 76 <version>${version}</version> 77 <optional>true</optional> 78 </dependency> 79</dependencies> 80``` 81 82 83License 84------- 85 86 Copyright 2013 Google LLC 87 88 Licensed under the Apache License, Version 2.0 (the "License"); 89 you may not use this file except in compliance with the License. 90 You may obtain a copy of the License at 91 92 http://www.apache.org/licenses/LICENSE-2.0 93 94 Unless required by applicable law or agreed to in writing, software 95 distributed under the License is distributed on an "AS IS" BASIS, 96 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 97 See the License for the specific language governing permissions and 98 limitations under the License. 99 100[java]: https://en.wikipedia.org/wiki/Java_(programming_language) 101 102