Skip to content

Commit

Permalink
Turn on experimental dagger error messages by default. The old messag…
Browse files Browse the repository at this point in the history
…es can still be used by setting -Adagger.experimentalDaggerErrorMessages=disabled as a javacopt

RELNOTES=n/a
PiperOrigin-RevId: 343134835
  • Loading branch information
Chang-Eric authored and Dagger Team committed Nov 18, 2020
1 parent 55c06b5 commit 0e8f761
Show file tree
Hide file tree
Showing 18 changed files with 392 additions and 310 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ enum Feature implements EnumOption<FeatureStatus> {

FLOATING_BINDS_METHODS,

EXPERIMENTAL_DAGGER_ERROR_MESSAGES,
EXPERIMENTAL_DAGGER_ERROR_MESSAGES(ENABLED),

STRICT_MULTIBINDING_VALIDATION,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void testBinds() {
assertThat(compilation).failed();
assertThat(compilation).hadErrorCount(1);
assertThat(compilation)
.hadErrorContaining("java.lang.Long cannot be provided without an @Inject constructor")
.hadErrorContaining("Long cannot be provided without an @Inject constructor")
.inFile(parentComponent)
.onLineContaining("interface ParentComponent");
}
Expand Down Expand Up @@ -175,7 +175,7 @@ public void testSetBindings() {
assertThat(compilation).failed();
assertThat(compilation).hadErrorCount(1);
assertThat(compilation)
.hadErrorContaining("java.lang.Long cannot be provided without an @Inject constructor")
.hadErrorContaining("Long cannot be provided without an @Inject constructor")
.inFile(parentComponent)
.onLineContaining("interface ParentComponent");
}
Expand Down Expand Up @@ -255,7 +255,7 @@ public void testSetValueBindings() {
assertThat(compilation).failed();
assertThat(compilation).hadErrorCount(1);
assertThat(compilation)
.hadErrorContaining("java.lang.Long cannot be provided without an @Inject constructor")
.hadErrorContaining("Long cannot be provided without an @Inject constructor")
.inFile(parentComponent)
.onLineContaining("interface ParentComponent");
}
Expand Down Expand Up @@ -333,7 +333,7 @@ public void testMapBindings() {
assertThat(compilation).failed();
assertThat(compilation).hadErrorCount(1);
assertThat(compilation)
.hadErrorContaining("java.lang.Long cannot be provided without an @Inject constructor")
.hadErrorContaining("Long cannot be provided without an @Inject constructor")
.inFile(parentComponent)
.onLineContaining("interface ParentComponent");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void bindsMissingDelegate_duplicateBinding() {
.hadErrorContainingMatch(
"\\Qtest.C.NotBound cannot be provided\\E|"
+ message(
"\\Qjava.lang.Object is bound multiple times:",
"\\QObject is bound multiple times:",
" @Binds Object test.C.TestModule.bindObject(test.C.NotBound)",
" @Provides Object test.C.TestModule.provideObject()\\E"))
.inFile(component)
Expand Down
8 changes: 4 additions & 4 deletions javatests/dagger/internal/codegen/ComponentProcessorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ public ComponentProcessorTest(CompilerMode compilerMode) {
.compile(parent, child, another, componentFile);
assertThat(compilation).failed();
assertThat(compilation)
.hadErrorContaining("java.util.List<java.lang.Integer> is bound multiple times");
.hadErrorContaining("List<Integer> is bound multiple times");
assertThat(compilation)
.hadErrorContaining("@Provides List<Integer> test.ChildNumberModule.provideListB(Integer)");
.hadErrorContaining("@Provides List<Integer> ChildNumberModule.provideListB(Integer)");
assertThat(compilation)
.hadErrorContaining("@Provides List<Integer> test.AnotherModule.provideListOfInteger()");
.hadErrorContaining("@Provides List<Integer> AnotherModule.provideListOfInteger()");
}

@Test public void privateNestedClassWithWarningThatIsAnErrorInComponent() {
Expand Down Expand Up @@ -2160,7 +2160,7 @@ public void bindsToDuplicateBinding_bindsKeyIsNotDuplicated() {
assertThat(compilation).failed();
assertThat(compilation).hadErrorCount(1);
assertThat(compilation)
.hadErrorContaining("java.lang.String is bound multiple times")
.hadErrorContaining("String is bound multiple times")
.inFile(component)
.onLineContaining("interface TestComponent");
}
Expand Down
162 changes: 85 additions & 77 deletions javatests/dagger/internal/codegen/DependencyCycleValidationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ public void cyclicDependency() {
.hadErrorContaining(
message(
"Found a dependency cycle:",
" test.Outer.C is injected at",
" test.Outer.A(cParam)",
" test.Outer.A is injected at",
" test.Outer.B(aParam)",
" test.Outer.B is injected at",
" test.Outer.C(bParam)",
" test.Outer.C is requested at",
" test.Outer.CComponent.getC()"))
" Outer.C is injected at",
" Outer.A(cParam)",
" Outer.A is injected at",
" Outer.B(aParam)",
" Outer.B is injected at",
" Outer.C(bParam)",
" Outer.C is requested at",
" Outer.CComponent.getC()"))
.inFile(SIMPLE_CYCLIC_DEPENDENCY)
.onLineContaining("interface CComponent");

Expand All @@ -97,12 +97,20 @@ public void cyclicDependencyWithModuleBindingValidation() {
Pattern moduleBindingValidationError =
endsWithMessage(
"Found a dependency cycle:",
" test.Outer.C is injected at",
" test.Outer.A(cParam)",
" test.Outer.A is injected at",
" test.Outer.B(aParam)",
" test.Outer.B is injected at",
" test.Outer.C(bParam)");
" Outer.C is injected at",
" Outer.A(cParam)",
" Outer.A is injected at",
" Outer.B(aParam)",
" Outer.B is injected at",
" Outer.C(bParam)",
"",
"======================",
"Full classname legend:",
"======================",
"Outer: test.Outer",
"========================",
"End of classname legend:",
"========================");

Compilation compilation =
daggerCompiler()
Expand Down Expand Up @@ -163,16 +171,16 @@ public void cyclicDependencyWithModuleBindingValidation() {
.hadErrorContaining(
message(
"Found a dependency cycle:",
" test.Outer.C is injected at",
" test.Outer.A(cParam)",
" test.Outer.A is injected at",
" test.Outer.B(aParam)",
" test.Outer.B is injected at",
" test.Outer.C(bParam)",
" test.Outer.C is injected at",
" test.Outer.D(cParam)",
" test.Outer.D is requested at",
" test.Outer.DComponent.getD()"))
" Outer.C is injected at",
" Outer.A(cParam)",
" Outer.A is injected at",
" Outer.B(aParam)",
" Outer.B is injected at",
" Outer.C(bParam)",
" Outer.C is injected at",
" Outer.D(cParam)",
" Outer.D is requested at",
" Outer.DComponent.getD()"))
.inFile(component)
.onLineContaining("interface DComponent");
}
Expand Down Expand Up @@ -226,16 +234,16 @@ public void cyclicDependencyNotBrokenByMapBinding() {
.hadErrorContaining(
message(
"Found a dependency cycle:",
" test.Outer.C is injected at",
" test.Outer.CModule.c(c)",
" java.util.Map<java.lang.String,test.Outer.C> is injected at",
" test.Outer.A(cMap)",
" test.Outer.A is injected at",
" test.Outer.B(aParam)",
" test.Outer.B is injected at",
" test.Outer.C(bParam)",
" test.Outer.C is requested at",
" test.Outer.CComponent.getC()"))
" Outer.C is injected at",
" Outer.CModule.c(c)",
" Map<String,Outer.C> is injected at",
" Outer.A(cMap)",
" Outer.A is injected at",
" Outer.B(aParam)",
" Outer.B is injected at",
" Outer.C(bParam)",
" Outer.C is requested at",
" Outer.CComponent.getC()"))
.inFile(component)
.onLineContaining("interface CComponent");
}
Expand Down Expand Up @@ -287,16 +295,16 @@ public void cyclicDependencyWithSetBinding() {
.hadErrorContaining(
message(
"Found a dependency cycle:",
" test.Outer.C is injected at",
" test.Outer.CModule.c(c)",
" java.util.Set<test.Outer.C> is injected at",
" test.Outer.A(cSet)",
" test.Outer.A is injected at",
" test.Outer.B(aParam)",
" test.Outer.B is injected at",
" test.Outer.C(bParam)",
" test.Outer.C is requested at",
" test.Outer.CComponent.getC()"))
" Outer.C is injected at",
" Outer.CModule.c(c)",
" Set<Outer.C> is injected at",
" Outer.A(cSet)",
" Outer.A is injected at",
" Outer.B(aParam)",
" Outer.B is injected at",
" Outer.C(bParam)",
" Outer.C is requested at",
" Outer.CComponent.getC()"))
.inFile(component)
.onLineContaining("interface CComponent");
}
Expand Down Expand Up @@ -343,16 +351,16 @@ public void falsePositiveCyclicDependencyIndirectionDetected() {
.hadErrorContaining(
message(
"Found a dependency cycle:",
" test.Outer.C is injected at",
" test.Outer.A(cParam)",
" test.Outer.A is injected at",
" test.Outer.B(aParam)",
" test.Outer.B is injected at",
" test.Outer.C(bParam)",
" javax.inject.Provider<test.Outer.C> is injected at",
" test.Outer.D(cParam)",
" test.Outer.D is requested at",
" test.Outer.DComponent.getD()"))
" Outer.C is injected at",
" Outer.A(cParam)",
" Outer.A is injected at",
" Outer.B(aParam)",
" Outer.B is injected at",
" Outer.C(bParam)",
" Provider<Outer.C> is injected at",
" Outer.D(cParam)",
" Outer.D is requested at",
" Outer.DComponent.getD()"))
.inFile(component)
.onLineContaining("interface DComponent");
}
Expand Down Expand Up @@ -427,12 +435,12 @@ public void cyclicDependencyInSubcomponents() {
.hadErrorContaining(
message(
"Found a dependency cycle:",
" java.lang.String is injected at",
" test.CycleModule.object(string)",
" java.lang.Object is injected at",
" test.CycleModule.string(object)",
" java.lang.String is requested at",
" test.Grandchild.entry()"))
" String is injected at",
" CycleModule.object(string)",
" Object is injected at",
" CycleModule.string(object)",
" String is requested at",
" Grandchild.entry()"))
.inFile(parent)
.onLineContaining("interface Parent");
}
Expand Down Expand Up @@ -509,12 +517,12 @@ public void cyclicDependencyInSubcomponentsWithChildren() {
.hadErrorContaining(
message(
"Found a dependency cycle:",
" java.lang.String is injected at",
" test.CycleModule.object(string)",
" java.lang.Object is injected at",
" test.CycleModule.string(object)",
" java.lang.String is requested at",
" test.Child.entry() [test.Parent → test.Child]"))
" String is injected at",
" CycleModule.object(string)",
" Object is injected at",
" CycleModule.string(object)",
" String is requested at",
" Child.entry() [Parent → Child]"))
.inFile(parent)
.onLineContaining("interface Parent");
}
Expand Down Expand Up @@ -560,12 +568,12 @@ public void circularBindsMethods() {
.hadErrorContaining(
message(
"Found a dependency cycle:",
" java.lang.Object is injected at",
" test.TestModule.bindQualified(unqualified)",
" @test.SomeQualifier java.lang.Object is injected at",
" test.TestModule.bindUnqualified(qualified)",
" java.lang.Object is requested at",
" test.TestComponent.unqualified()"))
" Object is injected at",
" TestModule.bindQualified(unqualified)",
" @SomeQualifier Object is injected at",
" TestModule.bindUnqualified(qualified)",
" Object is requested at",
" TestComponent.unqualified()"))
.inFile(component)
.onLineContaining("interface TestComponent");
}
Expand Down Expand Up @@ -602,10 +610,10 @@ public void selfReferentialBinds() {
.hadErrorContaining(
message(
"Found a dependency cycle:",
" java.lang.Object is injected at",
" test.TestModule.bindToSelf(sameKey)",
" java.lang.Object is requested at",
" test.TestComponent.selfReferential()"))
" Object is injected at",
" TestModule.bindToSelf(sameKey)",
" Object is requested at",
" TestComponent.selfReferential()"))
.inFile(component)
.onLineContaining("interface TestComponent");
}
Expand Down Expand Up @@ -659,7 +667,7 @@ public void cycleFromMembersInjectionMethod_WithSameKeyAsMembersInjectionMethod(
" test.B is injected at",
" test.A.b",
" test.A is injected at",
" test.CycleComponent.inject(test.A)"))
" CycleComponent.inject(test.A)"))
.inFile(component)
.onLineContaining("interface CycleComponent");
}
Expand Down
Loading

0 comments on commit 0e8f761

Please sign in to comment.