• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 app;
18 
19 import dagger.Component;
20 import dagger.assisted.Assisted;
21 import dagger.assisted.AssistedFactory;
22 import dagger.assisted.AssistedInject;
23 import javax.inject.Inject;
24 
25 // This is a regression test for https://github.com/google/dagger/issues/2309
26 /** A simple, skeletal application that defines an assisted inject binding. */
27 public class AssistedInjectClasses {
28   @Component
29   interface MyComponent {
fooFactory()30     FooFactory fooFactory();
31 
parameterizedFooFactory()32     ParameterizedFooFactory<Bar, String> parameterizedFooFactory();
33   }
34 
35   static final class Bar {
36     @Inject
Bar()37     Bar() {}
38   }
39 
40   static class Foo {
41     String assistedStr;
42     Bar bar;
43 
44     @AssistedInject
Foo(Bar bar, @Assisted String assistedStr)45     Foo(Bar bar, @Assisted String assistedStr) {
46       this.assistedStr = assistedStr;
47       this.bar = bar;
48     }
49   }
50 
51   @AssistedFactory
52   interface FooFactory {
create(String str)53     Foo create(String str);
54   }
55 
56   static class ParameterizedFoo<T1, T2> {
57     T1 t1;
58     T2 assistedT2;
59 
60     @AssistedInject
ParameterizedFoo(T1 t1, @Assisted T2 assistedT2)61     ParameterizedFoo(T1 t1, @Assisted T2 assistedT2) {
62       this.t1 = t1;
63       this.assistedT2 = assistedT2;
64     }
65   }
66 
67   @AssistedFactory
68   interface ParameterizedFooFactory<T1, T2> {
create(T2 t2)69     ParameterizedFoo<T1, T2> create(T2 t2);
70   }
71 }
72