Binder.withSource() added. I'd still like to start using it within the exceptions, and then cleanup their static configuration of SourceProviders.

git-svn-id: https://google-guice.googlecode.com/svn/trunk@524 d779f126-a31b-0410-b53b-1d3aecad763e
diff --git a/src/com/google/inject/commands/CommandReplayer.java b/src/com/google/inject/commands/CommandReplayer.java
index 96f3f7a..b40f793 100644
--- a/src/com/google/inject/commands/CommandReplayer.java
+++ b/src/com/google/inject/commands/CommandReplayer.java
@@ -16,6 +16,7 @@
 
 package com.google.inject.commands;
 
+import static com.google.common.base.Preconditions.checkNotNull;
 import com.google.inject.Binder;
 import com.google.inject.Key;
 import com.google.inject.Module;
@@ -23,11 +24,8 @@
 import com.google.inject.binder.ConstantBindingBuilder;
 import com.google.inject.binder.LinkedBindingBuilder;
 import com.google.inject.binder.ScopedBindingBuilder;
-import com.google.inject.spi.SourceProviders;
-import static com.google.common.base.Preconditions.checkNotNull;
-import org.aopalliance.intercept.MethodInterceptor;
-
 import java.util.List;
+import org.aopalliance.intercept.MethodInterceptor;
 
 /**
  * Executes commands against a binder.
@@ -108,95 +106,65 @@
   }
 
   public void replayAddMessageError(final Binder binder, final AddMessageErrorCommand command) {
-    SourceProviders.withDefault(command.getSource(), new Runnable() {
-      public void run() {
-        binder.addError(command.getMessage(), command.getArguments().toArray());
-      }
-    });
+    binder.withSource(command.getSource())
+        .addError(command.getMessage(), command.getArguments().toArray());
   }
 
   public void replayAddError(final Binder binder, final AddThrowableErrorCommand command) {
-    SourceProviders.withDefault(command.getSource(), new Runnable() {
-      public void run() {
-        binder.addError(command.getThrowable());
-      }
-    });
+    binder.withSource(command.getSource()).addError(command.getThrowable());
   }
 
   public void replayBindInterceptor(final Binder binder, final BindInterceptorCommand command) {
-    SourceProviders.withDefault(command.getSource(), new Runnable() {
-      public void run() {
-        List<MethodInterceptor> interceptors = command.getInterceptors();
-        binder.bindInterceptor(command.getClassMatcher(), command.getMethodMatcher(),
-            interceptors.toArray(new MethodInterceptor[interceptors.size()]));
-      }
-    });
+    List<MethodInterceptor> interceptors = command.getInterceptors();
+    binder.withSource(command.getSource()).bindInterceptor(
+        command.getClassMatcher(), command.getMethodMatcher(),
+        interceptors.toArray(new MethodInterceptor[interceptors.size()]));
   }
 
   public void replayBindScope(final Binder binder, final BindScopeCommand command) {
-    SourceProviders.withDefault(command.getSource(), new Runnable() {
-      public void run() {
-        binder.bindScope(command.getAnnotationType(), command.getScope());
-      }
-    });
+    binder.withSource(command.getSource()).bindScope(
+        command.getAnnotationType(), command.getScope());
   }
 
   public void replayRequestStaticInjection(final Binder binder,
       final RequestStaticInjectionCommand command) {
-    SourceProviders.withDefault(command.getSource(), new Runnable() {
-      public void run() {
-        List<Class> types = command.getTypes();
-        binder.requestStaticInjection(types.toArray(new Class[types.size()]));
-      }
-    });
+    List<Class> types = command.getTypes();
+    binder.withSource(command.getSource())
+        .requestStaticInjection(types.toArray(new Class[types.size()]));
   }
 
   public void replayBindConstant(final Binder binder, final BindConstantCommand command) {
-    SourceProviders.withDefault(command.getSource(), new Runnable() {
-      public void run() {
-        AnnotatedConstantBindingBuilder constantBindingBuilder = binder.bindConstant();
+    AnnotatedConstantBindingBuilder constantBindingBuilder
+        = binder.withSource(command.getSource()).bindConstant();
 
-        Key<Object> key = command.getKey();
-        ConstantBindingBuilder builder = key.getAnnotation() != null
-            ? constantBindingBuilder.annotatedWith(key.getAnnotation())
-            : constantBindingBuilder.annotatedWith(key.getAnnotationType());
+    Key<Object> key = command.getKey();
+    ConstantBindingBuilder builder = key.getAnnotation() != null
+        ? constantBindingBuilder.annotatedWith(key.getAnnotation())
+        : constantBindingBuilder.annotatedWith(key.getAnnotationType());
 
-        command.getTarget().execute(builder);
-      }
-    });
+    command.getTarget().execute(builder);
   }
 
   public void replayConvertToTypes(final Binder binder, final ConvertToTypesCommand command) {
-    SourceProviders.withDefault(command.getSource(), new Runnable() {
-      public void run() {
-        binder.convertToTypes(command.getTypeMatcher(), command.getTypeConverter());
-      }
-    });
+    binder.withSource(command.getSource())
+        .convertToTypes(command.getTypeMatcher(), command.getTypeConverter());
   }
 
   public <T> void replayBind(final Binder binder, final BindCommand<T> command) {
-    SourceProviders.withDefault(command.getSource(), new Runnable() {
-      public void run() {
-        LinkedBindingBuilder<T> lbb = binder.bind(command.getKey());
+    LinkedBindingBuilder<T> lbb = binder.withSource(command.getSource()).bind(command.getKey());
 
-        BindTarget<T> bindTarget = command.getTarget();
-        ScopedBindingBuilder sbb = bindTarget != null
-            ? bindTarget.execute(lbb)
-            : lbb;
+    BindTarget<T> bindTarget = command.getTarget();
+    ScopedBindingBuilder sbb = bindTarget != null
+        ? bindTarget.execute(lbb)
+        : lbb;
 
-        BindScoping scoping = command.getScoping();
-        if (scoping != null) {
-          scoping.execute(sbb);
-        }
-      }
-    });
+    BindScoping scoping = command.getScoping();
+    if (scoping != null) {
+      scoping.execute(sbb);
+    }
   }
 
   public <T> void replayGetProvider(final Binder binder, final GetProviderCommand<T> command) {
-    SourceProviders.withDefault(command.getSource(), new Runnable() {
-      public void run() {
-        binder.getProvider(command.getKey());
-      }
-    });
+    binder.withSource(command.getSource()).getProvider(command.getKey());
   }
 }