Author: limpbizkit
Date: Mon Sep 29 11:24:45 2008
New Revision: 627
Modified:
trunk/extensions/assistedinject/src/com/google/inject/assistedinject/FactoryProvider.java
trunk/extensions/assistedinject/test/com/google/inject/assistedinject/FactoryProviderTest.java
Log:
jmourits' changes to assistedinject so toString() etc. on the proxies work.
Previously they were blowing up with NPEs in some situations.
Modified:
trunk/extensions/assistedinject/src/com/google/inject/assistedinject/FactoryProvider.java
==============================================================================
---
trunk/extensions/assistedinject/src/com/google/inject/assistedinject/FactoryProvider.java
(original)
+++
trunk/extensions/assistedinject/src/com/google/inject/assistedinject/FactoryProvider.java
Mon Sep 29 11:24:45 2008
@@ -209,8 +209,12 @@
InvocationHandler invocationHandler = new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[]
creationArgs) throws Throwable {
+ // pass methods from Object.class to the proxy
+ if (method.getDeclaringClass().equals(Object.class)) {
+ return method.invoke(this, creationArgs);
+ }
+
AssistedConstructor<?> constructor =
factoryMethodToConstructor.get(method);
-
Object[] constructorArgs = gatherArgsForConstructor(
constructor, creationArgs);
Object objectToReturn = constructor.newInstance(constructorArgs);
Modified:
trunk/extensions/assistedinject/test/com/google/inject/assistedinject/FactoryProviderTest.java
==============================================================================
---
trunk/extensions/assistedinject/test/com/google/inject/assistedinject/FactoryProviderTest.java
(original)
+++
trunk/extensions/assistedinject/test/com/google/inject/assistedinject/FactoryProviderTest.java
Mon Sep 29 11:24:45 2008
@@ -518,6 +518,22 @@
"Parameter of type 'double' is not injectable or annotated with
@Assisted");
}
}
+
+ public void testMethodsDeclaredInObject() {
+ Injector injector = Guice.createInjector(new AbstractModule() {
+ @Override protected void configure() {
+ bind(Double.class).toInstance(5.0d);
+ bind(ColoredCarFactory.class)
+ .toProvider(FactoryProvider.newFactory(ColoredCarFactory.class,
Mustang.class));
+ }
+ });
+
+ ColoredCarFactory carFactory =
injector.getInstance(ColoredCarFactory.class);
+
+ carFactory.equals(carFactory);
+ carFactory.hashCode();
+ carFactory.toString();
+ }
// TODO(jessewilson): test for duplicate constructors
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/google-guice-dev?hl=en
-~----------~----~----~----~------~----~------~--~---