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 | package com.google.inject; |
| 18 | |
limpbizkit | b3a8f0b | 2008-09-05 22:30:40 +0000 | [diff] [blame] | 19 | import com.google.inject.internal.Annotations; |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 20 | import com.google.inject.internal.BindingImpl; |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 21 | import com.google.inject.internal.Errors; |
| 22 | import com.google.inject.internal.ErrorsException; |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 23 | import com.google.inject.internal.ExposedBindingImpl; |
limpbizkit | 53664a7 | 2009-02-21 00:25:27 +0000 | [diff] [blame] | 24 | import com.google.inject.internal.ImmutableSet; |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 25 | import com.google.inject.internal.InstanceBindingImpl; |
| 26 | import com.google.inject.internal.InternalFactory; |
| 27 | import com.google.inject.internal.LinkedBindingImpl; |
| 28 | import com.google.inject.internal.LinkedProviderBindingImpl; |
limpbizkit | 53664a7 | 2009-02-21 00:25:27 +0000 | [diff] [blame] | 29 | import com.google.inject.internal.Lists; |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 30 | import com.google.inject.internal.ProviderInstanceBindingImpl; |
limpbizkit | 759662b | 2009-04-26 21:00:24 +0000 | [diff] [blame] | 31 | import com.google.inject.internal.ProviderMethod; |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 32 | import com.google.inject.internal.Scoping; |
| 33 | import com.google.inject.internal.UntargettedBindingImpl; |
limpbizkit | afa4b5d | 2008-08-02 18:40:47 +0000 | [diff] [blame] | 34 | import com.google.inject.spi.BindingTargetVisitor; |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 35 | import com.google.inject.spi.ConstructorBinding; |
| 36 | import com.google.inject.spi.ConvertedConstantBinding; |
| 37 | import com.google.inject.spi.ExposedBinding; |
limpbizkit | b3a8f0b | 2008-09-05 22:30:40 +0000 | [diff] [blame] | 38 | import com.google.inject.spi.InjectionPoint; |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 39 | import com.google.inject.spi.InstanceBinding; |
| 40 | import com.google.inject.spi.LinkedKeyBinding; |
limpbizkit | c3f9284 | 2008-12-30 19:43:47 +0000 | [diff] [blame] | 41 | import com.google.inject.spi.PrivateElements; |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 42 | import com.google.inject.spi.ProviderBinding; |
| 43 | import com.google.inject.spi.ProviderInstanceBinding; |
| 44 | import com.google.inject.spi.ProviderKeyBinding; |
| 45 | import com.google.inject.spi.UntargettedBinding; |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 46 | import java.util.List; |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 47 | import java.util.Set; |
| 48 | |
| 49 | /** |
| 50 | * Handles {@link Binder#bind} and {@link Binder#bindConstant} elements. |
| 51 | * |
| 52 | * @author crazybob@google.com (Bob Lee) |
| 53 | * @author jessewilson@google.com (Jesse Wilson) |
| 54 | */ |
limpbizkit | 00ca9f7 | 2008-08-02 17:56:17 +0000 | [diff] [blame] | 55 | class BindingProcessor extends AbstractProcessor { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 56 | |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 57 | private final List<CreationListener> creationListeners = Lists.newArrayList(); |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 58 | private final Initializer initializer; |
limpbizkit | fcbdf99 | 2008-11-26 02:37:35 +0000 | [diff] [blame] | 59 | private final List<Runnable> uninitializedBindings = Lists.newArrayList(); |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 60 | |
limpbizkit | c3f9284 | 2008-12-30 19:43:47 +0000 | [diff] [blame] | 61 | BindingProcessor(Errors errors, Initializer initializer) { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 62 | super(errors); |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 63 | this.initializer = initializer; |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 64 | } |
| 65 | |
limpbizkit | 03b81a6 | 2009-03-18 05:34:39 +0000 | [diff] [blame] | 66 | @Override public <T> Boolean visit(Binding<T> command) { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 67 | final Object source = command.getSource(); |
| 68 | |
limpbizkit | d1fe130 | 2008-08-01 06:40:18 +0000 | [diff] [blame] | 69 | if (Void.class.equals(command.getKey().getRawType())) { |
limpbizkit | 759662b | 2009-04-26 21:00:24 +0000 | [diff] [blame] | 70 | if (command instanceof ProviderInstanceBinding |
| 71 | && ((ProviderInstanceBinding) command).getProviderInstance() instanceof ProviderMethod) { |
| 72 | errors.voidProviderMethod(); |
| 73 | } else { |
| 74 | errors.missingConstantValues(); |
| 75 | } |
limpbizkit | d1fe130 | 2008-08-01 06:40:18 +0000 | [diff] [blame] | 76 | return true; |
| 77 | } |
| 78 | |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 79 | final Key<T> key = command.getKey(); |
| 80 | Class<? super T> rawType = key.getTypeLiteral().getRawType(); |
| 81 | |
| 82 | if (rawType == Provider.class) { |
| 83 | errors.bindingToProvider(); |
| 84 | return true; |
| 85 | } |
| 86 | |
| 87 | validateKey(command.getSource(), command.getKey()); |
| 88 | |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 89 | final Scoping scoping = Scopes.makeInjectable( |
| 90 | ((BindingImpl<?>) command).getScoping(), injector, errors); |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 91 | |
limpbizkit | afa4b5d | 2008-08-02 18:40:47 +0000 | [diff] [blame] | 92 | command.acceptTargetVisitor(new BindingTargetVisitor<T, Void>() { |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 93 | |
limpbizkit | 03b81a6 | 2009-03-18 05:34:39 +0000 | [diff] [blame] | 94 | public Void visit(InstanceBinding<? extends T> binding) { |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 95 | Set<InjectionPoint> injectionPoints = binding.getInjectionPoints(); |
| 96 | T instance = binding.getInstance(); |
limpbizkit | fcbdf99 | 2008-11-26 02:37:35 +0000 | [diff] [blame] | 97 | Initializable<T> ref = initializer.requestInjection( |
| 98 | injector, instance, source, injectionPoints); |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 99 | ConstantFactory<? extends T> factory = new ConstantFactory<T>(ref); |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 100 | InternalFactory<? extends T> scopedFactory = Scopes.scope(key, injector, factory, scoping); |
limpbizkit | b3a8f0b | 2008-09-05 22:30:40 +0000 | [diff] [blame] | 101 | putBinding(new InstanceBindingImpl<T>(injector, key, source, scopedFactory, injectionPoints, |
| 102 | instance)); |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 103 | return null; |
| 104 | } |
| 105 | |
limpbizkit | 03b81a6 | 2009-03-18 05:34:39 +0000 | [diff] [blame] | 106 | public Void visit(ProviderInstanceBinding<? extends T> binding) { |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 107 | Provider<? extends T> provider = binding.getProviderInstance(); |
| 108 | Set<InjectionPoint> injectionPoints = binding.getInjectionPoints(); |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 109 | Initializable<Provider<? extends T>> initializable = initializer |
limpbizkit | fcbdf99 | 2008-11-26 02:37:35 +0000 | [diff] [blame] | 110 | .<Provider<? extends T>>requestInjection(injector, provider, source, injectionPoints); |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 111 | InternalFactory<T> factory = new InternalFactoryToProviderAdapter<T>(initializable, source); |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 112 | InternalFactory<? extends T> scopedFactory = Scopes.scope(key, injector, factory, scoping); |
| 113 | putBinding(new ProviderInstanceBindingImpl<T>(injector, key, source, scopedFactory, scoping, |
| 114 | provider, injectionPoints)); |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 115 | return null; |
| 116 | } |
| 117 | |
limpbizkit | 03b81a6 | 2009-03-18 05:34:39 +0000 | [diff] [blame] | 118 | public Void visit(ProviderKeyBinding<? extends T> binding) { |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 119 | Key<? extends Provider<? extends T>> providerKey = binding.getProviderKey(); |
limpbizkit | fcbdf99 | 2008-11-26 02:37:35 +0000 | [diff] [blame] | 120 | BoundProviderFactory<T> boundProviderFactory |
| 121 | = new BoundProviderFactory<T>(injector, providerKey, source); |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 122 | creationListeners.add(boundProviderFactory); |
| 123 | InternalFactory<? extends T> scopedFactory = Scopes.scope( |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 124 | key, injector, (InternalFactory<? extends T>) boundProviderFactory, scoping); |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 125 | putBinding(new LinkedProviderBindingImpl<T>( |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 126 | injector, key, source, scopedFactory, scoping, providerKey)); |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 127 | return null; |
| 128 | } |
| 129 | |
limpbizkit | 03b81a6 | 2009-03-18 05:34:39 +0000 | [diff] [blame] | 130 | public Void visit(LinkedKeyBinding<? extends T> binding) { |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 131 | Key<? extends T> linkedKey = binding.getLinkedKey(); |
| 132 | if (key.equals(linkedKey)) { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 133 | errors.recursiveBinding(); |
| 134 | } |
| 135 | |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 136 | FactoryProxy<T> factory = new FactoryProxy<T>(injector, key, linkedKey, source); |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 137 | creationListeners.add(factory); |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 138 | InternalFactory<? extends T> scopedFactory = Scopes.scope(key, injector, factory, scoping); |
| 139 | putBinding( |
| 140 | new LinkedBindingImpl<T>(injector, key, source, scopedFactory, scoping, linkedKey)); |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 141 | return null; |
| 142 | } |
| 143 | |
limpbizkit | 03b81a6 | 2009-03-18 05:34:39 +0000 | [diff] [blame] | 144 | public Void visit(UntargettedBinding<? extends T> untargetted) { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 145 | // Error: Missing implementation. |
| 146 | // Example: bind(Date.class).annotatedWith(Red.class); |
| 147 | // We can't assume abstract types aren't injectable. They may have an |
| 148 | // @ImplementedBy annotation or something. |
limpbizkit | 8ba9788 | 2008-11-04 02:52:54 +0000 | [diff] [blame] | 149 | if (key.hasAnnotationType()) { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 150 | errors.missingImplementation(key); |
| 151 | putBinding(invalidBinding(injector, key, source)); |
| 152 | return null; |
| 153 | } |
| 154 | |
| 155 | // This cast is safe after the preceeding check. |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 156 | final BindingImpl<T> binding; |
| 157 | try { |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 158 | binding = injector.createUnitializedBinding(key, scoping, source, errors); |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 159 | putBinding(binding); |
| 160 | } catch (ErrorsException e) { |
| 161 | errors.merge(e.getErrors()); |
| 162 | putBinding(invalidBinding(injector, key, source)); |
| 163 | return null; |
| 164 | } |
| 165 | |
limpbizkit | fcbdf99 | 2008-11-26 02:37:35 +0000 | [diff] [blame] | 166 | uninitializedBindings.add(new Runnable() { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 167 | public void run() { |
| 168 | try { |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 169 | ((InjectorImpl) binding.getInjector()).initializeBinding( |
| 170 | binding, errors.withSource(source)); |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 171 | } catch (ErrorsException e) { |
| 172 | errors.merge(e.getErrors()); |
| 173 | } |
| 174 | } |
| 175 | }); |
| 176 | |
| 177 | return null; |
| 178 | } |
| 179 | |
limpbizkit | 03b81a6 | 2009-03-18 05:34:39 +0000 | [diff] [blame] | 180 | public Void visit(ExposedBinding<? extends T> binding) { |
limpbizkit | aa07ab0 | 2009-05-15 07:10:43 +0000 | [diff] [blame] | 181 | throw new IllegalArgumentException("Cannot apply a non-module element"); |
limpbizkit | fcbdf99 | 2008-11-26 02:37:35 +0000 | [diff] [blame] | 182 | } |
| 183 | |
limpbizkit | 03b81a6 | 2009-03-18 05:34:39 +0000 | [diff] [blame] | 184 | public Void visit(ConvertedConstantBinding<? extends T> binding) { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 185 | throw new IllegalArgumentException("Cannot apply a non-module element"); |
| 186 | } |
| 187 | |
limpbizkit | 03b81a6 | 2009-03-18 05:34:39 +0000 | [diff] [blame] | 188 | public Void visit(ConstructorBinding<? extends T> binding) { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 189 | throw new IllegalArgumentException("Cannot apply a non-module element"); |
| 190 | } |
| 191 | |
limpbizkit | 03b81a6 | 2009-03-18 05:34:39 +0000 | [diff] [blame] | 192 | public Void visit(ProviderBinding<? extends T> binding) { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 193 | throw new IllegalArgumentException("Cannot apply a non-module element"); |
| 194 | } |
| 195 | }); |
| 196 | |
| 197 | return true; |
| 198 | } |
| 199 | |
limpbizkit | aa07ab0 | 2009-05-15 07:10:43 +0000 | [diff] [blame] | 200 | @Override public Boolean visit(PrivateElements privateElements) { |
| 201 | for (Key<?> key : privateElements.getExposedKeys()) { |
| 202 | bindExposed(privateElements, key); |
| 203 | } |
| 204 | return false; // leave the private elements for the PrivateElementsProcessor to handle |
| 205 | } |
| 206 | |
| 207 | private <T> void bindExposed(PrivateElements privateElements, Key<T> key) { |
| 208 | ExposedKeyFactory<T> exposedKeyFactory = new ExposedKeyFactory<T>(key, privateElements); |
| 209 | creationListeners.add(exposedKeyFactory); |
| 210 | putBinding(new ExposedBindingImpl<T>( |
| 211 | injector, privateElements.getExposedSource(key), key, exposedKeyFactory, privateElements)); |
| 212 | } |
| 213 | |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 214 | private <T> void validateKey(Object source, Key<T> key) { |
limpbizkit | b3a8f0b | 2008-09-05 22:30:40 +0000 | [diff] [blame] | 215 | Annotations.checkForMisplacedScopeAnnotations(key.getRawType(), source, errors); |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 216 | } |
| 217 | |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 218 | <T> UntargettedBindingImpl<T> invalidBinding(InjectorImpl injector, Key<T> key, Object source) { |
| 219 | return new UntargettedBindingImpl<T>(injector, key, source); |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 220 | } |
| 221 | |
limpbizkit | fcbdf99 | 2008-11-26 02:37:35 +0000 | [diff] [blame] | 222 | public void initializeBindings() { |
| 223 | for (Runnable initializer : uninitializedBindings) { |
| 224 | initializer.run(); |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
limpbizkit | c3f9284 | 2008-12-30 19:43:47 +0000 | [diff] [blame] | 228 | public void runCreationListeners() { |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 229 | for (CreationListener creationListener : creationListeners) { |
limpbizkit | c3f9284 | 2008-12-30 19:43:47 +0000 | [diff] [blame] | 230 | creationListener.notify(errors); |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
| 234 | private void putBinding(BindingImpl<?> binding) { |
| 235 | Key<?> key = binding.getKey(); |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 236 | |
| 237 | Class<?> rawType = key.getRawType(); |
| 238 | if (FORBIDDEN_TYPES.contains(rawType)) { |
| 239 | errors.cannotBindToGuiceType(rawType.getSimpleName()); |
| 240 | return; |
| 241 | } |
| 242 | |
limpbizkit | fcbdf99 | 2008-11-26 02:37:35 +0000 | [diff] [blame] | 243 | Binding<?> original = injector.state.getExplicitBinding(key); |
| 244 | if (original != null && !isOkayDuplicate(original, binding)) { |
| 245 | errors.bindingAlreadySet(key, original.getSource()); |
| 246 | return; |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 247 | } |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 248 | |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 249 | // prevent the parent from creating a JIT binding for this key |
limpbizkit | fcbdf99 | 2008-11-26 02:37:35 +0000 | [diff] [blame] | 250 | injector.state.parent().blacklist(key); |
| 251 | injector.state.putBinding(key, binding); |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * We tolerate duplicate bindings only if one exposes the other. |
| 256 | * |
| 257 | * @param original the binding in the parent injector (candidate for an exposing binding) |
| 258 | * @param binding the binding to check (candidate for the exposed binding) |
| 259 | */ |
| 260 | private boolean isOkayDuplicate(Binding<?> original, BindingImpl<?> binding) { |
| 261 | if (original instanceof ExposedBindingImpl) { |
| 262 | ExposedBindingImpl exposed = (ExposedBindingImpl) original; |
limpbizkit | c3f9284 | 2008-12-30 19:43:47 +0000 | [diff] [blame] | 263 | InjectorImpl exposedFrom = (InjectorImpl) exposed.getPrivateElements().getInjector(); |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 264 | return (exposedFrom == binding.getInjector()); |
limpbizkit | fcbdf99 | 2008-11-26 02:37:35 +0000 | [diff] [blame] | 265 | } |
| 266 | return false; |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 267 | } |
| 268 | |
limpbizkit | 5789ef4 | 2008-08-04 06:44:30 +0000 | [diff] [blame] | 269 | // It's unfortunate that we have to maintain a blacklist of specific |
| 270 | // classes, but we can't easily block the whole package because of |
| 271 | // all our unit tests. |
| 272 | private static final Set<Class<?>> FORBIDDEN_TYPES = ImmutableSet.of( |
| 273 | AbstractModule.class, |
| 274 | Binder.class, |
| 275 | Binding.class, |
limpbizkit | 86cb3bb | 2008-10-15 21:25:50 +0000 | [diff] [blame] | 276 | Injector.class, |
limpbizkit | 5789ef4 | 2008-08-04 06:44:30 +0000 | [diff] [blame] | 277 | Key.class, |
limpbizkit | 0ca7f91 | 2009-03-28 19:11:40 +0000 | [diff] [blame] | 278 | MembersInjector.class, |
limpbizkit | 5789ef4 | 2008-08-04 06:44:30 +0000 | [diff] [blame] | 279 | Module.class, |
limpbizkit | 0ca7f91 | 2009-03-28 19:11:40 +0000 | [diff] [blame] | 280 | Provider.class, |
limpbizkit | 5789ef4 | 2008-08-04 06:44:30 +0000 | [diff] [blame] | 281 | Scope.class, |
| 282 | TypeLiteral.class); |
limpbizkit | 86cb3bb | 2008-10-15 21:25:50 +0000 | [diff] [blame] | 283 | // TODO(jessewilson): fix BuiltInModule, then add Stage |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 284 | |
| 285 | interface CreationListener { |
limpbizkit | c3f9284 | 2008-12-30 19:43:47 +0000 | [diff] [blame] | 286 | void notify(Errors errors); |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 287 | } |
| 288 | } |