Fixing compile problems in r438, rearranging Reflection code
git-svn-id: https://google-guice.googlecode.com/svn/trunk@439 d779f126-a31b-0410-b53b-1d3aecad763e
diff --git a/src/com/google/inject/BindCommandProcessor.java b/src/com/google/inject/BindCommandProcessor.java
index 7fb618b..d375047 100644
--- a/src/com/google/inject/BindCommandProcessor.java
+++ b/src/com/google/inject/BindCommandProcessor.java
@@ -73,9 +73,7 @@
}
if (Logger.class == rawType) {
- // TODO(jessewilson): assert this is coming from the internal module?
- // addError(source, ErrorMessages.LOGGER_ALREADY_BOUND);
- // return true;
+ addError(source, ErrorMessages.LOGGER_ALREADY_BOUND);
}
validateKey(command.getSource(), command.getKey());
@@ -273,7 +271,7 @@
public Void call(InternalContext context) {
InjectionPoint<?> injectionPoint
- = InjectionPoint.newInstance(key, context.getInjectorImpl());
+ = InjectionPoint.newInstance(key, context.getInjector());
context.setInjectionPoint(injectionPoint);
try {
factory.get(context, injectionPoint);
diff --git a/src/com/google/inject/InjectorImpl.java b/src/com/google/inject/InjectorImpl.java
index fa1f289..6db93b3 100644
--- a/src/com/google/inject/InjectorImpl.java
+++ b/src/com/google/inject/InjectorImpl.java
@@ -1229,7 +1229,7 @@
/**
* Injects a field or method in a given object.
*/
- interface SingleMemberInjector {
+ public interface SingleMemberInjector {
void inject(InternalContext context, Object o);
Collection<Dependency<?>> getDependencies();
}
diff --git a/src/com/google/inject/InternalContext.java b/src/com/google/inject/InternalContext.java
index 3b0def1..3e035e4 100644
--- a/src/com/google/inject/InternalContext.java
+++ b/src/com/google/inject/InternalContext.java
@@ -27,20 +27,20 @@
*/
class InternalContext {
- final InjectorImpl injector;
- Map<Object, ConstructionContext<?>> constructionContexts;
- InjectionPoint injectionPoint;
+ private final InjectorImpl injector;
+ private Map<Object, ConstructionContext<?>> constructionContexts;
+ private InjectionPoint injectionPoint;
- InternalContext(InjectorImpl injector) {
+ public InternalContext(InjectorImpl injector) {
this.injector = injector;
}
- InjectorImpl getInjectorImpl() {
+ public InjectorImpl getInjector() {
return injector;
}
@SuppressWarnings("unchecked")
- <T> ConstructionContext<T> getConstructionContext(Object key) {
+ public <T> ConstructionContext<T> getConstructionContext(Object key) {
if (constructionContexts == null) {
constructionContexts = new HashMap<Object, ConstructionContext<?>>();
ConstructionContext<T> constructionContext = new ConstructionContext<T>();
diff --git a/src/com/google/inject/internal/Reflection.java b/src/com/google/inject/Reflection.java
similarity index 83%
rename from src/com/google/inject/internal/Reflection.java
rename to src/com/google/inject/Reflection.java
index 1cbc236..339d668 100644
--- a/src/com/google/inject/internal/Reflection.java
+++ b/src/com/google/inject/Reflection.java
@@ -15,7 +15,11 @@
*/
-package com.google.inject.internal;
+package com.google.inject;
+
+import com.google.inject.internal.ConstructionProxy;
+import com.google.inject.internal.ConstructionProxyFactory;
+import com.google.inject.internal.ErrorHandler;
/**
* Abstraction for Java's reflection APIs. This interface exists to provide a
@@ -24,7 +28,7 @@
*
* @author jessewilson@google.com (Jesse Wilson)
*/
-public interface Reflection {
+interface Reflection {
public <T> ConstructionProxy<T> getConstructionProxy(Class<T> implementation);
diff --git a/src/com/google/inject/internal/RuntimeReflectionFactory.java b/src/com/google/inject/RuntimeReflectionFactory.java
similarity index 95%
rename from src/com/google/inject/internal/RuntimeReflectionFactory.java
rename to src/com/google/inject/RuntimeReflectionFactory.java
index 742b22a..0bd7b2b 100644
--- a/src/com/google/inject/internal/RuntimeReflectionFactory.java
+++ b/src/com/google/inject/RuntimeReflectionFactory.java
@@ -15,9 +15,9 @@
*/
-package com.google.inject.internal;
+package com.google.inject;
-import com.google.inject.Inject;
+import com.google.inject.internal.*;
import static com.google.inject.internal.Objects.nonNull;
import java.lang.reflect.Constructor;
@@ -25,7 +25,7 @@
/**
* @author jessewilson@google.com (Jesse Wilson)
*/
-public class RuntimeReflectionFactory implements Reflection.Factory {
+class RuntimeReflectionFactory implements Reflection.Factory {
public Reflection create(ErrorHandler errorHandler,
ConstructionProxyFactory constructionProxyFactory) {
return new RuntimeReflection(errorHandler, constructionProxyFactory);
diff --git a/src/com/google/inject/commands/BindCommand.java b/src/com/google/inject/commands/BindCommand.java
index b57c50a..0b21ed6 100644
--- a/src/com/google/inject/commands/BindCommand.java
+++ b/src/com/google/inject/commands/BindCommand.java
@@ -23,6 +23,7 @@
import com.google.inject.binder.LinkedBindingBuilder;
import com.google.inject.binder.ScopedBindingBuilder;
import static com.google.inject.internal.Objects.nonNull;
+import com.google.inject.internal.ErrorMessages;
import java.lang.annotation.Annotation;
@@ -181,10 +182,7 @@
}
public void toInstance(final T instance) {
- // might someday want to tolerate null here, probably by setting up a
- // Provider<null> rather than trying to distinguish between null and
- // not set
- nonNull(instance, "instance");
+ nonNull(instance, ErrorMessages.CANNOT_BIND_TO_NULL_INSTANCE);
checkNotTargetted();
bindTarget = new AbstractTarget<T>() {
diff --git a/src/com/google/inject/internal/ErrorMessages.java b/src/com/google/inject/internal/ErrorMessages.java
index d56de5a..afbabd6 100644
--- a/src/com/google/inject/internal/ErrorMessages.java
+++ b/src/com/google/inject/internal/ErrorMessages.java
@@ -169,6 +169,10 @@
public static final String CANNOT_BIND_TO_GUICE_TYPE = "Binding to core guice"
+ " framework type is not allowed: %s.";
+ public static final String CANNOT_BIND_TO_NULL_INSTANCE = "Binding to null "
+ + "instances is not allowed. Use toProvider(Providers.of(null)) if this "
+ + "is your intended behaviour.";
+
public static final String SCOPE_NOT_FOUND = "No scope is bound to %s.";
public static final String CONSTRUCTOR_RULES = "Classes must have either one (and"