Skip to content

Commit

Permalink
Fix the @GenerationOptions retrieval and enable a build_test for the …
Browse files Browse the repository at this point in the history
…dagger.functional.aot.fastinit libraries so that we catch this in presubmit.

I originally had this and dpb@ asked what it was doing, and I wasn't able to remember why I had done it that way, and all of the tests were passing so I "simplified" it. I added a comment about what's going on so it's clearer in the future.

RELNOTES=n/a

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=229463931
  • Loading branch information
ronshapiro committed Jan 16, 2019
1 parent 13f0cbe commit e0e47f1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions java/dagger/internal/codegen/GenerationOptionsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import dagger.Module;
import dagger.Provides;
import dagger.internal.GenerationOptions;
import java.util.Optional;

/** Adds bindings for serializing and rereading {@link GenerationOptions}. */
@Module
Expand All @@ -30,9 +31,18 @@ static CompilerOptions generationOptions(
CompilerOptions defaultOptions,
ComponentImplementation componentImplementation,
DaggerElements elements) {
return componentImplementation
.baseImplementation()
// Inspect the base implementation for the @GenerationOptions annotation. Even if
// componentImplementation is the base implementation, inspect it for the case where we are
// recomputing the ComponentImplementation from a previous compilation.
// TODO(b/117833324): consider adding a method that returns baseImplementation.orElse(this).
// The current state of the world is a little confusing and maybe not intuitive: the base
// implementation has no base implementation, but it _is_ a base implementation.
return Optional.of(componentImplementation.baseImplementation().orElse(componentImplementation))
.map(baseImplementation -> elements.getTypeElement(baseImplementation.name()))
// If this returns null, the type has not been generated yet and Optional will switch to an
// empty state. This means that we're currently generating componentImplementation, or that
// the base implementation is being generated in this round, and thus the options passed to
// this compilation are applicable
.map(typeElement -> typeElement.getAnnotation(GenerationOptions.class))
.map(defaultOptions::withGenerationOptions)
.orElse(defaultOptions);
Expand Down

0 comments on commit e0e47f1

Please sign in to comment.