Author: limpbizkit
Date: Fri Feb 27 15:47:39 2009
New Revision: 872
Modified:
trunk/extensions/assistedinject/src/com/google/inject/assistedinject/Assisted.java
trunk/extensions/assistedinject/src/com/google/inject/assistedinject/FactoryProvider.java
trunk/src/com/google/inject/internal/MoreTypes.java
trunk/test/com/google/inject/util/TypesTest.java
Log:
Misc small changes.
Fix for bug 341, and tweaking assisted inject Javadoc.
Modified:
trunk/extensions/assistedinject/src/com/google/inject/assistedinject/Assisted.java
==============================================================================
---
trunk/extensions/assistedinject/src/com/google/inject/assistedinject/Assisted.java
(original)
+++
trunk/extensions/assistedinject/src/com/google/inject/assistedinject/Assisted.java
Fri Feb 27 15:47:39 2009
@@ -35,7 +35,7 @@
/**
* The unique name for this parameter. This is matched to the {...@literal
@Assisted} constructor
- * parameter with the same value.
+ * parameter with the same value. Names are not necessary when the
parameter types are distinct.
*/
String value() default "";
}
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
Fri Feb 27 15:47:39 2009
@@ -41,12 +41,12 @@
import java.util.Set;
/**
- * Provides a factory that combines caller-provided parameters with
injector-provided values when
- * constructing objects.
+ * Provides a factory that combines the caller's arguments with
injector-supplied values to
+ * construct objects.
*
* <h3>Defining a factory</h3>
- * Create an interface whose methods return the constructed type, or its
supertypes. The method's
- * parameters are the arguments required to build the constructed type.
+ * Create an interface whose methods return the constructed type, or any
of its supertypes. The
+ * method's parameters are the arguments required to build the constructed
type.
* <pre>public interface PaymentFactory {
* Payment create(Date startDate, Money amount);
* }</pre>
@@ -55,8 +55,8 @@
*
* <h3>Creating a type that accepts factory parameters</h3>
* {...@code constructedType} is a concrete class with an {...@literal
@}...@link
Inject}-annotated
- * constructor. In addition to injector-provided parameters, the
constructor should have
- * parameters that match each of the factory method's parameters. Each
factory-provided parameter
+ * constructor. In addition to injector-supplied parameters, the
constructor should have
+ * parameters that match each of the factory method's parameters. Each
factory-supplied parameter
* requires an {...@literal @}...@link Assisted} annotation. This serves to
document that the parameter
* is not bound by your application's modules.
* <pre>public class RealPayment implements Payment {
@@ -80,7 +80,7 @@
*
* <h3>Using the factory</h3>
* Inject your factory into your application classes. When you use the
factory, your arguments
- * will be combined with values from the injector to produce a concrete
instance.
+ * will be combined with values from the injector to construct an instance.
* <pre>public class PaymentAction {
* {...@literal @}Inject private PaymentFactory paymentFactory;
*
Modified: trunk/src/com/google/inject/internal/MoreTypes.java
==============================================================================
--- trunk/src/com/google/inject/internal/MoreTypes.java (original)
+++ trunk/src/com/google/inject/internal/MoreTypes.java Fri Feb 27 15:47:39
2009
@@ -276,11 +276,14 @@
if (ownerType != null) {
stringBuilder.append(toString(ownerType)).append(".");
}
- stringBuilder.append(toString(parameterizedType.getRawType()))
- .append("<")
- .append(toString(arguments[0]));
- for (int i = 1; i < arguments.length; i++) {
- stringBuilder.append(", ").append(toString(arguments[i]));
+ stringBuilder.append(toString(parameterizedType.getRawType()));
+ if (arguments.length > 0) {
+ stringBuilder
+ .append("<")
+ .append(toString(arguments[0]));
+ for (int i = 1; i < arguments.length; i++) {
+ stringBuilder.append(", ").append(toString(arguments[i]));
+ }
}
return stringBuilder.append(">").toString();
Modified: trunk/test/com/google/inject/util/TypesTest.java
==============================================================================
--- trunk/test/com/google/inject/util/TypesTest.java (original)
+++ trunk/test/com/google/inject/util/TypesTest.java Fri Feb 27 15:47:39
2009
@@ -20,6 +20,7 @@
import static com.google.inject.Asserts.assertContains;
import static com.google.inject.Asserts.assertEqualWhenReserialized;
import static com.google.inject.Asserts.assertEqualsBothWays;
+import com.google.inject.TypeLiteral;
import com.google.inject.internal.MoreTypes;
import static com.google.inject.util.Types.subtypeOf;
import static com.google.inject.util.Types.supertypeOf;
@@ -45,6 +46,7 @@
List<String[][]> c;
List<String> d;
Set<String> e;
+ Outer<String>.Inner f;
private ParameterizedType mapStringInteger;
private ParameterizedType innerFloatDouble;
@@ -52,6 +54,7 @@
private ParameterizedType listString;
private ParameterizedType setString;
private GenericArrayType stringArray;
+ private ParameterizedType outerInner;
protected void setUp() throws Exception {
super.setUp();
@@ -61,6 +64,7 @@
listString = (ParameterizedType)
getClass().getDeclaredField("d").getGenericType();
setString = (ParameterizedType)
getClass().getDeclaredField("e").getGenericType();
stringArray = (GenericArrayType)
listStringArray.getActualTypeArguments()[0];
+ outerInner = (ParameterizedType)
getClass().getDeclaredField("f").getGenericType();
}
public void testListSetMap() {
@@ -184,4 +188,18 @@
@SuppressWarnings("UnusedDeclaration")
class Inner<T1, T2> {}
+
+ public void testInnerParameterizedEvenWithZeroArgs() {
+ TypeLiteral<Outer<String>.Inner> type = new
TypeLiteral<Outer<String>.Inner>() {};
+ assertEqualsBothWays(outerInner, type.getType());
+
+ ParameterizedType parameterizedType = (ParameterizedType)
type.getType();
+ assertEquals(0, parameterizedType.getActualTypeArguments().length);
+ assertEquals(new TypeLiteral<Outer<String>>() {}.getType(),
parameterizedType.getOwnerType());
+ assertEquals(Outer.Inner.class, parameterizedType.getRawType());
+ }
+
+ static class Outer<T> {
+ class Inner {}
+ }
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---