Commit Graph
271 Commits
Author SHA1 Message Date
Guice TeamandGuice Team 2712230640 Fix formatting of source with module stack. Add NullInjectedIntoNonNullable tests.
PiperOrigin-RevId: 346890324
2020-12-10 16:30:51 -08:00
Guice TeamandGuice Team a795fcc1b8 Clarify wording of the MissingConstructor Guice error message
PiperOrigin-RevId: 345502715
2020-12-03 11:57:18 -08:00
Guice TeamandGuice Team 80b91afae2 Update tests to support running with Java 15.
In Java 15, the annotation `toString` implementation omits the member name.

PiperOrigin-RevId: 338746927
2020-10-23 14:37:28 -07:00
Guice TeamandGuice Team b97095d388 Delete obsolete methods in Messages and migrate callers to use equivalent methods in SourceFormatter.
PiperOrigin-RevId: 338582362
2020-10-22 17:32:37 -07:00
Guice TeamandGuice Team d3df2d5854 Delete deprecated dependency stack APIs.
PiperOrigin-RevId: 338343877
2020-10-21 14:44:42 -07:00
Guice TeamandGuice Team 5caa549395 Enable the new Guice error messages.
Changes include:

 - update Guice tests that asserts error messages
 - export new errors tests
 - update Guice compiler flag so parameter names are available at runtime, which is required for the errors tests

PiperOrigin-RevId: 337602195
2020-10-16 16:55:03 -07:00
Guice TeamandGuice Team 9a8e46716e Revert previous change because it broke some tests when running with openjdk8.
PiperOrigin-RevId: 337517262
2020-10-16 09:13:55 -07:00
Guice TeamandGuice Team 2c8c7fed12 Enable the new Guice error messages.
Changes include:
- update Guice tests that asserts error messages
- export new errors tests
- update Guice compiler flag so parameter names are available at runtime, which is required for the errors tests

PiperOrigin-RevId: 337401912
2020-10-15 16:06:22 -07:00
Guice TeamandGuice Team 1ae63eb443 Strip embedded class name legend in the case that one Guice error is included in another Guice error.
PiperOrigin-RevId: 336366033
2020-10-09 14:30:12 -07:00
Guice TeamandGuice Team 0781568a6c Fix test when bytecode generation is disabled.
PiperOrigin-RevId: 336311235
2020-10-09 09:51:37 -07:00
Guice TeamandGuice Team dd873be400 Remove AOP build variant.
Changes include:

- skip tests that are testing bytecode generation enabled behaviors
- make line number and source file name information available even when bytecode generation is disabled since it does not use bytecode generation and makes testing easier (some tests rely on the information being available)
- update maven pom files to stop producing a no-aop version of Guice
- added test profile to execute tests with bytecode generation disabled

PiperOrigin-RevId: 336306344
2020-10-09 09:23:54 -07:00
Guice TeamandGuice Team b7cadc1cfa Migrate several tests to junit4 so that tests that rely on AOP can be skipped using Assume.assumeTrue.
PiperOrigin-RevId: 335755255
2020-10-06 17:18:53 -07:00
Guice TeamandGuice Team 690e189a7d Use assumeTrue to skip tests that only need to run under certain conditions.
This requires migrating some tests from JUnit3 to JUnit4.

PiperOrigin-RevId: 335094691
2020-10-02 13:55:43 -07:00
Guice TeamandGuice Team 67c957b5e4 Include the @RestrictedBindingSource explanation as a missing binding suggestion.
PiperOrigin-RevId: 334803319
2020-10-01 06:48:28 -07:00
Guice TeamandGuice Team 9997527a93 Quote the duplicate key in DuplicateMapKeyError.
This will ensure that the key will not be modified by Guice's package name compressor.

Also fix package name compressor to handle single letter class names.

PiperOrigin-RevId: 334653432
2020-09-30 12:24:00 -07:00
Guice TeamandGuice Team 471a25f1c7 Do not compress package names in string literals.
Previously any string that matches the package name pattern will be shortened and this is undesirable when the text is not actually meant to be interpreted as a package name.

This change gives user a way to disable the package name compressor by putting the text in double quotation marks.

PiperOrigin-RevId: 334254171
2020-09-28 15:48:31 -07:00
Guice TeamandGuice Team 0beaff51e0 Add a check for OptionalBinder infinite recursion.
When an optional binder binding was linked to the same class like below, infinite recursion occurs. There is a check for recursive binding in BindingProcessor class for all linked bindings but that did not work for OptionalBinder since OptionalBinder original key annotation is wrapped into something. So, comparing the original key and linked binding key didn't work.

Added a check for that.

Example:

```
OptionalBinder.newOptionalBinder(binder(), MyClass.class)
    .setBinding()
    .to(MyClass.class);
```

PiperOrigin-RevId: 332062297
2020-09-16 12:29:41 -07:00
Colin DeckerandGuice Team 835084290b Replace some usernames in TODOs.
PiperOrigin-RevId: 329928334
2020-09-03 09:01:02 -07:00
Guice TeamandGuice Team a689de7884 Only compress class names with at least 2 package names.
This avoid mistaking normal sentences in user added error message as class names. It is also rare and less useful to compress a short class name anyway.

PiperOrigin-RevId: 329401381
2020-08-31 16:28:41 -07:00
Guice TeamandColin Decker 83c9a329f4 Automatic code cleanup.
PiperOrigin-RevId: 328979463
2020-08-28 15:28:47 -04:00
xiaomingjiaandDavid P. Baker 2ebc207348 Make error identifier optional, since it's not very useful to print out [Guice/Other].
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=328825320
2020-08-28 11:17:23 -04:00
nishachaudhariandDavid P. Baker f123130d30 Throw error if no. of type parameters passed to ParameterizedTypeImpl are less than actual generic params for a class.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=327319511
2020-08-19 14:58:24 -04:00
xiaomingjiaandColin Decker 51ba928a1b Implement MissingConstructor error in the new format.
This also merge MISSING_CONSTRUCTOR with AT_INJECT_REQUIRED into a single error since they are essentially about the same issue.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=325867978
2020-08-12 11:24:17 -04:00
xiaomingjiaandKurt Alfred Kluever 84e0ce89ba Fix or suppress more javac warnings in Guice.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=325069224
2020-08-06 13:57:00 -04:00
croyerandKurt Alfred Kluever 671a36ed86 Create a new MapBinder alternate key of Map<K, ? extends V> when using a MapBinder<K, V>.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=325038314
2020-08-06 13:57:00 -04:00
xiaomingjiaandKurt Alfred Kluever 363c593aa7 Fix or suppress some unchecked/rawtypes javac warnings in Guice code.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=324884430
2020-08-05 09:53:37 -04:00
xiaomingjiaandKurt Alfred Kluever af26c72479 Fix some unchecked and rawtypes warnings in Guice code.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=324843912
2020-08-05 09:53:37 -04:00
xiaomingjiaandKurt Alfred Kluever ffb154d030 Fix some unchecked and rawtypes warnings in Guice code.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=324668014
2020-08-04 11:22:03 -04:00
xiaomingjiaandKurt Alfred Kluever db66b74249 Fix some unchecked and rawtypes warnings in Guice code.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=324662892
2020-08-04 11:22:03 -04:00
xiaomingjiaandKurt Alfred Kluever ab52436c91 Allow custom error to include their own id and learn more links.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=324280204
2020-08-03 10:03:47 -04:00
adfuandKurt Alfred Kluever c03bbe80f9 Rewrite the Guice Stopwatch class to make it testable. Rename this Stopwatch to ContinuousStopwatch to avoid a naming collision with its internal Stopwatch.
Automated g4 rollback of changelist 324101718.

*** Reason for rollback ***

Roll forward of [] with fix: Stopwatch's Duration elapsed() method cannot be used here. Possibly related to b/156759807.

*** Original change description ***

Automated g4 rollback of changelist 324072869.

*** Reason for rollback ***

Broke a bunch of things.

*** Original change description ***

Rewrite the Guice Stopwatch class to make it testable. Rename this Stopwatch to ContinuousStopwatch to avoid a naming collision with its internal Stopwatch.

***

***

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=324246423
2020-08-03 10:03:47 -04:00
vzmandNick 969dff1892 Fix @RestrictedBindingSource bug where scanner-installed modules don't inherit permits.
Without this fix @RBS doesn't work with @ProvidesForRequest, because it provides the binding via a module installed in the scanner.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=324205733
2020-07-31 13:12:22 -05:00
xiaomingjiaandNick c5b35af17b Revert f58167b7e8
It broke a bunch of internal things

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=324101718
2020-07-31 13:12:22 -05:00
adfuandNick acf6122e9c Rewrite the Guice Stopwatch class to make it testable. Rename this Stopwatch to ContinuousStopwatch to avoid a naming collision with its internal Stopwatch.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=324072869
2020-07-31 13:12:22 -05:00
xiaomingjiaandNick 32b4a12045 Change ErrorDetail subclass to only format the part of error that needs customization.
All new errors will be formatted using with the following format:

```
1 ): [Guice/SOME_ERROR]: Summary about this error

Detail from the implementation of ErrorDetail subclass.

Learn more:
    http://github.com/google/guice/wiki/SOME_ERROR
```

Also add the initial documentation on MISSING_IMPLEMENTATION error.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=324051288
2020-07-31 13:12:22 -05:00
Jesse WilsonandNick e543c75d80 Import https://github.com/google/guice/pull/1366
Create a new multibinder alternate for Set<? extends T>

Closes #1366

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=323843272
2020-07-30 09:54:20 -05:00
xiaomingjiaandNick 76a721005f Implement missing implementation error in the new format.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=323624909
2020-07-29 09:45:31 -05:00
xiaomingjiaandChris Povirk 928554a9b2 Copy dagger's package name compressor code to Guice and use it to compress packages in Guice error message.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=322610400
2020-07-23 13:13:04 -04:00
adfuandChris Povirk 0e6f70518d Move the lock from being InjectorBindingData -> InjectorJitBindingData.
This is a better place for the lock, since it is needed for JIT bindings.
Also inline InjectorShell's getBindingData(): it's only called from one place.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=322466470
2020-07-22 10:23:58 -04:00
adfuandDavid P. Baker 402144383c Merge State and InheritingState into the InjectorBindingData class.
InheritingState is the only implementation of State outside of testing, and both are package private, so it's unnecessary to have both an interface and an implementation class.

This refactor should not change any observed behavior.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=321065049
2020-07-14 11:53:43 -04:00
adfuandDavid P. Baker 655eab1c9e Remove State.NONE (which was used as a placeholder object when a State didn't have a parent) and use Optional<State> instead for storing parent State.
Make State return immutable lists for some of its methods.

This refactor shouldn't change any observable behavior.

This CL will make it easier to merge State and InheritingState.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=321014769
2020-07-14 11:53:43 -04:00
xiaomingjiaandDavid P. Baker ee6abe38ae Run tests with different class loading options.
Changed to skip certain tests explicitly instead of excluding the test class, which makes the setup easier.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=320982966
2020-07-14 11:53:43 -04:00
vzmandDavid P. Baker 1bfd944682 Enable logging warnings on RestrictedBindingSource violations (ie. the restrictionLevel knob).
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=320716882
2020-07-13 11:39:49 -04:00
adfuandkevinb9n 3d98f869fc Aggregate the Guice injector's JIT binding data into an InjectorJitBindingData object.
In particular:
- Move jitBindings and failedJitBindings out of InjectorImpl and into a new InjectorJitBindingData class, which is constructed in parallel with State in the InjectorShell.
- Move blacklistedKeys (and associated methods) out of InheritingState and into InjectorJitBindingData.
- Rename blacklistedKeys methods: blacklist -> banKey; isBlacklisted -> isBannedKey; getSourcesForBlacklistedKey -> getSourcesForBannedKey
- Replace parent().blacklist() with banKeyInParent() since it's the only reason the parent jit binding data is ever accessed.

This should be a refactor only: no change in behavior is expected from this CL.

This is Step 1 of this design doc: https://docs.google.com/document/d/1az6yShBLpN9DKr1uvFlMUQEqj-2eXl0frckmVWDEdkg/edit

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=320495996
2020-07-10 09:15:17 -07:00
Stuart McCullochandkevinb9n 85e30beafe Import https://github.com/google/guice/pull/1298
Replace CGLIB with custom code to generate "enhancers" and "fast-classes".

Some user visible changes from using cglib:
- intercepted method that has a return type of int but returns null from the interceptor will no longer be automatically converted to 0, instead a NullPointerException will be thrown.
- Scope implementation can no longer check for circular proxy instance using CircularDependencyProxy marker class, instead should use Scopes.isCircularProxy
- Depending on which custom class loading option is used, Guice enhanced class may no longer be mockable/spyable
- Generated class name is slightly longer.

Closes #1298

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=320433559
2020-07-10 08:43:31 -07:00
diamondmandkevinb9n d65c576a21 Simplify some usages of Key.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=320184863
2020-07-08 12:51:29 -07:00
vzmandkevinb9n d854f75339 Support permits on anonymous classes.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=319854009
2020-07-08 12:51:29 -07:00
vzmandkevinb9n 654f7098eb Enable permits to be given to ModuleAnnotatedMethodScanners.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=319814886
2020-07-06 15:07:52 -07:00
vzmandKurt Alfred Kluever 2b7477458d Track the ModuleAnnotatedMethodScanner in the ElementSource.
First step to give permits to scanners.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=319266905
2020-07-01 15:10:52 -04:00
xiaomingjiaandKurt Alfred Kluever 02b6ecb028 Add API to allow custom error message formatting.
Since `Message` is used in various public APIs it's infesiable to change
it to be a subclass of a error message class. Instead this CL moves all the
details about the error into an `ErrorDetail` class and wraps it with `Message`. Errors that needs custom formatting can inherit `ErrorDetail` and a generic implementation is added that uses the current formatting options.

Follow up changes to add different implementations for specific errors that should be formatted differently if the experimental new error feature is enabled.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=318520440
2020-06-29 11:03:49 -04:00