Skip to content

Commit

Permalink
Internal changes.
Browse files Browse the repository at this point in the history
RELNOTES=n/a
PiperOrigin-RevId: 428623624
  • Loading branch information
Chang-Eric authored and Dagger Team committed Feb 14, 2022
1 parent 703ccc8 commit 3ae46b8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,27 +151,34 @@ private MethodSpec componentManagerMethod() {
// }
// }
private TypeSpec creatorType() {
ClassName component =
componentNames.generatedComponent(
metadata.elementClassName(), AndroidClassNames.SINGLETON_COMPONENT);
return TypeSpec.anonymousClassBuilder("")
.addSuperinterface(AndroidClassNames.COMPONENT_SUPPLIER)
.addMethod(
MethodSpec.methodBuilder("get")
.addAnnotation(Override.class)
.addModifiers(Modifier.PUBLIC)
.returns(TypeName.OBJECT)
.addStatement(
"return $T.builder()\n"
+ ".applicationContextModule(new $T($T.this))\n"
+ ".build()",
Processors.prepend(Processors.getEnclosedClassName(component), "Dagger"),
AndroidClassNames.APPLICATION_CONTEXT_MODULE,
wrapperClassName)
.addCode(componentBuilder())
.build())
.build();
}

// return DaggerApplicationComponent.builder()
// .applicationContextModule(new ApplicationContextModule(Hilt_$APP.this))
// .build();
private CodeBlock componentBuilder() {
ClassName component =
componentNames.generatedComponent(
metadata.elementClassName(), AndroidClassNames.SINGLETON_COMPONENT);
return CodeBlock.builder()
.addStatement(
"return $T.builder()$Z" + ".applicationContextModule(new $T($T.this))$Z" + ".build()",
Processors.prepend(Processors.getEnclosedClassName(component), "Dagger"),
AndroidClassNames.APPLICATION_CONTEXT_MODULE,
wrapperClassName)
.build();
}

// @CallSuper
// @Override
// public void onCreate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ java_library(
"//java/dagger/hilt/processor/internal:base_processor",
"//java/dagger/hilt/processor/internal:compiler_options",
"//java/dagger/hilt/processor/internal:processor_errors",
"//java/dagger/hilt/processor/internal:processors",
"//third_party/java/auto:service",
"//third_party/java/guava/collect",
"//third_party/java/incap",
Expand Down
2 changes: 2 additions & 0 deletions java/dagger/hilt/processor/internal/root/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ java_library(
deps = [
":root_metadata",
":root_type",
"//java/dagger/hilt/android/processor/internal/androidentrypoint:android_generators",
"//java/dagger/hilt/android/processor/internal/androidentrypoint:metadata",
"//java/dagger/hilt/processor/internal:aggregated_elements",
"//java/dagger/hilt/processor/internal:base_processor",
"//java/dagger/hilt/processor/internal:classnames",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ private void generateApplication(TypeElement rootElement) throws IOException {
if (!useAggregatingRootProcessor(getProcessingEnv())) {
AndroidEntryPointMetadata metadata =
AndroidEntryPointMetadata.of(getProcessingEnv(), rootElement);
new ApplicationGenerator(getProcessingEnv(), metadata).generate();
new ApplicationGenerator(
getProcessingEnv(),
metadata)
.generate();
}
}
}
10 changes: 5 additions & 5 deletions java/dagger/hilt/processor/internal/root/RootType.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@

/** The valid root types for Hilt applications. */
// TODO(erichang): Fix this class so we don't have to have placeholders
enum RootType {
ROOT(ClassNames.HILT_ANDROID_APP),
enum RootType {
ROOT(ClassNames.HILT_ANDROID_APP),

// Placeholder to make sure @HiltAndroidTest usages get processed
HILT_ANDROID_TEST_ROOT(ClassNames.HILT_ANDROID_TEST),
// Placeholder to make sure @HiltAndroidTest usages get processed
HILT_ANDROID_TEST_ROOT(ClassNames.HILT_ANDROID_TEST),

TEST_ROOT(ClassNames.INTERNAL_TEST_ROOT);
TEST_ROOT(ClassNames.INTERNAL_TEST_ROOT);

@SuppressWarnings("ImmutableEnumChecker")
private final ClassName annotation;
Expand Down

0 comments on commit 3ae46b8

Please sign in to comment.