Skip to content

Commit 9b81e10

Browse files
gk5885cgruber
authored andcommittedOct 21, 2015
Prune modules that do not provide bindings that require a module instance. The methods that would set those modules remain on the builder, but are @deprecated no-op methods.
------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=103132967
1 parent fb7a9d4 commit 9b81e10

File tree

12 files changed

+302
-238
lines changed

12 files changed

+302
-238
lines changed
 

‎compiler/src/it/functional-tests/src/test/java/test/staticprovides/StaticProvidesTest.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@
1515
*/
1616
package test.staticprovides;
1717

18-
import static com.google.common.truth.Truth.assertThat;
19-
2018
import com.google.common.collect.ImmutableSet;
21-
19+
import java.lang.reflect.Field;
20+
import java.lang.reflect.Method;
21+
import java.util.Arrays;
2222
import org.junit.Test;
2323
import org.junit.runner.RunWith;
2424
import org.junit.runners.JUnit4;
2525

26+
import static com.google.common.truth.Truth.assertThat;
27+
import static com.google.common.truth.Truth.assertWithMessage;
28+
2629
@RunWith(JUnit4.class)
2730
public class StaticProvidesTest {
2831
private final StaticTestComponent component = DaggerStaticTestComponent.create();
@@ -33,4 +36,21 @@ public class StaticProvidesTest {
3336
SomeStaticModule.class + ".contributeStringFromAStaticMethod",
3437
SomeStaticModule.class + ".contributeStringFromAnInstanceMethod"));
3538
}
39+
40+
@Test public void allStaticProvidesModules_noFieldInComponentBuilder() {
41+
for (Field field : DaggerStaticTestComponent.Builder.class.getDeclaredFields()) {
42+
assertWithMessage(field.getName())
43+
.that(field.getType()).isNotEqualTo(AllStaticModule.class);
44+
}
45+
}
46+
47+
@Test public void allStaticProvidesModules_deprecatedMethodInComponentBuilder() {
48+
for (Method method : DaggerStaticTestComponent.Builder.class.getDeclaredMethods()) {
49+
if (Arrays.asList(method.getParameterTypes()).contains(AllStaticModule.class)) {
50+
assertWithMessage(method.getName())
51+
.that(method.isAnnotationPresent(Deprecated.class))
52+
.isTrue();
53+
}
54+
}
55+
}
3656
}

‎compiler/src/it/producers-functional-tests/src/test/java/test/ProducerFactoryTest.java

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,23 @@
1515
*/
1616
package test;
1717

18+
import static com.google.common.truth.Truth.assertThat;
19+
import static org.junit.Assert.fail;
20+
import static org.mockito.Matchers.any;
21+
import static org.mockito.Mockito.inOrder;
22+
import static org.mockito.Mockito.verify;
23+
import static org.mockito.Mockito.verifyZeroInteractions;
24+
import static org.mockito.Mockito.when;
25+
1826
import com.google.common.util.concurrent.ListenableFuture;
1927
import com.google.common.util.concurrent.MoreExecutors;
2028
import com.google.common.util.concurrent.SettableFuture;
29+
2130
import dagger.producers.Producer;
2231
import dagger.producers.monitoring.ProducerMonitor;
2332
import dagger.producers.monitoring.ProducerToken;
2433
import dagger.producers.monitoring.ProductionComponentMonitor;
25-
import java.util.concurrent.ExecutionException;
34+
2635
import org.junit.Before;
2736
import org.junit.Test;
2837
import org.junit.runner.RunWith;
@@ -31,13 +40,7 @@
3140
import org.mockito.Mock;
3241
import org.mockito.MockitoAnnotations;
3342

34-
import static com.google.common.truth.Truth.assertThat;
35-
import static org.junit.Assert.fail;
36-
import static org.mockito.Mockito.any;
37-
import static org.mockito.Mockito.inOrder;
38-
import static org.mockito.Mockito.verify;
39-
import static org.mockito.Mockito.verifyZeroInteractions;
40-
import static org.mockito.Mockito.when;
43+
import java.util.concurrent.ExecutionException;
4144

4245
@RunWith(JUnit4.class)
4346
public class ProducerFactoryTest {
@@ -53,10 +56,9 @@ public void setUpMocks() {
5356
@Test
5457
public void noArgMethod() throws Exception {
5558
ProducerToken token = ProducerToken.create(SimpleProducerModule_StrFactory.class);
56-
SimpleProducerModule module = new SimpleProducerModule();
5759
Producer<String> producer =
5860
new SimpleProducerModule_StrFactory(
59-
componentMonitor, module, MoreExecutors.directExecutor());
61+
componentMonitor, MoreExecutors.directExecutor());
6062
assertThat(producer.get().get()).isEqualTo("str");
6163
InOrder order = inOrder(componentMonitor, monitor);
6264
order.verify(componentMonitor).producerMonitorFor(token);
@@ -67,12 +69,11 @@ public void noArgMethod() throws Exception {
6769
}
6870

6971
@Test public void singleArgMethod() throws Exception {
70-
SimpleProducerModule module = new SimpleProducerModule();
7172
SettableFuture<Integer> intFuture = SettableFuture.create();
7273
Producer<Integer> intProducer = producerOfFuture(intFuture);
7374
Producer<String> producer =
7475
new SimpleProducerModule_StrWithArgFactory(
75-
componentMonitor, module, MoreExecutors.directExecutor(), intProducer);
76+
componentMonitor, MoreExecutors.directExecutor(), intProducer);
7677
assertThat(producer.get().isDone()).isFalse();
7778
intFuture.set(42);
7879
assertThat(producer.get().get()).isEqualTo("str with arg");
@@ -82,13 +83,12 @@ public void noArgMethod() throws Exception {
8283
public void successMonitor() throws Exception {
8384
ProducerToken token = ProducerToken.create(SimpleProducerModule_SettableFutureStrFactory.class);
8485

85-
SimpleProducerModule module = new SimpleProducerModule();
8686
SettableFuture<String> strFuture = SettableFuture.create();
8787
SettableFuture<SettableFuture<String>> strFutureFuture = SettableFuture.create();
8888
Producer<SettableFuture<String>> strFutureProducer = producerOfFuture(strFutureFuture);
8989
Producer<String> producer =
9090
new SimpleProducerModule_SettableFutureStrFactory(
91-
componentMonitor, module, MoreExecutors.directExecutor(), strFutureProducer);
91+
componentMonitor, MoreExecutors.directExecutor(), strFutureProducer);
9292
assertThat(producer.get().isDone()).isFalse();
9393

9494
InOrder order = inOrder(componentMonitor, monitor);
@@ -110,13 +110,12 @@ public void successMonitor() throws Exception {
110110
public void failureMonitor() throws Exception {
111111
ProducerToken token = ProducerToken.create(SimpleProducerModule_SettableFutureStrFactory.class);
112112

113-
SimpleProducerModule module = new SimpleProducerModule();
114113
SettableFuture<String> strFuture = SettableFuture.create();
115114
SettableFuture<SettableFuture<String>> strFutureFuture = SettableFuture.create();
116115
Producer<SettableFuture<String>> strFutureProducer = producerOfFuture(strFutureFuture);
117116
Producer<String> producer =
118117
new SimpleProducerModule_SettableFutureStrFactory(
119-
componentMonitor, module, MoreExecutors.directExecutor(), strFutureProducer);
118+
componentMonitor, MoreExecutors.directExecutor(), strFutureProducer);
120119
assertThat(producer.get().isDone()).isFalse();
121120

122121
InOrder order = inOrder(componentMonitor, monitor);
@@ -144,10 +143,9 @@ public void failureMonitor() throws Exception {
144143
public void failureMonitorDueToThrowingProducer() throws Exception {
145144
ProducerToken token = ProducerToken.create(SimpleProducerModule_ThrowingProducerFactory.class);
146145

147-
SimpleProducerModule module = new SimpleProducerModule();
148146
Producer<String> producer =
149147
new SimpleProducerModule_ThrowingProducerFactory(
150-
componentMonitor, module, MoreExecutors.directExecutor());
148+
componentMonitor, MoreExecutors.directExecutor());
151149
assertThat(producer.get().isDone()).isTrue();
152150

153151
InOrder order = inOrder(componentMonitor, monitor);
@@ -168,9 +166,8 @@ public void failureMonitorDueToThrowingProducer() throws Exception {
168166

169167
@Test
170168
public void nullComponentMonitor() throws Exception {
171-
SimpleProducerModule module = new SimpleProducerModule();
172169
Producer<String> producer =
173-
new SimpleProducerModule_StrFactory(null, module, MoreExecutors.directExecutor());
170+
new SimpleProducerModule_StrFactory(null, MoreExecutors.directExecutor());
174171
assertThat(producer.get().get()).isEqualTo("str");
175172
verifyZeroInteractions(componentMonitor, monitor);
176173
}
@@ -180,10 +177,9 @@ public void nullMonitor() throws Exception {
180177
when(componentMonitor.producerMonitorFor(any(ProducerToken.class))).thenReturn(null);
181178

182179
ProducerToken token = ProducerToken.create(SimpleProducerModule_StrFactory.class);
183-
SimpleProducerModule module = new SimpleProducerModule();
184180
Producer<String> producer =
185181
new SimpleProducerModule_StrFactory(
186-
componentMonitor, module, MoreExecutors.directExecutor());
182+
componentMonitor, MoreExecutors.directExecutor());
187183
assertThat(producer.get().get()).isEqualTo("str");
188184
verify(componentMonitor).producerMonitorFor(token);
189185
verifyZeroInteractions(monitor);

‎compiler/src/main/java/dagger/internal/codegen/AbstractComponentWriter.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
import static dagger.internal.codegen.Util.getProvidedValueTypeOfMap;
111111
import static dagger.internal.codegen.Util.isMapWithNonProvidedValues;
112112
import static dagger.internal.codegen.writer.Snippet.memberSelectSnippet;
113+
import static dagger.internal.codegen.writer.Snippet.nullCheck;
113114
import static javax.lang.model.element.Modifier.FINAL;
114115
import static javax.lang.model.element.Modifier.PRIVATE;
115116
import static javax.lang.model.element.Modifier.PUBLIC;
@@ -226,7 +227,7 @@ protected MemberSelect getMemberSelect(BindingKey key) {
226227
protected Optional<MemberSelect> getMultibindingContributionSnippet(ContributionBinding binding) {
227228
return Optional.fromNullable(multibindingContributionSnippets.get(binding));
228229
}
229-
230+
230231
/**
231232
* Returns the initialization state of the factory field for a binding key in this component.
232233
*/
@@ -303,8 +304,16 @@ protected void addBuilder() {
303304
constructorWriter.addParameter(builderWriter, "builder");
304305
constructorWriter.body().addSnippet("assert builder != null;");
305306

307+
builderFields = addBuilderMethods(builderWriter, builderSpec, buildMethod);
308+
buildMethod.body().addSnippet("return new %s(this);", name);
309+
}
310+
311+
private ImmutableMap<TypeElement, FieldWriter> addBuilderMethods(
312+
ClassWriter builderWriter, Optional<BuilderSpec> builderSpec, MethodWriter buildMethod) {
306313
ImmutableMap.Builder<TypeElement, FieldWriter> builderFieldsBuilder = ImmutableMap.builder();
307-
for (TypeElement contributionElement : graph.componentRequirements()) {
314+
ImmutableSet<TypeElement> componentRequirements = graph.componentRequirements();
315+
316+
for (TypeElement contributionElement : componentRequirements) {
308317
String contributionName = simpleVariableName(contributionElement);
309318
FieldWriter builderField = builderWriter.addField(contributionElement, contributionName);
310319
builderField.addModifiers(PRIVATE);
@@ -344,10 +353,7 @@ protected void addBuilder() {
344353
builderMethod.addParameter(contributionElement, contributionName);
345354
builderMethod
346355
.body()
347-
.addSnippet("if (%s == null) {", contributionName)
348-
.addSnippet(
349-
" throw new NullPointerException(%s);", StringLiteral.forValue(contributionName))
350-
.addSnippet("}")
356+
.addSnippet(nullCheck(contributionName))
351357
.addSnippet("this.%s = %s;", builderField.name(), contributionName);
352358
if (!builderMethod.returnType().equals(VoidName.VOID)) {
353359
builderMethod.body().addSnippet("return this;");
@@ -359,7 +365,7 @@ protected void addBuilder() {
359365
* component requirements that are in the builder spec but _not_ owned by the component must
360366
* be inherited. */
361367
for (TypeElement inheritedRequirement :
362-
Sets.difference(builderSpec.get().methodMap().keySet(), graph.componentRequirements())) {
368+
Sets.difference(builderSpec.get().methodMap().keySet(), componentRequirements)) {
363369
MethodWriter builderMethod =
364370
addBuilderMethodFromSpec(
365371
builderWriter, builderSpec.get().methodMap().get(inheritedRequirement));
@@ -375,10 +381,23 @@ protected void addBuilder() {
375381
"%s cannot be set because it is inherited from the enclosing component"),
376382
ClassName.fromTypeElement(inheritedRequirement));
377383
}
384+
} else {
385+
for (TypeElement ownedButNotRequired :
386+
Sets.difference(graph.ownedModuleTypes(), componentRequirements)) {
387+
String contributionName = simpleVariableName(ownedButNotRequired);
388+
MethodWriter builderMethod =
389+
builderWriter.addMethod(builderWriter, contributionName);
390+
builderMethod.addModifiers(PUBLIC);
391+
builderMethod.annotate(Deprecated.class);
392+
builderMethod.addParameter(ownedButNotRequired, contributionName);
393+
builderMethod.body()
394+
.addSnippet("// This module is declared, but not used in the component. "
395+
+ "This method is a no-op")
396+
.addSnippet(nullCheck(contributionName))
397+
.addSnippet("return this;");
398+
}
378399
}
379-
380-
builderFields = builderFieldsBuilder.build();
381-
buildMethod.body().addSnippet("return new %s(this);", name);
400+
return builderFieldsBuilder.build();
382401
}
383402

384403
private MethodWriter addBuilderMethodFromSpec(
@@ -966,7 +985,9 @@ private Snippet initializeFactoryForProductionBinding(ProductionBinding binding)
966985
Lists.newArrayListWithCapacity(binding.dependencies().size() + 3);
967986
// TODO(beder): Pass the actual ProductionComponentMonitor.
968987
parameters.add(Snippet.format("null"));
969-
parameters.add(getComponentContributionSnippet(binding.bindingTypeElement()));
988+
if (!binding.bindingElement().getModifiers().contains(STATIC)) {
989+
parameters.add(getComponentContributionSnippet(binding.bindingTypeElement()));
990+
}
970991
parameters.add(
971992
getComponentContributionSnippet(
972993
graph.componentDescriptor().executorDependency().get()));

‎compiler/src/main/java/dagger/internal/codegen/BindingGraph.java

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.google.auto.common.MoreTypes;
1919
import com.google.auto.value.AutoValue;
2020
import com.google.common.base.Equivalence;
21+
import com.google.common.base.Function;
2122
import com.google.common.base.Optional;
2223
import com.google.common.cache.Cache;
2324
import com.google.common.cache.CacheBuilder;
@@ -29,6 +30,7 @@
2930
import com.google.common.collect.Lists;
3031
import com.google.common.collect.Maps;
3132
import com.google.common.collect.Sets;
33+
import com.google.common.collect.TreeTraverser;
3234
import dagger.Component;
3335
import dagger.Subcomponent;
3436
import dagger.internal.codegen.ComponentDescriptor.ComponentMethodDescriptor;
@@ -51,13 +53,16 @@
5153
import javax.lang.model.util.Elements;
5254

5355
import static com.google.auto.common.MoreElements.getAnnotationMirror;
56+
import static com.google.common.base.Predicates.in;
5457
import static com.google.common.base.Verify.verify;
58+
import static dagger.internal.codegen.BindingKey.Kind.CONTRIBUTION;
5559
import static dagger.internal.codegen.ComponentDescriptor.isComponentContributionMethod;
5660
import static dagger.internal.codegen.ComponentDescriptor.isComponentProductionMethod;
5761
import static dagger.internal.codegen.ComponentDescriptor.Kind.PRODUCTION_COMPONENT;
5862
import static dagger.internal.codegen.ConfigurationAnnotations.getComponentDependencies;
5963
import static dagger.internal.codegen.MembersInjectionBinding.Strategy.INJECT_MEMBERS;
6064
import static dagger.internal.codegen.MembersInjectionBinding.Strategy.NO_OP;
65+
import static javax.lang.model.element.Modifier.STATIC;
6166

6267
/**
6368
* The canonical representation of a full-resolved graph.
@@ -86,17 +91,47 @@ ImmutableSet<TypeElement> ownedModuleTypes() {
8691
.toSet();
8792
}
8893

94+
private static final TreeTraverser<BindingGraph> SUBGRAPH_TRAVERSER =
95+
new TreeTraverser<BindingGraph>() {
96+
@Override
97+
public Iterable<BindingGraph> children(BindingGraph node) {
98+
return node.subgraphs().values();
99+
}
100+
};
101+
89102
/**
90103
* Returns the set of types necessary to implement the component, but are not part of the injected
91104
* graph. This includes modules, component dependencies and an {@link Executor} in the case of
92105
* {@link ProductionComponent}.
93106
*/
94107
ImmutableSet<TypeElement> componentRequirements() {
95-
return new ImmutableSet.Builder<TypeElement>()
96-
.addAll(ownedModuleTypes())
97-
.addAll(componentDescriptor().dependencies())
98-
.addAll(componentDescriptor().executorDependency().asSet())
99-
.build();
108+
return SUBGRAPH_TRAVERSER.preOrderTraversal(this)
109+
.transformAndConcat(new Function<BindingGraph, Iterable<ResolvedBindings>>() {
110+
@Override
111+
public Iterable<ResolvedBindings> apply(BindingGraph input) {
112+
return input.resolvedBindings().values();
113+
}
114+
})
115+
.transformAndConcat(new Function<ResolvedBindings, Set<? extends ContributionBinding>>() {
116+
@Override
117+
public Set<? extends ContributionBinding> apply(ResolvedBindings input) {
118+
return (input.bindingKey().kind().equals(CONTRIBUTION))
119+
? input.contributionBindings()
120+
: ImmutableSet.<ContributionBinding>of();
121+
}
122+
})
123+
.transformAndConcat(new Function<ContributionBinding, Set<TypeElement>>() {
124+
@Override
125+
public Set<TypeElement> apply(ContributionBinding input) {
126+
return input.bindingElement().getModifiers().contains(STATIC)
127+
? ImmutableSet.<TypeElement>of()
128+
: input.contributedBy().asSet();
129+
}
130+
})
131+
.filter(in(ownedModuleTypes()))
132+
.append(componentDescriptor().dependencies())
133+
.append(componentDescriptor().executorDependency().asSet())
134+
.toSet();
100135
}
101136

102137
ImmutableSet<TypeElement> availableDependencies() {

‎compiler/src/main/java/dagger/internal/codegen/ProducerFactoryGenerator.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import static javax.lang.model.element.Modifier.PRIVATE;
6565
import static javax.lang.model.element.Modifier.PROTECTED;
6666
import static javax.lang.model.element.Modifier.PUBLIC;
67+
import static javax.lang.model.element.Modifier.STATIC;
6768

6869
/**
6970
* Generates {@link Producer} implementations from {@link ProductionBinding} instances.
@@ -119,11 +120,14 @@ ImmutableSet<JavaWriter> write(ClassName generatedTypeName, ProductionBinding bi
119120
ClassName.fromClass(ProducerToken.class),
120121
factoryWriter.name());
121122

122-
factoryWriter.addField(binding.bindingTypeElement(), "module").addModifiers(PRIVATE, FINAL);
123-
constructorWriter.addParameter(binding.bindingTypeElement(), "module");
124-
constructorWriter.body()
125-
.addSnippet("assert module != null;")
126-
.addSnippet("this.module = module;");
123+
if (!binding.bindingElement().getModifiers().contains(STATIC)) {
124+
factoryWriter.addField(binding.bindingTypeElement(), "module")
125+
.addModifiers(PRIVATE, FINAL);
126+
constructorWriter.addParameter(binding.bindingTypeElement(), "module");
127+
constructorWriter.body()
128+
.addSnippet("assert module != null;")
129+
.addSnippet("this.module = module;");
130+
}
127131

128132
factoryWriter.addField(Executor.class, "executor")
129133
.addModifiers(PRIVATE, FINAL);
@@ -383,6 +387,13 @@ static InvocationSnippets create(
383387
*/
384388
private InvocationSnippets getInvocationSnippets(
385389
boolean wrapWithFuture, ProductionBinding binding, ImmutableList<Snippet> parameterSnippets) {
390+
Snippet moduleSnippet = Snippet.format("%s.%s(%s)",
391+
binding.bindingElement().getModifiers().contains(STATIC)
392+
? ClassName.fromTypeElement(binding.bindingTypeElement())
393+
: "module",
394+
binding.bindingElement().getSimpleName(),
395+
makeParametersSnippet(parameterSnippets));
396+
386397
// NOTE(beder): We don't worry about catching exeptions from the monitor methods themselves
387398
// because we'll wrap all monitoring in non-throwing monitors before we pass them to the
388399
// factories.
@@ -398,12 +409,11 @@ private InvocationSnippets getInvocationSnippets(
398409
Joiner.on('\n')
399410
.join(
400411
"try {",
401-
" value = module.%s(%s);",
412+
" value = %s;",
402413
"} finally {",
403414
" if (monitor != null) { monitor.methodFinished(); }",
404415
"}"),
405-
binding.bindingElement().getSimpleName(),
406-
makeParametersSnippet(parameterSnippets)));
416+
moduleSnippet));
407417
final Snippet valueSnippet;
408418
if (binding.productionType().equals(Produces.Type.SET)) {
409419
if (binding.bindingKind().equals(ProductionBinding.Kind.FUTURE_PRODUCTION)) {

‎compiler/src/main/java/dagger/internal/codegen/writer/Snippet.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ public static Snippet memberSelectSnippet(Iterable<? extends Object> selectors)
110110
selectors);
111111
}
112112

113+
public static Snippet nullCheck(Object thingToCheck) {
114+
return format("if (%s == null) { throw new NullPointerException();} ", thingToCheck);
115+
}
116+
117+
public static Snippet nullCheck(Object thingToCheck, String message) {
118+
return format("if (%s == null) { throw new NullPointerException(%s);} ",
119+
thingToCheck,
120+
StringLiteral.forValue(message));
121+
}
122+
113123
public static Snippet makeParametersSnippet(Iterable<Snippet> parameterSnippets) {
114124
Iterator<Snippet> iterator = parameterSnippets.iterator();
115125
StringBuilder stringBuilder = new StringBuilder();

‎compiler/src/test/java/dagger/internal/codegen/ComponentBuilderTest.java

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
/** Tests for {@link dagger.Component.Builder} */
3030
@RunWith(JUnit4.class)
3131
public class ComponentBuilderTest {
32-
32+
3333
private static final ErrorMessages.ComponentBuilderMessages MSGS =
3434
ErrorMessages.ComponentBuilderMessages.INSTANCE;
35-
35+
3636
@Test
3737
public void testEmptyBuilder() {
3838
JavaFileObject injectableTypeFile = JavaFileObjects.forSourceLines("test.SomeInjectableType",
@@ -57,7 +57,7 @@ public void testEmptyBuilder() {
5757
" @Component.Builder",
5858
" static interface Builder {",
5959
" SimpleComponent build();",
60-
" }",
60+
" }",
6161
"}");
6262
JavaFileObject generatedComponent = JavaFileObjects.forSourceLines(
6363
"test.DaggerSimpleComponent",
@@ -101,7 +101,7 @@ public void testEmptyBuilder() {
101101
.compilesWithoutError()
102102
.and().generatesSources(generatedComponent);
103103
}
104-
104+
105105
@Test
106106
public void testUsesBuildAndSetterNames() {
107107
JavaFileObject moduleFile = JavaFileObjects.forSourceLines("test.TestModule",
@@ -178,7 +178,7 @@ public void testUsesBuildAndSetterNames() {
178178
" @Override",
179179
" public Builder setTestModule(TestModule testModule) {",
180180
" if (testModule == null) {",
181-
" throw new NullPointerException(\"testModule\");",
181+
" throw new NullPointerException();",
182182
" }",
183183
" this.testModule = testModule;",
184184
" return this;",
@@ -191,7 +191,7 @@ public void testUsesBuildAndSetterNames() {
191191
.compilesWithoutError()
192192
.and().generatesSources(generatedComponent);
193193
}
194-
194+
195195
@Test
196196
public void testIgnoresModulesNotInApi() {
197197
JavaFileObject module1 = JavaFileObjects.forSourceLines("test.TestModule1",
@@ -290,7 +290,7 @@ public void testIgnoresModulesNotInApi() {
290290
" @Override",
291291
" public Builder testModule1(TestModule1 testModule1) {",
292292
" if (testModule1 == null) {",
293-
" throw new NullPointerException(\"testModule1\");",
293+
" throw new NullPointerException();",
294294
" }",
295295
" this.testModule1 = testModule1;",
296296
" return this;",
@@ -303,7 +303,7 @@ public void testIgnoresModulesNotInApi() {
303303
.compilesWithoutError()
304304
.and().generatesSources(generatedComponent);
305305
}
306-
306+
307307
@Test
308308
public void testMoreThanOneBuilderFails() {
309309
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -323,7 +323,7 @@ public void testMoreThanOneBuilderFails() {
323323
" @Component.Builder",
324324
" interface Builder2 {",
325325
" SimpleComponent build();",
326-
" }",
326+
" }",
327327
"}");
328328
assertAbout(javaSource()).that(componentFile)
329329
.processedWith(new ComponentProcessor())
@@ -332,7 +332,7 @@ public void testMoreThanOneBuilderFails() {
332332
"[test.SimpleComponent.Builder, test.SimpleComponent.Builder2]"))
333333
.in(componentFile);
334334
}
335-
335+
336336
@Test
337337
public void testBuilderGenericsFails() {
338338
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -347,15 +347,15 @@ public void testBuilderGenericsFails() {
347347
" @Component.Builder",
348348
" interface Builder<T> {",
349349
" SimpleComponent build();",
350-
" }",
350+
" }",
351351
"}");
352352
assertAbout(javaSource()).that(componentFile)
353353
.processedWith(new ComponentProcessor())
354354
.failsToCompile()
355355
.withErrorContaining(MSGS.generics())
356356
.in(componentFile);
357357
}
358-
358+
359359
@Test
360360
public void testBuilderNotInComponentFails() {
361361
JavaFileObject builder = JavaFileObjects.forSourceLines("test.Builder",
@@ -371,7 +371,7 @@ public void testBuilderNotInComponentFails() {
371371
.withErrorContaining(MSGS.mustBeInComponent())
372372
.in(builder);
373373
}
374-
374+
375375
@Test
376376
public void testBuilderMissingBuildMethodFails() {
377377
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -392,7 +392,7 @@ public void testBuilderMissingBuildMethodFails() {
392392
.withErrorContaining(MSGS.missingBuildMethod())
393393
.in(componentFile);
394394
}
395-
395+
396396
@Test
397397
public void testPrivateBuilderFails() {
398398
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -413,7 +413,7 @@ public void testPrivateBuilderFails() {
413413
.withErrorContaining(MSGS.isPrivate())
414414
.in(componentFile);
415415
}
416-
416+
417417
@Test
418418
public void testNonStaticBuilderFails() {
419419
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -434,7 +434,7 @@ public void testNonStaticBuilderFails() {
434434
.withErrorContaining(MSGS.mustBeStatic())
435435
.in(componentFile);
436436
}
437-
437+
438438
@Test
439439
public void testNonAbstractBuilderFails() {
440440
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -454,7 +454,7 @@ public void testNonAbstractBuilderFails() {
454454
.failsToCompile()
455455
.withErrorContaining(MSGS.mustBeAbstract());
456456
}
457-
457+
458458
@Test
459459
public void testBuilderOneCxtorWithArgsFails() {
460460
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -477,7 +477,7 @@ public void testBuilderOneCxtorWithArgsFails() {
477477
.withErrorContaining(MSGS.cxtorOnlyOneAndNoArgs())
478478
.in(componentFile);
479479
}
480-
480+
481481
@Test
482482
public void testBuilderMoreThanOneCxtorFails() {
483483
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -501,7 +501,7 @@ public void testBuilderMoreThanOneCxtorFails() {
501501
.withErrorContaining(MSGS.cxtorOnlyOneAndNoArgs())
502502
.in(componentFile);
503503
}
504-
504+
505505
@Test
506506
public void testBuilderEnumFails() {
507507
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -522,7 +522,7 @@ public void testBuilderEnumFails() {
522522
.withErrorContaining(MSGS.mustBeClassOrInterface())
523523
.in(componentFile);
524524
}
525-
525+
526526
@Test
527527
public void testBuilderBuildReturnsWrongTypeFails() {
528528
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -545,7 +545,7 @@ public void testBuilderBuildReturnsWrongTypeFails() {
545545
.withErrorContaining(MSGS.buildMustReturnComponentType())
546546
.in(componentFile).onLine(11);
547547
}
548-
548+
549549
@Test
550550
public void testInheritedBuilderBuildReturnsWrongTypeFails() {
551551
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -571,7 +571,7 @@ public void testInheritedBuilderBuildReturnsWrongTypeFails() {
571571
String.format(MSGS.inheritedBuildMustReturnComponentType(), "build"))
572572
.in(componentFile).onLine(14);
573573
}
574-
574+
575575
@Test
576576
public void testTwoBuildMethodsFails() {
577577
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -595,7 +595,7 @@ public void testTwoBuildMethodsFails() {
595595
.withErrorContaining(String.format(MSGS.twoBuildMethods(), "build()"))
596596
.in(componentFile).onLine(12);
597597
}
598-
598+
599599
@Test
600600
public void testInheritedTwoBuildMethodsFails() {
601601
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -622,7 +622,7 @@ public void testInheritedTwoBuildMethodsFails() {
622622
String.format(MSGS.inheritedTwoBuildMethods(), "create()", "build()"))
623623
.in(componentFile).onLine(15);
624624
}
625-
625+
626626
@Test
627627
public void testMoreThanOneArgFails() {
628628
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -649,7 +649,7 @@ public void testMoreThanOneArgFails() {
649649
.and().withErrorContaining(MSGS.methodsMustTakeOneArg())
650650
.in(componentFile).onLine(13);
651651
}
652-
652+
653653
@Test
654654
public void testInheritedMoreThanOneArgFails() {
655655
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -677,7 +677,7 @@ public void testInheritedMoreThanOneArgFails() {
677677
"set1(java.lang.String,java.lang.Integer)"))
678678
.in(componentFile).onLine(15);
679679
}
680-
680+
681681
@Test
682682
public void testSetterReturningNonVoidOrBuilderFails() {
683683
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -701,7 +701,7 @@ public void testSetterReturningNonVoidOrBuilderFails() {
701701
.withErrorContaining(MSGS.methodsMustReturnVoidOrBuilder())
702702
.in(componentFile).onLine(12);
703703
}
704-
704+
705705
@Test
706706
public void testInheritedSetterReturningNonVoidOrBuilderFails() {
707707
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -727,9 +727,9 @@ public void testInheritedSetterReturningNonVoidOrBuilderFails() {
727727
.withErrorContaining(
728728
String.format(MSGS.inheritedMethodsMustReturnVoidOrBuilder(),
729729
"set(java.lang.Integer)"))
730-
.in(componentFile).onLine(15);
730+
.in(componentFile).onLine(15);
731731
}
732-
732+
733733
@Test
734734
public void testGenericsOnSetterMethodFails() {
735735
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -753,7 +753,7 @@ public void testGenericsOnSetterMethodFails() {
753753
.withErrorContaining(MSGS.methodsMayNotHaveTypeParameters())
754754
.in(componentFile).onLine(12);
755755
}
756-
756+
757757
@Test
758758
public void testGenericsOnInheritedSetterMethodFails() {
759759
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -778,9 +778,9 @@ public void testGenericsOnInheritedSetterMethodFails() {
778778
.failsToCompile()
779779
.withErrorContaining(
780780
String.format(MSGS.inheritedMethodsMayNotHaveTypeParameters(), "<T>set(T)"))
781-
.in(componentFile).onLine(15);
781+
.in(componentFile).onLine(15);
782782
}
783-
783+
784784
@Test
785785
public void testMultipleSettersPerTypeFails() {
786786
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -807,7 +807,7 @@ public void testMultipleSettersPerTypeFails() {
807807
"java.lang.String", "[set1(java.lang.String), set2(java.lang.String)]"))
808808
.in(componentFile).onLine(10);
809809
}
810-
810+
811811
@Test
812812
public void testMultipleSettersPerTypeIncludingResolvedGenericsFails() {
813813
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -837,7 +837,7 @@ public void testMultipleSettersPerTypeIncludingResolvedGenericsFails() {
837837
"java.lang.String", "[set1(T), set2(java.lang.String)]"))
838838
.in(componentFile).onLine(14);
839839
}
840-
840+
841841
@Test
842842
public void testExtraSettersFails() {
843843
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
@@ -864,9 +864,9 @@ public void testExtraSettersFails() {
864864
"[void test.SimpleComponent.Builder.set1(String),"
865865
+ " void test.SimpleComponent.Builder.set2(Integer)]"))
866866
.in(componentFile).onLine(10);
867-
867+
868868
}
869-
869+
870870
@Test
871871
public void testMissingSettersFail() {
872872
JavaFileObject moduleFile = JavaFileObjects.forSourceLines("test.TestModule",

‎compiler/src/test/java/dagger/internal/codegen/ComponentProcessorTest.java

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ private void checkCannotReferToModuleOfType(String moduleType) {
525525
"",
526526
" public Builder testModule(TestModule testModule) {",
527527
" if (testModule == null) {",
528-
" throw new NullPointerException(\"testModule\");",
528+
" throw new NullPointerException();",
529529
" }",
530530
" this.testModule = testModule;",
531531
" return this;",
@@ -631,83 +631,58 @@ private void checkCannotReferToModuleOfType(String moduleType) {
631631
" }",
632632
"",
633633
" public static final class Builder {",
634-
" private TestModule testModule;",
635-
" private ParentTestIncluded parentTestIncluded;",
636-
" private AlwaysIncluded alwaysIncluded;",
637-
" private DepModule depModule;",
638-
" private ParentDepIncluded parentDepIncluded;",
639-
" private RefByDep refByDep;",
640-
"",
641634
" private Builder() {",
642635
" }",
643636
"",
644637
" public TestComponent build() {",
645-
" if (testModule == null) {",
646-
" this.testModule = new TestModule();",
647-
" }",
648-
" if (parentTestIncluded == null) {",
649-
" this.parentTestIncluded = new ParentTestIncluded();",
650-
" }",
651-
" if (alwaysIncluded == null) {",
652-
" this.alwaysIncluded = new AlwaysIncluded();",
653-
" }",
654-
" if (depModule == null) {",
655-
" this.depModule = new DepModule();",
656-
" }",
657-
" if (parentDepIncluded == null) {",
658-
" this.parentDepIncluded = new ParentDepIncluded();",
659-
" }",
660-
" if (refByDep == null) {",
661-
" this.refByDep = new RefByDep();",
662-
" }",
663638
" return new DaggerTestComponent(this);",
664639
" }",
665640
"",
641+
" @Deprecated",
666642
" public Builder testModule(TestModule testModule) {",
667643
" if (testModule == null) {",
668-
" throw new NullPointerException(\"testModule\");",
644+
" throw new NullPointerException();",
669645
" }",
670-
" this.testModule = testModule;",
671646
" return this;",
672647
" }",
673648
"",
649+
" @Deprecated",
674650
" public Builder parentTestIncluded(ParentTestIncluded parentTestIncluded) {",
675651
" if (parentTestIncluded == null) {",
676-
" throw new NullPointerException(\"parentTestIncluded\");",
652+
" throw new NullPointerException();",
677653
" }",
678-
" this.parentTestIncluded = parentTestIncluded;",
679654
" return this;",
680655
" }",
681656
"",
657+
" @Deprecated",
682658
" public Builder alwaysIncluded(AlwaysIncluded alwaysIncluded) {",
683659
" if (alwaysIncluded == null) {",
684-
" throw new NullPointerException(\"alwaysIncluded\");",
660+
" throw new NullPointerException();",
685661
" }",
686-
" this.alwaysIncluded = alwaysIncluded;",
687662
" return this;",
688663
" }",
689664
"",
665+
" @Deprecated",
690666
" public Builder depModule(DepModule depModule) {",
691667
" if (depModule == null) {",
692-
" throw new NullPointerException(\"depModule\");",
668+
" throw new NullPointerException();",
693669
" }",
694-
" this.depModule = depModule;",
695670
" return this;",
696671
" }",
697672
"",
673+
" @Deprecated",
698674
" public Builder parentDepIncluded(ParentDepIncluded parentDepIncluded) {",
699675
" if (parentDepIncluded == null) {",
700-
" throw new NullPointerException(\"parentDepIncluded\");",
676+
" throw new NullPointerException();",
701677
" }",
702-
" this.parentDepIncluded = parentDepIncluded;",
703678
" return this;",
704679
" }",
705680
"",
681+
" @Deprecated",
706682
" public Builder refByDep(RefByDep refByDep) {",
707683
" if (refByDep == null) {",
708-
" throw new NullPointerException(\"refByDep\");",
684+
" throw new NullPointerException();",
709685
" }",
710-
" this.refByDep = refByDep;",
711686
" return this;",
712687
" }",
713688
" }",
@@ -933,15 +908,15 @@ public void generatedModuleInSubcomponent() {
933908
"",
934909
" public Builder emptySetModule(EmptySetModule emptySetModule) {",
935910
" if (emptySetModule == null) {",
936-
" throw new NullPointerException(\"emptySetModule\");",
911+
" throw new NullPointerException();",
937912
" }",
938913
" this.emptySetModule = emptySetModule;",
939914
" return this;",
940915
" }",
941916
"",
942917
" public Builder setModule(SetModule setModule) {",
943918
" if (setModule == null) {",
944-
" throw new NullPointerException(\"setModule\");",
919+
" throw new NullPointerException();",
945920
" }",
946921
" this.setModule = setModule;",
947922
" return this;",
@@ -1368,7 +1343,7 @@ public void generatedModuleInSubcomponent() {
13681343
"",
13691344
" public Builder aComponent(AComponent aComponent) {",
13701345
" if (aComponent == null) {",
1371-
" throw new NullPointerException(\"aComponent\");",
1346+
" throw new NullPointerException();",
13721347
" }",
13731348
" this.aComponent = aComponent;",
13741349
" return this;",
@@ -1487,15 +1462,15 @@ public void generatedModuleInSubcomponent() {
14871462
"",
14881463
" public Builder testModule(test.TestModule testModule) {",
14891464
" if (testModule == null) {",
1490-
" throw new NullPointerException(\"testModule\");",
1465+
" throw new NullPointerException();",
14911466
" }",
14921467
" this.testModule = testModule;",
14931468
" return this;",
14941469
" }",
14951470
"",
14961471
" public Builder testModule(TestModule testModule) {",
14971472
" if (testModule == null) {",
1498-
" throw new NullPointerException(\"testModule\");",
1473+
" throw new NullPointerException();",
14991474
" }",
15001475
" this.testModule1 = testModule;",
15011476
" return this;",

‎compiler/src/test/java/dagger/internal/codegen/MapBindingComponentProcessorTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ public void mapBindingsWithEnumKey() {
175175
"",
176176
" public Builder mapModuleOne(MapModuleOne mapModuleOne) {",
177177
" if (mapModuleOne == null) {",
178-
" throw new NullPointerException(\"mapModuleOne\");",
178+
" throw new NullPointerException();",
179179
" }",
180180
" this.mapModuleOne = mapModuleOne;",
181181
" return this;",
182182
" }",
183183
"",
184184
" public Builder mapModuleTwo(MapModuleTwo mapModuleTwo) {",
185185
" if (mapModuleTwo == null) {",
186-
" throw new NullPointerException(\"mapModuleTwo\");",
186+
" throw new NullPointerException();",
187187
" }",
188188
" this.mapModuleTwo = mapModuleTwo;",
189189
" return this;",
@@ -332,15 +332,15 @@ public void mapBindingsWithStringKey() {
332332
"",
333333
" public Builder mapModuleOne(MapModuleOne mapModuleOne) {",
334334
" if (mapModuleOne == null) {",
335-
" throw new NullPointerException(\"mapModuleOne\");",
335+
" throw new NullPointerException();",
336336
" }",
337337
" this.mapModuleOne = mapModuleOne;",
338338
" return this;",
339339
" }",
340340
"",
341341
" public Builder mapModuleTwo(MapModuleTwo mapModuleTwo) {",
342342
" if (mapModuleTwo == null) {",
343-
" throw new NullPointerException(\"mapModuleTwo\");",
343+
" throw new NullPointerException();",
344344
" }",
345345
" this.mapModuleTwo = mapModuleTwo;",
346346
" return this;",
@@ -500,15 +500,15 @@ public void mapBindingsWithWrappedKey() {
500500
"",
501501
" public Builder mapModuleOne(MapModuleOne mapModuleOne) {",
502502
" if (mapModuleOne == null) {",
503-
" throw new NullPointerException(\"mapModuleOne\");",
503+
" throw new NullPointerException();",
504504
" }",
505505
" this.mapModuleOne = mapModuleOne;",
506506
" return this;",
507507
" }",
508508
"",
509509
" public Builder mapModuleTwo(MapModuleTwo mapModuleTwo) {",
510510
" if (mapModuleTwo == null) {",
511-
" throw new NullPointerException(\"mapModuleTwo\");",
511+
" throw new NullPointerException();",
512512
" }",
513513
" this.mapModuleTwo = mapModuleTwo;",
514514
" return this;",
@@ -674,15 +674,15 @@ public void mapBindingsWithNonProviderValue() {
674674
"",
675675
" public Builder mapModuleOne(MapModuleOne mapModuleOne) {",
676676
" if (mapModuleOne == null) {",
677-
" throw new NullPointerException(\"mapModuleOne\");",
677+
" throw new NullPointerException();",
678678
" }",
679679
" this.mapModuleOne = mapModuleOne;",
680680
" return this;",
681681
" }",
682682
"",
683683
" public Builder mapModuleTwo(MapModuleTwo mapModuleTwo) {",
684684
" if (mapModuleTwo == null) {",
685-
" throw new NullPointerException(\"mapModuleTwo\");",
685+
" throw new NullPointerException();",
686686
" }",
687687
" this.mapModuleTwo = mapModuleTwo;",
688688
" return this;",
@@ -779,7 +779,7 @@ public void injectMapWithoutMapBinding() {
779779
"",
780780
" public Builder mapModule(MapModule mapModule) {",
781781
" if (mapModule == null) {",
782-
" throw new NullPointerException(\"mapModule\");",
782+
" throw new NullPointerException();",
783783
" }",
784784
" this.mapModule = mapModule;",
785785
" return this;",

‎compiler/src/test/java/dagger/internal/codegen/MapKeyProcessorTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,15 @@ public void mapKeyComponentFileWithDisorderedKeyField() {
264264
"",
265265
" public Builder mapModuleOne(MapModuleOne mapModuleOne) {",
266266
" if (mapModuleOne == null) {",
267-
" throw new NullPointerException(\"mapModuleOne\");",
267+
" throw new NullPointerException();",
268268
" }",
269269
" this.mapModuleOne = mapModuleOne;",
270270
" return this;",
271271
" }",
272272
"",
273273
" public Builder mapModuleTwo(MapModuleTwo mapModuleTwo) {",
274274
" if (mapModuleTwo == null) {",
275-
" throw new NullPointerException(\"mapModuleTwo\");",
275+
" throw new NullPointerException();",
276276
" }",
277277
" this.mapModuleTwo = mapModuleTwo;",
278278
" return this;",
@@ -439,15 +439,15 @@ public void mapKeyComponentFileWithDefaultField() {
439439
"",
440440
" public Builder mapModuleOne(MapModuleOne mapModuleOne) {",
441441
" if (mapModuleOne == null) {",
442-
" throw new NullPointerException(\"mapModuleOne\");",
442+
" throw new NullPointerException();",
443443
" }",
444444
" this.mapModuleOne = mapModuleOne;",
445445
" return this;",
446446
" }",
447447
"",
448448
" public Builder mapModuleTwo(MapModuleTwo mapModuleTwo) {",
449449
" if (mapModuleTwo == null) {",
450-
" throw new NullPointerException(\"mapModuleTwo\");",
450+
" throw new NullPointerException();",
451451
" }",
452452
" this.mapModuleTwo = mapModuleTwo;",
453453
" return this;",

‎compiler/src/test/java/dagger/internal/codegen/ProductionComponentProcessorTest.java

Lines changed: 93 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -123,103 +123,100 @@ public class ProductionComponentProcessorTest {
123123
" ListenableFuture<A> a();",
124124
" }",
125125
"}");
126-
JavaFileObject generatedComponent =
127-
JavaFileObjects.forSourceLines(
128-
"test.DaggerTestClass_SimpleComponent",
129-
"package test;",
130-
"",
131-
"import com.google.common.util.concurrent.ListenableFuture;",
132-
"import dagger.producers.Producer;",
133-
"import dagger.producers.internal.Producers;",
134-
"import java.util.concurrent.Executor;",
135-
"import javax.annotation.Generated;",
136-
"import javax.inject.Provider;",
137-
"import test.TestClass.A;",
138-
"import test.TestClass.AModule;",
139-
"import test.TestClass.B;",
140-
"import test.TestClass.BModule;",
141-
"import test.TestClass.SimpleComponent;",
142-
"",
143-
"@Generated(\"dagger.internal.codegen.ComponentProcessor\")",
144-
"public final class DaggerTestClass_SimpleComponent implements SimpleComponent {",
145-
" private Provider<B> bProvider;",
146-
" private Producer<A> aProducer;",
147-
"",
148-
" private DaggerTestClass_SimpleComponent(Builder builder) {",
149-
" assert builder != null;",
150-
" initialize(builder);",
151-
" }",
152-
"",
153-
" public static Builder builder() {",
154-
" return new Builder();",
155-
" }",
156-
"",
157-
" private void initialize(final Builder builder) {",
158-
" this.bProvider = TestClass$BModule_BFactory.create(",
159-
" builder.bModule, TestClass$C_Factory.create());",
160-
" this.aProducer = new TestClass$AModule_AFactory(",
161-
" null,",
162-
" builder.aModule,",
163-
" builder.executor,",
164-
" Producers.producerFromProvider(bProvider));",
165-
" }",
166-
"",
167-
" @Override",
168-
" public ListenableFuture<A> a() {",
169-
" return aProducer.get();",
170-
" }",
171-
"",
172-
" public static final class Builder {",
173-
" private AModule aModule;",
174-
" private BModule bModule;",
175-
" private Executor executor;",
176-
"",
177-
" private Builder() {",
178-
" }",
179-
"",
180-
" public SimpleComponent build() {",
181-
" if (aModule == null) {",
182-
" this.aModule = new AModule();",
183-
" }",
184-
" if (bModule == null) {",
185-
" this.bModule = new BModule();",
186-
" }",
187-
" if (executor == null) {",
188-
" throw new IllegalStateException(\"executor must be set\");",
189-
" }",
190-
" return new DaggerTestClass_SimpleComponent(this);",
191-
" }",
192-
"",
193-
" public Builder aModule(AModule aModule) {",
194-
" if (aModule == null) {",
195-
" throw new NullPointerException(\"aModule\");",
196-
" }",
197-
" this.aModule = aModule;",
198-
" return this;",
199-
" }",
200-
"",
201-
" public Builder bModule(BModule bModule) {",
202-
" if (bModule == null) {",
203-
" throw new NullPointerException(\"bModule\");",
204-
" }",
205-
" this.bModule = bModule;",
206-
" return this;",
207-
" }",
208-
"",
209-
" public Builder executor(Executor executor) {",
210-
" if (executor == null) {",
211-
" throw new NullPointerException(\"executor\");",
212-
" }",
213-
" this.executor = executor;",
214-
" return this;",
215-
" }",
216-
" }",
217-
"}");
218-
assertAbout(javaSource())
219-
.that(component)
126+
JavaFileObject generatedComponent = JavaFileObjects.forSourceLines(
127+
"test.DaggerTestClass_SimpleComponent",
128+
"package test;",
129+
"",
130+
"import com.google.common.util.concurrent.ListenableFuture;",
131+
"import dagger.producers.Producer;",
132+
"import dagger.producers.internal.Producers;",
133+
"import java.util.concurrent.Executor;",
134+
"import javax.annotation.Generated;",
135+
"import javax.inject.Provider;",
136+
"import test.TestClass.A;",
137+
"import test.TestClass.AModule;",
138+
"import test.TestClass.B;",
139+
"import test.TestClass.BModule;",
140+
"import test.TestClass.SimpleComponent;",
141+
"",
142+
"@Generated(\"dagger.internal.codegen.ComponentProcessor\")",
143+
"public final class DaggerTestClass_SimpleComponent implements SimpleComponent {",
144+
" private Provider<B> bProvider;",
145+
" private Producer<A> aProducer;",
146+
"",
147+
" private DaggerTestClass_SimpleComponent(Builder builder) {",
148+
" assert builder != null;",
149+
" initialize(builder);",
150+
" }",
151+
"",
152+
" public static Builder builder() {",
153+
" return new Builder();",
154+
" }",
155+
"",
156+
" private void initialize(final Builder builder) {",
157+
" this.bProvider = TestClass$BModule_BFactory.create(",
158+
" builder.bModule, TestClass$C_Factory.create());",
159+
" this.aProducer = new TestClass$AModule_AFactory(",
160+
" null,",
161+
" builder.aModule,",
162+
" builder.executor,",
163+
" Producers.producerFromProvider(bProvider));",
164+
" }",
165+
"",
166+
" @Override",
167+
" public ListenableFuture<A> a() {",
168+
" return aProducer.get();",
169+
" }",
170+
"",
171+
" public static final class Builder {",
172+
" private BModule bModule;",
173+
" private AModule aModule;",
174+
" private Executor executor;",
175+
"",
176+
" private Builder() {",
177+
" }",
178+
"",
179+
" public SimpleComponent build() {",
180+
" if (bModule == null) {",
181+
" this.bModule = new BModule();",
182+
" }",
183+
" if (aModule == null) {",
184+
" this.aModule = new AModule();",
185+
" }",
186+
" if (executor == null) {",
187+
" throw new IllegalStateException(\"executor must be set\");",
188+
" }",
189+
" return new DaggerTestClass_SimpleComponent(this);",
190+
" }",
191+
"",
192+
" public Builder bModule(BModule bModule) {",
193+
" if (bModule == null) {",
194+
" throw new NullPointerException();",
195+
" }",
196+
" this.bModule = bModule;",
197+
" return this;",
198+
" }",
199+
"",
200+
" public Builder aModule(AModule aModule) {",
201+
" if (aModule == null) {",
202+
" throw new NullPointerException();",
203+
" }",
204+
" this.aModule = aModule;",
205+
" return this;",
206+
" }",
207+
"",
208+
" public Builder executor(Executor executor) {",
209+
" if (executor == null) {",
210+
" throw new NullPointerException();",
211+
" }",
212+
" this.executor = executor;",
213+
" return this;",
214+
" }",
215+
" }",
216+
"}");
217+
assertAbout(javaSource()).that(component)
220218
.processedWith(new ComponentProcessor())
221219
.compilesWithoutError()
222-
.and()
223-
.generatesSources(generatedComponent);
220+
.and().generatesSources(generatedComponent);
224221
}
225222
}

‎compiler/src/test/java/dagger/tests/integration/operation/PrimitiveInjectionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public final class PrimitiveInjectionTest {
124124
"",
125125
" public Builder primitiveModule(PrimitiveModule primitiveModule) {",
126126
" if (primitiveModule == null) {",
127-
" throw new NullPointerException(\"primitiveModule\");",
127+
" throw new NullPointerException();",
128128
" }",
129129
" this.primitiveModule = primitiveModule;",
130130
" return this;",

0 commit comments

Comments
 (0)
Please sign in to comment.