limpbizkit | 97eac0f | 2009-03-28 18:25:35 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2008 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; |
| 18 | |
| 19 | import com.google.inject.internal.Errors; |
| 20 | import com.google.inject.internal.ErrorsException; |
| 21 | import com.google.inject.spi.MembersInjectorLookup; |
| 22 | import com.google.inject.spi.ProviderLookup; |
| 23 | |
| 24 | /** |
| 25 | * Handles {@link Binder#getProvider} and {@link Binder#getMembersInjector(TypeLiteral)} commands. |
| 26 | * |
| 27 | * @author crazybob@google.com (Bob Lee) |
| 28 | * @author jessewilson@google.com (Jesse Wilson) |
| 29 | */ |
| 30 | class LookupProcessor extends AbstractProcessor { |
| 31 | |
| 32 | LookupProcessor(Errors errors) { |
| 33 | super(errors); |
| 34 | } |
| 35 | |
| 36 | @Override public <T> Boolean visit(MembersInjectorLookup<T> lookup) { |
| 37 | try { |
| 38 | MembersInjector<T> membersInjector |
limpbizkit | 7cef5b0 | 2009-03-29 21:16:51 +0000 | [diff] [blame] | 39 | = injector.membersInjectorStore.get(lookup.getType(), errors); |
limpbizkit | 97eac0f | 2009-03-28 18:25:35 +0000 | [diff] [blame] | 40 | lookup.initializeDelegate(membersInjector); |
| 41 | } catch (ErrorsException e) { |
| 42 | errors.merge(e.getErrors()); // TODO: source |
| 43 | } |
| 44 | |
| 45 | return true; |
| 46 | } |
| 47 | |
| 48 | @Override public <T> Boolean visit(ProviderLookup<T> lookup) { |
| 49 | // ensure the provider can be created |
| 50 | try { |
| 51 | Provider<T> provider = injector.getProviderOrThrow(lookup.getKey(), errors); |
| 52 | lookup.initializeDelegate(provider); |
| 53 | } catch (ErrorsException e) { |
| 54 | errors.merge(e.getErrors()); // TODO: source |
| 55 | } |
| 56 | |
| 57 | return true; |
| 58 | } |
| 59 | } |