Skip to content

Commit

Permalink
Merge pull request #364 from google/moe_writing_branch_from_3294e6842…
Browse files Browse the repository at this point in the history
…ad6d4f3190c7e6f5310901991a60ecd

Follow up MOE sync for 2.4
  • Loading branch information
ronshapiro committed Apr 21, 2016
2 parents 28d7710 + 6305c4e commit f60266a
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 50 deletions.
4 changes: 2 additions & 2 deletions compiler/src/main/java/dagger/internal/codegen/MapKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.collect.Iterables.transform;
import static dagger.internal.codegen.CodeBlocks.makeParametersCodeBlock;
import static dagger.internal.codegen.SourceFiles.canonicalName;
import static dagger.internal.codegen.SourceFiles.classFileName;
import static javax.lang.model.util.ElementFilter.methodsIn;

/**
Expand Down Expand Up @@ -138,7 +138,7 @@ public DeclaredType visitDeclared(DeclaredType t, Void p) {
*/
public static ClassName getMapKeyCreatorClassName(TypeElement mapKeyType) {
ClassName mapKeyTypeName = ClassName.get(mapKeyType);
return mapKeyTypeName.topLevelClassName().peerClass(canonicalName(mapKeyTypeName) + "Creator");
return mapKeyTypeName.topLevelClassName().peerClass(classFileName(mapKeyTypeName) + "Creator");
}

/**
Expand Down
14 changes: 2 additions & 12 deletions compiler/src/main/java/dagger/internal/codegen/SourceFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
class SourceFiles {

private static final Joiner CLASS_FILE_NAME_JOINER = Joiner.on('_');
private static final Joiner CANONICAL_NAME_JOINER = Joiner.on('$');

/**
* Sorts {@link DependencyRequest} instances in an order likely to reflect their logical
Expand Down Expand Up @@ -159,7 +158,7 @@ static ClassName generatedClassNameForBinding(Binding binding) {
return enclosingClassName
.topLevelClassName()
.peerClass(
canonicalName(enclosingClassName)
classFileName(enclosingClassName)
+ "_"
+ factoryPrefix(contribution)
+ "Factory");
Expand Down Expand Up @@ -239,15 +238,6 @@ static ClassName membersInjectorNameForType(TypeElement typeElement) {
return siblingClassName(typeElement, "_MembersInjector");
}

/**
* @deprecated prefer {@link #classFileName(ClassName)} instead and avoid dollar signs in
* generated source.
*/
@Deprecated
static String canonicalName(ClassName className) {
return CANONICAL_NAME_JOINER.join(className.simpleNames());
}

static String classFileName(ClassName className) {
return CLASS_FILE_NAME_JOINER.join(className.simpleNames());
}
Expand All @@ -265,7 +255,7 @@ static ClassName generatedProductionExecutorModuleName(TypeElement componentElem
// which could use this.
private static ClassName siblingClassName(TypeElement typeElement, String suffix) {
ClassName className = ClassName.get(typeElement);
return className.topLevelClassName().peerClass(canonicalName(className) + suffix);
return className.topLevelClassName().peerClass(classFileName(className) + suffix);
}

private static String factoryPrefix(ContributionBinding binding) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,12 @@ public class ComponentProcessorTest {
" @SuppressWarnings(\"unchecked\")",
" private void initialize(final Builder builder) {",
" this.bMembersInjector =",
" OuterType$B_MembersInjector.create(OuterType$A_Factory.create());",
" OuterType_B_MembersInjector.create(OuterType_A_Factory.create());",
" }",
"",
" @Override",
" public OuterType.A a() {",
" return OuterType$A_Factory.create().get();",
" return OuterType_A_Factory.create().get();",
" }",
"",
" @Override",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1205,14 +1205,14 @@ public void noDeps() {
" }",
"}");
JavaFileObject aFactory = JavaFileObjects.forSourceLines(
"test.OuterType$A_Factory",
"test.OuterType_A_Factory",
"package test;",
"",
"import dagger.internal.Factory;",
"import javax.annotation.Generated;",
"",
GENERATED_ANNOTATION,
"public enum OuterType$A_Factory implements Factory<OuterType.A> {",
"public enum OuterType_A_Factory implements Factory<OuterType.A> {",
" INSTANCE;",
"",
" @Override public OuterType.A get() {",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,20 @@ public void nestedMapKeyCreatorFile() {
"}");
JavaFileObject generatedKeyCreator =
JavaFileObjects.forSourceLines(
"test.Container$PathKeyCreator",
"test.Container_PathKeyCreator",
"package test;",
"",
"import com.google.auto.value.AutoAnnotation;",
"import javax.annotation.Generated;",
"",
GENERATED_ANNOTATION,
"public final class Container$PathKeyCreator {",
" private Container$PathKeyCreator() {}",
"public final class Container_PathKeyCreator {",
" private Container_PathKeyCreator() {}",
"",
" @AutoAnnotation",
" public static Container.PathKey createPathKey("
+ "PathEnum value, String relativePath) {",
" return new AutoAnnotation_Container$PathKeyCreator_createPathKey(",
" return new AutoAnnotation_Container_PathKeyCreator_createPathKey(",
" value, relativePath);",
" }",
"}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -737,24 +737,25 @@ public void simpleComponentWithNesting() {
" }",
"}");
JavaFileObject bMembersInjector = JavaFileObjects.forSourceLines(
"test.OuterType$B_MembersInjector",
"test.OuterType_B_MembersInjector",
"package test;",
"",
"import dagger.MembersInjector;",
"import javax.annotation.Generated;",
"import javax.inject.Provider;",
"",
GENERATED_ANNOTATION,
"public final class OuterType$B_MembersInjector implements MembersInjector<OuterType.B> {",
"public final class OuterType_B_MembersInjector",
" implements MembersInjector<OuterType.B> {",
" private final Provider<OuterType.A> aProvider;",
"",
" public OuterType$B_MembersInjector(Provider<OuterType.A> aProvider) {",
" public OuterType_B_MembersInjector(Provider<OuterType.A> aProvider) {",
" assert aProvider != null;",
" this.aProvider = aProvider;",
" }",
"",
" public static MembersInjector<OuterType.B> create(Provider<OuterType.A> aProvider) {",
" return new OuterType$B_MembersInjector(aProvider);",
" return new OuterType_B_MembersInjector(aProvider);",
" }",
"",
" @Override",
Expand Down Expand Up @@ -802,24 +803,25 @@ public void componentWithNestingAndGeneratedType() {
"}");
JavaFileObject bMembersInjector =
JavaFileObjects.forSourceLines(
"test.OuterType$B_MembersInjector",
"test.OuterType_B_MembersInjector",
"package test;",
"",
"import dagger.MembersInjector;",
"import javax.annotation.Generated;",
"import javax.inject.Provider;",
"",
GENERATED_ANNOTATION,
"public final class OuterType$B_MembersInjector implements MembersInjector<OuterType.B> {",
"public final class OuterType_B_MembersInjector",
" implements MembersInjector<OuterType.B> {",
" private final Provider<OuterType.A> aProvider;",
"",
" public OuterType$B_MembersInjector(Provider<OuterType.A> aProvider) {",
" public OuterType_B_MembersInjector(Provider<OuterType.A> aProvider) {",
" assert aProvider != null;",
" this.aProvider = aProvider;",
" }",
"",
" public static MembersInjector<OuterType.B> create(Provider<OuterType.A> aProvider) {",
" return new OuterType$B_MembersInjector(aProvider);",
" return new OuterType_B_MembersInjector(aProvider);",
" }",
"",
" @Override",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,22 +241,22 @@ public void simpleComponent() {
" @SuppressWarnings(\"unchecked\")",
" private void initialize(final Builder builder) {",
" this.executorProvider =",
" TestClass$BModule_ExecutorFactory.create(builder.bModule);",
" TestClass_BModule_ExecutorFactory.create(builder.bModule);",
" this.executorProvider2 =",
" DoubleCheck.provider(",
" TestClass$SimpleComponent_ProductionExecutorModule_ExecutorFactory.create(",
" executorProvider));",
" TestClass_SimpleComponent_ProductionExecutorModule_ExecutorFactory",
" .create(executorProvider));",
" this.simpleComponentProvider =",
" InstanceFactory.<TestClass.SimpleComponent>create(this);",
" this.monitorProvider =",
" DoubleCheck.provider(",
" TestClass$SimpleComponent_MonitoringModule_MonitorFactory.create(",
" TestClass_SimpleComponent_MonitoringModule_MonitorFactory.create(",
" simpleComponentProvider,",
" SetFactory.<ProductionComponentMonitor.Factory>create());",
" this.bProvider = TestClass$BModule_BFactory.create(",
" builder.bModule, TestClass$C_Factory.create());",
" this.bProvider = TestClass_BModule_BFactory.create(",
" builder.bModule, TestClass_C_Factory.create());",
" this.bProducer = Producers.producerFromProvider(bProvider);",
" this.aProducer = new TestClass$AModule_AFactory(",
" this.aProducer = new TestClass_AModule_AFactory(",
" builder.aModule,",
" executorProvider2,",
" monitorProvider,",
Expand Down Expand Up @@ -296,18 +296,18 @@ public void simpleComponent() {
" }",
"",
" @Deprecated",
" public Builder testClass$SimpleComponent_MonitoringModule(",
" TestClass$SimpleComponent_MonitoringModule",
" testClass$SimpleComponent_MonitoringModule) {",
" Preconditions.checkNotNull(testClass$SimpleComponent_MonitoringModule);",
" public Builder testClass_SimpleComponent_MonitoringModule(",
" TestClass_SimpleComponent_MonitoringModule",
" testClass_SimpleComponent_MonitoringModule) {",
" Preconditions.checkNotNull(testClass_SimpleComponent_MonitoringModule);",
" return this;",
" }",
"",
" @Deprecated",
" public Builder testClass$SimpleComponent_ProductionExecutorModule(",
" TestClass$SimpleComponent_ProductionExecutorModule",
" testClass$SimpleComponent_ProductionExecutorModule) {",
" Preconditions.checkNotNull(testClass$SimpleComponent_ProductionExecutorModule);",
" public Builder testClass_SimpleComponent_ProductionExecutorModule(",
" TestClass_SimpleComponent_ProductionExecutorModule",
" testClass_SimpleComponent_ProductionExecutorModule) {",
" Preconditions.checkNotNull(testClass_SimpleComponent_ProductionExecutorModule);",
" return this;",
" }",
"}");
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/dagger/Binds.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
/**
* Annotates <em>abstract</em> methods of a {@link Module} that delegate bindings. For example, to
* bind {@link java.util.Random} to {@link java.security.SecureRandom} a module could declare the
* following: {@code @Bind abstract Random bindRandom(SecureRandom secureRandom);}
* following: {@code @Binds abstract Random bindRandom(SecureRandom secureRandom);}
*
* <p>{@code @Bind} methods are a drop-in replacement for {@link Provides} methods that simply
* return an injected parameter. Prefer {@code @Bind} because the generated implementation is
* <p>{@code @Binds} methods are a drop-in replacement for {@link Provides} methods that simply
* return an injected parameter. Prefer {@code @Binds} because the generated implementation is
* likely to be more efficient.
*
* <p>A {@code @Bind} method:
* <p>A {@code @Binds} method:
* <ul>
* <li>Must be {@code abstract}.
* <li>Must have a single parameter whose type is assignable to the return type. The return type is
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<auto.value.version>1.2</auto.value.version>
<errorprone.version>2.0.8</errorprone.version>
<guava.version>19.0</guava.version>
<google.java.format.version>0.1-alpha</google.java.format.version>
<google.java.format.version>1.0</google.java.format.version>


<!-- Test Dependencies -->
Expand Down

0 comments on commit f60266a

Please sign in to comment.