• 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 com.google.auto.value.AutoValue;
20 import com.google.auto.value.extension.memoized.Memoized;
21 import com.google.common.collect.ImmutableSet;
22 import com.google.errorprone.annotations.CheckReturnValue;
23 import dagger.internal.codegen.base.ContributionType;
24 import dagger.internal.codegen.model.BindingKind;
25 import dagger.internal.codegen.model.DependencyRequest;
26 import dagger.internal.codegen.xprocessing.Nullability;
27 import java.util.Optional;
28 
29 /** A binding for a {@link BindingKind#DELEGATE}. */
30 @CheckReturnValue
31 @AutoValue
32 public abstract class DelegateBinding extends ContributionBinding {
33   @Override
kind()34   public BindingKind kind() {
35     return BindingKind.DELEGATE;
36   }
37 
38   @Override
39   @Memoized
dependencies()40   public ImmutableSet<DependencyRequest> dependencies() {
41     return ImmutableSet.of(delegateRequest());
42   }
43 
44   /** Returns a request for the binding that this binding delegates to. */
delegateRequest()45   abstract DependencyRequest delegateRequest();
46 
47   @Override
requiresModuleInstance()48   public boolean requiresModuleInstance() {
49     return false;
50   }
51 
52   @Override
toBuilder()53   public abstract Builder toBuilder();
54 
55   @Memoized
56   @Override
hashCode()57   public abstract int hashCode();
58 
59   // TODO(ronshapiro,dpb): simplify the equality semantics
60   @Override
equals(Object obj)61   public abstract boolean equals(Object obj);
62 
builder()63   static Builder builder() {
64     return new AutoValue_DelegateBinding.Builder();
65   }
66 
67   /** A {@link DelegateBinding} builder. */
68   @AutoValue.Builder
69   abstract static class Builder extends ContributionBinding.Builder<DelegateBinding, Builder> {
delegateRequest(DependencyRequest delegateRequest)70     abstract Builder delegateRequest(DependencyRequest delegateRequest);
71 
optionalBindingType(Optional<BindingType> bindingType)72     abstract Builder optionalBindingType(Optional<BindingType> bindingType);
73 
contributionType(ContributionType contributionType)74     abstract Builder contributionType(ContributionType contributionType);
75 
nullability(Nullability nullability)76     abstract Builder nullability(Nullability nullability);
77   }
78 }
79