Author: limpbizkit
Date: Thu Jul  9 11:37:40 2009
New Revision: 1043

Added:
    tags/snapshot20090706/
       - copied from r1040, /trunk/
    tags/snapshot20090706/src/com/google/inject/commands/
    tags/snapshot20090706/src/com/google/inject/commands/intercepting/
     
tags/snapshot20090706/src/com/google/inject/commands/intercepting/InterceptingInjectorBuilder.java
     
tags/snapshot20090706/src/com/google/inject/commands/intercepting/ProvisionInterceptor.java
    tags/snapshot20090706/src/com/google/inject/internal/base/
     
tags/snapshot20090706/src/com/google/inject/internal/base/Preconditions.java
    tags/snapshot20090706/src/com/google/inject/internal/collect/
    tags/snapshot20090706/src/com/google/inject/internal/collect/Lists.java
    tags/snapshot20090706/src/com/google/inject/internal/collect/Maps.java
    tags/snapshot20090706/src/com/google/inject/internal/collect/Sets.java
    tags/snapshot20090706/src/com/google/inject/spi/ModuleWriter.java
Modified:
    tags/snapshot20090706/common.xml
    tags/snapshot20090706/guice.ipr
    tags/snapshot20090706/src/com/google/inject/AbstractModule.java
    tags/snapshot20090706/src/com/google/inject/ConfigurationException.java
    tags/snapshot20090706/src/com/google/inject/ProvisionException.java
    tags/snapshot20090706/src/com/google/inject/internal/Errors.java
    tags/snapshot20090706/src/com/google/inject/internal/Iterables.java
    tags/snapshot20090706/src/com/google/inject/internal/Lists.java
    tags/snapshot20090706/src/com/google/inject/internal/Maps.java
    tags/snapshot20090706/src/com/google/inject/internal/Preconditions.java
    tags/snapshot20090706/src/com/google/inject/internal/Sets.java
     
tags/snapshot20090706/src/com/google/inject/spi/DefaultBindingTargetVisitor.java
     
tags/snapshot20090706/src/com/google/inject/spi/DefaultElementVisitor.java

Log:
Changes since 20090512

New API: Multibinder.permitDuplicates() and MapBinder.permitDuplicates().

Fixed bug where a unmatched scoping annotation didn't cause a required  
failure. (reported by Dmitry Skavish)

Fixed bug where Provider.get() would break if used while scoping another  
provider.

Moved JNDI and JMX extensions out as external build targets.

Servlet: Making forward() pass the original request URI. (Andrew McLaughlin)

Servlet: SerlvetRequest and ServletResponse bindings are now chained.  
(Isaac Shum)

SPI: Scopes.isSingleton()

SPI: Injector.getAllBindings().

SPI: Replaced ModuleWriter with Element.applyTo(Binder). ModuleWriter still  
exists in Google3 for backwards compatibility, but it is now deprecated.  
The main difference between the two is the treatment of private modules.

SPI: bind(Foo.class).toConstructor(...). Useful for the Turkey bacon  
problem and for using Guice with third-party APIs.

SPI: change scoping of instance bindings (Andrew McLaughlin)



Modified: tags/snapshot20090706/common.xml
==============================================================================
--- /trunk/common.xml   (original)
+++ tags/snapshot20090706/common.xml    Thu Jul  9 11:37:40 2009
@@ -6,8 +6,8 @@

    <!-- can be overridden at the command line with -Dversion=
         or in IDEA, in the ant properties dialog -->
-  <property name="version" value="2.0"/>
-  <property name="api.version" value="1.2"/>
+  <property name="version" value="snapshot"/>
+  <property name="api.version" value="1.3"/>

    <target name="compile" description="Compile Java source.">
      <mkdir dir="${build.dir}/classes"/>

Modified: tags/snapshot20090706/guice.ipr
==============================================================================
--- /trunk/guice.ipr    (original)
+++ tags/snapshot20090706/guice.ipr     Thu Jul  9 11:37:40 2009
@@ -110,6 +110,24 @@
            <option name="LABEL_INDENT_SIZE" value="0" />
            <option name="LABEL_INDENT_ABSOLUTE" value="false" />
          </ADDITIONAL_INDENT_OPTIONS>
+        <ADDITIONAL_INDENT_OPTIONS fileType="groovy">
+          <option name="INDENT_SIZE" value="2" />
+          <option name="CONTINUATION_INDENT_SIZE" value="8" />
+          <option name="TAB_SIZE" value="4" />
+          <option name="USE_TAB_CHARACTER" value="false" />
+          <option name="SMART_TABS" value="false" />
+          <option name="LABEL_INDENT_SIZE" value="0" />
+          <option name="LABEL_INDENT_ABSOLUTE" value="false" />
+        </ADDITIONAL_INDENT_OPTIONS>
+        <ADDITIONAL_INDENT_OPTIONS fileType="gsp">
+          <option name="INDENT_SIZE" value="2" />
+          <option name="CONTINUATION_INDENT_SIZE" value="8" />
+          <option name="TAB_SIZE" value="4" />
+          <option name="USE_TAB_CHARACTER" value="false" />
+          <option name="SMART_TABS" value="false" />
+          <option name="LABEL_INDENT_SIZE" value="0" />
+          <option name="LABEL_INDENT_ABSOLUTE" value="false" />
+        </ADDITIONAL_INDENT_OPTIONS>
          <ADDITIONAL_INDENT_OPTIONS fileType="java">
            <option name="INDENT_SIZE" value="2" />
            <option name="CONTINUATION_INDENT_SIZE" value="4" />
@@ -137,6 +155,15 @@
            <option name="LABEL_INDENT_SIZE" value="0" />
            <option name="LABEL_INDENT_ABSOLUTE" value="false" />
          </ADDITIONAL_INDENT_OPTIONS>
+        <ADDITIONAL_INDENT_OPTIONS fileType="sql">
+          <option name="INDENT_SIZE" value="2" />
+          <option name="CONTINUATION_INDENT_SIZE" value="8" />
+          <option name="TAB_SIZE" value="4" />
+          <option name="USE_TAB_CHARACTER" value="false" />
+          <option name="SMART_TABS" value="false" />
+          <option name="LABEL_INDENT_SIZE" value="0" />
+          <option name="LABEL_INDENT_ABSOLUTE" value="false" />
+        </ADDITIONAL_INDENT_OPTIONS>
          <ADDITIONAL_INDENT_OPTIONS fileType="xml">
            <option name="INDENT_SIZE" value="4" />
            <option name="CONTINUATION_INDENT_SIZE" value="8" />
@@ -513,7 +540,7 @@
    </component>
    <component name="ProjectFileVersion" converted="true" />
    <component name="ProjectKey">
-    <option name="state"  
value="https://google-guice.googlecode.com/svn/trunk/guice.ipr"; />
+    <option name="state"  
value="https://google-guice.googlecode.com/svn/tags/snapshot20090706/guice.ipr"; 
 
/>
    </component>
    <component name="ProjectModuleManager">
      <modules>
@@ -530,7 +557,7 @@
        <module  
fileurl="file://$PROJECT_DIR$/extensions/throwingproviders/throwingproviders.iml"
  
filepath="$PROJECT_DIR$/extensions/throwingproviders/throwingproviders.iml"  
/>
      </modules>
    </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_5"  
assert-keyword="true" jdk-15="true" project-jdk-name="1.6"  
project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_5"  
assert-keyword="true" jdk-15="true" project-jdk-name="java version  
&quot;1.5.0_06&quot;" project-jdk-type="JavaSDK">
      <output url="file://$PROJECT_DIR$/classes" />
    </component>
    <component name="ResourceManagerContainer">

Modified: tags/snapshot20090706/src/com/google/inject/AbstractModule.java
==============================================================================
--- /trunk/src/com/google/inject/AbstractModule.java    (original)
+++ tags/snapshot20090706/src/com/google/inject/AbstractModule.java     Thu  
Jul  9 11:37:40 2009
@@ -149,6 +149,16 @@
    }

    /**
+   * @deprecated use multiple calls to {...@link #requestInjection}.
+   */
+  @Deprecated
+  protected void requestInjection(Object... objects) {
+    for (Object o : objects) {
+      requestInjection(o);
+    }
+  }
+
+  /**
     * @see Binder#requestStaticInjection(Class[])
     */
    protected void requestStaticInjection(Class<?>... types) {

Modified:  
tags/snapshot20090706/src/com/google/inject/ConfigurationException.java
==============================================================================
--- /trunk/src/com/google/inject/ConfigurationException.java    (original)
+++ tags/snapshot20090706/src/com/google/inject/ConfigurationException.java     
 
Thu Jul  9 11:37:40 2009
@@ -26,18 +26,18 @@
   * Thrown when a programming error such as a misplaced annotation, illegal  
binding, or unsupported
   * scope is found. Clients should catch this exception, log it, and stop  
execution.
   *
+ * <strong>Note:</strong> this class temporarily extends  
ProvisionException to ease migration.
+ *
   * @author [email protected] (Jesse Wilson)
   * @since 2.0
   */
-public final class ConfigurationException extends RuntimeException {
+public final class ConfigurationException extends ProvisionException  {

-  private final ImmutableSet<Message> messages;
    private Object partialValue = null;

    /** Creates a ConfigurationException containing {...@code messages}. */
    public ConfigurationException(Iterable<Message> messages) {
-    this.messages = ImmutableSet.copyOf(messages);
-    initCause(Errors.getOnlyCause(this.messages));
+    super(messages);
    }

    /** Returns a copy of this configuration exception with the specified  
partial value. */
@@ -71,4 +71,4 @@
    }

    private static final long serialVersionUID = 0;
-}
\ No newline at end of file
+}

Modified:  
tags/snapshot20090706/src/com/google/inject/ProvisionException.java
==============================================================================
--- /trunk/src/com/google/inject/ProvisionException.java        (original)
+++ tags/snapshot20090706/src/com/google/inject/ProvisionException.java Thu  
Jul  9 11:37:40 2009
@@ -30,9 +30,9 @@
   * @author [email protected] (Jesse Wilson)
   * @since 2.0
   */
-public final class ProvisionException extends RuntimeException {
+public class ProvisionException extends RuntimeException {

-  private final ImmutableSet<Message> messages;
+  protected final ImmutableSet<Message> messages;

    /** Creates a ConfigurationException containing {...@code messages}. */
    public ProvisionException(Iterable<Message> messages) {

Added:  
tags/snapshot20090706/src/com/google/inject/commands/intercepting/InterceptingInjectorBuilder.java
==============================================================================
--- (empty file)
+++  
tags/snapshot20090706/src/com/google/inject/commands/intercepting/InterceptingInjectorBuilder.java
       
Thu Jul  9 11:37:40 2009
@@ -0,0 +1,220 @@
+/**
+ * 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.commands.intercepting;
+
+import static com.google.inject.internal.Preconditions.checkArgument;
+import static com.google.inject.internal.Preconditions.checkNotNull;
+import com.google.inject.internal.Sets;
+import com.google.inject.AbstractModule;
+import com.google.inject.Binder;
+import com.google.inject.Binding;
+import com.google.inject.Guice;
+import com.google.inject.ImplementedBy;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.Key;
+import com.google.inject.Module;
+import com.google.inject.ProvidedBy;
+import com.google.inject.Provider;
+import com.google.inject.TypeLiteral;
+import com.google.inject.binder.ScopedBindingBuilder;
+import com.google.inject.internal.UniqueAnnotations;
+import com.google.inject.name.Names;
+import com.google.inject.spi.DefaultBindingTargetVisitor;
+import com.google.inject.spi.Element;
+import com.google.inject.spi.Elements;
+import com.google.inject.spi.ModuleWriter;
+import com.google.inject.spi.UntargettedBinding;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Builds an {...@link Injector} that intercepts provision.
+ *
+ * <p>The injector contains an extra binding for {...@code Set<Key>} annotated
+ * with the name "Interceptable". This bound set contains all intercepted  
keys.
+ *
+ * <h3>Limitations of the current implementation</h3>
+ *
+ * <p>All intercepted bindings must have binding targets - for example, a  
type
+ * that is bound to itself cannot be intercepted:
+ * <pre class="code">bind(MyServiceClass.class);</pre>
+ *
+ * <p>All intercepted bindings must be bound explicitly. Interception  
cannot
+ * be applied to implicit bindings, or bindings that depend on
+ * {...@literal @}...@link ProvidedBy}, {...@literal @}...@link ImplementedBy}
+ * annotations.
+ *
+ * <p><strong>Implementation note:</strong> To intercept provision, an
+ * additional, internal binding is created for each intercepted key. This  
is
+ * used to bind the original (non-intercepted) provisioning strategy, and  
an
+ * intercepting binding is created for the original key. This shouldn't  
have
+ * any side-effects on the behaviour of the injector, but may confuse tools
+ * that depend on {...@link Injector#getBindings()} and similar methods.
+ *
+ * @deprecated copy this class into your own project, or use guiceberry
+ * @author [email protected] (Jesse Wilson)
+ * @author [email protected] (Jerome Mourits)
+ */
+...@deprecated
+public final class InterceptingInjectorBuilder {
+
+  private static final Key<ProvisionInterceptor> INJECTION_INTERCEPTOR_KEY
+      = Key.get(ProvisionInterceptor.class);
+
+  private final Collection<Module> modules = new ArrayList<Module>();
+  private final Set<Key<?>> keysToIntercept = Sets.newHashSet();
+  private boolean tolerateUnmatchedInterceptions = false;
+
+  public InterceptingInjectorBuilder() {
+    // bind the keys to intercept
+    modules.add(new AbstractModule() {
+      protected void configure() {
+        bind(new TypeLiteral<Set<Key>>() {})
+            .annotatedWith(Names.named("Interceptable"))
+            .toInstance(Collections.<Key>unmodifiableSet(keysToIntercept));
+      }
+    });
+  }
+
+  public InterceptingInjectorBuilder install(Module... modules) {
+    this.modules.addAll(Arrays.asList(modules));
+    return this;
+  }
+
+  public InterceptingInjectorBuilder install(Collection<Module> modules) {
+    this.modules.addAll(modules);
+    return this;
+  }
+
+  public InterceptingInjectorBuilder intercept(Key<?>... keys) {
+    this.keysToIntercept.addAll(Arrays.asList(keys));
+    return this;
+  }
+
+  public InterceptingInjectorBuilder intercept(Collection<Key<?>> keys) {
+    checkArgument(!keys.contains(INJECTION_INTERCEPTOR_KEY),
+        "Cannot intercept the interceptor!");
+
+    keysToIntercept.addAll(keys);
+    return this;
+  }
+
+  public InterceptingInjectorBuilder intercept(Class<?>... classes) {
+    List<Key<?>> keysAsList = new ArrayList<Key<?>>(classes.length);
+    for (Class<?> clas : classes) {
+      keysAsList.add(Key.get(clas));
+    }
+
+    return intercept(keysAsList);
+  }
+
+  public InterceptingInjectorBuilder tolerateUnmatchedInterceptions() {
+    this.tolerateUnmatchedInterceptions = true;
+    return this;
+  }
+
+  public Injector build() {
+    // record commands from the modules
+    List<Element> elements = Elements.getElements(modules);
+
+    // rewrite the commands to insert interception
+    ModuleRewriter rewriter = new ModuleRewriter();
+    Module module = rewriter.create(elements);
+
+    // create and injector with the rewritten commands
+    Injector injector = Guice.createInjector(module);
+
+    // fail if any interceptions were missing
+    if (!tolerateUnmatchedInterceptions
+        && !rewriter.keysIntercepted.equals(keysToIntercept)) {
+      Set<Key<?>> keysNotIntercepted = Sets.newHashSet();
+      keysNotIntercepted.addAll(keysToIntercept);
+      keysNotIntercepted.removeAll(rewriter.keysIntercepted);
+      throw new IllegalArgumentException("An explicit binding is required  
for "
+          + "all intercepted keys, but was not found for " +  
keysNotIntercepted);
+    }
+
+    return injector;
+  }
+
+  /** Replays commands, inserting the InterceptingProvider where  
necessary. */
+  private class ModuleRewriter extends ModuleWriter {
+    private Set<Key<?>> keysIntercepted = Sets.newHashSet();
+
+    @Override public <T> void writeBind(Binder binder, Binding<T> binding)  
{
+      final Key<T> key = binding.getKey();
+
+      if (!keysToIntercept.contains(key)) {
+        super.writeBind(binder, binding);
+        return;
+      }
+
+      binding.acceptTargetVisitor(new DefaultBindingTargetVisitor<T,  
Void>() {
+        public Void visitUntargetted(UntargettedBinding<? extends T>  
untargettedBinding) {
+          throw new UnsupportedOperationException(
+              String.format("Cannot intercept bare binding of %s.", key));
+        }
+      });
+
+      Key<T> anonymousKey = Key.get(key.getTypeLiteral(),  
UniqueAnnotations.create());
+      binder.bind(key).toProvider(new InterceptingProvider<T>(key,  
anonymousKey));
+
+      ScopedBindingBuilder scopedBindingBuilder = bindKeyToTarget(binding,  
binder, anonymousKey);
+
+      // we scope the user's provider, not the interceptor. This is  
dangerous,
+      // but convenient. It means that although the user's provider will  
live
+      // in its proper scope, the intereptor gets invoked without a scope
+      applyScoping(binding, scopedBindingBuilder);
+
+      keysIntercepted.add(key);
+    }
+  }
+
+  /**
+   * Provide {...@code T}, with a hook for an {...@link ProvisionInterceptor}.
+   */
+  private static class InterceptingProvider<T> implements Provider<T> {
+    private final Key<T> key;
+    private final Key<T> anonymousKey;
+    private Provider<ProvisionInterceptor> injectionInterceptorProvider;
+    private Provider<? extends T> delegateProvider;
+
+    public InterceptingProvider(Key<T> key, Key<T> anonymousKey) {
+      this.key = key;
+      this.anonymousKey = anonymousKey;
+    }
+
+    @Inject void initialize(Injector injector,
+        Provider<ProvisionInterceptor> injectionInterceptorProvider) {
+      this.injectionInterceptorProvider
+          =  
checkNotNull(injectionInterceptorProvider, "injectionInterceptorProvider");
+      this.delegateProvider
+          =  
checkNotNull(injector.getProvider(anonymousKey), "delegateProvider");
+    }
+
+    public T get() {
+       
checkNotNull(injectionInterceptorProvider, "injectionInterceptorProvider");
+      checkNotNull(delegateProvider, "delegateProvider");
+      return injectionInterceptorProvider.get().intercept(key,  
delegateProvider);
+    }
+  }
+}

Added:  
tags/snapshot20090706/src/com/google/inject/commands/intercepting/ProvisionInterceptor.java
==============================================================================
--- (empty file)
+++  
tags/snapshot20090706/src/com/google/inject/commands/intercepting/ProvisionInterceptor.java
      
Thu Jul  9 11:37:40 2009
@@ -0,0 +1,32 @@
+/**
+ * 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.commands.intercepting;
+
+import com.google.inject.Key;
+import com.google.inject.Provider;
+
+/**
+ * Intercepts object provision.
+ *
+ * @deprecated copy this class into your own project, or use guiceberry
+ * @author [email protected] (Jesse Wilson)
+ * @author [email protected] (Jerome Mourits)
+ */
+...@deprecated
+public interface ProvisionInterceptor {
+  <T> T intercept(Key<T> key, Provider<? extends T> delegate);
+}

Modified: tags/snapshot20090706/src/com/google/inject/internal/Errors.java
==============================================================================
--- /trunk/src/com/google/inject/internal/Errors.java   (original)
+++ tags/snapshot20090706/src/com/google/inject/internal/Errors.java    Thu  
Jul  9 11:37:40 2009
@@ -24,6 +24,7 @@
  import com.google.inject.ProvisionException;
  import com.google.inject.Scope;
  import com.google.inject.TypeLiteral;
+import com.google.inject.Guice;
  import com.google.inject.spi.Dependency;
  import com.google.inject.spi.InjectionListener;
  import com.google.inject.spi.InjectionPoint;
@@ -42,6 +43,8 @@
  import java.util.Comparator;
  import java.util.Formatter;
  import java.util.List;
+import java.util.logging.Logger;
+import java.util.concurrent.atomic.AtomicInteger;

  /**
   * A collection of error messages. If this type is passed as a method  
parameter, the method is
@@ -60,6 +63,21 @@
   */
  public final class Errors implements Serializable {

+  private static final AtomicInteger warningsLogged = new AtomicInteger(0);
+
+  // TODO(kevinb): gee, ya think we might want to remove this?
+  private static boolean allowNullsBadBadBad(Dependency<?> dependency) {
+    boolean allowNulls = "I'm a bad hack"
+        .equals(System.getProperty("guice.allow.nulls.bad.bad.bad"));
+
+    if (allowNulls && warningsLogged.getAndIncrement() < 50) {
+      Logger.getLogger(Guice.class.getName()).warning(
+          "Guice injected null into " + dependency + "; please mark it  
@Nullable");
+    }
+
+    return allowNulls;
+  }
+
    /**
     * The root errors object. Used to access the list of error messages.
     */
@@ -503,7 +521,7 @@
     */
    public <T> T checkForNull(T value, Object source, Dependency<?>  
dependency)
        throws ErrorsException {
-    if (value != null || dependency.isNullable()) {
+    if (value != null || dependency.isNullable() ||  
allowNullsBadBadBad(dependency)) {
        return value;
      }


Modified:  
tags/snapshot20090706/src/com/google/inject/internal/Iterables.java
==============================================================================
--- /trunk/src/com/google/inject/internal/Iterables.java        (original)
+++ tags/snapshot20090706/src/com/google/inject/internal/Iterables.java Thu  
Jul  9 11:37:40 2009
@@ -20,14 +20,8 @@
  import java.util.Iterator;
  import java.util.NoSuchElementException;

-/**
- * This class contains static utility methods that operate on or return  
objects
- * of type {...@code Iterable}. Also see the parallel implementations in  
{...@link
- * Iterators}.
- *
- * @author Kevin Bourrillion
- * @author Scott Bonneau
- */
+/** @deprecated please use the official version in {...@code  
com.google.common.collect}. */
+...@deprecated
  public final class Iterables {
    private Iterables() {}


Modified: tags/snapshot20090706/src/com/google/inject/internal/Lists.java
==============================================================================
--- /trunk/src/com/google/inject/internal/Lists.java    (original)
+++ tags/snapshot20090706/src/com/google/inject/internal/Lists.java     Thu  
Jul  9 11:37:40 2009
@@ -20,17 +20,10 @@
  import java.util.Collection;
  import java.util.Collections;
  import java.util.Iterator;
-import java.util.List;

-/**
- * Static utility methods pertaining to {...@link List} instances. Also see  
this
- * class's counterparts {...@link Sets} and {...@link Maps}.
- *
- * @author Kevin Bourrillion
- * @author Mike Bostock
- */
-public final class Lists {
-  private Lists() {}
+/** @deprecated please use the official version in {...@code  
com.google.common.collect}. */
+...@deprecated
+public class Lists {

    // ArrayList

@@ -124,4 +117,4 @@
      }
      return result;
    }
-}
\ No newline at end of file
+}

Modified: tags/snapshot20090706/src/com/google/inject/internal/Maps.java
==============================================================================
--- /trunk/src/com/google/inject/internal/Maps.java     (original)
+++ tags/snapshot20090706/src/com/google/inject/internal/Maps.java      Thu Jul 
  
9 11:37:40 2009
@@ -20,20 +20,12 @@
  import java.util.HashMap;
  import java.util.IdentityHashMap;
  import java.util.LinkedHashMap;
-import java.util.Map;
  import java.util.Map.Entry;
  import java.util.TreeMap;

-/**
- * Static utility methods pertaining to {...@link Map} instances. Also see  
this
- * class's counterparts {...@link Lists} and {...@link Sets}.
- *
- * @author Kevin Bourrillion
- * @author Mike Bostock
- * @author Isaac Shum
- */
-public final class Maps {
-  private Maps() {}
+/** @deprecated please use the official version in {...@code  
com.google.common.collect}. */
+...@deprecated
+public class Maps {

    /**
     * Creates a {...@code HashMap} instance.

Modified:  
tags/snapshot20090706/src/com/google/inject/internal/Preconditions.java
==============================================================================
--- /trunk/src/com/google/inject/internal/Preconditions.java    (original)
+++ tags/snapshot20090706/src/com/google/inject/internal/Preconditions.java     
 
Thu Jul  9 11:37:40 2009
@@ -17,48 +17,10 @@
  package com.google.inject.internal;

  import java.util.Collection;
-import java.util.NoSuchElementException;

-/**
- * Simple static methods to be called at the start of your own methods to  
verify
- * correct arguments and state. This allows constructs such as
- * <pre>
- *     if (count <= 0) {
- *       throw new IllegalArgumentException("must be positive: " + count);
- *     }</pre>
- *
- * to be replaced with the more compact
- * <pre>
- *     checkArgument(count > 0, "must be positive: %s", count);</pre>
- *
- * Note that the sense of the expression is inverted; with {...@code  
Preconditions}
- * you declare what you expect to be <i>true</i>, just as you do with an
- * <a  
href="http://java.sun.com/j2se/1.5.0/docs/guide/language/assert.html";>
- * {...@code assert}</a> or a JUnit {...@code assertTrue()} call.
- *
- * <p>Take care not to confuse precondition checking with other similar  
types
- * of checks! Precondition exceptions -- including those provided here,  
but also
- * {...@link IndexOutOfBoundsException}, {...@link NoSuchElementException},  
{...@link
- * UnsupportedOperationException} and others -- are used to signal that the
- * <i>calling method</i> has made an error. This tells the caller that it  
should
- * not have invoked the method when it did, with the arguments it did, or
- * perhaps <i>ever</i>. Postcondition or other invariant failures should  
not
- * throw these types of exceptions.
- *
- * <p><b>Note:</b> The methods of the {...@code Preconditions} class are  
highly
- * unusual in one way: they are <i>supposed to</i> throw exceptions, and  
promise
- * in their specifications to do so even when given perfectly valid input.  
That
- * is, {...@code null} is a valid parameter to the method {...@link
- * #checkNotNull(Object)} -- and technically this parameter could be even  
marked
- * as {...@link Nullable} -- yet the method will still throw an exception  
anyway,
- * because that's what its contract says to do.
- *
- * <p>This class may be used with the Google Web Toolkit (GWT).
- *
- * @author Kevin Bourrillion
- */
-public final class Preconditions {
-  private Preconditions() {}
+/** @deprecated please use the official version in {...@code  
com.google.common.base}. */
+...@deprecated
+public class Preconditions {

    /**
     * Ensures the truth of an expression involving one or more parameters  
to the

Modified: tags/snapshot20090706/src/com/google/inject/internal/Sets.java
==============================================================================
--- /trunk/src/com/google/inject/internal/Sets.java     (original)
+++ tags/snapshot20090706/src/com/google/inject/internal/Sets.java      Thu Jul 
  
9 11:37:40 2009
@@ -31,15 +31,9 @@
  import java.util.Set;
  import java.util.TreeMap;

-/**
- * Static utility methods pertaining to {...@link Set} instances. Also see  
this
- * class's counterparts {...@link Lists} and {...@link Maps}.
- *
- * @author Kevin Bourrillion
- * @author Jared Levy
- */
-public final class Sets {
-  private Sets() {}
+/** @deprecated please use the official version in {...@code  
com.google.common.collect}. */
+...@deprecated
+public class Sets {

    // HashSet


Added:  
tags/snapshot20090706/src/com/google/inject/internal/base/Preconditions.java
==============================================================================
--- (empty file)
+++  
tags/snapshot20090706/src/com/google/inject/internal/base/Preconditions.java    
 
Thu Jul  9 11:37:40 2009
@@ -0,0 +1,22 @@
+/**
+ * Copyright (C) 2009 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.base;
+
+/** @deprecated please use the official version in {...@code  
com.google.common.base}. */
+...@deprecated
+public class Preconditions extends  
com.google.inject.internal.Preconditions {
+}

Added:  
tags/snapshot20090706/src/com/google/inject/internal/collect/Lists.java
==============================================================================
--- (empty file)
+++ tags/snapshot20090706/src/com/google/inject/internal/collect/Lists.java     
 
Thu Jul  9 11:37:40 2009
@@ -0,0 +1,22 @@
+/**
+ * Copyright (C) 2009 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.collect;
+
+/** @deprecated please use the official version in {...@code  
com.google.common.collect}. */
+...@deprecated
+public class Lists extends com.google.inject.internal.Lists {
+}

Added:  
tags/snapshot20090706/src/com/google/inject/internal/collect/Maps.java
==============================================================================
--- (empty file)
+++ tags/snapshot20090706/src/com/google/inject/internal/collect/Maps.java      
 
Thu Jul  9 11:37:40 2009
@@ -0,0 +1,22 @@
+/**
+ * Copyright (C) 2009 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.collect;
+
+/** @deprecated please use the official version in {...@code  
com.google.common.collect}. */
+...@deprecated
+public class Maps extends com.google.inject.internal.Maps {
+}

Added:  
tags/snapshot20090706/src/com/google/inject/internal/collect/Sets.java
==============================================================================
--- (empty file)
+++ tags/snapshot20090706/src/com/google/inject/internal/collect/Sets.java      
 
Thu Jul  9 11:37:40 2009
@@ -0,0 +1,22 @@
+/**
+ * Copyright (C) 2009 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.collect;
+
+/** @deprecated please use the official version in {...@code  
com.google.common.collect}. */
+...@deprecated
+public class Sets extends com.google.inject.internal.Sets {
+}

Modified:  
tags/snapshot20090706/src/com/google/inject/spi/DefaultBindingTargetVisitor.java
==============================================================================
--- /trunk/src/com/google/inject/spi/DefaultBindingTargetVisitor.java    
(original)
+++  
tags/snapshot20090706/src/com/google/inject/spi/DefaultBindingTargetVisitor.java
         
Thu Jul  9 11:37:40 2009
@@ -17,6 +17,10 @@
  package com.google.inject.spi;

  import com.google.inject.Binding;
+import com.google.inject.Provider;
+import com.google.inject.Key;
+import java.util.Set;
+import java.lang.reflect.Constructor;

  /**
   * No-op visitor for subclassing. All interface methods simply delegate to  
{...@link
@@ -38,40 +42,157 @@
    }

    public V visit(InstanceBinding<? extends T> instanceBinding) {
-    return visitOther(instanceBinding);
+    return visitInstance(instanceBinding);
    }

    public V visit(ProviderInstanceBinding<? extends T>  
providerInstanceBinding) {
-    return visitOther(providerInstanceBinding);
+    return visitProviderInstance(providerInstanceBinding);
    }

    public V visit(ProviderKeyBinding<? extends T> providerKeyBinding) {
-    return visitOther(providerKeyBinding);
+    return visitProviderKey(providerKeyBinding);
    }

    public V visit(LinkedKeyBinding<? extends T> linkedKeyBinding) {
-    return visitOther(linkedKeyBinding);
+    return visitLinkedKey(linkedKeyBinding);
    }

    public V visit(ExposedBinding<? extends T> exposedBinding) {
-    return visitOther(exposedBinding);
+    return visitExposed(exposedBinding);
    }

    public V visit(UntargettedBinding<? extends T> untargettedBinding) {
-    return visitOther(untargettedBinding);
+    return visitUntargetted(untargettedBinding);
    }

    public V visit(ConstructorBinding<? extends T> constructorBinding) {
-    return visitOther(constructorBinding);
+    return visitConstructor(constructorBinding);
    }

    public V visit(ConvertedConstantBinding<? extends T>  
convertedConstantBinding) {
-    return visitOther(convertedConstantBinding);
+    return visitConvertedConstant(convertedConstantBinding);
    }

-   // javac says it's an error to cast ProviderBinding<? extends T> to  
Binding<? extends T>
+  // javac says it's an error to cast ProviderBinding<? extends T> to  
Binding<? extends T>
    @SuppressWarnings("unchecked")
    public V visit(ProviderBinding<? extends T> providerBinding) {
      return visitOther((Binding) providerBinding);
+  }
+
+  // this API has gone through two major changes
+  //   originally each method had the form visitInstance(T,  
injectionPoints)
+  //                     and then the form visitInstance(InstanceBinding)
+  //                      and now the form visit(InstanceBinding)
+  //
+  // apologies for the churn.
+
+  /** @deprecated override {...@code visit} instead. */
+  @Deprecated protected V visitOther() {
+    return null;
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  @Deprecated public V visitInstance(T instance, Set<InjectionPoint>  
injectionPoints) {
+    return visitOther();
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  @Deprecated public V visitProvider(
+      Provider<? extends T> provider, Set<InjectionPoint> injectionPoints)  
{
+    return visitOther();
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  @Deprecated public V visitProviderKey(Key<? extends Provider<? extends  
T>> providerKey) {
+    return visitOther();
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  @Deprecated public V visitKey(Key<? extends T> key) {
+    return visitOther();
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  @Deprecated public V visitUntargetted() {
+    return visitOther();
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  @Deprecated public V visitConstructor(Constructor<? extends T>  
constructor,
+      Set<InjectionPoint> injectionPoints) {
+    return visitOther();
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  @Deprecated public V visitConvertedConstant(T value) {
+    return visitOther();
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  @Deprecated public V visitProviderBinding(Key<?> provided) {
+    return visitOther();
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  @Deprecated public V visitExposed(PrivateElements privateElements) {
+    return visitOther();
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  @Deprecated public V visitInstance(InstanceBinding<? extends T> binding)  
{
+    V result = visitInstance(binding.getInstance(),  
binding.getInjectionPoints());
+    return result != null ? result : visitOther(binding);
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  @Deprecated public V visitProviderInstance(ProviderInstanceBinding<?  
extends T> binding) {
+    V result = visitProvider(binding.getProviderInstance(),  
binding.getInjectionPoints());
+    return result != null ? result : visitOther(binding);
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  @Deprecated public V visitProviderKey(ProviderKeyBinding<? extends T>  
binding) {
+    V result = visitProviderKey(binding.getProviderKey());
+    return result != null ? result : visitOther(binding);
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  @Deprecated public V visitLinkedKey(LinkedKeyBinding<? extends T>  
binding) {
+    V result = visitKey(binding.getLinkedKey());
+    return result != null ? result : visitOther(binding);
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  @Deprecated public V visitExposed(ExposedBinding<? extends T> binding) {
+    V result = visitExposed(binding.getPrivateElements());
+    return result != null ? result : visitOther(binding);
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  @Deprecated public V visitUntargetted(UntargettedBinding<? extends T>  
binding) {
+    V result = visitUntargetted();
+    return result != null ? result : visitOther(binding);
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  @SuppressWarnings("unchecked")
+  @Deprecated public V visitConstructor(ConstructorBinding<? extends T>  
binding) {
+    V result = visitConstructor((Constructor)  
binding.getConstructor().getMember(),
+        binding.getInjectableMembers());
+    return result != null ? result : visitOther(binding);
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  @Deprecated public V visitConvertedConstant(ConvertedConstantBinding<?  
extends T> binding) {
+    V result = visitConvertedConstant(binding.getValue());
+    return result != null ? result : visitOther(binding);
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  // javac says it's an error to cast ProviderBinding<? extends T> to  
Binding<? extends T>
+  @SuppressWarnings("unchecked")
+  @Deprecated public V visitProviderBinding(ProviderBinding<? extends T>  
binding) {
+    V result = visitProviderBinding(binding.getProvidedKey());
+    return result != null ? result : visitOther((Binding) binding);
    }
  }

Modified:  
tags/snapshot20090706/src/com/google/inject/spi/DefaultElementVisitor.java
==============================================================================
--- /trunk/src/com/google/inject/spi/DefaultElementVisitor.java (original)
+++  
tags/snapshot20090706/src/com/google/inject/spi/DefaultElementVisitor.java      
 
Thu Jul  9 11:37:40 2009
@@ -38,41 +38,41 @@
    }

    public V visit(Message message) {
-    return visitOther(message);
+    return visitMessage(message);
    }

    public <T> V visit(Binding<T> binding) {
-    return visitOther(binding);
+    return visitBinding(binding);
    }

    /*if[AOP]*/
    public V visit(InterceptorBinding interceptorBinding) {
-    return visitOther(interceptorBinding);
+    return visitInterceptorBinding(interceptorBinding);
    }
    /*end[AOP]*/

    public V visit(ScopeBinding scopeBinding) {
-    return visitOther(scopeBinding);
+    return visitScopeBinding(scopeBinding);
    }

    public V visit(TypeConverterBinding typeConverterBinding) {
-    return visitOther(typeConverterBinding);
+    return visitTypeConverterBinding(typeConverterBinding);
    }

    public <T> V visit(ProviderLookup<T> providerLookup) {
-    return visitOther(providerLookup);
+    return visitProviderLookup(providerLookup);
    }

    public V visit(InjectionRequest<?> injectionRequest) {
-    return visitOther(injectionRequest);
+    return visitInjectionRequest(injectionRequest);
    }

    public V visit(StaticInjectionRequest staticInjectionRequest) {
-    return visitOther(staticInjectionRequest);
+    return visitStaticInjectionRequest(staticInjectionRequest);
    }

    public V visit(PrivateElements privateElements) {
-    return visitOther(privateElements);
+    return visitPrivateElements(privateElements);
    }

    public <T> V visit(MembersInjectorLookup<T> lookup) {
@@ -81,5 +81,57 @@

    public V visit(TypeListenerBinding binding) {
      return visitOther(binding);
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  protected V visitElement(Element element) {
+    return visitOther(element);
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  public V visitMessage(Message message) {
+    return visitElement(message);
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  public <T> V visitBinding(Binding<T> binding) {
+    return visitElement(binding);
+  }
+
+  /*if[AOP]*/
+  /** @deprecated override {...@code visit} instead. */
+  public V visitInterceptorBinding(InterceptorBinding interceptorBinding) {
+    return visitElement(interceptorBinding);
+  }
+  /*end[AOP]*/
+
+  /** @deprecated override {...@code visit} instead. */
+  public V visitScopeBinding(ScopeBinding scopeBinding) {
+    return visitElement(scopeBinding);
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  public V visitTypeConverterBinding(TypeConverterBinding  
typeConverterBinding) {
+    return visitElement(typeConverterBinding);
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  public <T> V visitProviderLookup(ProviderLookup<T> providerLookup) {
+    return visitElement(providerLookup);
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  public V visitInjectionRequest(InjectionRequest injectionRequest) {
+    return visitElement(injectionRequest);
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  public V visitStaticInjectionRequest(StaticInjectionRequest  
staticInjectionRequest) {
+    return visitElement(staticInjectionRequest);
+  }
+
+  /** @deprecated override {...@code visit} instead. */
+  public V visitPrivateElements(PrivateElements privateElements) {
+    return visitElement(privateElements);
    }
  }

Added: tags/snapshot20090706/src/com/google/inject/spi/ModuleWriter.java
==============================================================================
--- (empty file)
+++ tags/snapshot20090706/src/com/google/inject/spi/ModuleWriter.java   Thu  
Jul  9 11:37:40 2009
@@ -0,0 +1,289 @@
+/**
+ * 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.spi;
+
+import com.google.inject.Binder;
+import com.google.inject.Binding;
+import com.google.inject.Key;
+import com.google.inject.MembersInjector;
+import com.google.inject.Module;
+import com.google.inject.PrivateBinder;
+import com.google.inject.Provider;
+import com.google.inject.Scope;
+import com.google.inject.binder.ScopedBindingBuilder;
+import com.google.inject.internal.Maps;
+import static com.google.inject.internal.Preconditions.checkArgument;
+import static com.google.inject.internal.Preconditions.checkNotNull;
+import java.lang.annotation.Annotation;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Creates a Module from a collection of component elements.
+ *
+ * @deprecated use Element#applyTo instead
+ *
+ * @author [email protected] (Jesse Wilson)
+ * @since 2.0
+ */
+...@deprecated
+public class ModuleWriter {
+
+  private final Map<PrivateElements, PrivateBinder> environmentToBinder =  
Maps.newHashMap();
+
+  /**
+   * Returns a module that executes the specified elements using this  
executing visitor.
+   */
+  public final Module create(final Iterable<? extends Element> elements) {
+    return new Module() {
+      public void configure(Binder binder) {
+        apply(binder, elements);
+      }
+    };
+  }
+
+  /**
+   * Replays {...@code elements} against {...@code binder}.
+   */
+  public final void apply(final Binder binder, Iterable<? extends Element>  
elements) {
+    checkNotNull(binder, "binder");
+    checkNotNull(elements, "elements");
+
+    ElementVisitor<Void> visitor = new ElementVisitor<Void>() {
+
+      public Void visit(Message message) {
+        writeMessage(binder, message);
+        return null;
+      }
+
+      /*if[AOP]*/
+      public Void visit(InterceptorBinding element) {
+        writeBindInterceptor(binder, element);
+        return null;
+      }
+      /*end[AOP]*/
+
+      public Void visit(ScopeBinding element) {
+        writeBindScope(binder, element);
+        return null;
+      }
+
+      public Void visit(InjectionRequest element) {
+        writeRequestInjection(binder, element);
+        return null;
+      }
+
+      public Void visit(StaticInjectionRequest element) {
+        writeRequestStaticInjection(binder, element);
+        return null;
+      }
+
+      public Void visit(TypeConverterBinding element) {
+        writeConvertToTypes(binder, element);
+        return null;
+      }
+
+      public <T> Void visit(Binding<T> element) {
+        writeBind(binder, element);
+        return null;
+      }
+
+      public <T> Void visit(ProviderLookup<T> element) {
+        writeGetProvider(binder, element);
+        return null;
+      }
+
+      public <T> Void visit(MembersInjectorLookup<T> element) {
+        writeGetMembersInjector(binder, element);
+        return null;
+      }
+
+      public Void visit(TypeListenerBinding element) {
+        writeBindListener(binder, element);
+        return null;
+      }
+
+      public Void visit(PrivateElements privateElements) {
+        writePrivateElements(binder, privateElements);
+        return null;
+      }
+    };
+
+    for (Element element : elements) {
+      element.acceptVisitor(visitor);
+    }
+  }
+
+  protected void writeMessage(Binder binder, Message element) {
+    binder.addError(element);
+  }
+
+  /*if[AOP]*/
+  protected void writeBindInterceptor(Binder binder, InterceptorBinding  
element) {
+    List<org.aopalliance.intercept.MethodInterceptor> interceptors =  
element.getInterceptors();
+    binder.withSource(element.getSource()).bindInterceptor(
+        element.getClassMatcher(), element.getMethodMatcher(),
+        interceptors.toArray(new  
org.aopalliance.intercept.MethodInterceptor[interceptors.size()]));
+  }
+  /*end[AOP]*/
+
+  protected void writeBindListener(Binder binder, TypeListenerBinding  
element) {
+    binder.withSource(element.getSource())
+        .bindListener(element.getTypeMatcher(), element.getListener());
+  }
+
+  protected void writeBindScope(Binder binder, ScopeBinding element) {
+    binder.withSource(element.getSource()).bindScope(
+        element.getAnnotationType(), element.getScope());
+  }
+
+  protected void writeRequestInjection(Binder binder, InjectionRequest  
element) {
+     
binder.withSource(element.getSource()).requestInjection(element.getInstance());
+  }
+
+  protected void writeRequestStaticInjection(Binder binder,  
StaticInjectionRequest element) {
+    Class<?> type = element.getType();
+    binder.withSource(element.getSource()).requestStaticInjection(type);
+  }
+
+  protected void writeConvertToTypes(Binder binder, TypeConverterBinding  
element) {
+    binder.withSource(element.getSource())
+        .convertToTypes(element.getTypeMatcher(),  
element.getTypeConverter());
+  }
+
+  protected <T> void writeBind(Binder binder, Binding<T> element) {
+    ScopedBindingBuilder sbb
+        = bindKeyToTarget(element, binder.withSource(element.getSource()),  
element.getKey());
+    applyScoping(element, sbb);
+  }
+
+  /**
+   * Writes the elements of the private environment to a new private  
binder and {...@link
+   * #setPrivateBinder associates} the two.
+   */
+  protected void writePrivateElements(Binder binder, PrivateElements  
element) {
+    PrivateBinder privateBinder =  
binder.withSource(element.getSource()).newPrivateBinder();
+    setPrivateBinder(element, privateBinder);
+    apply(privateBinder, element.getElements());
+    for (Key<?> key : element.getExposedKeys()) {
+      privateBinder.withSource(element.getExposedSource(key)).expose(key);
+    }
+  }
+
+  /**
+   * Execute this target against the linked binding builder.
+   */
+  protected <T> ScopedBindingBuilder bindKeyToTarget(
+      final Binding<T> binding, Binder binder, final Key<T> key) {
+    final Binder sourcedBinder = binder.withSource(binding.getSource());
+
+    return binding.acceptTargetVisitor(new BindingTargetVisitor<T,  
ScopedBindingBuilder>() {
+      public ScopedBindingBuilder visit(InstanceBinding<? extends T>  
binding) {
+        sourcedBinder.bind(key).toInstance(binding.getInstance());
+        return null;
+      }
+
+      public ScopedBindingBuilder visit(ProviderInstanceBinding<? extends  
T> binding) {
+        return  
sourcedBinder.bind(key).toProvider(binding.getProviderInstance());
+      }
+
+      public ScopedBindingBuilder visit(ProviderKeyBinding<? extends T>  
binding) {
+        return  
sourcedBinder.bind(key).toProvider(binding.getProviderKey());
+      }
+
+      public ScopedBindingBuilder visit(LinkedKeyBinding<? extends T>  
binding) {
+        return sourcedBinder.bind(key).to(binding.getLinkedKey());
+      }
+
+      public ScopedBindingBuilder visit(UntargettedBinding<? extends T>  
binding) {
+        return sourcedBinder.bind(key);
+      }
+
+      public ScopedBindingBuilder visit(ExposedBinding<? extends T>  
binding) {
+        throw new IllegalArgumentException("Non-module element");
+      }
+
+      public ScopedBindingBuilder visit(ConvertedConstantBinding<? extends  
T> binding) {
+        throw new IllegalArgumentException("Non-module element");
+      }
+
+      public ScopedBindingBuilder visit(ConstructorBinding<? extends T>  
binding) {
+        throw new IllegalArgumentException("Non-module element");
+      }
+
+      public ScopedBindingBuilder visit(ProviderBinding<? extends T>  
binding) {
+        throw new IllegalArgumentException("Non-module element");
+      }
+    });
+  }
+
+  /** Associates {...@code binder} with {...@code privateElements}. */
+  protected void setPrivateBinder(PrivateElements privateElements,  
PrivateBinder binder) {
+    checkArgument(!environmentToBinder.containsKey(privateElements),
+        "A private binder already exists for %s", privateElements);
+    environmentToBinder.put(privateElements, binder);
+  }
+
+  /**
+   * Returns the {...@code binder} accociated with {...@code privateElements}. 
 
This can be used to
+   * expose bindings to the enclosing environment.
+   */
+  protected PrivateBinder getPrivateBinder(PrivateElements  
privateElements) {
+    PrivateBinder privateBinder = environmentToBinder.get(privateElements);
+    checkArgument(privateBinder != null, "No private binder for %s",  
privateElements);
+    return privateBinder;
+  }
+
+  protected void applyScoping(Binding<?> binding, final  
ScopedBindingBuilder scopedBindingBuilder) {
+    if (scopedBindingBuilder == null) {
+      return; // assume it's a binding that cannot be scoped, such as an  
instance binding
+    }
+
+    binding.acceptScopingVisitor(new BindingScopingVisitor<Void>() {
+      public Void visitEagerSingleton() {
+        scopedBindingBuilder.asEagerSingleton();
+        return null;
+      }
+
+      public Void visitScope(Scope scope) {
+        scopedBindingBuilder.in(scope);
+        return null;
+      }
+
+      public Void visitScopeAnnotation(Class<? extends Annotation>  
scopeAnnotation) {
+        scopedBindingBuilder.in(scopeAnnotation);
+        return null;
+      }
+
+      public Void visitNoScoping() {
+        // do nothing
+        return null;
+      }
+    });
+  }
+
+  protected <T> void writeGetProvider(Binder binder, ProviderLookup<T>  
element) {
+    Provider<T> provider =  
binder.withSource(element.getSource()).getProvider(element.getKey());
+    element.initializeDelegate(provider);
+  }
+
+  protected <T> void writeGetMembersInjector(Binder binder,  
MembersInjectorLookup<T> element) {
+    MembersInjector<T> membersInjector
+        =  
binder.withSource(element.getSource()).getMembersInjector(element.getType());
+    element.initializeDelegate(membersInjector);
+  }
+}

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to