• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Dagger Authors.
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 dagger.internal.codegen.binding;
18 
19 import static dagger.internal.codegen.extension.DaggerStreams.toImmutableSet;
20 
21 import com.google.auto.value.AutoValue;
22 import com.google.auto.value.extension.memoized.Memoized;
23 import com.google.common.collect.ImmutableSet;
24 import com.google.common.collect.ImmutableSortedSet;
25 import com.google.errorprone.annotations.CheckReturnValue;
26 import dagger.internal.codegen.base.ContributionType;
27 import dagger.internal.codegen.binding.MembersInjectionBinding.InjectionSite;
28 import dagger.internal.codegen.model.BindingKind;
29 import dagger.internal.codegen.model.DependencyRequest;
30 import dagger.internal.codegen.xprocessing.Nullability;
31 import java.util.Optional;
32 
33 /** A binding for a {@link BindingKind#MEMBERS_INJECTOR}. */
34 @CheckReturnValue
35 @AutoValue
36 public abstract class MembersInjectorBinding extends ContributionBinding {
37   @Override
kind()38   public BindingKind kind() {
39     return BindingKind.MEMBERS_INJECTOR;
40   }
41 
42   @Override
optionalBindingType()43   public Optional<BindingType> optionalBindingType() {
44     return Optional.of(BindingType.PROVISION);
45   }
46 
47   @Override
contributionType()48   public ContributionType contributionType() {
49     return ContributionType.UNIQUE;
50   }
51 
52   @Override
nullability()53   public Nullability nullability() {
54     return Nullability.NOT_NULLABLE;
55   }
56 
57   @Override
58   @Memoized
dependencies()59   public ImmutableSet<DependencyRequest> dependencies() {
60     return injectionSites().stream()
61         .flatMap(i -> i.dependencies().stream())
62         .collect(toImmutableSet());
63   }
64 
65   /** {@link InjectionSite}s for all {@code @Inject} members. */
injectionSites()66   public abstract ImmutableSortedSet<InjectionSite> injectionSites();
67 
68   @Override
toBuilder()69   public abstract Builder toBuilder();
70 
71   @Memoized
72   @Override
hashCode()73   public abstract int hashCode();
74 
75   // TODO(ronshapiro,dpb): simplify the equality semantics
76   @Override
equals(Object obj)77   public abstract boolean equals(Object obj);
78 
builder()79   static Builder builder() {
80     return new AutoValue_MembersInjectorBinding.Builder();
81   }
82 
83   /** A {@link MembersInjectorBinding} builder. */
84   @AutoValue.Builder
85   abstract static class Builder
86       extends ContributionBinding.Builder<MembersInjectorBinding, Builder> {
injectionSites(ImmutableSortedSet<InjectionSite> injectionSites)87     abstract Builder injectionSites(ImmutableSortedSet<InjectionSite> injectionSites);
88   }
89 }
90