• 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 AssistedInjects {
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     @AssistedInject
Foo(Bar bar, @Assisted String str)42     Foo(Bar bar, @Assisted String str) {}
43   }
44 
45   @AssistedFactory
46   interface FooFactory {
create(String str)47     Foo create(String str);
48   }
49 
50   static class ParameterizedFoo<T1, T2> {
51     @AssistedInject
ParameterizedFoo(T1 t1, @Assisted T2 t2)52     ParameterizedFoo(T1 t1, @Assisted T2 t2) {}
53   }
54 
55   @AssistedFactory
56   interface ParameterizedFooFactory<T1, T2> {
create(T2 t2)57     ParameterizedFoo<T1, T2> create(T2 t2);
58   }
59 
main(String[] args)60   public static void main(String[] args) {
61     Foo foo = DaggerAssistedInjects_MyComponent.create().fooFactory().create("");
62 
63     ParameterizedFoo<Bar, String> parameterizedFoo =
64         DaggerAssistedInjects_MyComponent.create().parameterizedFooFactory().create("");
65   }
66 }
67