Skip to content

Commit a4bb781

Browse files
authored
Merge pull request square#453 from google/moe_sync_8/31
MOE sync 8/31
2 parents e2e4e9e + fbb6840 commit a4bb781

File tree

75 files changed

+4532
-887
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+4532
-887
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (C) 2016 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 test;
18+
19+
import dagger.Component;
20+
import dagger.Module;
21+
import dagger.Provides;
22+
23+
/**
24+
* This tests that @Module.includes are traversed for supertypes of a module.
25+
*/
26+
final class ModuleIncludesCollectedFromModuleSuperclasses {
27+
@Component(modules = TopLevelModule.class)
28+
interface C {
29+
Foo<String> foo();
30+
int includedInTopLevelModule();
31+
String includedFromModuleInheritance();
32+
}
33+
34+
@Module(includes = IncludedTopLevel.class)
35+
static class TopLevelModule extends FooModule<String> {}
36+
37+
static class Foo<T> {}
38+
39+
@Module(includes = IncludedFromModuleInheritance.class)
40+
abstract static class FooModule<T> extends FooCreator {
41+
@Provides Foo<T> fooOfT() {
42+
return createFoo();
43+
}
44+
}
45+
46+
static class FooCreator {
47+
<T> Foo<T> createFoo() {
48+
return new Foo<T>();
49+
}
50+
}
51+
52+
@Module
53+
static class IncludedTopLevel {
54+
@Provides int i() {
55+
return 123;
56+
}
57+
}
58+
59+
@Module
60+
static class IncludedFromModuleInheritance {
61+
@Provides String inheritedProvision() {
62+
return "inherited";
63+
}
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (C) 2016 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 test.subcomponent;
18+
19+
import dagger.Component;
20+
import dagger.Module;
21+
import dagger.Subcomponent;
22+
23+
/**
24+
* Tests for {@link Subcomponent}s which are defined with {@link Module#subcomponents()} and are
25+
* also requested as component factory methods.
26+
*/
27+
public class SubcomponentFromModuleAndFactoryMethod {
28+
@Subcomponent
29+
interface Sub {
30+
@Subcomponent.Builder
31+
interface Builder {
32+
Sub sub();
33+
}
34+
}
35+
36+
@Module(subcomponents = Sub.class)
37+
class ModuleWithSubcomponent {}
38+
39+
@Component(modules = ModuleWithSubcomponent.class)
40+
interface ExposesBuilder {
41+
Sub.Builder subcomponentBuilder();
42+
}
43+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (C) 2016 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 test.subcomponent;
18+
19+
import dagger.Component;
20+
import dagger.Module;
21+
import dagger.Provides;
22+
import dagger.Subcomponent;
23+
import dagger.multibindings.IntoSet;
24+
import java.util.Set;
25+
import javax.inject.Inject;
26+
27+
/** Supporting types for {@link ModuleWithSubcomponentsTest}. */
28+
@Component(modules = UsesModuleSubcomponents.ModuleWithSubcomponents.class)
29+
public interface UsesModuleSubcomponents {
30+
UsesChild usesChild();
31+
32+
Set<String> strings();
33+
34+
@Module(subcomponents = Child.class, includes = AlsoIncludesSubcomponents.class)
35+
class ModuleWithSubcomponents {
36+
@Provides
37+
@IntoSet
38+
static String provideStringInParent() {
39+
return "from parent";
40+
}
41+
}
42+
43+
@Module(subcomponents = Child.class)
44+
class AlsoIncludesSubcomponents {}
45+
46+
@Subcomponent(modules = ChildModule.class)
47+
interface Child {
48+
Set<String> strings();
49+
50+
@Subcomponent.Builder
51+
interface Builder {
52+
Child build();
53+
}
54+
}
55+
56+
@Module
57+
class ChildModule {
58+
@Provides
59+
@IntoSet
60+
static String provideStringInChild() {
61+
return "from child";
62+
}
63+
}
64+
65+
class UsesChild {
66+
Set<String> strings;
67+
68+
@Inject
69+
UsesChild(Child.Builder childBuilder) {
70+
this.strings = childBuilder.build().strings();
71+
}
72+
}
73+
74+
@Module(includes = ModuleWithSubcomponents.class)
75+
class OnlyIncludesModuleWithSubcomponents {}
76+
77+
@Component(modules = OnlyIncludesModuleWithSubcomponents.class)
78+
interface ParentIncludesSubcomponentTransitively extends UsesModuleSubcomponents {}
79+
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright (C) 2016 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 test.subcomponent.pruning;
18+
19+
import dagger.Component;
20+
import dagger.Module;
21+
import dagger.Provides;
22+
import dagger.Subcomponent;
23+
import dagger.multibindings.IntoSet;
24+
import java.util.Set;
25+
import javax.inject.Qualifier;
26+
27+
/**
28+
* Supporting types for {@link SubcomponentOnlyRequestedBySiblingTest}. {@link ChildA} is a direct
29+
* child of the top level component, but is only requested within its sibling, not directly from its
30+
* parent.
31+
*/
32+
@Component(modules = ParentDoesntUseSubcomponent.ParentModule.class)
33+
interface ParentDoesntUseSubcomponent {
34+
35+
ChildB.Builder childBBuilder();
36+
37+
@Subcomponent(modules = ChildAModule.class)
38+
interface ChildA {
39+
@Subcomponent.Builder
40+
interface Builder {
41+
ChildA build();
42+
}
43+
44+
Set<Class<?>> componentHierarchy();
45+
}
46+
47+
@Subcomponent(modules = ChildBModule.class)
48+
interface ChildB {
49+
@Subcomponent.Builder
50+
interface Builder {
51+
ChildB build();
52+
}
53+
54+
Set<Class<?>> componentHierarchy();
55+
56+
@FromChildA
57+
Set<Class<?>> componentHierarchyFromChildA();
58+
}
59+
60+
@Module(subcomponents = {ChildA.class, ChildB.class})
61+
class ParentModule {
62+
@Provides
63+
@IntoSet
64+
static Class<?> provideComponentType() {
65+
return ParentDoesntUseSubcomponent.class;
66+
}
67+
}
68+
69+
@Module
70+
class ChildAModule {
71+
@Provides
72+
@IntoSet
73+
static Class<?> provideComponentType() {
74+
return ChildA.class;
75+
}
76+
}
77+
78+
@Module
79+
class ChildBModule {
80+
@Provides
81+
@IntoSet
82+
static Class<?> provideComponentType() {
83+
return ChildB.class;
84+
}
85+
86+
@Provides
87+
@FromChildA
88+
Set<Class<?>> fromChildA(ChildA.Builder childABuilder) {
89+
return childABuilder.build().componentHierarchy();
90+
}
91+
}
92+
93+
@Qualifier
94+
@interface FromChildA {}
95+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (C) 2015 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 test.subcomponent.repeat;
18+
19+
import dagger.Subcomponent;
20+
21+
@Subcomponent(modules = RepeatedModule.class)
22+
interface OtherSubcomponentWithRepeatedModule extends SubcomponentWithRepeatedModule {
23+
24+
@Subcomponent.Builder
25+
interface Builder {
26+
Builder repeatedModule(RepeatedModule repeatedModule);
27+
28+
OtherSubcomponentWithRepeatedModule build();
29+
}
30+
}

compiler/src/it/functional-tests/src/main/java/test/subcomponent/repeat/SubcomponentWithoutRepeatedModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020

2121
@Subcomponent
2222
interface SubcomponentWithoutRepeatedModule {
23-
SubcomponentWithRepeatedModule.Builder newGrandchildBuilder();
23+
OtherSubcomponentWithRepeatedModule.Builder newGrandchildBuilder();
2424
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (C) 2016 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 test.subcomponent;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
21+
import dagger.Module;
22+
import org.junit.Test;
23+
import org.junit.runner.RunWith;
24+
import org.junit.runners.JUnit4;
25+
import test.subcomponent.UsesModuleSubcomponents.ParentIncludesSubcomponentTransitively;
26+
27+
/** Tests for {@link Module#subcomponents()}. */
28+
@RunWith(JUnit4.class)
29+
public class ModuleWithSubcomponentsTest {
30+
31+
@Test
32+
public void subcomponentFromModules() {
33+
UsesModuleSubcomponents parent = DaggerUsesModuleSubcomponents.create();
34+
assertThat(parent.strings()).containsExactly("from parent");
35+
assertThat(parent.usesChild().strings).containsExactly("from parent", "from child");
36+
}
37+
38+
@Test
39+
public void subcomponentFromModules_transitively() {
40+
ParentIncludesSubcomponentTransitively parent =
41+
DaggerUsesModuleSubcomponents_ParentIncludesSubcomponentTransitively.create();
42+
assertThat(parent.strings()).containsExactly("from parent");
43+
assertThat(parent.usesChild().strings).containsExactly("from parent", "from child");
44+
}
45+
}

0 commit comments

Comments
 (0)