1 /* 2 * Copyright (C) 2015 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.multibindings; 18 19 import static java.lang.annotation.ElementType.METHOD; 20 import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 22 import com.google.inject.Module; 23 import java.lang.annotation.Documented; 24 import java.lang.annotation.Retention; 25 import java.lang.annotation.Target; 26 27 /** 28 * Annotates methods of a {@link Module} to add items to a {@link MapBinder}. The method's return 29 * type, binding annotation and additional key annotation determines what Map this will contribute 30 * to. For example, 31 * 32 * <pre> 33 * {@literal @}ProvidesIntoMap 34 * {@literal @}StringMapKey("Foo") 35 * {@literal @}Named("urls") 36 * Plugin provideFooUrl(FooManager fm) { return fm.getPlugin(); } 37 * 38 * {@literal @}ProvidesIntoMap 39 * {@literal @}StringMapKey("Bar") 40 * {@literal @}Named("urls") 41 * Plugin provideBarUrl(BarManager bm) { return bm.getPlugin(); } 42 * </pre> 43 * 44 * will add two items to the {@code @Named("urls") Map<String, Plugin>} map. The key 'Foo' will map 45 * to the provideFooUrl method, and the key 'Bar' will map to the provideBarUrl method. The values 46 * are bound as providers and will be evaluated at injection time. 47 * 48 * <p>Because the key is specified as an annotation, only Strings, Classes, enums, primitive types 49 * and annotation instances are supported as keys. 50 * 51 * @author sameb@google.com (Sam Berlin) 52 * @since 4.0 53 */ 54 @Documented 55 @Target(METHOD) 56 @Retention(RUNTIME) 57 public @interface ProvidesIntoMap {} 58