Commit Graph
14 Commits
Author SHA1 Message Date
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 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
lukesandSam Berlin 34e7c5d715 Run google-java-format on all Guice code.
configure a presubmit to ensure that it stays formatted.

Highlights include:
* simplified import order
* method annotations are now consistently defined on the preceding line
* javadoc reformatted to 100 chars column width

One test that contained line numbers in error messages had to be modified and
the formatter didn't like some of the more complicated preprocessor directives
(MOE and AOP).

To avoid formatting the copyright notices as javadoc i did a preprocessing step to rewrite the initial '/**' to '/*' using perl

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=132718493
2016-09-13 11:47:18 -04:00
lukesandSam Berlin 713c06cce9 Fix issues reported by errorprone
99% of this is adding missing @Override annotations, in the long tail we also have

* insert missing calls to Assert.fail() in tests that are testing exception behavior
* rewrite a few cases of Foo.class.instanceof(c) to c instanceof Foo
* rewrite Class.newInstance - > Class.getConstructor().newInstance() which doesn't break checked exception checking.
* adding @javax.inject.Inject annotations to methods that override methods annotated with @javax.inject.Inject

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=131839622
2016-09-07 17:45:54 -04:00
lukesandSam Berlin 592dcb251b Rewrite RealOptionalBinder to use the InternalFactory interfaces and avoid the overheads of normal ProviderInstanceBindings + Providers.
A couple of notes on the implementation
* all the mutable state (besides Binder) has been moved into a new helper object 'BindingSelection'.  I think by moving things into a helper object the interactions are a bit clearer.  This also allows us to make all the factories static.
* calculating the keys + optional binder 'name' have been delayed until configure() time or until setDefault()/setBinding() is called.  I would assume that most optionalbinders are deduped or that setDefault()/setBinding() is not called, so we can avoid work in the common cases.
* None of the factories need circular deps resolution because they simply delegate to other factories. (in this way they are much like the ProxyFactory used for LinkedKeyBindings, we just wrap the result in Optional)
* I performed a minor refactoring the the java.util.Optional reflection helpers

Benchmark results:
timeOptionalBinderInjection measures how long to inject an object that depends on other OptionalBinders in every configuration
timeProvidesInjection times how long it takes to inject an @Provides method
timeOptionalBinderSetBinding times how long it takes to directly inject an OptionalBinder.setBinding() binding that delegates to the same bindings as 'timeProvidesInjection'.  So we should be able to see the overhead of OptionalBinder to fetch the same object.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=130648042
2016-08-29 16:42:10 -04:00
lukesandSam Berlin d1e25e68d3 When formatting method/constructor dependencies for error messages print the 'ordinal' of the parameter rather than the index.
Given the method

  void foo(A a, B b) {}

Guice currently prints "parameter 1 of foo" to refer to 'b', but most people (based on an informal survey), believe it refers to 'a'.  To resolve this confusion Guice will now print "the 2nd parameter of foo" to refer to 'b'.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125128691
2016-06-17 12:19:27 -04:00
Christian Edward Gruber ba5acdf7cf Allow turning off stack trace collection in Guice.
By setting guice_include_stack_traces flag OFF, Guice does not collect stack traces for identifying the declaring source of a binding. Instead it uses the first non-skipped module class name from the modules stack. As a result, in some cases, error messages can be slightly different with this flag. For example, the file name and line number are not always available.

A sample error message with this flag :

Guice creation errors:
1) Received null converting foo (bound at com.google.inject.TypeConversionTest.configure(Unknown Source) (via modules: com.google.inject.TypeConversionTest -> com.google.inject.TypeConversionTest)) to java.util.Date
using CustomConverter which matches only(java.util.Date) (bound at com.google.inject.TypeConversionTest.configure(Unknown Source) (via modules: com.google.inject.TypeConversionTest -> com.google.inject.TypeConversionTest -> com.google.inject.TypeConversionTest)).
while locating java.util.Date annotated with @com.google.inject.TypeConversionTest()
for field at com.google.inject.TypeConversionTest.date(TypeConversionTest.java:478)
at com.google.inject.TypeConversionTest.configure(Unknown Source) (via modules: com.google.inject.TypeConversionTest -> com.google.inject.TypeConversionTest)

This also changes the DEFAULT flag name to ONLY_FOR_DECLARTION_SOURCE.
Adds InternalFlags.getIncludeStackTraceOption() to wrap system property access.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=53610378
2013-10-05 14:12:59 -07:00
sberlin b7a02b02d8 * Remove unused imports
* Sort imports
* Convert tabs to spaces
* Fix the ant no_aop build


Revision created by MOE tool push_codebase.
MOE_MIGRATION=2532


git-svn-id: https://google-guice.googlecode.com/svn/trunk@1572 d779f126-a31b-0410-b53b-1d3aecad763e
2011-07-08 00:34:16 +00:00
sberlin d9c913acca switch Guice from manually repackaging Guava to depending on Guava. it's still jarjar'd right now, which is causing a ~400k increase in guice-snapshot.jar. next step is to switch to ProGuard to remove the unnecessary code and cut it back down (even further?!). this will let people build from Guice source and depend directly on Guava code without having to worry about hiding internal/util.
git-svn-id: https://google-guice.googlecode.com/svn/trunk@1558 d779f126-a31b-0410-b53b-1d3aecad763e
2011-06-26 21:02:54 +00:00
sberlin 7f6067d388 Update test to make sure custom @Nullable annotations work, in addition to c.g.i.i.util.Nullable.
git-svn-id: https://google-guice.googlecode.com/svn/trunk@1326 d779f126-a31b-0410-b53b-1d3aecad763e
2010-10-29 03:01:12 +00:00
sberlin 6f0aee6977 move @nullable to internal.util
git-svn-id: https://google-guice.googlecode.com/svn/trunk@1323 d779f126-a31b-0410-b53b-1d3aecad763e
2010-10-27 02:03:52 +00:00
mcculls 74d714c1e7 Issue 552: (step 1) move core code to its own subdirectory
git-svn-id: https://google-guice.googlecode.com/svn/trunk@1300 d779f126-a31b-0410-b53b-1d3aecad763e
2010-10-21 19:10:16 +00:00