| beder | 72466bc | 2014-12-08 10:51:05 -0800 | [diff] [blame] | 1 | /* |
| ronshapiro | 5dde42d | 2016-06-17 09:03:35 -0700 | [diff] [blame] | 2 | * Copyright (C) 2014 The Dagger Authors. |
| beder | 72466bc | 2014-12-08 10:51:05 -0800 | [diff] [blame] | 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 | */ |
| dpb | 1b65b6a | 2016-07-11 12:11:24 -0700 | [diff] [blame] | 16 | |
| beder | 72466bc | 2014-12-08 10:51:05 -0800 | [diff] [blame] | 17 | package dagger.internal.codegen; |
| 18 | |
| gak | e55f074 | 2016-07-12 15:36:42 -0700 | [diff] [blame] | 19 | import static com.google.common.collect.Sets.immutableEnumSet; |
| 20 | import static dagger.internal.codegen.ContributionBinding.FactoryCreationStrategy.CLASS_CONSTRUCTOR; |
| 21 | import static dagger.internal.codegen.ContributionBinding.FactoryCreationStrategy.DELEGATE; |
| gak | 4d86019 | 2016-10-13 23:41:00 -0700 | [diff] [blame] | 22 | import static dagger.internal.codegen.ContributionBinding.FactoryCreationStrategy.SINGLETON_INSTANCE; |
| gak | e55f074 | 2016-07-12 15:36:42 -0700 | [diff] [blame] | 23 | import static dagger.internal.codegen.MapKeys.unwrapValue; |
| 24 | import static dagger.internal.codegen.MoreAnnotationMirrors.unwrapOptionalEquivalence; |
| ronshapiro | dc1a84c | 2016-08-24 10:47:50 -0700 | [diff] [blame] | 25 | import static javax.lang.model.element.Modifier.ABSTRACT; |
| 26 | import static javax.lang.model.element.Modifier.STATIC; |
| gak | e55f074 | 2016-07-12 15:36:42 -0700 | [diff] [blame] | 27 | |
| dpb | fb7a9d4 | 2015-09-15 14:04:03 -0700 | [diff] [blame] | 28 | import com.google.auto.common.MoreTypes; |
| 29 | import com.google.common.base.Equivalence; |
| 30 | import com.google.common.base.Equivalence.Wrapper; |
| gak | 6624110 | 2016-09-13 12:23:00 -0700 | [diff] [blame] | 31 | import com.google.common.collect.ImmutableSet; |
| dpb | 482cbd4 | 2015-08-07 08:17:31 -0700 | [diff] [blame] | 32 | import com.google.common.collect.ImmutableSetMultimap; |
| dpb | fb7a9d4 | 2015-09-15 14:04:03 -0700 | [diff] [blame] | 33 | import com.google.common.collect.Multimaps; |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 34 | import com.google.common.util.concurrent.ListenableFuture; |
| dpb | 6313ae3 | 2016-06-21 15:15:26 -0700 | [diff] [blame] | 35 | import com.google.errorprone.annotations.CanIgnoreReturnValue; |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 36 | import dagger.Component; |
| dpb | 482cbd4 | 2015-08-07 08:17:31 -0700 | [diff] [blame] | 37 | import dagger.MapKey; |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 38 | import dagger.Provides; |
| dpb | a262042 | 2015-08-15 10:06:54 -0700 | [diff] [blame] | 39 | import dagger.internal.codegen.ContributionType.HasContributionType; |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 40 | import dagger.producers.Produces; |
| dpb | ffd98f6 | 2016-12-20 10:05:16 -0800 | [diff] [blame] | 41 | import java.util.Optional; |
| beder | 72466bc | 2014-12-08 10:51:05 -0800 | [diff] [blame] | 42 | import java.util.Set; |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 43 | import javax.inject.Inject; |
| dpb | 482cbd4 | 2015-08-07 08:17:31 -0700 | [diff] [blame] | 44 | import javax.lang.model.element.AnnotationMirror; |
| 45 | import javax.lang.model.element.AnnotationValue; |
| dpb | 6313ae3 | 2016-06-21 15:15:26 -0700 | [diff] [blame] | 46 | import javax.lang.model.element.Element; |
| ronshapiro | dc1a84c | 2016-08-24 10:47:50 -0700 | [diff] [blame] | 47 | import javax.lang.model.element.Modifier; |
| dpb | 6313ae3 | 2016-06-21 15:15:26 -0700 | [diff] [blame] | 48 | import javax.lang.model.element.TypeElement; |
| sameb | 725e783 | 2015-01-30 05:30:55 -0800 | [diff] [blame] | 49 | import javax.lang.model.type.DeclaredType; |
| ronshapiro | e56af6a | 2016-05-13 08:25:40 -0700 | [diff] [blame] | 50 | import javax.lang.model.type.TypeMirror; |
| beder | 72466bc | 2014-12-08 10:51:05 -0800 | [diff] [blame] | 51 | |
| beder | 72466bc | 2014-12-08 10:51:05 -0800 | [diff] [blame] | 52 | /** |
| 53 | * An abstract class for a value object representing the mechanism by which a {@link Key} can be |
| 54 | * contributed to a dependency graph. |
| 55 | * |
| 56 | * @author Jesse Beder |
| 57 | * @since 2.0 |
| 58 | */ |
| dpb | a262042 | 2015-08-15 10:06:54 -0700 | [diff] [blame] | 59 | abstract class ContributionBinding extends Binding implements HasContributionType { |
| dpb | bf29ab3 | 2015-12-09 07:37:21 -0800 | [diff] [blame] | 60 | |
| sameb | 725e783 | 2015-01-30 05:30:55 -0800 | [diff] [blame] | 61 | /** Returns the type that specifies this' nullability, absent if not nullable. */ |
| 62 | abstract Optional<DeclaredType> nullableType(); |
| beder | 72466bc | 2014-12-08 10:51:05 -0800 | [diff] [blame] | 63 | |
| ronshapiro | d42ce7c | 2016-05-16 08:04:51 -0700 | [diff] [blame] | 64 | abstract Optional<Equivalence.Wrapper<AnnotationMirror>> wrappedMapKey(); |
| 65 | |
| 66 | final Optional<AnnotationMirror> mapKey() { |
| 67 | return unwrapOptionalEquivalence(wrappedMapKey()); |
| 68 | } |
| 69 | |
| beder | 01fed47 | 2015-02-26 06:29:53 -0800 | [diff] [blame] | 70 | /** |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 71 | * The kind of contribution this binding represents. Defines which elements can specify this kind |
| 72 | * of contribution. |
| beder | 01fed47 | 2015-02-26 06:29:53 -0800 | [diff] [blame] | 73 | */ |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 74 | enum Kind { |
| 75 | /** |
| dpb | bf29ab3 | 2015-12-09 07:37:21 -0800 | [diff] [blame] | 76 | * The synthetic binding for {@code Map<K, V>} that depends on either |
| 77 | * {@code Map<K, Provider<V>>} or {@code Map<K, Producer<V>>}. |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 78 | */ |
| dpb | bf29ab3 | 2015-12-09 07:37:21 -0800 | [diff] [blame] | 79 | SYNTHETIC_MAP, |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 80 | |
| dpb | db24072 | 2016-01-25 14:06:41 -0800 | [diff] [blame] | 81 | /** |
| 82 | * A synthetic binding for a multibound set that depends on the individual multibinding |
| 83 | * {@link Provides @Provides} or {@link Produces @Produces} methods. |
| 84 | */ |
| 85 | SYNTHETIC_MULTIBOUND_SET, |
| 86 | |
| 87 | /** |
| 88 | * A synthetic binding for a multibound map that depends on the individual multibinding |
| 89 | * {@link Provides @Provides} or {@link Produces @Produces} methods. |
| 90 | */ |
| 91 | SYNTHETIC_MULTIBOUND_MAP, |
| 92 | |
| gak | e1b68a2 | 2016-04-07 11:54:06 -0700 | [diff] [blame] | 93 | /** |
| 94 | * A binding (provision or production) that delegates from requests for one key to another. |
| ronshapiro | 01f9e6e | 2016-05-12 13:18:14 -0700 | [diff] [blame] | 95 | * These are the bindings that satisfy {@code @Binds} declarations. |
| gak | e1b68a2 | 2016-04-07 11:54:06 -0700 | [diff] [blame] | 96 | */ |
| 97 | SYNTHETIC_DELEGATE_BINDING, |
| 98 | |
| dpb | d8d950a | 2016-08-30 09:24:37 -0700 | [diff] [blame] | 99 | /** |
| ronshapiro | d804a30 | 2016-11-08 10:21:56 -0800 | [diff] [blame] | 100 | * A binding for a {@link dagger.releasablereferences.ReleasableReferenceManager} or {@link |
| 101 | * dagger.releasablereferences.TypedReleasableReferenceManager} object for a scope. |
| 102 | */ |
| 103 | SYNTHETIC_RELEASABLE_REFERENCE_MANAGER, |
| 104 | |
| 105 | /** |
| 106 | * A binding for a set of {@link dagger.releasablereferences.ReleasableReferenceManager} or |
| 107 | * {@link dagger.releasablereferences.TypedReleasableReferenceManager} objects. |
| 108 | */ |
| 109 | SYNTHETIC_RELEASABLE_REFERENCE_MANAGERS, |
| 110 | |
| 111 | /** |
| dpb | d8d950a | 2016-08-30 09:24:37 -0700 | [diff] [blame] | 112 | * A synthetic binding for {@code Optional} of a type or a {@link javax.inject.Provider}, {@link |
| 113 | * dagger.Lazy}, or {@code Provider} of {@code Lazy} of a type. Generated by a {@link |
| 114 | * dagger.BindsOptionalOf} declaration. |
| 115 | */ |
| 116 | SYNTHETIC_OPTIONAL_BINDING, |
| 117 | |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 118 | // Provision kinds |
| 119 | |
| 120 | /** An {@link Inject}-annotated constructor. */ |
| 121 | INJECTION, |
| 122 | |
| 123 | /** A {@link Provides}-annotated method. */ |
| 124 | PROVISION, |
| 125 | |
| 126 | /** An implicit binding to a {@link Component @Component}-annotated type. */ |
| 127 | COMPONENT, |
| 128 | |
| 129 | /** A provision method on a component's {@linkplain Component#dependencies() dependency}. */ |
| 130 | COMPONENT_PROVISION, |
| 131 | |
| dpb | 99d6408 | 2015-11-12 11:27:12 -0800 | [diff] [blame] | 132 | /** |
| 133 | * A subcomponent builder method on a component or subcomponent. |
| 134 | */ |
| 135 | SUBCOMPONENT_BUILDER, |
| 136 | |
| beder | b50b8ae | 2016-12-07 08:36:26 -0800 | [diff] [blame] | 137 | /** A builder binding method. */ |
| 138 | BUILDER_BINDING, |
| 139 | |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 140 | // Production kinds |
| 141 | |
| Ron Shapiro | 5f21a80 | 2016-09-21 10:23:55 -0400 | [diff] [blame] | 142 | /** A {@link Produces}-annotated method. */ |
| 143 | PRODUCTION, |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 144 | |
| 145 | /** |
| gak | f53c3f9 | 2016-08-17 09:55:56 -0700 | [diff] [blame] | 146 | * A production method on a production component's {@linkplain |
| 147 | * dagger.producers.ProductionComponent#dependencies()} dependency} that returns a |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 148 | * {@link ListenableFuture}. Methods on production component dependencies that don't return a |
| 149 | * {@link ListenableFuture} are considered {@linkplain #PROVISION provision bindings}. |
| 150 | */ |
| 151 | COMPONENT_PRODUCTION, |
| dpb | db24072 | 2016-01-25 14:06:41 -0800 | [diff] [blame] | 152 | ; |
| 153 | |
| gak | 6624110 | 2016-09-13 12:23:00 -0700 | [diff] [blame] | 154 | static final ImmutableSet<Kind> SYNTHETIC_MULTIBOUND_KINDS = |
| 155 | immutableEnumSet(SYNTHETIC_MULTIBOUND_SET, SYNTHETIC_MULTIBOUND_MAP); |
| dpb | db24072 | 2016-01-25 14:06:41 -0800 | [diff] [blame] | 156 | |
| 157 | /** |
| gak | f53c3f9 | 2016-08-17 09:55:56 -0700 | [diff] [blame] | 158 | * {@link #SYNTHETIC_MULTIBOUND_SET} or {@link #SYNTHETIC_MULTIBOUND_MAP}, depending on the key. |
| dpb | db24072 | 2016-01-25 14:06:41 -0800 | [diff] [blame] | 159 | */ |
| gak | f53c3f9 | 2016-08-17 09:55:56 -0700 | [diff] [blame] | 160 | static Kind forMultibindingKey(Key key) { |
| ronshapiro | 698653f | 2016-06-03 09:14:13 -0700 | [diff] [blame] | 161 | if (SetType.isSet(key)) { |
| dpb | db24072 | 2016-01-25 14:06:41 -0800 | [diff] [blame] | 162 | return SYNTHETIC_MULTIBOUND_SET; |
| ronshapiro | 698653f | 2016-06-03 09:14:13 -0700 | [diff] [blame] | 163 | } else if (MapType.isMap(key)) { |
| dpb | db24072 | 2016-01-25 14:06:41 -0800 | [diff] [blame] | 164 | return SYNTHETIC_MULTIBOUND_MAP; |
| 165 | } else { |
| gak | f53c3f9 | 2016-08-17 09:55:56 -0700 | [diff] [blame] | 166 | throw new IllegalArgumentException(String.format("key is not for a set or map: %s", key)); |
| dpb | db24072 | 2016-01-25 14:06:41 -0800 | [diff] [blame] | 167 | } |
| 168 | } |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 169 | } |
| beder | 01fed47 | 2015-02-26 06:29:53 -0800 | [diff] [blame] | 170 | |
| 171 | /** |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 172 | * The kind of this contribution binding. |
| beder | 72466bc | 2014-12-08 10:51:05 -0800 | [diff] [blame] | 173 | */ |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 174 | protected abstract Kind bindingKind(); |
| gak | e1b68a2 | 2016-04-07 11:54:06 -0700 | [diff] [blame] | 175 | |
| dpb | 99d6408 | 2015-11-12 11:27:12 -0800 | [diff] [blame] | 176 | /** |
| ronshapiro | dc1a84c | 2016-08-24 10:47:50 -0700 | [diff] [blame] | 177 | * {@code true} if {@link #contributingModule()} is present and this is a nonabstract instance |
| 178 | * method. |
| 179 | */ |
| 180 | boolean requiresModuleInstance() { |
| 181 | if (!bindingElement().isPresent() || !contributingModule().isPresent()) { |
| 182 | return false; |
| 183 | } |
| 184 | Set<Modifier> modifiers = bindingElement().get().getModifiers(); |
| 185 | return !modifiers.contains(ABSTRACT) && !modifiers.contains(STATIC); |
| 186 | } |
| 187 | |
| 188 | /** |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 189 | * The strategy for getting an instance of a factory for a {@link ContributionBinding}. |
| 190 | */ |
| 191 | enum FactoryCreationStrategy { |
| gak | 4d86019 | 2016-10-13 23:41:00 -0700 | [diff] [blame] | 192 | /** The factory class is a single instance. */ |
| 193 | SINGLETON_INSTANCE, |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 194 | /** The factory must be created by calling the constructor. */ |
| 195 | CLASS_CONSTRUCTOR, |
| gak | e1b68a2 | 2016-04-07 11:54:06 -0700 | [diff] [blame] | 196 | /** The factory is simply delegated to another. */ |
| 197 | DELEGATE, |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /** |
| dpb | 7edcd4d | 2016-06-21 07:52:39 -0700 | [diff] [blame] | 201 | * Returns the {@link FactoryCreationStrategy} appropriate for a binding. |
| 202 | * |
| dpb | a69ead5 | 2016-07-11 10:05:20 -0700 | [diff] [blame] | 203 | * <p>Delegate bindings use the {@link FactoryCreationStrategy#DELEGATE} strategy. |
| dpb | 7edcd4d | 2016-06-21 07:52:39 -0700 | [diff] [blame] | 204 | * |
| dpb | a69ead5 | 2016-07-11 10:05:20 -0700 | [diff] [blame] | 205 | * <p>Bindings without dependencies that don't require a module instance use the {@link |
| gak | 4d86019 | 2016-10-13 23:41:00 -0700 | [diff] [blame] | 206 | * FactoryCreationStrategy#SINGLETON_INSTANCE} strategy. |
| dpb | 7edcd4d | 2016-06-21 07:52:39 -0700 | [diff] [blame] | 207 | * |
| 208 | * <p>All other bindings use the {@link FactoryCreationStrategy#CLASS_CONSTRUCTOR} strategy. |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 209 | */ |
| 210 | FactoryCreationStrategy factoryCreationStrategy() { |
| 211 | switch (bindingKind()) { |
| gak | e1b68a2 | 2016-04-07 11:54:06 -0700 | [diff] [blame] | 212 | case SYNTHETIC_DELEGATE_BINDING: |
| dpb | 7edcd4d | 2016-06-21 07:52:39 -0700 | [diff] [blame] | 213 | return DELEGATE; |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 214 | case PROVISION: |
| gak | 75b9b72 | 2016-09-29 15:48:40 -0700 | [diff] [blame] | 215 | return dependencies().isEmpty() && !requiresModuleInstance() |
| gak | 4d86019 | 2016-10-13 23:41:00 -0700 | [diff] [blame] | 216 | ? SINGLETON_INSTANCE |
| dpb | 7edcd4d | 2016-06-21 07:52:39 -0700 | [diff] [blame] | 217 | : CLASS_CONSTRUCTOR; |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 218 | case INJECTION: |
| dpb | db24072 | 2016-01-25 14:06:41 -0800 | [diff] [blame] | 219 | case SYNTHETIC_MULTIBOUND_SET: |
| 220 | case SYNTHETIC_MULTIBOUND_MAP: |
| gak | 4d86019 | 2016-10-13 23:41:00 -0700 | [diff] [blame] | 221 | return dependencies().isEmpty() ? SINGLETON_INSTANCE : CLASS_CONSTRUCTOR; |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 222 | default: |
| dpb | 7edcd4d | 2016-06-21 07:52:39 -0700 | [diff] [blame] | 223 | return CLASS_CONSTRUCTOR; |
| dpb | 6bd55de | 2015-09-28 07:58:09 -0700 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | |
| 227 | /** |
| ronshapiro | e56af6a | 2016-05-13 08:25:40 -0700 | [diff] [blame] | 228 | * The {@link TypeMirror type} for the {@code Factory<T>} or {@code Producer<T>} which is created |
| dpb | df43ccb | 2017-04-25 10:19:10 -0700 | [diff] [blame] | 229 | * for this binding. Uses the binding's key, V in the case of {@code Map<K, FrameworkClass<V>>>}, |
| ronshapiro | e56af6a | 2016-05-13 08:25:40 -0700 | [diff] [blame] | 230 | * and E {@code Set<E>} for {@link dagger.multibindings.IntoSet @IntoSet} methods. |
| 231 | */ |
| gak | 4d86019 | 2016-10-13 23:41:00 -0700 | [diff] [blame] | 232 | final TypeMirror contributedType() { |
| ronshapiro | e56af6a | 2016-05-13 08:25:40 -0700 | [diff] [blame] | 233 | switch (contributionType()) { |
| 234 | case MAP: |
| gak | 8449ca3 | 2016-08-18 19:59:29 -0700 | [diff] [blame] | 235 | return MapType.from(key()).unwrappedValueType(bindingType().frameworkClass()); |
| ronshapiro | e56af6a | 2016-05-13 08:25:40 -0700 | [diff] [blame] | 236 | case SET: |
| ronshapiro | 698653f | 2016-06-03 09:14:13 -0700 | [diff] [blame] | 237 | return SetType.from(key()).elementType(); |
| ronshapiro | e56af6a | 2016-05-13 08:25:40 -0700 | [diff] [blame] | 238 | case SET_VALUES: |
| 239 | case UNIQUE: |
| 240 | return key().type(); |
| 241 | default: |
| 242 | throw new AssertionError(); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | /** |
| dpb | 482cbd4 | 2015-08-07 08:17:31 -0700 | [diff] [blame] | 247 | * Indexes map-multibindings by map key (the result of calling |
| 248 | * {@link AnnotationValue#getValue()} on a single member or the whole {@link AnnotationMirror} |
| 249 | * itself, depending on {@link MapKey#unwrapValue()}). |
| 250 | */ |
| dpb | 7c3ff29 | 2015-10-06 12:50:32 -0700 | [diff] [blame] | 251 | static ImmutableSetMultimap<Object, ContributionBinding> indexMapBindingsByMapKey( |
| 252 | Set<ContributionBinding> mapBindings) { |
| dpb | fb7a9d4 | 2015-09-15 14:04:03 -0700 | [diff] [blame] | 253 | return ImmutableSetMultimap.copyOf( |
| 254 | Multimaps.index( |
| 255 | mapBindings, |
| gak | 6624110 | 2016-09-13 12:23:00 -0700 | [diff] [blame] | 256 | mapBinding -> { |
| 257 | AnnotationMirror mapKey = mapBinding.mapKey().get(); |
| dpb | ffd98f6 | 2016-12-20 10:05:16 -0800 | [diff] [blame] | 258 | return unwrapValue(mapKey).map(AnnotationValue::getValue).orElse(mapKey); |
| dpb | fb7a9d4 | 2015-09-15 14:04:03 -0700 | [diff] [blame] | 259 | })); |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Indexes map-multibindings by map key annotation type. |
| 264 | */ |
| dpb | 7c3ff29 | 2015-10-06 12:50:32 -0700 | [diff] [blame] | 265 | static ImmutableSetMultimap<Wrapper<DeclaredType>, ContributionBinding> |
| 266 | indexMapBindingsByAnnotationType(Set<ContributionBinding> mapBindings) { |
| dpb | fb7a9d4 | 2015-09-15 14:04:03 -0700 | [diff] [blame] | 267 | return ImmutableSetMultimap.copyOf( |
| 268 | Multimaps.index( |
| 269 | mapBindings, |
| gak | 6624110 | 2016-09-13 12:23:00 -0700 | [diff] [blame] | 270 | mapBinding -> |
| 271 | MoreTypes.equivalence().wrap(mapBinding.mapKey().get().getAnnotationType()))); |
| dpb | 482cbd4 | 2015-08-07 08:17:31 -0700 | [diff] [blame] | 272 | } |
| dpb | 6313ae3 | 2016-06-21 15:15:26 -0700 | [diff] [blame] | 273 | |
| 274 | /** |
| 275 | * Base builder for {@link com.google.auto.value.AutoValue @AutoValue} subclasses of |
| 276 | * {@link ContributionBinding}. |
| 277 | */ |
| 278 | @CanIgnoreReturnValue |
| 279 | abstract static class Builder<B extends Builder<B>> { |
| 280 | abstract B contributionType(ContributionType contributionType); |
| 281 | |
| 282 | abstract B bindingElement(Element bindingElement); |
| 283 | |
| 284 | abstract B contributingModule(TypeElement contributingModule); |
| 285 | |
| 286 | abstract B key(Key key); |
| 287 | |
| dpb | 6313ae3 | 2016-06-21 15:15:26 -0700 | [diff] [blame] | 288 | abstract B nullableType(Optional<DeclaredType> nullableType); |
| 289 | |
| dpb | 6313ae3 | 2016-06-21 15:15:26 -0700 | [diff] [blame] | 290 | abstract B wrappedMapKey(Optional<Equivalence.Wrapper<AnnotationMirror>> wrappedMapKey); |
| 291 | |
| 292 | abstract B bindingKind(ContributionBinding.Kind kind); |
| 293 | } |
| beder | 72466bc | 2014-12-08 10:51:05 -0800 | [diff] [blame] | 294 | } |