Skip to content

Commit

Permalink
Merge pull request square#414 from google/fixed_moe_writing_branch
Browse files Browse the repository at this point in the history
Sync changes via MOE from google internal
  • Loading branch information
ronshapiro authored Jul 25, 2016
2 parents deb480c + 9761f5d commit cbd4286
Show file tree
Hide file tree
Showing 54 changed files with 1,310 additions and 651 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ In order to activate code generation and generate implementations to manage
your graph you will need to include `dagger-compiler-2.1.jar` in your build
at compile time.

### Maven

In a Maven project, include the `dagger` artifact in the dependencies section
of your `pom.xml` and the `dagger-compiler` artifact as either an `optional` or
`provided` dependency:
Expand Down Expand Up @@ -77,6 +79,41 @@ parallelizable execution graphs), then add this to your maven configuration:
</dependencies>
```

### Java Gradle
```groovy
// Add plugin https://plugins.gradle.org/plugin/net.ltgt.apt
plugins {
id "net.ltgt.apt" version "0.5"
}
// Add Dagger dependencies
dependencies {
compile 'com.google.dagger:dagger:2.0.2'
apt 'com.google.dagger:dagger-compiler:2.0.2'
}
```

### Android Gradle
```groovy
// Add plugin https://bitbucket.org/hvisser/android-apt
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
// Apply plugin
apply plugin: 'com.neenbedankt.android-apt'
// Add Dagger dependencies
dependencies {
compile 'com.google.dagger:dagger:2.0.2'
apt 'com.google.dagger:dagger-compiler:2.0.2'
}
```

### Download

Expand Down
1 change: 0 additions & 1 deletion compiler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>1.1</version>
<scope>provided</scope> <!-- to leave out of the all-deps jar -->
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

import dagger.Component;

/**
* A component that indirectly depends on code generated by another processor, in this case
* {@link com.google.auto.factory.AutoFactory}. Neither this type nor its immediately referenced
* types are generated, but {@link NeedsFactory} depends on the generated
* {@link NeedsFactory_SomethingFactory}.
*
*/
@Component
interface ComponentDependsOnGeneratedCode {
NeedsFactory needsFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

import dagger.Component;

/**
* A component whose supertype depends on code generated by another processor, in this case
* {@link com.google.auto.factory.AutoFactory}.
*
*/
@Component
interface ComponentSupertypeDependsOnGeneratedCode
extends ComponentSupertypeDependsOnGeneratedCodeInterface {}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
*/
package test.cycle;

import dagger.Binds;
import dagger.Component;
import dagger.Lazy;
import dagger.Module;
import dagger.Provides;
import dagger.Subcomponent;
import dagger.multibindings.IntoMap;
import dagger.multibindings.StringKey;

import java.util.Map;

import javax.inject.Inject;
import javax.inject.Provider;

Expand Down Expand Up @@ -117,20 +120,16 @@ static class Y {
}

@Module
static class CycleMapModule {
@Provides
abstract static class CycleMapModule {
@Binds
@IntoMap
@StringKey("X")
static X x(X x) {
return x;
}
abstract X x(X x);

@Provides
@Binds
@IntoMap
@StringKey("Y")
static Y y(Y y) {
return y;
}
abstract Y y(Y y);
}

@SuppressWarnings("dependency-cycle")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
import javax.inject.Inject;
import javax.inject.Provider;

/**
* Component with a long enough cycle such that the initialization of a provider happens in a
* separate {@code initialize} method from the one where it is used as a delegated factory.
*
*/
// Each nested class's constructor has an intentionally unused parameter.
@SuppressWarnings("unused")
final class LongCycle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,41 @@

package test.multipackage.a;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import dagger.multibindings.ElementsIntoSet;
import dagger.multibindings.IntoMap;
import dagger.multibindings.IntoSet;
import dagger.multibindings.StringKey;

import java.util.HashSet;
import java.util.Set;

import javax.inject.Inject;

@Module
public final class AModule {
public abstract class AModule {
@Provides
@IntoSet
static String provideString() {
return "a";
}

@Provides
@Binds
@IntoSet
static Inaccessible provideInaccessible(Inaccessible inaccessible) {
return inaccessible;
}
abstract Inaccessible provideInaccessible(Inaccessible inaccessible);

@Provides
@ElementsIntoSet
static Set<Inaccessible> provideSetOfInaccessibles() {
return new HashSet<>();
}

@Provides
@Binds
@IntoMap
@StringKey("inaccessible")
static Inaccessible provideInaccessibleToMap(Inaccessible inaccessible) {
return inaccessible;
}
abstract Inaccessible provideInaccessibleToMap(Inaccessible inaccessible);

static class Inaccessible {
@Inject Inaccessible() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
*/
package test.subcomponent;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import dagger.multibindings.IntoSet;

@Module
final class GrandchildModule {
abstract class GrandchildModule {
@Provides
@IntoSet
static Object provideUnscopedObject() {
Expand All @@ -31,10 +32,8 @@ static Object provideUnscopedObject() {
};
}

@Provides
static AnInterface provideAnInterface(ImplementsAnInterface implementsAnInterface) {
return implementsAnInterface;
}
@Binds
abstract AnInterface provideAnInterface(ImplementsAnInterface implementsAnInterface);

@Provides
static NeedsAnInterface provideNeedsAnInterface(AnInterface anInterface) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@
*/
package test.subcomponent;

import dagger.Binds;
import dagger.Component;
import dagger.Module;
import dagger.Provides;
import dagger.Subcomponent;
import dagger.multibindings.IntoMap;
import dagger.multibindings.IntoSet;
import dagger.multibindings.StringKey;

import java.util.Map;
import java.util.Objects;
import java.util.Set;

import javax.inject.Inject;

final class MultibindingSubcomponents {
Expand Down Expand Up @@ -83,7 +86,7 @@ public String toString() {
}

@Module
static final class ParentMultibindingModule {
abstract static class ParentMultibindingModule {

@Provides
@IntoSet
Expand Down Expand Up @@ -113,13 +116,11 @@ static BoundInParentAndChild inParentAndChildEntry() {

/* This is not static because otherwise we have no tests that cover the case where a
* subcomponent uses a module instance installed onto a parent component. */
@Provides
@Binds
@IntoSet
static RequiresMultibindings<BoundInParentAndChild>
abstract RequiresMultibindings<BoundInParentAndChild>
requiresMultibindingsInParentAndChildElement(
RequiresMultibindings<BoundInParentAndChild> requiresMultibindingsInParentAndChild) {
return requiresMultibindingsInParentAndChild;
}
RequiresMultibindings<BoundInParentAndChild> requiresMultibindingsInParentAndChild);
}

@Module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
*/
package test.subcomponent;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import dagger.multibindings.IntoSet;

import javax.inject.Singleton;

@Module
final class ParentModule {
abstract class ParentModule {
@Provides
@IntoSet
static Object provideUnscopedObject() {
Expand All @@ -43,10 +45,8 @@ static Object provideSingletonObject() {
};
}

@Provides
@Binds
@Singleton
@BoundAsSingleton
static UnscopedType provideUnscopedTypeBoundAsSingleton(UnscopedType unscopedType) {
return unscopedType;
}
abstract UnscopedType provideUnscopedTypeBoundAsSingleton(UnscopedType unscopedType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

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

/**
* @see <a href="http://b/19435358">Bug 19435358</a>
*/
@RunWith(JUnit4.class)
public class DependsOnGeneratedCodeTest {
@Test public void testComponentDependsOnGeneratedCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ public void testParentWithoutProvisionHasChildWithoutProvision() {
.requiresMultibindingsBoundInChild())
.isEqualTo(BOUND_IN_CHILD);

/*
* Even though the multibinding for Set<RequiresMultiboundObjects> does not itself have a
* contribution from the child, it must be pushed down to (not duplicated in) the child because
* its contribution depends on multibindings that have one contribution from the parent and one
* from the child.
*
*/
assertThat(
parentWithoutProvisionHasChildWithoutProvision
.childWithoutProvision()
Expand Down Expand Up @@ -132,6 +139,13 @@ public void testParentWithoutProvisionHasChildWithProvision() {
.requiresMultibindingsBoundInChild())
.isEqualTo(BOUND_IN_CHILD);

/*
* Even though the multibinding for Set<RequiresMultiboundObjects> does not itself have a
* contribution from the child, it must be pushed down to (not duplicated in) the child because
* its contribution depends on multibindings that have one contribution from the parent and one
* from the child.
*
*/
assertThat(
parentWithoutProvisionHasChildWithProvision
.childWithProvision()
Expand Down Expand Up @@ -172,6 +186,13 @@ public void testParentWithProvisionHasChildWithoutProvision() {
.requiresMultibindingsBoundInParentAndChild())
.isEqualTo(BOUND_IN_PARENT_AND_CHILD);

/*
* Even though the multibinding for Set<RequiresMultiboundObjects> does not itself have a
* contribution from the child, it must be pushed down to (not duplicated in) the child because
* its contribution depends on multibindings that have one contribution from the parent and one
* from the child.
*
*/
assertThat(
parentWithProvisionHasChildWithoutProvision
.childWithoutProvision()
Expand Down Expand Up @@ -203,6 +224,13 @@ public void testParentWithProvisionHasChildWithProvision() {
.requiresMultibindingsBoundInParentAndChild())
.isEqualTo(BOUND_IN_PARENT_AND_CHILD);

/*
* Even though the multibinding for Set<RequiresMultiboundObjects> does not itself have a
* contribution from the child, it must be pushed down to (not duplicated in) the child because
* its contribution depends on multibindings that have one contribution from the parent and one
* from the child.
*
*/
assertThat(
parentWithProvisionHasChildWithProvision
.childWithProvision()
Expand All @@ -229,6 +257,13 @@ public void testParentWithProvisionHasChildWithProvision() {
.requiresMultibindingsBoundInParentAndChild())
.isEqualTo(BOUND_IN_PARENT_AND_CHILD);

/*
* Even though the multibinding for Set<RequiresMultiboundObjects> does not itself have a
* contribution from the child, it must be pushed down to (not duplicated in) the child because
* its contribution depends on multibindings that have one contribution from the parent and one
* from the child.
*
*/
assertThat(
parentWithProvisionHasChildWithProvision
.childWithProvision()
Expand Down
Loading

0 comments on commit cbd4286

Please sign in to comment.