Skip to content

Commit

Permalink
[Dagger Cleanup]: Remove unused code.
Browse files Browse the repository at this point in the history
RELNOTES=N/A
PiperOrigin-RevId: 428579465
  • Loading branch information
bcorso authored and Dagger Team committed Feb 14, 2022
1 parent 6758662 commit c295d12
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 112 deletions.
15 changes: 1 addition & 14 deletions java/dagger/internal/codegen/base/ComponentAnnotation.java
Expand Up @@ -49,19 +49,6 @@ public abstract class ComponentAnnotation {
private static final ImmutableSet<ClassName> SUBCOMPONENT_ANNOTATIONS =
ImmutableSet.of(TypeNames.SUBCOMPONENT, TypeNames.PRODUCTION_SUBCOMPONENT);

// TODO(erichang): Move ComponentCreatorAnnotation into /base and use that here?
/** The component/subcomponent creator annotation types. */
private static final ImmutableSet<ClassName> CREATOR_ANNOTATIONS =
ImmutableSet.of(
TypeNames.COMPONENT_BUILDER,
TypeNames.COMPONENT_FACTORY,
TypeNames.PRODUCTION_COMPONENT_BUILDER,
TypeNames.PRODUCTION_COMPONENT_FACTORY,
TypeNames.SUBCOMPONENT_BUILDER,
TypeNames.SUBCOMPONENT_FACTORY,
TypeNames.PRODUCTION_SUBCOMPONENT_BUILDER,
TypeNames.PRODUCTION_SUBCOMPONENT_FACTORY);

/** All component annotation types. */
private static final ImmutableSet<ClassName> ALL_COMPONENT_ANNOTATIONS =
ImmutableSet.<ClassName>builder()
Expand All @@ -73,7 +60,7 @@ public abstract class ComponentAnnotation {
private static final ImmutableSet<ClassName> ALL_COMPONENT_AND_CREATOR_ANNOTATIONS =
ImmutableSet.<ClassName>builder()
.addAll(ALL_COMPONENT_ANNOTATIONS)
.addAll(CREATOR_ANNOTATIONS)
.addAll(ComponentCreatorAnnotation.allCreatorAnnotations())
.build();

/** All production annotation types. */
Expand Down
Expand Up @@ -16,11 +16,9 @@

package dagger.internal.codegen.base;

import static androidx.room.compiler.processing.compat.XConverters.toJavac;
import static com.google.common.base.Ascii.toUpperCase;
import static dagger.internal.codegen.extension.DaggerStreams.toImmutableSet;
import static dagger.internal.codegen.extension.DaggerStreams.valuesOf;
import static dagger.internal.codegen.langmodel.DaggerElements.isAnnotationPresent;
import static java.util.stream.Collectors.mapping;

import androidx.room.compiler.processing.XTypeElement;
Expand All @@ -29,7 +27,6 @@
import dagger.internal.codegen.javapoet.TypeNames;
import java.util.stream.Collector;
import java.util.stream.Stream;
import javax.lang.model.element.TypeElement;

/** Simple representation of a component creator annotation type. */
public enum ComponentCreatorAnnotation {
Expand Down Expand Up @@ -133,14 +130,7 @@ public static ImmutableSet<ClassName> creatorAnnotationsFor(

/** Returns all creator annotations present on the given {@code type}. */
public static ImmutableSet<ComponentCreatorAnnotation> getCreatorAnnotations(XTypeElement type) {
return getCreatorAnnotations(toJavac(type));
}

/** Returns all creator annotations present on the given {@code type}. */
public static ImmutableSet<ComponentCreatorAnnotation> getCreatorAnnotations(TypeElement type) {
return stream()
.filter(cca -> isAnnotationPresent(type, cca.annotation()))
.collect(toImmutableSet());
return stream().filter(cca -> type.hasAnnotation(cca.annotation())).collect(toImmutableSet());
}

private static Stream<ComponentCreatorAnnotation> stream() {
Expand Down
81 changes: 10 additions & 71 deletions java/dagger/internal/codegen/base/ComponentKind.java
Expand Up @@ -30,52 +30,15 @@

/** Enumeration of the different kinds of components. */
public enum ComponentKind {
/** {@code @Component} */
COMPONENT(TypeNames.COMPONENT, true, false),
COMPONENT(TypeNames.COMPONENT),
SUBCOMPONENT(TypeNames.SUBCOMPONENT),
PRODUCTION_COMPONENT(TypeNames.PRODUCTION_COMPONENT),
PRODUCTION_SUBCOMPONENT(TypeNames.PRODUCTION_SUBCOMPONENT),
MODULE(TypeNames.MODULE),
PRODUCER_MODULE(TypeNames.PRODUCER_MODULE);

/** {@code @Subcomponent} */
SUBCOMPONENT(TypeNames.SUBCOMPONENT, false, false),

/** {@code @ProductionComponent} */
PRODUCTION_COMPONENT(TypeNames.PRODUCTION_COMPONENT, true, true),

/** {@code @ProductionSubcomponent} */
PRODUCTION_SUBCOMPONENT(TypeNames.PRODUCTION_SUBCOMPONENT, false, true),

/**
* Kind for a descriptor that was generated from a {@link dagger.Module} instead of a component
* type in order to validate the module's bindings.
*/
MODULE(TypeNames.MODULE, true, false),

/**
* Kind for a descriptor was generated from a {@link dagger.producers.ProducerModule} instead of a
* component type in order to validate the module's bindings.
*/
PRODUCER_MODULE(TypeNames.PRODUCER_MODULE, true, true),
;

private static final ImmutableSet<ComponentKind> ROOT_COMPONENT_KINDS =
valuesOf(ComponentKind.class)
.filter(kind -> !kind.isForModuleValidation())
.filter(kind -> kind.isRoot())
.collect(toImmutableSet());

private static final ImmutableSet<ComponentKind> SUBCOMPONENT_KINDS =
valuesOf(ComponentKind.class)
.filter(kind -> !kind.isForModuleValidation())
.filter(kind -> !kind.isRoot())
.collect(toImmutableSet());

/** Returns the set of kinds for root components. */
public static ImmutableSet<ComponentKind> rootComponentKinds() {
return ROOT_COMPONENT_KINDS;
}

/** Returns the set of kinds for subcomponents. */
public static ImmutableSet<ComponentKind> subcomponentKinds() {
return SUBCOMPONENT_KINDS;
}
private static final ImmutableSet<ComponentKind> PRODUCER_KINDS =
ImmutableSet.of(PRODUCTION_COMPONENT, PRODUCTION_SUBCOMPONENT, PRODUCER_MODULE);

/** Returns the annotations for components of the given kinds. */
public static ImmutableSet<ClassName> annotationsFor(Iterable<ComponentKind> kinds) {
Expand Down Expand Up @@ -106,13 +69,9 @@ public static Optional<ComponentKind> forAnnotatedElement(XTypeElement element)
}

private final ClassName annotation;
private final boolean isRoot;
private final boolean production;

ComponentKind(ClassName annotation, boolean isRoot, boolean production) {
ComponentKind(ClassName annotation) {
this.annotation = annotation;
this.isRoot = isRoot;
this.production = production;
}

/** Returns the annotation that marks a component of this kind. */
Expand All @@ -134,28 +93,8 @@ public ImmutableSet<ComponentKind> legalSubcomponentKinds() {
: immutableEnumSet(SUBCOMPONENT, PRODUCTION_SUBCOMPONENT);
}

/**
* Returns {@code true} if the descriptor is for a root component (not a subcomponent) or is for
* {@linkplain #isForModuleValidation() module-validation}.
*/
public boolean isRoot() {
return isRoot;
}

/** Returns true if this is a production component. */
public boolean isProducer() {
return production;
}

/** Returns {@code true} if the descriptor is for a module in order to validate its bindings. */
public boolean isForModuleValidation() {
switch (this) {
case MODULE:
case PRODUCER_MODULE:
return true;
default:
// fall through
}
return false;
return PRODUCER_KINDS.contains(this);
}
}
18 changes: 2 additions & 16 deletions java/dagger/internal/codegen/base/ModuleKind.java
Expand Up @@ -16,10 +16,8 @@

package dagger.internal.codegen.base;

import static androidx.room.compiler.processing.compat.XConverters.toJavac;
import static com.google.common.base.Preconditions.checkArgument;
import static dagger.internal.codegen.extension.DaggerStreams.toImmutableSet;
import static dagger.internal.codegen.langmodel.DaggerElements.isAnnotationPresent;

import androidx.room.compiler.processing.XAnnotation;
import androidx.room.compiler.processing.XTypeElement;
Expand All @@ -30,7 +28,6 @@
import java.util.EnumSet;
import java.util.Optional;
import java.util.Set;
import javax.lang.model.element.TypeElement;

/** Enumeration of the kinds of modules. */
public enum ModuleKind {
Expand All @@ -41,7 +38,7 @@ public enum ModuleKind {
PRODUCER_MODULE(TypeNames.PRODUCER_MODULE);

/** Returns the annotations for modules of the given kinds. */
public static ImmutableSet<ClassName> annotationsFor(Set<ModuleKind> kinds) {
private static ImmutableSet<ClassName> annotationsFor(Set<ModuleKind> kinds) {
return kinds.stream().map(ModuleKind::annotation).collect(toImmutableSet());
}

Expand All @@ -53,20 +50,9 @@ public static ImmutableSet<ClassName> annotationsFor(Set<ModuleKind> kinds) {
* annotations
*/
public static Optional<ModuleKind> forAnnotatedElement(XTypeElement element) {
return forAnnotatedElement(toJavac(element));
}

/**
* Returns the kind of an annotated element if it is annotated with one of the module {@linkplain
* #annotation() annotations}.
*
* @throws IllegalArgumentException if the element is annotated with more than one of the module
* annotations
*/
public static Optional<ModuleKind> forAnnotatedElement(TypeElement element) {
Set<ModuleKind> kinds = EnumSet.noneOf(ModuleKind.class);
for (ModuleKind kind : values()) {
if (isAnnotationPresent(element, kind.annotation())) {
if (element.hasAnnotation(kind.annotation())) {
kinds.add(kind);
}
}
Expand Down

0 comments on commit c295d12

Please sign in to comment.