AutoFactory
======
A source code generator for JSR-330-compatible factories.
AutoWhat‽
-------------
[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!_
AutoFactory 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.
[Dagger](https://dagger.dev/) users: Dagger's own
[assisted injection](https://dagger.dev/dev-guide/assisted-injection.html) is
now usually preferred to AutoFactory.
Example
-------
Say you have:
```java
@AutoFactory
final class SomeClass {
private final String providedDepA;
private final String depB;
SomeClass(@Provided @AQualifier String providedDepA, String depB) {
this.providedDepA = providedDepA;
this.depB = depB;
}
// …
}
```
AutoFactory will generate:
```java
import javax.annotation.Generated;
import javax.inject.Inject;
import javax.inject.Provider;
@Generated(value = "com.google.auto.factory.processor.AutoFactoryProcessor")
final class SomeClassFactory {
private final Provider<String> providedDepAProvider;
@Inject SomeClassFactory(
@AQualifier Provider<String> providedDepAProvider) {
this.providedDepAProvider = providedDepAProvider;
}
SomeClass create(String depB) {
return new SomeClass(providedDepAProvider.get(), depB);
}
}
```
> NOTE: AutoFactory only supports JSR-330 @Qualifier annotations. Older,
> framework-specific annotations from Guice, Spring, etc are not
> supported (though these all support JSR-330)
Mocking
-------
By default, the factory class generated by AutoFactory is final, and thus cannot
be mocked. The generated factory class can be made mockable by setting
`allowSubclasses = true`, as follows:
```java
@AutoFactory(allowSubclasses = true)
final class SomeClass {
// …
}
```
Download
--------
In order to activate code generation you will need to
include `auto-factory-${version}.jar` in your build at
compile time.
In a Maven project, one would include the `auto-factory`
artifact as an "optional" dependency:
```xml
<dependencies>
<dependency>
<groupId>com.google.auto.factory</groupId>
<artifactId>auto-factory</artifactId>
<version>${version}</version>
<optional>true</optional>
</dependency>
</dependencies>
```
License
-------
Copyright 2013 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
[java]: https://en.wikipedia.org/wiki/Java_(programming_language)
没有合适的资源?快使用搜索试试~ 我知道了~
A collection of source code generators for Java..zip
共376个文件
java:319个
md:23个
xml:13个
需积分: 1 0 下载量 197 浏览量
2024-02-28
21:22:12
上传
评论
收藏 746KB ZIP 举报
温馨提示
A collection of source code generators for Java..zip
资源推荐
资源详情
资源评论
收起资源包目录
A collection of source code generators for Java..zip (376个子文件)
test.AnotherService 28B
.gitignore 189B
AutoValueCompilationTest.java 151KB
AutoValueTest.java 122KB
AutoValueishProcessor.java 59KB
ExtensionTest.java 51KB
AutoValueJava8Test.java 44KB
MoreTypes.java 38KB
BasicAnnotationProcessorTest.java 37KB
AutoBuilderProcessor.java 36KB
BasicAnnotationProcessor.java 35KB
AutoBuilderCompilationTest.java 35KB
BuilderMethodClassifier.java 33KB
ToPrettyStringTest.java 28KB
AutoAnnotationProcessor.java 25KB
TypeEncoder.java 25KB
AutoValueExtension.java 25KB
BuilderSpec.java 24KB
AutoValueProcessor.java 24KB
MoreElements.java 24KB
OverridesTest.java 24KB
MoreTypesTest.java 23KB
AutoBuilderTest.java 23KB
AutoAnnotationTest.java 23KB
ToPrettyStringExtension.java 22KB
AutoFactoryProcessorTest.java 22KB
Overrides.java 21KB
PropertyBuilderClassifier.java 21KB
AutoOneOfCompilationTest.java 21KB
MoreElementsTest.java 21KB
AutoAnnotationCompilationTest.java 20KB
PropertyAnnotationsTest.java 20KB
MemoizeExtension.java 18KB
TypeEncoderTest.java 18KB
AnnotationValues.java 18KB
MemoizedTest.java 18KB
BuilderRequiredProperties.java 17KB
AutoOneOfTest.java 17KB
BuilderRequiredPropertiesTest.java 17KB
TypeSimplifier.java 16KB
SerializableAutoValueExtensionTest.java 16KB
FactoryWriter.java 16KB
AnnotationMirrorsTest.java 16KB
AutoFactoryProcessor.java 15KB
GwtCompilationTest.java 15KB
AnnotationValuesTest.java 14KB
AutoServiceProcessor.java 14KB
AutoAnnotationErrorsTest.java 13KB
SerializableAutoValueExtension.java 13KB
AutoOneOfProcessor.java 12KB
AnnotationOutput.java 12KB
TypeVariables.java 12KB
SuperficialValidation.java 11KB
TypeSimplifierTest.java 11KB
SuperficialValidationTest.java 11KB
CustomFieldSerializerTest.java 11KB
GwtSerialization.java 10KB
BuilderMethodClassifierForAutoBuilder.java 10KB
AutoBuilderKotlinTest.java 10KB
AutoServiceProcessorTest.java 10KB
GeneratedDoesNotExistTest.java 9KB
AutoFactoryDeclaration.java 9KB
FactoryDescriptor.java 9KB
GeneratedAnnotationsTest.java 9KB
TypeVariablesTest.java 9KB
AutoFactoryProcessorNegativeTest.java 9KB
AnnotationMirrors.java 9KB
AnnotationOutput.java 9KB
ForwardingClassGenerator.java 9KB
SimpleServiceLoaderTest.java 8KB
SimplifyWithAnnotationsTest.java 8KB
NullablesTest.java 8KB
ToPrettyStringValidatorTest.java 8KB
TemplateVars.java 7KB
GwtSerializerTest.java 7KB
Nullables.java 7KB
MoreTypesIsTypeOfTest.java 7KB
FactoryDescriptorGenerator.java 7KB
GradleIT.java 7KB
DependencyInjectionIntegrationTest.java 7KB
VisibilityTest.java 6KB
ImmutableMapSerializerExtension.java 6KB
AutoValueOrBuilderTemplateVars.java 6KB
ExtensionClassTypeSpecBuilder.java 6KB
CompileWithEclipseTest.java 6KB
ForwardingClassGeneratorTest.java 6KB
BuilderMethodClassifierForAutoValue.java 6KB
AutoValue.java 6KB
Parameter.java 6KB
ExtensionContext.java 5KB
MissingTypes.java 5KB
ToPrettyStringValidator.java 5KB
ImmutableMapSerializerExtensionTest.java 5KB
Executable.java 5KB
SimpleAnnotationMirror.java 5KB
EmptyExtension.java 5KB
SimpleServiceLoader.java 5KB
IncrementalExtensionTest.java 5KB
ReformatterTest.java 5KB
Reformatter.java 5KB
共 376 条
- 1
- 2
- 3
- 4
资源评论
日刷百题
- 粉丝: 5365
- 资源: 951
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功