Renamed 'ForBinding' to 'Binder'. Introduced Stage. Added name package to Javadocs. Updated some random Javadocs.
git-svn-id: https://google-guice.googlecode.com/svn/trunk@150 d779f126-a31b-0410-b53b-1d3aecad763e
diff --git a/build.properties b/build.properties
index 7c4b292..d53d869 100644
--- a/build.properties
+++ b/build.properties
@@ -3,4 +3,5 @@
src.dir=src
test.dir=test
build.dir=build
-javadoc.packagenames=com.google.inject,com.google.inject.spi,com.google.inject.matcher,com.google.inject.servlet
+javadoc.packagenames=com.google.inject,com.google.inject.spi,\
+ com.google.inject.matcher,com.google.inject.servlet,com.google.inject.name
diff --git a/guice.ipr b/guice.ipr
index 5b906aa..ccd1b86 100644
--- a/guice.ipr
+++ b/guice.ipr
@@ -13,11 +13,11 @@
<component name="Build editor project-level loader">
<settings>
<class-settings class="com.google.devtools.intellig.configcheck.ProjectPathChecker" />
+ <class-settings class="com.google.devtools.intellig.configcheck.PythonSdkChecker" />
<class-settings class="com.google.devtools.intellig.configcheck.ProjectJdkChecker">
<setting name="getProjectJdk" value="$PROJECT_DIR$/../../buildtools/java/jdk1.5.0_06" />
<setting name="getModuleJdks" value="rO0ABXNyABFqYXZhLnV0aWwuSGFzaFNldLpEhZWWuLc0AwAAeHB3DAAAABA/QAAAAAAAAHg=" />
</class-settings>
- <class-settings class="com.google.devtools.intellig.configcheck.PythonSdkChecker" />
<class-settings class="com.google.devtools.intellig.configcheck.ClearOutputChecker" />
</settings>
</component>
diff --git a/src/com/google/inject/AbstractModule.java b/src/com/google/inject/AbstractModule.java
index b0a702e..f1dbc2d 100644
--- a/src/com/google/inject/AbstractModule.java
+++ b/src/com/google/inject/AbstractModule.java
@@ -17,8 +17,6 @@
package com.google.inject;
import com.google.inject.util.Objects;
-import java.util.Map;
-import java.util.Properties;
import java.lang.annotation.Annotation;
/**
@@ -28,12 +26,14 @@
* those found in {@link ContainerBuilder}. For example:
*
* <pre>
+ * import static com.google.inject.Names.named;
+ *
* public class MyModule extends AbstractModule {
* protected void configure() {
* bind(Foo.class).to(FooImpl.class).in(Scopes.CONTAINER);
* bind(BarImpl.class);
* link(Bar.class).to(BarImpl.class);
- * bind("port").to(8080);
+ * bindConstant(named("port")).to(8080);
* }
* }
* </pre>
diff --git a/src/com/google/inject/ForBinding.java b/src/com/google/inject/Binder.java
similarity index 79%
rename from src/com/google/inject/ForBinding.java
rename to src/com/google/inject/Binder.java
index 637d541..c87a360 100644
--- a/src/com/google/inject/ForBinding.java
+++ b/src/com/google/inject/Binder.java
@@ -22,10 +22,12 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
- * Annotates annotations which are used for binding.
+ * Annotates annotations which are used for binding. Only one such annotation
+ * may apply to a single injection point. You must also annotate binder
+ * annotations with {@code @Retention(RUNTIME)}.
*
* @author crazybob@google.com (Bob Lee)
*/
@Target({ ElementType.ANNOTATION_TYPE })
@Retention(RUNTIME)
-public @interface ForBinding {}
+public @interface Binder {}
diff --git a/src/com/google/inject/Container.java b/src/com/google/inject/Container.java
index a7113ff..e0de052 100644
--- a/src/com/google/inject/Container.java
+++ b/src/com/google/inject/Container.java
@@ -24,6 +24,11 @@
* Injects dependencies into constructors, methods and fields annotated with
* {@code @}{@link Inject}. Provides access to {@link Binding}s.
*
+ * <p>Automatically converts constants as needed from {@code String} to any
+ * primitive type as well as {@code enum} and {@code Class<?>}. Automatically
+ * boxes and unboxes primitives. For example, in the absence of a binding to
+ * {@code int}, the container will look for a binding to {@code Integer}.
+ *
* @author crazybob@google.com (Bob Lee)
* @see ContainerBuilder
*/
diff --git a/src/com/google/inject/ContainerBuilder.java b/src/com/google/inject/ContainerBuilder.java
index 4062186..5b926e7 100644
--- a/src/com/google/inject/ContainerBuilder.java
+++ b/src/com/google/inject/ContainerBuilder.java
@@ -33,28 +33,22 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import java.util.logging.Logger;
import org.aopalliance.intercept.MethodInterceptor;
/**
* Builds a dependency injection {@link Container}. Binds {@link Key}s to
- * implementations. A binding implementation could be anything from a constant
- * value to an object in the HTTP session.
+ * implementations.
*
- * <p>Not safe for concurrent use.
- *
- * <p>Default bindings include:
+ * <p>Creates several bindings by default:
*
* <ul>
* <li>A {@code Factory<T>} for each binding of type {@code T}
* <li>The {@link Container} iself
* <li>The {@link Logger} for the class being injected
+ * <li>The {@link Stage} passed to the builder's constructor
* </ul>
*
- * <p>Converts constants as needed from {@code String} to any primitive type in
- * addition to {@code enum} and {@code Class<?>}.
- *
* @author crazybob@google.com (Bob Lee)
*/
public final class ContainerBuilder extends SourceConsumer {
@@ -76,6 +70,8 @@
ContainerImpl container;
+ final Stage stage;
+
/**
* Keeps error messages in order and prevents duplicates.
*/
@@ -104,14 +100,28 @@
/**
* Constructs a new builder.
+ *
+ * @param stage we're running in. If the stage is {@link Stage#PRODUCTION},
+ * we will eagerly load container-scoped objects.
*/
- public ContainerBuilder() {
+ public ContainerBuilder(Stage stage) {
scope(ContainerScoped.class, CONTAINER);
bind(Container.class).to(CONTAINER_FACTORY);
bind(Logger.class).to(LOGGER_FACTORY);
+ bind(Stage.class).to(stage);
this.proxyFactoryBuilder = new ProxyFactoryBuilder();
+
+ this.stage = stage;
+ }
+
+ /**
+ * Constructs a new builder for a development environment (see
+ * {@link Stage#DEVELOPMENT}).
+ */
+ public ContainerBuilder() {
+ this(Stage.DEVELOPMENT);
}
final List<CreationListener> creationListeners
@@ -254,15 +264,11 @@
* Creates a {@link Container} instance. Injects static members for classes
* which were registered using {@link #requestStaticInjection(Class...)}.
*
- * @param preload If true, the container will load all container-scoped
- * bindings now. If false, the container will lazily load them. Eager
- * loading is appropriate for production use (catch errors early and take
- * any performance hit up front) while lazy loading can speed development.
* @throws ContainerCreationException if configuration errors are found. The
* expectation is that the application will log this exception and exit.
* @throws IllegalStateException if called more than once
*/
- public synchronized Container create(boolean preload)
+ public synchronized Container create()
throws ContainerCreationException {
stopwatch.resetAndLog(logger, "Configuration");
@@ -278,7 +284,7 @@
final List<ContextualCallable<Void>> preloaders
= new ArrayList<ContextualCallable<Void>>();
- createBindings(preload, preloaders);
+ createBindings(preloaders);
createLinkedBindings();
stopwatch.resetAndLog(logger, "Binding creation");
@@ -361,14 +367,13 @@
putBinding(binding);
}
- private void createBindings(boolean preload,
- List<ContextualCallable<Void>> preloaders) {
+ private void createBindings(List<ContextualCallable<Void>> preloaders) {
for (BindingBuilder<?> builder : bindingBuilders) {
- createBinding(builder, preload, preloaders);
+ createBinding(builder, preloaders);
}
}
- private <T> void createBinding(BindingBuilder<T> builder, boolean preload,
+ private <T> void createBinding(BindingBuilder<T> builder,
List<ContextualCallable<Void>> preloaders) {
final Key<T> key = builder.getKey();
final InternalFactory<? extends T> factory
@@ -379,6 +384,7 @@
putBinding(binding);
// Register to preload if necessary.
+ boolean preload = stage == Stage.PRODUCTION;
if (builder.isContainerScoped()) {
if (preload || builder.shouldPreload()) {
preloaders.add(new BindingPreloader(key, factory));
diff --git a/src/com/google/inject/Inject.java b/src/com/google/inject/Inject.java
index 7fa96c9..4c88381 100644
--- a/src/com/google/inject/Inject.java
+++ b/src/com/google/inject/Inject.java
@@ -16,7 +16,6 @@
package com.google.inject;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
@@ -27,12 +26,9 @@
/**
* <p>Annotates members which should have their value[s] injected.
*
- * <p>Also applies to other annotations which can be used with {@link Key}s and
- * at injection points.
- *
* @author crazybob@google.com (Bob Lee)
*/
-@Target({ METHOD, CONSTRUCTOR, FIELD, ANNOTATION_TYPE })
+@Target({ METHOD, CONSTRUCTOR, FIELD })
@Retention(RUNTIME)
public @interface Inject {
diff --git a/src/com/google/inject/Key.java b/src/com/google/inject/Key.java
index ed993f6..51ed89a 100644
--- a/src/com/google/inject/Key.java
+++ b/src/com/google/inject/Key.java
@@ -31,7 +31,7 @@
*
* <pre>
* {@literal @}Inject
- * public void setService({@literal @}Transactional Service cities) {
+ * public void setService({@literal @}Transactional Service service) {
* ...
* }
* </pre>
@@ -265,7 +265,7 @@
ErrorHandler errorHandler) {
Annotation found = null;
for (Annotation annotation : annotations) {
- if (annotation.annotationType().getAnnotation(ForBinding.class) != null) {
+ if (annotation.annotationType().getAnnotation(Binder.class) != null) {
if (found == null) {
found = annotation;
} else {
diff --git a/src/com/google/inject/Scopes.java b/src/com/google/inject/Scopes.java
index 4f9b876..ff3d068 100644
--- a/src/com/google/inject/Scopes.java
+++ b/src/com/google/inject/Scopes.java
@@ -16,11 +16,8 @@
package com.google.inject;
-import com.google.inject.util.SurrogateAnnotations;
-import com.google.inject.util.DuplicateAnnotationException;
-
-import java.util.Map;
import java.lang.annotation.Annotation;
+import java.util.Map;
/**
* Built in scope implementations.
@@ -45,7 +42,7 @@
};
/**
- * One instance per container.
+ * One instance per container. Also see {@code @}{@link ContainerScoped}.
*/
public static final Scope CONTAINER = new Scope() {
public <T> Factory<T> scope(Key<T> key, final Factory<T> creator) {
diff --git a/src/com/google/inject/ForBinding.java b/src/com/google/inject/Stage.java
similarity index 67%
copy from src/com/google/inject/ForBinding.java
copy to src/com/google/inject/Stage.java
index 637d541..7b65a70 100644
--- a/src/com/google/inject/ForBinding.java
+++ b/src/com/google/inject/Stage.java
@@ -16,16 +16,22 @@
package com.google.inject;
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
/**
- * Annotates annotations which are used for binding.
+ * The stage we're running in.
*
* @author crazybob@google.com (Bob Lee)
*/
-@Target({ ElementType.ANNOTATION_TYPE })
-@Retention(RUNTIME)
-public @interface ForBinding {}
+public enum Stage {
+
+ /**
+ * We want fast startup times and better error reporting at the expense of
+ * runtime performance and some up front error checking.
+ */
+ DEVELOPMENT,
+
+ /**
+ * We want to catch errors as early as possible and take performance hits
+ * up front.
+ */
+ PRODUCTION
+}
diff --git a/src/com/google/inject/name/Named.java b/src/com/google/inject/name/Named.java
index 5691814..844d51d 100644
--- a/src/com/google/inject/name/Named.java
+++ b/src/com/google/inject/name/Named.java
@@ -18,7 +18,7 @@
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import com.google.inject.ForBinding;
+import com.google.inject.Binder;
/**
* Annotates named things.
@@ -26,7 +26,7 @@
* @author crazybob@google.com (Bob Lee)
*/
@Retention(RUNTIME)
-@ForBinding
+@Binder
public @interface Named {
String value();
}
diff --git a/src/com/google/inject/name/Names.java b/src/com/google/inject/name/Names.java
index ed074f0..81e8308 100644
--- a/src/com/google/inject/name/Names.java
+++ b/src/com/google/inject/name/Names.java
@@ -35,7 +35,7 @@
/**
* Creates a {@link Named} annotation with {@code name} as the value.
*/
- public static Named annotationFor(String name) {
+ public static Named named(String name) {
return new NamedImpl(name);
}
diff --git a/src/com/google/inject/ForBinding.java b/src/com/google/inject/name/package-info.java
similarity index 60%
copy from src/com/google/inject/ForBinding.java
copy to src/com/google/inject/name/package-info.java
index 637d541..333fb45 100644
--- a/src/com/google/inject/ForBinding.java
+++ b/src/com/google/inject/name/package-info.java
@@ -14,18 +14,7 @@
* limitations under the License.
*/
-package com.google.inject;
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
/**
- * Annotates annotations which are used for binding.
- *
- * @author crazybob@google.com (Bob Lee)
+ * Support for binding to string-based names.
*/
-@Target({ ElementType.ANNOTATION_TYPE })
-@Retention(RUNTIME)
-public @interface ForBinding {}
+package com.google.inject.name;
\ No newline at end of file
diff --git a/src/com/google/inject/servlet/RequestParameters.java b/src/com/google/inject/servlet/RequestParameters.java
index 403f6e6..2d97bba 100644
--- a/src/com/google/inject/servlet/RequestParameters.java
+++ b/src/com/google/inject/servlet/RequestParameters.java
@@ -20,7 +20,7 @@
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import com.google.inject.ForBinding;
+import com.google.inject.Binder;
/**
* Apply this to field or parameters of type {@code Map<String, String[]>}
@@ -30,5 +30,5 @@
*/
@Retention(RUNTIME)
@Target({ ElementType.FIELD, ElementType.PARAMETER })
-@ForBinding
+@Binder
public @interface RequestParameters {}
diff --git a/src/com/google/inject/servlet/SessionScoped.java b/src/com/google/inject/servlet/SessionScoped.java
index 8bd679c..781c270 100644
--- a/src/com/google/inject/servlet/SessionScoped.java
+++ b/src/com/google/inject/servlet/SessionScoped.java
@@ -24,6 +24,7 @@
/**
* Apply this to implementation classes when you want one instance per session.
*
+ * @see com.google.inject.Scopes#CONTAINER
* @author crazybob@google.com (Bob Lee)
*/
@Target(ElementType.TYPE)
diff --git a/src/com/google/inject/ForBinding.java b/src/com/google/inject/servlet/package-info.java
similarity index 60%
copy from src/com/google/inject/ForBinding.java
copy to src/com/google/inject/servlet/package-info.java
index 637d541..945df9f 100644
--- a/src/com/google/inject/ForBinding.java
+++ b/src/com/google/inject/servlet/package-info.java
@@ -14,18 +14,11 @@
* limitations under the License.
*/
-package com.google.inject;
-
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
/**
- * Annotates annotations which are used for binding.
- *
- * @author crazybob@google.com (Bob Lee)
+ * Servlet API scopes and bindings. Apply {@link
+ * com.google.inject.servlet.GuiceFilter} to any servlets which will use the
+ * servlet scopes. Install {@link com.google.inject.servlet.ServletModule}
+ * into your {@link com.google.inject.ContainerBuilder} to install everything
+ * at once.
*/
-@Target({ ElementType.ANNOTATION_TYPE })
-@Retention(RUNTIME)
-public @interface ForBinding {}
+package com.google.inject.servlet;
\ No newline at end of file
diff --git a/test/com/google/inject/CircularDependencyTest.java b/test/com/google/inject/CircularDependencyTest.java
index c084706..6ae306b 100644
--- a/test/com/google/inject/CircularDependencyTest.java
+++ b/test/com/google/inject/CircularDependencyTest.java
@@ -29,7 +29,7 @@
builder.bind(A.class).to(AImpl.class);
builder.bind(B.class).to(BImpl.class);
- Container container = builder.create(false);
+ Container container = builder.create();
A a = container.getFactory(AImpl.class).get();
assertNotNull(a.getB().getA());
}
diff --git a/test/com/google/inject/ConstantConversionTest.java b/test/com/google/inject/ConstantConversionTest.java
index fdebfed..a610e79 100644
--- a/test/com/google/inject/ConstantConversionTest.java
+++ b/test/com/google/inject/ConstantConversionTest.java
@@ -18,8 +18,6 @@
import junit.framework.TestCase;
-import java.util.Map;
-import java.util.HashMap;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@@ -29,20 +27,16 @@
public class ConstantConversionTest extends TestCase {
@Retention(RUNTIME)
- @ForBinding
- @interface NumericValue {}
+ @Binder @interface NumericValue {}
@Retention(RUNTIME)
- @ForBinding
- @interface BooleanValue {}
+ @Binder @interface BooleanValue {}
@Retention(RUNTIME)
- @ForBinding
- @interface EnumValue {}
+ @Binder @interface EnumValue {}
@Retention(RUNTIME)
- @ForBinding
- @interface ClassName {}
+ @Binder @interface ClassName {}
public static class Foo {
@Inject @NumericValue Integer integerField;
@@ -71,7 +65,7 @@
ContainerBuilder builder = new ContainerBuilder();
builder.bindConstant(NumericValue.class).to("5");
builder.bind(Simple.class);
- Container container = builder.create(false);
+ Container container = builder.create();
Simple simple = container.getFactory(Simple.class).get();
assertEquals(5, simple.i);
}
@@ -86,7 +80,7 @@
b.bindConstant(BooleanValue.class).to("true");
b.bindConstant(EnumValue.class).to("TEE");
b.bindConstant(ClassName.class).to(Foo.class.getName());
- Container c = b.create(false);
+ Container c = b.create();
Foo foo = c.getFactory(Foo.class).get();
checkNumbers(
@@ -117,7 +111,7 @@
public void testInvalidInteger() throws ContainerCreationException {
ContainerBuilder b = new ContainerBuilder();
b.bindConstant(NumericValue.class).to("invalid");
- Container c = b.create(false);
+ Container c = b.create();
try {
c.getFactory(InvalidInteger.class).get();
fail();
@@ -131,7 +125,7 @@
public void testInvalidCharacter() throws ContainerCreationException {
ContainerBuilder b = new ContainerBuilder();
b.bindConstant(NumericValue.class).to("invalid");
- Container c = b.create(false);
+ Container c = b.create();
try {
c.getFactory(InvalidCharacter.class).get();
fail();
@@ -145,7 +139,7 @@
public void testInvalidEnum() throws ContainerCreationException {
ContainerBuilder b = new ContainerBuilder();
b.bindConstant(NumericValue.class).to("invalid");
- Container c = b.create(false);
+ Container c = b.create();
try {
c.getFactory(InvalidEnum.class).get();
fail();
diff --git a/test/com/google/inject/ContainerTest.java b/test/com/google/inject/ContainerTest.java
index 3457998..b181be6 100644
--- a/test/com/google/inject/ContainerTest.java
+++ b/test/com/google/inject/ContainerTest.java
@@ -26,16 +26,13 @@
public class ContainerTest extends TestCase {
@Retention(RUNTIME)
- @ForBinding
- @interface Other {}
+ @Binder @interface Other {}
@Retention(RUNTIME)
- @ForBinding
- @interface S {}
+ @Binder @interface S {}
@Retention(RUNTIME)
- @ForBinding
- @interface I {}
+ @Binder @interface I {}
public void testFactoryMethods() throws ContainerCreationException {
Singleton singleton = new Singleton();
@@ -46,7 +43,7 @@
builder.bind(Singleton.class)
.annotatedWith(Other.class)
.to(other);
- Container container = builder.create(true);
+ Container container = builder.create();
assertSame(singleton,
container.getFactory(Key.get(Singleton.class)).get());
@@ -97,7 +94,7 @@
}
});
- return builder.create(false);
+ return builder.create();
}
public void testGetInstance() throws ContainerCreationException {
@@ -112,7 +109,7 @@
throws ContainerCreationException {
ContainerBuilder builder = new ContainerBuilder();
builder.bindConstant(I.class).to(5);
- Container container = builder.create(false);
+ Container container = builder.create();
IntegerWrapper iw = container.getFactory(IntegerWrapper.class).get();
assertEquals(5, (int) iw.i);
}
@@ -194,7 +191,7 @@
builder.bind(A.class).to(AImpl.class);
builder.bind(B.class).to(BImpl.class);
- Container container = builder.create(false);
+ Container container = builder.create();
A a = container.getFactory(AImpl.class).get();
assertNotNull(a.getB().getA());
}
@@ -233,7 +230,7 @@
builder.bindConstant(S.class).to("test");
builder.bindConstant(I.class).to(5);
builder.requestStaticInjection(Static.class);
- builder.create(false);
+ builder.create();
assertEquals("test", Static.s);
assertEquals(5, Static.i);
diff --git a/test/com/google/inject/ErrorHandlingTest.java b/test/com/google/inject/ErrorHandlingTest.java
index b4e97f9..76cfa49 100644
--- a/test/com/google/inject/ErrorHandlingTest.java
+++ b/test/com/google/inject/ErrorHandlingTest.java
@@ -28,7 +28,7 @@
public static void main(String[] args) throws ContainerCreationException {
ContainerBuilder builder = new ContainerBuilder();
builder.install(new MyModule());
- builder.create(true);
+ builder.create();
}
@Inject @Named("missing")
@@ -69,7 +69,7 @@
bind(Bar.class);
bind(Tee.class);
bind(new TypeLiteral<List<String>>() {});
- bind(String.class).annotatedWith(Names.annotationFor("foo")).in(
+ bind(String.class).annotatedWith(Names.named("foo")).in(
Named.class);
link(Key.get(Runnable.class)).to(Key.get(Runnable.class));
requestStaticInjection(ErrorHandlingTest.class);
diff --git a/test/com/google/inject/FactoryInjectionTest.java b/test/com/google/inject/FactoryInjectionTest.java
index 3b92b50..ab0bebf 100644
--- a/test/com/google/inject/FactoryInjectionTest.java
+++ b/test/com/google/inject/FactoryInjectionTest.java
@@ -29,7 +29,7 @@
builder.bind(Bar.class);
builder.bind(ContainerScoped.class).in(Scopes.CONTAINER);
- Container container = builder.create(false);
+ Container container = builder.create();
Foo foo = container.getFactory(Foo.class).get();
diff --git a/test/com/google/inject/FactoryTest.java b/test/com/google/inject/FactoryTest.java
index 97cffb3..fa8cd4d 100644
--- a/test/com/google/inject/FactoryTest.java
+++ b/test/com/google/inject/FactoryTest.java
@@ -53,7 +53,7 @@
}
});
- Container c = cb.create(false);
+ Container c = cb.create();
A a = c.getFactory(A.class).get();
@@ -80,31 +80,25 @@
static class NegativeOne {}
@Retention(RUNTIME)
- @ForBinding
- @interface FooAnnotation {}
+ @Binder @interface FooAnnotation {}
@Retention(RUNTIME)
- @ForBinding
- @interface BarAnnotation {}
+ @Binder @interface BarAnnotation {}
@Retention(RUNTIME)
- @ForBinding
- @interface TeeAnnotation1 {}
+ @Binder @interface TeeAnnotation1 {}
@Retention(RUNTIME)
- @ForBinding
- @interface TeeAnnotation2 {}
+ @Binder @interface TeeAnnotation2 {}
@Retention(RUNTIME)
- @ForBinding
- @interface BobAnnotation1 {}
+ @Binder @interface BobAnnotation1 {}
@Retention(RUNTIME)
- @ForBinding
- @interface BobAnnotation2 {}
+ @Binder @interface BobAnnotation2 {}
public void testInjection() throws Exception {
- ContainerBuilder cb = new ContainerBuilder();
+ ContainerBuilder cb = new ContainerBuilder(Stage.PRODUCTION);
// Called from getInstance().
cb.bind(Foo.class)
@@ -134,7 +128,7 @@
cb.bind(Bob.class).annotatedWith(BobAnnotation2.class).to(
createFactory(Bob.class, BobAnnotation2.class, execute));
- Container c = cb.create(true);
+ Container c = cb.create();
Foo foo = c.getFactory(Key.get(Foo.class, FooAnnotation.class)).get();
diff --git a/test/com/google/inject/GenericInjectionTest.java b/test/com/google/inject/GenericInjectionTest.java
index b18b62b..1f8c9bb 100644
--- a/test/com/google/inject/GenericInjectionTest.java
+++ b/test/com/google/inject/GenericInjectionTest.java
@@ -30,7 +30,7 @@
List<String> names = Arrays.asList("foo", "bar", "bob");
ContainerBuilder builder = new ContainerBuilder();
builder.bind(new TypeLiteral<List<String>>() {}).to(names);
- Container container = builder.create(false);
+ Container container = builder.create();
Foo foo = container.getFactory(Foo.class).get();
assertEquals(names, foo.names);
}
diff --git a/test/com/google/inject/ImplicitBindingTest.java b/test/com/google/inject/ImplicitBindingTest.java
index 6ea31ed..7d4d33b 100644
--- a/test/com/google/inject/ImplicitBindingTest.java
+++ b/test/com/google/inject/ImplicitBindingTest.java
@@ -25,7 +25,7 @@
public void testCircularDependency() throws ContainerCreationException {
ContainerBuilder builder = new ContainerBuilder();
- Container container = builder.create(true);
+ Container container = builder.create();
Foo foo = container.getInstance(Foo.class);
assertSame(foo, foo.bar.foo);
}
diff --git a/test/com/google/inject/IntegrationTest.java b/test/com/google/inject/IntegrationTest.java
index a858eef..7201dcb 100644
--- a/test/com/google/inject/IntegrationTest.java
+++ b/test/com/google/inject/IntegrationTest.java
@@ -34,7 +34,7 @@
ContainerBuilder containerBuilder = new ContainerBuilder();
containerBuilder.bind(Foo.class);
containerBuilder.intercept(any(), any(), counter);
- Container container = containerBuilder.create(false);
+ Container container = containerBuilder.create();
Foo foo = container.getFactory(Key.get(Foo.class)).get();
foo.foo();
diff --git a/test/com/google/inject/KeyTest.java b/test/com/google/inject/KeyTest.java
index a4778c1..5d8de98 100644
--- a/test/com/google/inject/KeyTest.java
+++ b/test/com/google/inject/KeyTest.java
@@ -32,8 +32,7 @@
public void foo(List<String> a, List<String> b) {}
@Retention(RUNTIME)
- @ForBinding
- @interface Foo {}
+ @Binder @interface Foo {}
public void testOfType() {
Key<Object> k = Key.get(Object.class, Foo.class);
diff --git a/test/com/google/inject/NotRequiredTest.java b/test/com/google/inject/NotRequiredTest.java
index 784cb65..e6dd10d 100644
--- a/test/com/google/inject/NotRequiredTest.java
+++ b/test/com/google/inject/NotRequiredTest.java
@@ -26,14 +26,14 @@
public void testProvided() throws ContainerCreationException {
ContainerBuilder builder = new ContainerBuilder();
builder.bind(Bar.class).to(BarImpl.class);
- Container c = builder.create(false);
+ Container c = builder.create();
Foo foo = c.getFactory(Foo.class).get();
assertNotNull(foo.bar);
assertNotNull(foo.fromMethod);
}
public void testNotProvided() throws ContainerCreationException {
- Container c = new ContainerBuilder().create(false);
+ Container c = new ContainerBuilder().create();
Foo foo = c.getFactory(Foo.class).get();
assertNull(foo.bar);
assertNull(foo.fromMethod);
diff --git a/test/com/google/inject/PerformanceComparison.java b/test/com/google/inject/PerformanceComparison.java
index 8827c3a..9f91e09 100644
--- a/test/com/google/inject/PerformanceComparison.java
+++ b/test/com/google/inject/PerformanceComparison.java
@@ -109,7 +109,7 @@
});
try {
- fooFactory = builder.create(false).getFactory(Foo.class);
+ fooFactory = builder.create().getFactory(Foo.class);
} catch (ContainerCreationException e) {
throw new RuntimeException(e);
}
@@ -231,10 +231,8 @@
}
@Retention(RUNTIME)
- @ForBinding
- @interface I {}
+ @Binder @interface I {}
@Retention(RUNTIME)
- @ForBinding
- @interface S {}
+ @Binder @interface S {}
}
diff --git a/test/com/google/inject/PreloadingTest.java b/test/com/google/inject/PreloadingTest.java
index a03dfff..de4a86f 100644
--- a/test/com/google/inject/PreloadingTest.java
+++ b/test/com/google/inject/PreloadingTest.java
@@ -31,21 +31,21 @@
}
public void testPreloadSome() throws ContainerCreationException {
- ContainerBuilder builder = createContainerBuilder();
- builder.create(false);
+ ContainerBuilder builder = createContainerBuilder(Stage.DEVELOPMENT);
+ builder.create();
assertEquals(1, Foo.count);
assertEquals(0, Bar.count);
}
public void testPreloadAll() throws ContainerCreationException {
- ContainerBuilder builder = createContainerBuilder();
- builder.create(true);
+ ContainerBuilder builder = createContainerBuilder(Stage.PRODUCTION);
+ builder.create();
assertEquals(1, Foo.count);
assertEquals(1, Bar.count);
}
- private ContainerBuilder createContainerBuilder() {
- ContainerBuilder builder = new ContainerBuilder();
+ private ContainerBuilder createContainerBuilder(Stage stage) {
+ ContainerBuilder builder = new ContainerBuilder(stage);
builder.bind(Foo.class).in(CONTAINER).preload();
builder.bind(Bar.class);
return builder;
@@ -55,7 +55,7 @@
ContainerBuilder builder = new ContainerBuilder();
builder.bind(Foo.class).preload();
try {
- builder.create(false);
+ builder.create();
fail();
} catch (ContainerCreationException e) { /* expected */ }
}
diff --git a/test/com/google/inject/ReflectionTest.java b/test/com/google/inject/ReflectionTest.java
index 3fc62d5..3e6cc54 100644
--- a/test/com/google/inject/ReflectionTest.java
+++ b/test/com/google/inject/ReflectionTest.java
@@ -26,14 +26,13 @@
public class ReflectionTest extends TestCase {
@Retention(RUNTIME)
- @ForBinding
- @interface I {}
+ @Binder @interface I {}
public void testNormalBinding() throws ContainerCreationException {
ContainerBuilder builder = new ContainerBuilder();
Foo foo = new Foo();
builder.bind(Foo.class).to(foo);
- Container container = builder.create(false);
+ Container container = builder.create();
Binding<Foo> fooBinding = container.getBinding(Key.get(Foo.class));
assertSame(foo, fooBinding.getFactory().get());
assertNotNull(fooBinding.getSource());
@@ -44,7 +43,7 @@
public void testConstantBinding() throws ContainerCreationException {
ContainerBuilder builder = new ContainerBuilder();
builder.bindConstant(I.class).to(5);
- Container container = builder.create(false);
+ Container container = builder.create();
Binding<?> i = container.getBinding(Key.get(int.class, I.class));
assertEquals(5, i.getFactory().get());
assertNotNull(i.getSource());
@@ -57,7 +56,7 @@
Bar bar = new Bar();
builder.bind(Bar.class).to(bar);
builder.link(Key.get(Foo.class)).to(Key.get(Bar.class));
- Container container = builder.create(false);
+ Container container = builder.create();
Binding<Foo> fooBinding = container.getBinding(Key.get(Foo.class));
assertSame(bar, fooBinding.getFactory().get());
assertNotNull(fooBinding.getSource());
diff --git a/test/com/google/inject/ScopesTest.java b/test/com/google/inject/ScopesTest.java
index 114d2d0..18e16fc 100644
--- a/test/com/google/inject/ScopesTest.java
+++ b/test/com/google/inject/ScopesTest.java
@@ -18,11 +18,6 @@
import junit.framework.TestCase;
-import java.lang.annotation.Target;
-import java.lang.annotation.Retention;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.RetentionPolicy;
-
/**
* @author crazybob@google.com (Bob Lee)
*/
@@ -33,7 +28,7 @@
ContainerBuilder builder = new ContainerBuilder();
Object bindingBuilder
= builder.bind(Singleton.class);
- builder.create(false);
+ builder.create();
assertSame(Scopes.CONTAINER,
((ContainerBuilder.BindingBuilder<?>) bindingBuilder).scope);
}
@@ -46,7 +41,7 @@
ContainerBuilder builder = new ContainerBuilder();
Object bindingBuilder
= builder.bind(Singleton.class).in(Scopes.DEFAULT);
- builder.create(false);
+ builder.create();
assertSame(Scopes.DEFAULT,
((ContainerBuilder.BindingBuilder<?>) bindingBuilder).scope);
}
@@ -55,7 +50,7 @@
ContainerBuilder builder = new ContainerBuilder();
builder.bind(Singleton.class).to(new Singleton()).in(Scopes.DEFAULT);
try {
- builder.create(false);
+ builder.create();
fail();
} catch (ContainerCreationException e) { /* expected */ }
}
diff --git a/test/com/google/inject/StaticInjectionTest.java b/test/com/google/inject/StaticInjectionTest.java
index c29d564..c7fe09b 100644
--- a/test/com/google/inject/StaticInjectionTest.java
+++ b/test/com/google/inject/StaticInjectionTest.java
@@ -26,12 +26,10 @@
public class StaticInjectionTest extends TestCase {
@Retention(RUNTIME)
- @ForBinding
- @interface I {}
+ @Binder @interface I {}
@Retention(RUNTIME)
- @ForBinding
- @interface S {}
+ @Binder @interface S {}
public void testInjectStatics() throws ContainerCreationException {
ContainerBuilder builder = new ContainerBuilder();
@@ -39,7 +37,7 @@
builder.bindConstant(I.class).to(5);
builder.requestStaticInjection(StaticInjectionTest.Static.class);
- Container c = builder.create(false);
+ Container c = builder.create();
assertEquals("test", StaticInjectionTest.Static.s);
assertEquals(5, StaticInjectionTest.Static.i);
diff --git a/test/com/google/inject/SuperclassTest.java b/test/com/google/inject/SuperclassTest.java
index 935146a..9b9b975 100644
--- a/test/com/google/inject/SuperclassTest.java
+++ b/test/com/google/inject/SuperclassTest.java
@@ -26,7 +26,7 @@
public void testSuperclassInjection() throws ContainerCreationException {
ContainerBuilder builder = new ContainerBuilder();
builder.bind(Foo.class);
- Container container = builder.create(false);
+ Container container = builder.create();
Factory<Sub> creator = container.getFactory(Sub.class);
Sub sub = creator.get();
sub = creator.get();
diff --git a/test/com/google/inject/servlet/ServletTest.java b/test/com/google/inject/servlet/ServletTest.java
index a8baca1..b72332a 100644
--- a/test/com/google/inject/servlet/ServletTest.java
+++ b/test/com/google/inject/servlet/ServletTest.java
@@ -178,7 +178,7 @@
builder.install(new ServletModule());
builder.bind(InSession.class);
builder.bind(InRequest.class);
- return builder.create(false);
+ return builder.create();
}
@SessionScoped