limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +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 | |
| 18 | package com.google.inject.spi; |
| 19 | |
| 20 | import com.google.inject.Binding; |
| 21 | |
| 22 | /** |
| 23 | * No-op visitor for subclassing. All interface methods simply delegate to |
| 24 | * {@link #visitElement(Element)}, returning its result. |
| 25 | * |
limpbizkit | 00ca9f7 | 2008-08-02 17:56:17 +0000 | [diff] [blame] | 26 | * @param <V> any type to be returned by the visit method. Use {@link Void} with |
| 27 | * {@code return null} if no return type is needed. |
| 28 | * |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 29 | * @author sberlin@gmail.com (Sam Berlin) |
| 30 | */ |
limpbizkit | afa4b5d | 2008-08-02 18:40:47 +0000 | [diff] [blame^] | 31 | public abstract class DefaultElementVisitor<V> implements ElementVisitor<V> { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 32 | |
| 33 | protected DefaultElementVisitor() {} |
| 34 | |
| 35 | /** |
| 36 | * Visit {@code element} and return a result. |
| 37 | */ |
| 38 | protected V visitElement(Element element) { |
| 39 | return null; |
| 40 | } |
| 41 | |
| 42 | public V visitMessage(Message message) { |
| 43 | return visitElement(message); |
| 44 | } |
| 45 | |
| 46 | public <T> V visitBinding(Binding<T> command) { |
| 47 | return visitElement(command); |
| 48 | } |
| 49 | |
limpbizkit | 00ca9f7 | 2008-08-02 17:56:17 +0000 | [diff] [blame] | 50 | public V visitInterceptorBinding(InterceptorBinding command) { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 51 | return visitElement(command); |
| 52 | } |
| 53 | |
limpbizkit | 00ca9f7 | 2008-08-02 17:56:17 +0000 | [diff] [blame] | 54 | public V visitScopeBinding(ScopeBinding command) { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 55 | return visitElement(command); |
| 56 | } |
| 57 | |
limpbizkit | 00ca9f7 | 2008-08-02 17:56:17 +0000 | [diff] [blame] | 58 | public V visitTypeConverterBinding(TypeConverterBinding command) { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 59 | return visitElement(command); |
| 60 | } |
| 61 | |
limpbizkit | 00ca9f7 | 2008-08-02 17:56:17 +0000 | [diff] [blame] | 62 | public <T> V visitProviderLookup(ProviderLookup<T> command) { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 63 | return visitElement(command); |
| 64 | } |
| 65 | |
limpbizkit | 00ca9f7 | 2008-08-02 17:56:17 +0000 | [diff] [blame] | 66 | public V visitInjectionRequest(InjectionRequest command) { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 67 | return visitElement(command); |
| 68 | } |
| 69 | |
limpbizkit | 00ca9f7 | 2008-08-02 17:56:17 +0000 | [diff] [blame] | 70 | public V visitStaticInjectionRequest(StaticInjectionRequest command) { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 71 | return visitElement(command); |
| 72 | } |
| 73 | } |