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#BOUND_INSTANCE}. */ 30 @CheckReturnValue 31 @AutoValue 32 public abstract class BoundInstanceBinding extends ContributionBinding { 33 @Override kind()34 public BindingKind kind() { 35 return BindingKind.BOUND_INSTANCE; 36 } 37 38 @Override optionalBindingType()39 public Optional<BindingType> optionalBindingType() { 40 return Optional.of(BindingType.PROVISION); 41 } 42 43 @Override contributionType()44 public ContributionType contributionType() { 45 return ContributionType.UNIQUE; 46 } 47 48 @Override dependencies()49 public final ImmutableSet<DependencyRequest> dependencies() { 50 return ImmutableSet.of(); 51 } 52 53 @Override toBuilder()54 public abstract Builder toBuilder(); 55 56 @Memoized 57 @Override hashCode()58 public abstract int hashCode(); 59 60 // TODO(ronshapiro,dpb): simplify the equality semantics 61 @Override equals(Object obj)62 public abstract boolean equals(Object obj); 63 builder()64 static Builder builder() { 65 return new AutoValue_BoundInstanceBinding.Builder(); 66 } 67 68 /** A {@link BoundInstanceBinding} builder. */ 69 @AutoValue.Builder 70 abstract static class Builder 71 extends ContributionBinding.Builder<BoundInstanceBinding, Builder> { nullability(Nullability nullability)72 abstract Builder nullability(Nullability nullability); 73 } 74 } 75