• 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.errorprone.annotations.CheckReturnValue;
22 import dagger.internal.codegen.base.ContributionType;
23 import dagger.internal.codegen.model.BindingKind;
24 import dagger.internal.codegen.model.DependencyRequest;
25 import dagger.internal.codegen.xprocessing.Nullability;
26 import java.util.Optional;
27 
28 /** A binding for a {@link BindingKind#PROVISION}. */
29 @CheckReturnValue
30 @AutoValue
31 public abstract class ProvisionBinding extends ContributionBinding {
32   @Override
kind()33   public BindingKind kind() {
34     return BindingKind.PROVISION;
35   }
36 
37   @Override
optionalBindingType()38   public Optional<BindingType> optionalBindingType() {
39     return Optional.of(BindingType.PROVISION);
40   }
41 
42   @Override
43   @Memoized
contributionType()44   public ContributionType contributionType() {
45     return ContributionType.fromBindingElement(bindingElement().get());
46   }
47 
48   // Profiling determined that this method is called enough times that memoizing it had a measurable
49   // performance improvement for large components.
50   @Memoized
51   @Override
requiresModuleInstance()52   public boolean requiresModuleInstance() {
53     return super.requiresModuleInstance();
54   }
55 
56   @Override
toBuilder()57   public abstract Builder toBuilder();
58 
59   @Memoized
60   @Override
hashCode()61   public abstract int hashCode();
62 
63   // TODO(ronshapiro,dpb): simplify the equality semantics
64   @Override
equals(Object obj)65   public abstract boolean equals(Object obj);
66 
builder()67   static Builder builder() {
68     return new AutoValue_ProvisionBinding.Builder();
69   }
70 
71   /** A {@link ProvisionBinding} builder. */
72   @AutoValue.Builder
73   abstract static class Builder extends ContributionBinding.Builder<ProvisionBinding, Builder> {
nullability(Nullability nullability)74     abstract Builder nullability(Nullability nullability);
75 
dependencies(Iterable<DependencyRequest> dependencies)76     abstract Builder dependencies(Iterable<DependencyRequest> dependencies);
77   }
78 }
79