-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add better Guice hints when using classes of the same name from diffe…
…rent packages. PiperOrigin-RevId: 696172862
- Loading branch information
1 parent
d83f677
commit 7b8cc46
Showing
5 changed files
with
226 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...st/com/google/inject/errors/testdata/missing_implementation_with_mismatched_optionals.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Unable to create injector, see the following errors: | ||
|
||
1) [Guice/MissingImplementation]: No implementation for base.Optional<String> was bound. | ||
|
||
Did you mean? | ||
* util.Optional<String> bound at MissingImplementationErrorTest$MismatchedOptionalsModule.provideString(MissingImplementationErrorTest.java:218) | ||
|
||
Requested by: | ||
1 : MissingImplementationErrorTest$MismatchedOptionalsModule.provideInteger(MissingImplementationErrorTest.java:223) | ||
\_ for 1st parameter dep | ||
at MissingImplementationErrorTest$MismatchedOptionalsModule.provideInteger(MissingImplementationErrorTest.java:223) | ||
|
||
Learn more: | ||
https://github.com/google/guice/wiki/MISSING_IMPLEMENTATION | ||
|
||
1 error | ||
|
||
====================== | ||
Full classname legend: | ||
====================== | ||
MissingImplementationErrorTest$MismatchedOptionalsModule: "com.google.inject.errors.MissingImplementationErrorTest$MismatchedOptionalsModule" | ||
base.Optional: "com.google.common.base.Optional" | ||
util.Optional: "java.util.Optional" | ||
======================== | ||
End of classname legend: | ||
======================== |
103 changes: 103 additions & 0 deletions
103
core/test/com/google/inject/internal/SimilarLookingTypesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.google.inject.internal; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
import static com.google.inject.internal.MissingImplementationErrorHints.areSimilarLookingTypes; | ||
|
||
import com.google.inject.TypeLiteral; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
@RunWith(JUnit4.class) | ||
public final class SimilarLookingTypesTest { | ||
|
||
private static class Wrapper { | ||
private static class Foo {} | ||
} | ||
|
||
private static class Foo {} | ||
|
||
@Test | ||
public void similarClasses() { | ||
assertThat(areSimilarLookingTypes(Foo.class, Wrapper.Foo.class)).isTrue(); | ||
} | ||
|
||
@Test | ||
public void differentClasses() { | ||
assertThat(areSimilarLookingTypes(String.class, Integer.class)).isFalse(); | ||
} | ||
|
||
@Test | ||
public void similarGenericTypes() { | ||
assertThat( | ||
areSimilarLookingTypes( | ||
new TypeLiteral<List<com.google.common.base.Optional<String>>>() {}.getType(), | ||
new TypeLiteral<List<Optional<String>>>() {}.getType())) | ||
.isTrue(); | ||
} | ||
|
||
@Test | ||
public void multipleSimilarGenericTypes() { | ||
assertThat( | ||
areSimilarLookingTypes( | ||
new TypeLiteral<Optional<com.google.common.base.Optional<String>>>() {}.getType(), | ||
new TypeLiteral<com.google.common.base.Optional<Optional<String>>>() {}.getType())) | ||
.isTrue(); | ||
} | ||
|
||
@Test | ||
public void differentGenericTypes() { | ||
assertThat( | ||
areSimilarLookingTypes( | ||
new TypeLiteral<List<String>>() {}.getType(), | ||
new TypeLiteral<List<Integer>>() {}.getType())) | ||
.isFalse(); | ||
} | ||
|
||
@Test | ||
public void similarGenericArrayTypes() { | ||
assertThat( | ||
areSimilarLookingTypes( | ||
new TypeLiteral<com.google.common.base.Optional<String>[]>() {}.getType(), | ||
new TypeLiteral<Optional<String>[]>() {}.getType())) | ||
.isTrue(); | ||
} | ||
|
||
@Test | ||
public void differentGenericArrayTypes() { | ||
assertThat( | ||
areSimilarLookingTypes( | ||
new TypeLiteral<List<String>[]>() {}.getType(), | ||
new TypeLiteral<List<String>[][]>() {}.getType())) | ||
.isFalse(); | ||
} | ||
|
||
@Test | ||
public void similarWildcardTypes() { | ||
assertThat( | ||
areSimilarLookingTypes( | ||
new TypeLiteral<com.google.common.base.Optional<?>>() {}.getType(), | ||
new TypeLiteral<Optional<?>>() {}.getType())) | ||
.isTrue(); | ||
} | ||
|
||
@Test | ||
public void differentWildcardType_extends() { | ||
assertThat( | ||
areSimilarLookingTypes( | ||
new TypeLiteral<List<?>>() {}.getType(), | ||
new TypeLiteral<List<? extends String>>() {}.getType())) | ||
.isFalse(); | ||
} | ||
|
||
@Test | ||
public void differentWildcardType_super() { | ||
assertThat( | ||
areSimilarLookingTypes( | ||
new TypeLiteral<List<?>>() {}.getType(), | ||
new TypeLiteral<List<? super String>>() {}.getType())) | ||
.isFalse(); | ||
} | ||
} |