Author: limpbizkit
Date: Tue Sep 2 11:20:45 2008
New Revision: 614
Added:
trunk/src/com/google/inject/internal/ConfigurationException.java
Modified:
trunk/src/com/google/inject/DefaultConstructionProxyFactory.java
trunk/src/com/google/inject/InjectionRequestProcessor.java
trunk/src/com/google/inject/InjectorImpl.java
trunk/src/com/google/inject/ProxyFactory.java
trunk/src/com/google/inject/internal/Errors.java
trunk/src/com/google/inject/spi/InjectionPoint.java
trunk/test/com/google/inject/InjectionPointTest.java
Log:
Splitting up finding member injectors from finding injection points. This
is intended to make it so the new SPI exposes injection points on Module
elements without actually having to resolve 'em.
Modified: trunk/src/com/google/inject/DefaultConstructionProxyFactory.java
==============================================================================
--- trunk/src/com/google/inject/DefaultConstructionProxyFactory.java
(original)
+++ trunk/src/com/google/inject/DefaultConstructionProxyFactory.java Tue
Sep 2 11:20:45 2008
@@ -20,6 +20,7 @@
import static com.google.inject.internal.BytecodeGen.newFastClass;
import com.google.inject.internal.Errors;
import com.google.inject.internal.ErrorsException;
+import com.google.inject.internal.ConfigurationException;
import com.google.inject.spi.InjectionPoint;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@@ -38,7 +39,14 @@
public <T> ConstructionProxy<T> get(Errors errors, final Constructor<T>
constructor)
throws ErrorsException {
- final InjectionPoint injectionPoint = InjectionPoint.get(constructor,
errors);
+ final InjectionPoint injectionPoint;
+
+ try {
+ injectionPoint = InjectionPoint.get(constructor);
+ } catch (ConfigurationException e) {
+ errors.merge(e.getErrorMessages());
+ throw errors.toException();
+ }
// We can't use FastConstructor if the constructor is non-public.
if (!Modifier.isPublic(constructor.getModifiers())) {
Modified: trunk/src/com/google/inject/InjectionRequestProcessor.java
==============================================================================
--- trunk/src/com/google/inject/InjectionRequestProcessor.java (original)
+++ trunk/src/com/google/inject/InjectionRequestProcessor.java Tue Sep 2
11:20:45 2008
@@ -16,10 +16,13 @@
package com.google.inject;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.inject.InjectorImpl.SingleMemberInjector;
import com.google.inject.internal.Errors;
import com.google.inject.internal.ErrorsException;
+import com.google.inject.internal.ConfigurationException;
+import com.google.inject.spi.InjectionPoint;
import com.google.inject.spi.InjectionRequest;
import com.google.inject.spi.StaticInjectionRequest;
import java.util.List;
@@ -72,7 +75,7 @@
private class StaticInjection {
final Object source;
final Class<?> type;
- final List<SingleMemberInjector> memberInjectors =
Lists.newArrayList();
+ ImmutableList<SingleMemberInjector> memberInjectors;
public StaticInjection(Object source, Class type) {
this.source = source;
@@ -81,10 +84,13 @@
void validate(final InjectorImpl injector) {
Errors errorsForMember = errors.withSource(source);
- injector.addSingleInjectorsForFields(
- type.getDeclaredFields(), true, memberInjectors,
errorsForMember);
- injector.addSingleInjectorsForMethods(
- type.getDeclaredMethods(), true, memberInjectors,
errorsForMember);
+ List<InjectionPoint> injectionPoints = Lists.newArrayList();
+ try {
+ InjectionPoint.addForStaticMethodsAndFields(type, injectionPoints);
+ } catch (ConfigurationException e) {
+ errors.merge(e.getErrorMessages());
+ }
+ memberInjectors = injector.getInjectors(injectionPoints,
errorsForMember);
}
void injectMembers(InjectorImpl injector) {
Modified: trunk/src/com/google/inject/InjectorImpl.java
==============================================================================
--- trunk/src/com/google/inject/InjectorImpl.java (original)
+++ trunk/src/com/google/inject/InjectorImpl.java Tue Sep 2 11:20:45 2008
@@ -17,6 +17,7 @@
package com.google.inject;
import static com.google.common.base.Preconditions.checkState;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@@ -26,6 +27,7 @@
import com.google.inject.internal.BytecodeGen.Visibility;
import static com.google.inject.internal.BytecodeGen.newFastClass;
import com.google.inject.internal.Classes;
+import com.google.inject.internal.ConfigurationException;
import com.google.inject.internal.Errors;
import com.google.inject.internal.ErrorsException;
import com.google.inject.internal.Keys;
@@ -46,7 +48,6 @@
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -634,10 +635,15 @@
* [EMAIL PROTECTED] List<SingleMemberInjector>}.
*/
private final Map<Class<?>, Object> injectors = new
ReferenceCache<Class<?>, Object>() {
- protected Object create(Class<?> key) {
+ protected Object create(Class<?> type) {
Errors errors = new Errors();
- List<SingleMemberInjector> injectors = Lists.newArrayList();
- addInjectors(key, injectors, errors);
+ List<InjectionPoint> injectionPoints = Lists.newArrayList();
+ try {
+ InjectionPoint.addForInstanceMethodsAndFields(type,
injectionPoints);
+ } catch (ConfigurationException e) {
+ errors.merge(e.getErrorMessages());
+ }
+ ImmutableList<SingleMemberInjector> injectors =
getInjectors(injectionPoints, errors);
return errors.hasErrors() ? errors.makeImmutable() : injectors;
}
};
@@ -658,66 +664,24 @@
}
/**
- * Recursively adds injectors for fields and methods from the given
class to the given list.
- * Injects parent classes before sub classes.
+ * Returns the injectors for the specified injection points.
*/
- void addInjectors(Class clazz, List<SingleMemberInjector> injectors,
Errors errors) {
- if (clazz == Object.class) {
- return;
- }
-
- // Add injectors for superclass first.
- addInjectors(clazz.getSuperclass(), injectors, errors);
-
- // TODO (crazybob): Filter out overridden members.
- addSingleInjectorsForFields(clazz.getDeclaredFields(), false,
injectors, errors);
- addSingleInjectorsForMethods(clazz.getDeclaredMethods(), false,
injectors, errors);
- }
-
- void addSingleInjectorsForMethods(Method[] methods, boolean statics,
- List<SingleMemberInjector> injectors, Errors errors) {
- addInjectorsForMembers(errors, Arrays.asList(methods), statics,
injectors,
- new SingleInjectorFactory<Method>() {
- public SingleMemberInjector create(InjectorImpl injector, Method
method, Errors errors)
- throws ErrorsException {
- return new SingleMethodInjector(errors, injector, method);
- }
- });
- }
-
- void addSingleInjectorsForFields(Field[] fields, boolean statics,
- List<SingleMemberInjector> injectors, Errors errors) {
- addInjectorsForMembers(errors, Arrays.asList(fields), statics,
injectors,
- new SingleInjectorFactory<Field>() {
- public SingleMemberInjector create(InjectorImpl injector, Field
field, Errors errors)
- throws ErrorsException {
- return new SingleFieldInjector(errors, injector, field);
- }
- });
- }
-
- <M extends Member & AnnotatedElement> void addInjectorsForMembers(
- Errors errors, List<M> members, boolean statics,
List<SingleMemberInjector> injectors,
- SingleInjectorFactory<M> injectorFactory) {
- for (M member : members) {
- if (isStatic(member) != statics) {
- continue;
- }
-
- Inject inject = member.getAnnotation(Inject.class);
- if (inject == null) {
- continue;
- }
-
- Errors errorsForMember = inject.optional()
- ? new Errors(member)
- : errors.withSource(member);
+ ImmutableList<SingleMemberInjector> getInjectors(
+ List<InjectionPoint> injectionPoints, Errors errors) {
+ List<SingleMemberInjector> injectors = Lists.newArrayList();
+ for (InjectionPoint injectionPoint : injectionPoints) {
try {
- injectors.add(injectorFactory.create(this, member,
errorsForMember));
+ Errors errorsForMember = injectionPoint.isOptional()
+ ? new Errors(injectionPoint.getMember())
+ : errors.withSource(injectionPoint.getMember());
+ SingleMemberInjector injector = injectionPoint.getMember()
instanceof Field
+ ? new SingleFieldInjector(errorsForMember, this,
injectionPoint)
+ : new SingleMethodInjector(errorsForMember, this,
injectionPoint);
+ injectors.add(injector);
} catch (ErrorsException ignoredForNow) {
- // if this was an optional injection, it is completely ignored
}
}
+ return ImmutableList.copyOf(injectors);
}
Map<Key<?>, BindingImpl<?>> internalBindings() {
@@ -734,10 +698,6 @@
throws ErrorsException;
}
- private boolean isStatic(Member member) {
- return Modifier.isStatic(member.getModifiers());
- }
-
private static class BindingsMultimap {
final Multimap<TypeLiteral<?>, Binding<?>> multimap =
Multimaps.newArrayListMultimap();
@@ -758,15 +718,14 @@
final InjectionPoint injectionPoint;
final Dependency<?> dependency;
- public SingleFieldInjector(final Errors errors, final InjectorImpl
injector, Field field)
+ public SingleFieldInjector(Errors errors, InjectorImpl injector,
InjectionPoint injectionPoint)
throws ErrorsException {
- this.field = field;
+ this.injectionPoint = injectionPoint;
+ this.field = (Field) injectionPoint.getMember();
+ this.dependency = injectionPoint.getDependencies().get(0);
// Ewwwww...
field.setAccessible(true);
-
- injectionPoint = InjectionPoint.get(field);
- dependency = injectionPoint.getDependencies().get(0);
factory = injector.getInternalFactory(dependency.getKey(),
errors.withSource(field));
}
@@ -839,8 +798,11 @@
final SingleParameterInjector<?>[] parameterInjectors;
final InjectionPoint injectionPoint;
- public SingleMethodInjector(Errors errors, InjectorImpl injector,
final Method method)
+ public SingleMethodInjector(Errors errors, InjectorImpl injector,
InjectionPoint injectionPoint)
throws ErrorsException {
+ this.injectionPoint = injectionPoint;
+ final Method method = (Method) injectionPoint.getMember();
+
// We can't use FastMethod if the method is private.
if (Modifier.isPrivate(method.getModifiers())
|| Modifier.isProtected(method.getModifiers())) {
@@ -864,7 +826,12 @@
};
}
- injectionPoint = InjectionPoint.get(method);
+ try {
+ injectionPoint = InjectionPoint.get(method);
+ } catch (ConfigurationException e) {
+ errors.merge(e.getErrorMessages());
+ throw errors.toException();
+ }
parameterInjectors = injectionPoint.getDependencies().isEmpty()
? null
Modified: trunk/src/com/google/inject/ProxyFactory.java
==============================================================================
--- trunk/src/com/google/inject/ProxyFactory.java (original)
+++ trunk/src/com/google/inject/ProxyFactory.java Tue Sep 2 11:20:45 2008
@@ -24,6 +24,7 @@
import com.google.inject.internal.Errors;
import com.google.inject.internal.ErrorsException;
import com.google.inject.internal.ReferenceCache;
+import com.google.inject.internal.ConfigurationException;
import com.google.inject.spi.InjectionPoint;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@@ -178,7 +179,14 @@
FastClass fastClass = newFastClass(clazz, Visibility.PUBLIC);
final FastConstructor fastConstructor
=
fastClass.getConstructor(standardConstructor.getParameterTypes());
- final InjectionPoint injectionPoint =
InjectionPoint.get(standardConstructor, errors);
+ final InjectionPoint injectionPoint;
+
+ try {
+ injectionPoint = InjectionPoint.get(standardConstructor);
+ } catch (ConfigurationException e) {
+ errors.merge(e.getErrorMessages());
+ throw errors.toException();
+ }
return new ConstructionProxy<T>() {
@SuppressWarnings("unchecked")
Added: trunk/src/com/google/inject/internal/ConfigurationException.java
==============================================================================
--- (empty file)
+++ trunk/src/com/google/inject/internal/ConfigurationException.java Tue
Sep 2 11:20:45 2008
@@ -0,0 +1,68 @@
+/**
+ * Copyright (C) 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.inject.internal;
+
+import com.google.inject.spi.Message;
+import java.util.Collection;
+
+/**
+ * Indicates that the injector or injection points are improperly
configured.
+ *
+ * @author [EMAIL PROTECTED] (Jesse Wilson)
+ */
+public class ConfigurationException extends RuntimeException {
+
+ /** non-null for Guice-created ProvisionExceptions */
+ private final Errors errors;
+
+ /**
+ * Constructs a new exception for the given errors.
+ */
+ ConfigurationException(Errors errors) {
+ errors.makeImmutable();
+ this.errors = errors;
+
+ // find a cause
+ for (Message message : errors.getMessages()) {
+ if (message.getCause() != null) {
+ initCause(message.getCause());
+ break;
+ }
+ }
+ }
+
+ /**
+ * Gets the error messages which resulted in this exception.
+ */
+ public Collection<Message> getErrorMessages() {
+ return errors.getMessages();
+ }
+
+ @Override public String getMessage() {
+ return Errors.format("Guice configuration errors",
errors.getMessages());
+ }
+
+ /**
+ * Throws a new provision exception if [EMAIL PROTECTED] errors} contains
any error
+ * messages.
+ */
+ public static void throwNewIfNonEmpty(Errors errors) {
+ if (errors.hasErrors()) {
+ throw new ConfigurationException(errors.makeImmutable());
+ }
+ }
+}
Modified: trunk/src/com/google/inject/internal/Errors.java
==============================================================================
--- trunk/src/com/google/inject/internal/Errors.java (original)
+++ trunk/src/com/google/inject/internal/Errors.java Tue Sep 2 11:20:45
2008
@@ -307,21 +307,29 @@
throw new CreationException(getMessages());
}
- public Errors merge(Errors moreErrors) {
- checkState(isMutable);
+ private Message merge(Message message) {
+ List<Dependency> dependencies = Lists.newArrayList();
+ dependencies.addAll(this.dependencies);
+ dependencies.addAll(message.getDependencies());
+ Object source = message.getSource() != SourceProvider.UNKNOWN_SOURCE
+ ? message.getSource()
+ : this.source;
+ return new Message(source, message.getMessage(), dependencies,
message.getCause());
+ }
- if (moreErrors.errors != this.errors) {
- for (Message message : moreErrors.errors) {
- List<Dependency> dependencies = Lists.newArrayList();
- dependencies.addAll(this.dependencies);
- dependencies.addAll(message.getDependencies());
- Object source = message.getSource() !=
SourceProvider.UNKNOWN_SOURCE
- ? message.getSource()
- : this.source;
- errors.add(new Message(source, message.getMessage(), dependencies,
message.getCause()));
+ public Errors merge(Collection<Message> messages) {
+ checkState(isMutable);
+ if (messages != this.errors) {
+ for (Message message : messages) {
+ errors.add(merge(message));
}
}
+ return this;
+ }
+ public Errors merge(Errors moreErrors) {
+ checkState(isMutable);
+ merge(moreErrors.errors);
return this;
}
@@ -352,6 +360,7 @@
}
public Errors addMessage(Message message) {
+ // TODO: merge the sources?
if (!isMutable) {
throw new AssertionError();
}
Modified: trunk/src/com/google/inject/spi/InjectionPoint.java
==============================================================================
--- trunk/src/com/google/inject/spi/InjectionPoint.java (original)
+++ trunk/src/com/google/inject/spi/InjectionPoint.java Tue Sep 2 11:20:45
2008
@@ -20,20 +20,24 @@
import com.google.common.collect.Lists;
import com.google.inject.Inject;
import com.google.inject.Key;
+import com.google.inject.internal.ConfigurationException;
import com.google.inject.internal.Errors;
import com.google.inject.internal.ErrorsException;
import com.google.inject.internal.Keys;
import com.google.inject.internal.MoreTypes;
import com.google.inject.internal.Nullability;
-import java.io.ObjectStreamException;
import java.io.Serializable;
+import java.io.ObjectStreamException;
import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -42,7 +46,7 @@
*
* @author [EMAIL PROTECTED] (Bob Lee)
*/
-public class InjectionPoint implements Serializable {
+public final class InjectionPoint implements Serializable {
private final boolean optional;
private final Member member;
@@ -55,38 +59,48 @@
this.optional = optional;
}
- private InjectionPoint(Method method) throws ErrorsException {
+ private InjectionPoint(Method method) {
this.member = method;
Inject inject = method.getAnnotation(Inject.class);
this.optional = inject.optional();
this.dependencies = forMember(method,
method.getGenericParameterTypes(),
- method.getParameterAnnotations(), new Errors());
+ method.getParameterAnnotations());
}
- private InjectionPoint(Constructor<?> constructor, Errors errors) throws
ErrorsException {
+ private InjectionPoint(Constructor<?> constructor) {
this.member = constructor;
this.optional = false;
// TODO(jessewilson): make sure that if @Inject it exists, its not
optional
this.dependencies = forMember(constructor,
constructor.getGenericParameterTypes(),
- constructor.getParameterAnnotations(), errors);
+ constructor.getParameterAnnotations());
}
- private InjectionPoint(Field field) throws ErrorsException {
+ private InjectionPoint(Field field) {
this.member = field;
Inject inject = field.getAnnotation(Inject.class);
this.optional = inject.optional();
Annotation[] annotations = field.getAnnotations();
- Key<?> key = Keys.get(field.getGenericType(), field, annotations, new
Errors());
+
+ Errors errors = new Errors(field);
+ Key<?> key = null;
+ try {
+ key = Keys.get(field.getGenericType(), field, annotations, errors);
+ } catch (ErrorsException e) {
+ errors.merge(e.getErrors());
+ }
+ ConfigurationException.throwNewIfNonEmpty(errors);
+
this.dependencies = ImmutableList.<Dependency<?>>of(
newDependency(key, Nullability.allowsNull(annotations), -1));
}
private ImmutableList<Dependency<?>> forMember(Member member, Type[]
genericParameterTypes,
- Annotation[][] annotations, Errors errors) throws ErrorsException {
+ Annotation[][] annotations) {
+ Errors errors = new Errors(member);
Iterator<Annotation[]> annotationsIterator =
Arrays.asList(annotations).iterator();
List<Dependency<?>> dependencies = Lists.newArrayList();
@@ -102,7 +116,7 @@
}
}
- errors.throwIfNecessary();
+ ConfigurationException.throwNewIfNonEmpty(errors);
return ImmutableList.copyOf(dependencies);
}
@@ -140,15 +154,19 @@
return MoreTypes.toString(member);
}
+ private Object writeReplace() throws ObjectStreamException {
+ Member serializableMember = member != null ?
MoreTypes.serializableCopy(member) : null;
+ return new InjectionPoint(serializableMember, dependencies, optional);
+ }
+
/**
* Returns a new injection point for [EMAIL PROTECTED] constructor}.
*
* @param constructor a no arguments constructor, or a constructor with
any number of arguments
* and the [EMAIL PROTECTED] @[EMAIL PROTECTED] Inject} annotation.
*/
- public static InjectionPoint get(Constructor constructor, Errors errors)
- throws ErrorsException {
- return new InjectionPoint(constructor, errors);
+ public static InjectionPoint get(Constructor constructor) {
+ return new InjectionPoint(constructor);
}
/**
@@ -156,7 +174,7 @@
*
* @param method a method with the [EMAIL PROTECTED] @[EMAIL PROTECTED]
Inject} annotation.
*/
- public static InjectionPoint get(Method method) throws ErrorsException {
+ public static InjectionPoint get(Method method) {
return new InjectionPoint(method);
}
@@ -165,12 +183,106 @@
*
* @param field a field with the [EMAIL PROTECTED] @[EMAIL PROTECTED]
Inject} annotation.
*/
- public static InjectionPoint get(Field field) throws ErrorsException {
+ public static InjectionPoint get(Field field) {
return new InjectionPoint(field);
}
- private Object writeReplace() throws ObjectStreamException {
- Member serializableMember = member != null ?
MoreTypes.serializableCopy(member) : null;
- return new InjectionPoint(serializableMember, dependencies, optional);
+ /**
+ * Adds all static method and field injection points on [EMAIL PROTECTED]
type} to
[EMAIL PROTECTED] injectionPoints}.
+ * All fields are added first, and then all methods. Within the fields,
supertype fields are added
+ * before subtype fields. Similarly, supertype methods are added before
subtype methods.
+ *
+ * @throws RuntimeException if there is a malformed injection point on
[EMAIL PROTECTED] type}, such as a
+ * field with multiple binding annotations. When such an exception
is thrown, the valid
+ * injection points are still added to the collection.
+ */
+ public static void addForStaticMethodsAndFields(Class<?> type,
+ Collection<InjectionPoint> injectionPoints) {
+ Errors errors = new Errors();
+ addInjectionPoints(type, Factory.FIELDS, true, injectionPoints,
errors);
+ addInjectionPoints(type, Factory.METHODS, true, injectionPoints,
errors);
+ ConfigurationException.throwNewIfNonEmpty(errors);
+ }
+
+ /**
+ * Adds all instance method and field injection points on [EMAIL PROTECTED]
type}
to [EMAIL PROTECTED] injectionPoints}.
+ * All fields are added first, and then all methods. Within the fields,
supertype fields are added
+ * before subtype fields. Similarly, supertype methods are added before
subtype methods.
+ *
+ * @throws RuntimeException if there is a malformed injection point on
[EMAIL PROTECTED] type}, such as a
+ * field with multiple binding annotations. When such an exception
is thrown, the valid
+ * injection points are still added to the collection.
+ */
+ public static void addForInstanceMethodsAndFields(Class<?> type,
+ List<InjectionPoint> injectionPoints) {
+ // TODO (crazybob): Filter out overridden members.
+ Errors errors = new Errors();
+ addInjectionPoints(type, Factory.FIELDS, false, injectionPoints,
errors);
+ addInjectionPoints(type, Factory.METHODS, false, injectionPoints,
errors);
+ ConfigurationException.throwNewIfNonEmpty(errors);
+ }
+
+ private static <M extends Member & AnnotatedElement> void
addInjectionPoints(Class<?> type,
+ Factory<M> factory, boolean statics, Collection<InjectionPoint>
injectionPoints,
+ Errors errors) {
+ if (type == Object.class) {
+ return;
+ }
+
+ // Add injectors for superclass first.
+ addInjectionPoints(type.getSuperclass(), factory, statics,
injectionPoints, errors);
+
+ // Add injectors for all members next
+ addInjectorsForMembers(type, factory, statics, injectionPoints,
errors);
+ }
+
+ private static <M extends Member & AnnotatedElement> void
addInjectorsForMembers(Class<?> type,
+ Factory<M> factory, boolean statics, Collection<InjectionPoint>
injectionPoints,
+ Errors errors) {
+ for (M member : factory.getMembers(type)) {
+ if (isStatic(member) != statics) {
+ continue;
+ }
+
+ Inject inject = member.getAnnotation(Inject.class);
+ if (inject == null) {
+ continue;
+ }
+
+ try {
+ injectionPoints.add(factory.create(member));
+ } catch (ConfigurationException e) {
+ if (!inject.optional()) {
+ errors.merge(e.getErrorMessages());
+ }
+ }
+ }
+ }
+
+ private static boolean isStatic(Member member) {
+ return Modifier.isStatic(member.getModifiers());
+ }
+
+ private interface Factory<M extends Member & AnnotatedElement> {
+ Factory<Field> FIELDS = new Factory<Field>() {
+ public Field[] getMembers(Class<?> type) {
+ return type.getDeclaredFields();
+ }
+ public InjectionPoint create(Field member) {
+ return get(member);
+ }
+ };
+
+ Factory<Method> METHODS = new Factory<Method>() {
+ public Method[] getMembers(Class<?> type) {
+ return type.getDeclaredMethods();
+ }
+ public InjectionPoint create(Method member) {
+ return get(member);
+ }
+ };
+
+ M[] getMembers(Class<?> type);
+ InjectionPoint create(M member);
}
}
Modified: trunk/test/com/google/inject/InjectionPointTest.java
==============================================================================
--- trunk/test/com/google/inject/InjectionPointTest.java (original)
+++ trunk/test/com/google/inject/InjectionPointTest.java Tue Sep 2
11:20:45 2008
@@ -19,7 +19,6 @@
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.inject.Asserts.assertEqualsBothWays;
import static com.google.inject.Asserts.assertSimilarWhenReserialized;
-import com.google.inject.internal.Errors;
import com.google.inject.internal.ErrorsException;
import com.google.inject.name.Named;
import com.google.inject.name.Names;
@@ -85,12 +84,12 @@
public void testConstructorInjectionPoint() throws
NoSuchMethodException, IOException,
ErrorsException {
Constructor<?> constructor =
Constructable.class.getConstructor(String.class);
- InjectionPoint injectionPoint = InjectionPoint.get(constructor, new
Errors());
+ InjectionPoint injectionPoint = InjectionPoint.get(constructor);
assertSame(constructor, injectionPoint.getMember());
assertFalse(injectionPoint.isOptional());
assertEquals("com.google.inject.InjectionPointTest$Constructable.<init>()",
injectionPoint.toString());
- assertEqualsBothWays(injectionPoint, InjectionPoint.get(constructor,
new Errors()));
+ assertEqualsBothWays(injectionPoint, InjectionPoint.get(constructor));
assertSimilarWhenReserialized(injectionPoint);
Dependency<?> dependency =
getOnlyElement(injectionPoint.getDependencies());
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---