Skip to content

Commit

Permalink
Remove the deprecated ApplicationComponent.
Browse files Browse the repository at this point in the history
RELNOTES=Remove the deprecated ApplicationComponent and handling for it. Users should migrate to SingletonComponent.
PiperOrigin-RevId: 346656300
  • Loading branch information
Chang-Eric authored and Dagger Team committed Dec 9, 2020
1 parent 8441d54 commit 37cb8c8
Show file tree
Hide file tree
Showing 14 changed files with 12 additions and 60 deletions.
2 changes: 1 addition & 1 deletion java/dagger/hilt/EntryPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*
* <pre><code>
* {@literal @}EntryPoint
* {@literal @}InstallIn(ApplicationComponent.class)
* {@literal @}InstallIn(SingletonComponent.class)
* public interface FooEntryPoint {
* Foo getFoo();
* }
Expand Down
2 changes: 1 addition & 1 deletion java/dagger/hilt/InstallIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* <pre><code>
* {@literal @}Module
* {@literal @}InstallIn(ApplicationComponent.class)
* {@literal @}InstallIn(SingletonComponent.class)
* public final class FooModule {
* {@literal @}Provides
* static Foo provideFoo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

import dagger.hilt.DefineComponent;
import dagger.hilt.android.scopes.ActivityRetainedScoped;
import dagger.hilt.components.SingletonComponent;

/** A Hilt component that has the lifetime of a configuration surviving activity. */
@ActivityRetainedScoped
@DefineComponent(parent = ApplicationComponent.class)
@DefineComponent(parent = SingletonComponent.class)
public interface ActivityRetainedComponent {}
27 changes: 0 additions & 27 deletions java/dagger/hilt/android/components/ApplicationComponent.java

This file was deleted.

1 change: 0 additions & 1 deletion java/dagger/hilt/android/components/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ android_library(
srcs = [
"ActivityComponent.java",
"ActivityRetainedComponent.java",
"ApplicationComponent.java",
"FragmentComponent.java",
"ServiceComponent.java",
"ViewComponent.java",
Expand Down
3 changes: 2 additions & 1 deletion java/dagger/hilt/android/components/ServiceComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

import dagger.hilt.DefineComponent;
import dagger.hilt.android.scopes.ServiceScoped;
import dagger.hilt.components.SingletonComponent;

/** A Hilt component that has the lifetime of the service. */
@ServiceScoped
@DefineComponent(parent = ApplicationComponent.class)
@DefineComponent(parent = SingletonComponent.class)
public interface ServiceComponent {}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ final class BindValueGenerator {
}

// @Module
// @InstallIn(ApplicationComponent.class)
// @InstallIn(SingletonComponent.class)
// public final class FooTest_BindValueModule {
// // providesMethods ...
// }
Expand Down
2 changes: 1 addition & 1 deletion java/dagger/hilt/android/testing/UninstallModules.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* })
* public class MyTest {
* {@literal @}Module
* {@literal @}InstallIn(ApplicationComponent.class)
* {@literal @}InstallIn(SingletonComponent.class)
* interface FakeFooModule {
* {@literal @}Binds Foo bindFoo(FakeFoo fakeFoo);
* }
Expand Down
2 changes: 1 addition & 1 deletion java/dagger/hilt/codegen/OriginatingElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* <pre><code>
* {@literal @}OriginatingElement(topLevelClass = Outer.class)
* {@literal @}EntryPoint
* {@literal @}InstallIn(ApplicationComponent.class) {
* {@literal @}InstallIn(SingletonComponent.class) {
* ...
* }
* </code></pre>
Expand Down
2 changes: 0 additions & 2 deletions java/dagger/hilt/processor/internal/ClassNames.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ public final class ClassNames {
public static final ClassName ARRAYS = get("java.util", "Arrays");

// Standard components
public static final ClassName LEGACY_APPLICATION_COMPONENT =
get("dagger.hilt.android.components", "ApplicationComponent");
public static final ClassName APPLICATION_COMPONENT =
get("dagger.hilt.components", "SingletonComponent");
public static final ClassName ACTIVITY_COMPONENT =
Expand Down
12 changes: 0 additions & 12 deletions java/dagger/hilt/processor/internal/Components.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ private static ImmutableSet<ClassName> getHiltInstallInComponents(
Processors.getAnnotationMirror(element, ClassNames.INSTALL_IN);
ImmutableSet<TypeElement> components =
Processors.getAnnotationClassValues(elements, hiltInstallIn, "value").stream()
.map(component -> mapComponents(elements, component))
.collect(toImmutableSet());
ImmutableSet<TypeElement> undefinedComponents =
components.stream()
Expand All @@ -106,16 +105,5 @@ private static ImmutableSet<ClassName> getHiltInstallInComponents(
return components.stream().map(ClassName::get).collect(toImmutableSet());
}

// Temporary hack while ApplicationComponent is renamed to SingletonComponent
private static TypeElement mapComponents(Elements elements, TypeElement element) {
if (ClassNames.LEGACY_APPLICATION_COMPONENT.equals(ClassName.get(element))) {
TypeElement singletonComponent =
elements.getTypeElement(ClassNames.APPLICATION_COMPONENT.canonicalName());
Preconditions.checkState(singletonComponent != null);
return singletonComponent;
}
return element;
}

private Components() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private static ImmutableMap<String, ComponentDescriptor> descriptorLookupMap(
// processor since new processors should convert to the new SingletonComponent when generating
// the metadata class.
if (descriptor.component().equals(ClassNames.APPLICATION_COMPONENT)) {
builder.put(ClassNames.LEGACY_APPLICATION_COMPONENT.toString(), descriptor);
builder.put("dagger.hilt.android.components.ApplicationComponent", descriptor);
}
builder.put(descriptor.component().toString(), descriptor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ DefineComponentMetadata get(Element element) {
}

private DefineComponentMetadata get(Element element, LinkedHashSet<Element> childPath) {
// This is a temporary hack to map the old ApplicationComponent to the new SingletonComponent
if (element.getKind().equals(ElementKind.INTERFACE)
&& asType(element).getQualifiedName()
.contentEquals(ClassNames.LEGACY_APPLICATION_COMPONENT.toString())) {
element = asTypeElement(asType(element).getInterfaces().get(0));
}

if (!metadatas.containsKey(element)) {
metadatas.put(element, getUncached(element, childPath));
}
Expand Down Expand Up @@ -159,7 +152,6 @@ private DefineComponentMetadata getUncached(

ProcessorErrors.checkState(
ClassName.get(parent).equals(ClassNames.DEFINE_COMPONENT_NO_PARENT)
|| ClassName.get(parent).equals(ClassNames.LEGACY_APPLICATION_COMPONENT)
|| Processors.hasAnnotation(parent, ClassNames.DEFINE_COMPONENT),
component,
"@DefineComponent %s, references a type not annotated with @DefineComponent: %s",
Expand All @@ -177,7 +169,7 @@ private DefineComponentMetadata getUncached(
component,
"@DefineComponent %s is missing a parent declaration.\n"
+ "Please declare the parent, for example: @DefineComponent(parent ="
+ " ApplicationComponent.class)",
+ " SingletonComponent.class)",
component);

return new AutoValue_DefineComponentMetadatas_DefineComponentMetadata(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public final class TestInjectorGenerator {
}

// @GeneratedEntryPoint
// @InstallIn(ApplicationComponent.class)
// @InstallIn(SingletonComponent.class)
// public interface FooTest_GeneratedInjector extends TestInjector<FooTest> {}
public void generate() throws IOException {
TypeSpec.Builder builder =
Expand Down

0 comments on commit 37cb8c8

Please sign in to comment.