• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.spi;
18 
19 import com.google.inject.Binding;
20 
21 /**
22  * No-op visitor for subclassing. All interface methods simply delegate to {@link
23  * #visitOther(Binding)}, returning its result.
24  *
25  * @param <V> any type to be returned by the visit method. Use {@link Void} with {@code return null}
26  *     if no return type is needed.
27  * @author jessewilson@google.com (Jesse Wilson)
28  * @since 2.0
29  */
30 public abstract class DefaultBindingTargetVisitor<T, V> implements BindingTargetVisitor<T, V> {
31 
32   /** Default visit implementation. Returns {@code null}. */
visitOther(Binding<? extends T> binding)33   protected V visitOther(Binding<? extends T> binding) {
34     return null;
35   }
36 
37   @Override
visit(InstanceBinding<? extends T> instanceBinding)38   public V visit(InstanceBinding<? extends T> instanceBinding) {
39     return visitOther(instanceBinding);
40   }
41 
42   @Override
visit(ProviderInstanceBinding<? extends T> providerInstanceBinding)43   public V visit(ProviderInstanceBinding<? extends T> providerInstanceBinding) {
44     return visitOther(providerInstanceBinding);
45   }
46 
47   @Override
visit(ProviderKeyBinding<? extends T> providerKeyBinding)48   public V visit(ProviderKeyBinding<? extends T> providerKeyBinding) {
49     return visitOther(providerKeyBinding);
50   }
51 
52   @Override
visit(LinkedKeyBinding<? extends T> linkedKeyBinding)53   public V visit(LinkedKeyBinding<? extends T> linkedKeyBinding) {
54     return visitOther(linkedKeyBinding);
55   }
56 
57   @Override
visit(ExposedBinding<? extends T> exposedBinding)58   public V visit(ExposedBinding<? extends T> exposedBinding) {
59     return visitOther(exposedBinding);
60   }
61 
62   @Override
visit(UntargettedBinding<? extends T> untargettedBinding)63   public V visit(UntargettedBinding<? extends T> untargettedBinding) {
64     return visitOther(untargettedBinding);
65   }
66 
67   @Override
visit(ConstructorBinding<? extends T> constructorBinding)68   public V visit(ConstructorBinding<? extends T> constructorBinding) {
69     return visitOther(constructorBinding);
70   }
71 
72   @Override
visit(ConvertedConstantBinding<? extends T> convertedConstantBinding)73   public V visit(ConvertedConstantBinding<? extends T> convertedConstantBinding) {
74     return visitOther(convertedConstantBinding);
75   }
76 
77   @Override
78   @SuppressWarnings("unchecked")
visit(ProviderBinding<? extends T> providerBinding)79   public V visit(ProviderBinding<? extends T> providerBinding) {
80     // TODO(cushon): remove raw (Binding) cast when we don't care about javac 6 anymore
81     return visitOther((Binding<? extends T>) (Binding) providerBinding);
82   }
83 }
84