01: /**
02: * Copyright (C) 2006 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */package com.google.inject;
16:
17: import static java.lang.annotation.ElementType.CONSTRUCTOR;
18: import static java.lang.annotation.ElementType.FIELD;
19: import static java.lang.annotation.ElementType.METHOD;
20: import java.lang.annotation.Retention;
21: import static java.lang.annotation.RetentionPolicy.RUNTIME;
22: import java.lang.annotation.Target;
23:
24: /**
25: * Annotates members of your implementation class (constructors, methods
26: * and fields) into which the {@link Injector} should inject values.
27: * The Injector fulfills injection requests for:
28: *
29: * <ul>
30: * <li>Every instance it constructs. The class being constructed must have
31: * exactly one of its constructors marked with {@code @Inject} or must have a
32: * constructor taking no parameters. The Injector then proceeds to perform
33: * method and field injections.
34: *
35: * <li>Pre-constructed instances passed to {@link Injector#injectMembers},
36: * {@link com.google.inject.binder.LinkedBindingBuilder#toInstance(Object)} and
37: * {@link com.google.inject.binder.LinkedBindingBuilder#toProvider(Provider)}.
38: * In this case all constructors are, of course, ignored.
39: *
40: * <li>Static fields and methods of classes which any {@link Module} has
41: * specifically requested static injection for, using
42: * {@link Binder#requestStaticInjection}.
43: * </ul>
44: *
45: * In all cases, a member can be injected regardless of its Java access
46: * specifier (private, default, protected, public).
47: *
48: * @author crazybob@google.com (Bob Lee)
49: */
50: @Target({METHOD,CONSTRUCTOR,FIELD})
51: @Retention(RUNTIME)
52: public @interface Inject {
53:
54: /**
55: * If true, and the appropriate binding is not found,
56: * the Injector will skip injection of this method or field rather than
57: * produce an error. When applied to a field, any default value already
58: * assigned to the field will remain (guice will not actively null out the
59: * field). When applied to a method, the method will only be invoked if
60: * bindings for <i>all</i> parameters are found. When applied to a
61: * constructor, an error will result upon Injector creation.
62: */
63: boolean optional() default false;
64: }
|