Skip to content

Commit

Permalink
Merge pull request square#453 from google/moe_sync_8/31
Browse files Browse the repository at this point in the history
MOE sync 8/31
  • Loading branch information
ronshapiro authored Sep 5, 2016
2 parents e2e4e9e + fbb6840 commit a4bb781
Show file tree
Hide file tree
Showing 75 changed files with 4,532 additions and 887 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (C) 2016 The Dagger Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package test;

import dagger.Component;
import dagger.Module;
import dagger.Provides;

/**
* This tests that @Module.includes are traversed for supertypes of a module.
*/
final class ModuleIncludesCollectedFromModuleSuperclasses {
@Component(modules = TopLevelModule.class)
interface C {
Foo<String> foo();
int includedInTopLevelModule();
String includedFromModuleInheritance();
}

@Module(includes = IncludedTopLevel.class)
static class TopLevelModule extends FooModule<String> {}

static class Foo<T> {}

@Module(includes = IncludedFromModuleInheritance.class)
abstract static class FooModule<T> extends FooCreator {
@Provides Foo<T> fooOfT() {
return createFoo();
}
}

static class FooCreator {
<T> Foo<T> createFoo() {
return new Foo<T>();
}
}

@Module
static class IncludedTopLevel {
@Provides int i() {
return 123;
}
}

@Module
static class IncludedFromModuleInheritance {
@Provides String inheritedProvision() {
return "inherited";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2016 The Dagger Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package test.subcomponent;

import dagger.Component;
import dagger.Module;
import dagger.Subcomponent;

/**
* Tests for {@link Subcomponent}s which are defined with {@link Module#subcomponents()} and are
* also requested as component factory methods.
*/
public class SubcomponentFromModuleAndFactoryMethod {
@Subcomponent
interface Sub {
@Subcomponent.Builder
interface Builder {
Sub sub();
}
}

@Module(subcomponents = Sub.class)
class ModuleWithSubcomponent {}

@Component(modules = ModuleWithSubcomponent.class)
interface ExposesBuilder {
Sub.Builder subcomponentBuilder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (C) 2016 The Dagger Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package test.subcomponent;

import dagger.Component;
import dagger.Module;
import dagger.Provides;
import dagger.Subcomponent;
import dagger.multibindings.IntoSet;
import java.util.Set;
import javax.inject.Inject;

/** Supporting types for {@link ModuleWithSubcomponentsTest}. */
@Component(modules = UsesModuleSubcomponents.ModuleWithSubcomponents.class)
public interface UsesModuleSubcomponents {
UsesChild usesChild();

Set<String> strings();

@Module(subcomponents = Child.class, includes = AlsoIncludesSubcomponents.class)
class ModuleWithSubcomponents {
@Provides
@IntoSet
static String provideStringInParent() {
return "from parent";
}
}

@Module(subcomponents = Child.class)
class AlsoIncludesSubcomponents {}

@Subcomponent(modules = ChildModule.class)
interface Child {
Set<String> strings();

@Subcomponent.Builder
interface Builder {
Child build();
}
}

@Module
class ChildModule {
@Provides
@IntoSet
static String provideStringInChild() {
return "from child";
}
}

class UsesChild {
Set<String> strings;

@Inject
UsesChild(Child.Builder childBuilder) {
this.strings = childBuilder.build().strings();
}
}

@Module(includes = ModuleWithSubcomponents.class)
class OnlyIncludesModuleWithSubcomponents {}

@Component(modules = OnlyIncludesModuleWithSubcomponents.class)
interface ParentIncludesSubcomponentTransitively extends UsesModuleSubcomponents {}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (C) 2016 The Dagger Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package test.subcomponent.pruning;

import dagger.Component;
import dagger.Module;
import dagger.Provides;
import dagger.Subcomponent;
import dagger.multibindings.IntoSet;
import java.util.Set;
import javax.inject.Qualifier;

/**
* Supporting types for {@link SubcomponentOnlyRequestedBySiblingTest}. {@link ChildA} is a direct
* child of the top level component, but is only requested within its sibling, not directly from its
* parent.
*/
@Component(modules = ParentDoesntUseSubcomponent.ParentModule.class)
interface ParentDoesntUseSubcomponent {

ChildB.Builder childBBuilder();

@Subcomponent(modules = ChildAModule.class)
interface ChildA {
@Subcomponent.Builder
interface Builder {
ChildA build();
}

Set<Class<?>> componentHierarchy();
}

@Subcomponent(modules = ChildBModule.class)
interface ChildB {
@Subcomponent.Builder
interface Builder {
ChildB build();
}

Set<Class<?>> componentHierarchy();

@FromChildA
Set<Class<?>> componentHierarchyFromChildA();
}

@Module(subcomponents = {ChildA.class, ChildB.class})
class ParentModule {
@Provides
@IntoSet
static Class<?> provideComponentType() {
return ParentDoesntUseSubcomponent.class;
}
}

@Module
class ChildAModule {
@Provides
@IntoSet
static Class<?> provideComponentType() {
return ChildA.class;
}
}

@Module
class ChildBModule {
@Provides
@IntoSet
static Class<?> provideComponentType() {
return ChildB.class;
}

@Provides
@FromChildA
Set<Class<?>> fromChildA(ChildA.Builder childABuilder) {
return childABuilder.build().componentHierarchy();
}
}

@Qualifier
@interface FromChildA {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2015 The Dagger Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package test.subcomponent.repeat;

import dagger.Subcomponent;

@Subcomponent(modules = RepeatedModule.class)
interface OtherSubcomponentWithRepeatedModule extends SubcomponentWithRepeatedModule {

@Subcomponent.Builder
interface Builder {
Builder repeatedModule(RepeatedModule repeatedModule);

OtherSubcomponentWithRepeatedModule build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@

@Subcomponent
interface SubcomponentWithoutRepeatedModule {
SubcomponentWithRepeatedModule.Builder newGrandchildBuilder();
OtherSubcomponentWithRepeatedModule.Builder newGrandchildBuilder();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2016 The Dagger Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package test.subcomponent;

import static com.google.common.truth.Truth.assertThat;

import dagger.Module;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import test.subcomponent.UsesModuleSubcomponents.ParentIncludesSubcomponentTransitively;

/** Tests for {@link Module#subcomponents()}. */
@RunWith(JUnit4.class)
public class ModuleWithSubcomponentsTest {

@Test
public void subcomponentFromModules() {
UsesModuleSubcomponents parent = DaggerUsesModuleSubcomponents.create();
assertThat(parent.strings()).containsExactly("from parent");
assertThat(parent.usesChild().strings).containsExactly("from parent", "from child");
}

@Test
public void subcomponentFromModules_transitively() {
ParentIncludesSubcomponentTransitively parent =
DaggerUsesModuleSubcomponents_ParentIncludesSubcomponentTransitively.create();
assertThat(parent.strings()).containsExactly("from parent");
assertThat(parent.usesChild().strings).containsExactly("from parent", "from child");
}
}
Loading

0 comments on commit a4bb781

Please sign in to comment.