aboutsummaryrefslogtreecommitdiff
path: root/javatests/dagger/internal/codegen/goldens/ComponentProcessorTest_dependencyNameCollision_FAST_INIT_MODE_test.DaggerBComponent
blob: 42a0386cb0173202096be41856dc3befd74672c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package test;

import dagger.internal.DaggerGenerated;
import dagger.internal.Preconditions;
import dagger.internal.Provider;
import javax.annotation.processing.Generated;
import pkg1.A;
import pkg1.AComponent;

@DaggerGenerated
@Generated(
    value = "dagger.internal.codegen.ComponentProcessor",
    comments = "https://dagger.dev"
)
@SuppressWarnings({
    "unchecked",
    "rawtypes",
    "KotlinInternal",
    "KotlinInternalInJava",
    "cast"
})
final class DaggerBComponent {
  private DaggerBComponent() {
  }

  public static Builder builder() {
    return new Builder();
  }

  static final class Builder {
    private AComponent aComponent;

    private pkg2.AComponent aComponent2;

    private Builder() {
    }

    public Builder aComponent(AComponent aComponent) {
      this.aComponent = Preconditions.checkNotNull(aComponent);
      return this;
    }

    public Builder aComponent(pkg2.AComponent aComponent) {
      this.aComponent2 = Preconditions.checkNotNull(aComponent);
      return this;
    }

    public BComponent build() {
      Preconditions.checkBuilderRequirement(aComponent, AComponent.class);
      Preconditions.checkBuilderRequirement(aComponent2, pkg2.AComponent.class);
      return new BComponentImpl(aComponent, aComponent2);
    }
  }

  private static final class BComponentImpl implements BComponent {
    private final AComponent aComponent;

    private final pkg2.AComponent aComponent2;

    private final BComponentImpl bComponentImpl = this;

    private Provider<A> aProvider;

    private Provider<pkg2.A> aProvider2;

    private BComponentImpl(AComponent aComponentParam, pkg2.AComponent aComponentParam2) {
      this.aComponent = aComponentParam;
      this.aComponent2 = aComponentParam2;
      initialize(aComponentParam, aComponentParam2);

    }

    @SuppressWarnings("unchecked")
    private void initialize(final AComponent aComponentParam,
        final pkg2.AComponent aComponentParam2) {
      this.aProvider = new SwitchingProvider<>(bComponentImpl, 0);
      this.aProvider2 = new SwitchingProvider<>(bComponentImpl, 1);
    }

    @Override
    public B b() {
      return new B(aProvider, aProvider2);
    }

    private static final class SwitchingProvider<T> implements Provider<T> {
      private final BComponentImpl bComponentImpl;

      private final int id;

      SwitchingProvider(BComponentImpl bComponentImpl, int id) {
        this.bComponentImpl = bComponentImpl;
        this.id = id;
      }

      @SuppressWarnings("unchecked")
      @Override
      public T get() {
        switch (id) {
          case 0: // pkg1.A 
          return (T) Preconditions.checkNotNullFromComponent(bComponentImpl.aComponent.a());

          case 1: // pkg2.A 
          return (T) Preconditions.checkNotNullFromComponent(bComponentImpl.aComponent2.a());

          default: throw new AssertionError(id);
        }
      }
    }
  }
}