• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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  */
16 
17 package com.google.inject.spi;
18 
19 import com.google.inject.TypeLiteral;
20 
21 /**
22  * Listens for Guice to encounter injectable types. If a given type has its constructor injected in
23  * one situation but only its methods and fields injected in another, Guice will notify this
24  * listener once.
25  *
26  * <p>Useful for extra type checking, {@linkplain TypeEncounter#register(InjectionListener)
27  * registering injection listeners}, and {@linkplain TypeEncounter#bindInterceptor(
28  * com.google.inject.matcher.Matcher, org.aopalliance.intercept.MethodInterceptor[]) binding method
29  * interceptors}.
30  *
31  * @since 2.0
32  */
33 public interface TypeListener {
34 
35   /**
36    * Invoked when Guice encounters a new type eligible for constructor or members injection. Called
37    * during injector creation (or afterwards if Guice encounters a type at run time and creates a
38    * JIT binding).
39    *
40    * @param type encountered by Guice
41    * @param encounter context of this encounter, enables reporting errors, registering injection
42    *     listeners and binding method interceptors for {@code type}.
43    * @param <I> the injectable type
44    */
hear(TypeLiteral<I> type, TypeEncounter<I> encounter)45   <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter);
46 }
47