Skip to content

Commit

Permalink
Migrate more classes from ClassName to XClassName.
Browse files Browse the repository at this point in the history
RELNOTES=N/A
PiperOrigin-RevId: 714986669
  • Loading branch information
bcorso authored and Dagger Team committed Jan 13, 2025
1 parent 91450da commit 5cfd6eb
Show file tree
Hide file tree
Showing 37 changed files with 317 additions and 312 deletions.
50 changes: 25 additions & 25 deletions java/dagger/internal/codegen/base/ComponentAnnotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
package dagger.internal.codegen.base;

import static dagger.internal.codegen.extension.DaggerStreams.toImmutableSet;
import static dagger.internal.codegen.xprocessing.XAnnotations.getClassName;
import static dagger.internal.codegen.xprocessing.XAnnotations.asClassName;
import static dagger.internal.codegen.xprocessing.XElements.getAnyAnnotation;

import androidx.room.compiler.codegen.XClassName;
import androidx.room.compiler.processing.XAnnotation;
import androidx.room.compiler.processing.XElement;
import androidx.room.compiler.processing.XType;
Expand All @@ -28,8 +29,7 @@
import com.google.auto.value.extension.memoized.Memoized;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.squareup.javapoet.ClassName;
import dagger.internal.codegen.javapoet.TypeNames;
import dagger.internal.codegen.xprocessing.XTypeNames;
import java.util.Collection;
import java.util.Optional;

Expand All @@ -42,33 +42,33 @@
@AutoValue
public abstract class ComponentAnnotation {
/** The root component annotation types. */
private static final ImmutableSet<ClassName> ROOT_COMPONENT_ANNOTATIONS =
ImmutableSet.of(TypeNames.COMPONENT, TypeNames.PRODUCTION_COMPONENT);
private static final ImmutableSet<XClassName> ROOT_COMPONENT_ANNOTATIONS =
ImmutableSet.of(XTypeNames.COMPONENT, XTypeNames.PRODUCTION_COMPONENT);

/** The subcomponent annotation types. */
private static final ImmutableSet<ClassName> SUBCOMPONENT_ANNOTATIONS =
ImmutableSet.of(TypeNames.SUBCOMPONENT, TypeNames.PRODUCTION_SUBCOMPONENT);
private static final ImmutableSet<XClassName> SUBCOMPONENT_ANNOTATIONS =
ImmutableSet.of(XTypeNames.SUBCOMPONENT, XTypeNames.PRODUCTION_SUBCOMPONENT);

/** All component annotation types. */
private static final ImmutableSet<ClassName> ALL_COMPONENT_ANNOTATIONS =
ImmutableSet.<ClassName>builder()
private static final ImmutableSet<XClassName> ALL_COMPONENT_ANNOTATIONS =
ImmutableSet.<XClassName>builder()
.addAll(ROOT_COMPONENT_ANNOTATIONS)
.addAll(SUBCOMPONENT_ANNOTATIONS)
.build();

/** All component and creator annotation types. */
private static final ImmutableSet<ClassName> ALL_COMPONENT_AND_CREATOR_ANNOTATIONS =
ImmutableSet.<ClassName>builder()
private static final ImmutableSet<XClassName> ALL_COMPONENT_AND_CREATOR_ANNOTATIONS =
ImmutableSet.<XClassName>builder()
.addAll(ALL_COMPONENT_ANNOTATIONS)
.addAll(ComponentCreatorAnnotation.allCreatorAnnotations())
.build();

/** All production annotation types. */
private static final ImmutableSet<ClassName> PRODUCTION_ANNOTATIONS =
private static final ImmutableSet<XClassName> PRODUCTION_ANNOTATIONS =
ImmutableSet.of(
TypeNames.PRODUCTION_COMPONENT,
TypeNames.PRODUCTION_SUBCOMPONENT,
TypeNames.PRODUCER_MODULE);
XTypeNames.PRODUCTION_COMPONENT,
XTypeNames.PRODUCTION_SUBCOMPONENT,
XTypeNames.PRODUCER_MODULE);

private XAnnotation annotation;

Expand All @@ -77,12 +77,12 @@ public final XAnnotation annotation() {
return annotation;
}

/** Returns the {@link ClassName} name of the annotation. */
public abstract ClassName className();
/** Returns the {@link XClassName} name of the annotation. */
public abstract XClassName className();

/** The simple name of the annotation type. */
public final String simpleName() {
return className().simpleName();
return XTypeNames.simpleName(className());
}

/**
Expand Down Expand Up @@ -172,7 +172,7 @@ public static Optional<ComponentAnnotation> anyComponentAnnotation(

private static Optional<ComponentAnnotation> anyComponentAnnotation(
XElement element,
Collection<ClassName> annotations,
Collection<XClassName> annotations,
DaggerSuperficialValidation superficialValidation) {
return getAnyAnnotation(element, annotations)
.map(
Expand All @@ -184,7 +184,7 @@ private static Optional<ComponentAnnotation> anyComponentAnnotation(

/** Returns {@code true} if the argument is a component annotation. */
public static boolean isComponentAnnotation(XAnnotation annotation) {
return ALL_COMPONENT_ANNOTATIONS.contains(getClassName(annotation));
return ALL_COMPONENT_ANNOTATIONS.contains(asClassName(annotation));
}

/** Creates a fictional component annotation representing a module. */
Expand All @@ -194,28 +194,28 @@ public static ComponentAnnotation fromModuleAnnotation(ModuleAnnotation moduleAn

private static ComponentAnnotation create(XAnnotation annotation) {
ComponentAnnotation componentAnnotation =
new AutoValue_ComponentAnnotation(getClassName(annotation));
new AutoValue_ComponentAnnotation(asClassName(annotation));
componentAnnotation.annotation = annotation;
return componentAnnotation;
}

/** The root component annotation types. */
public static ImmutableSet<ClassName> rootComponentAnnotations() {
public static ImmutableSet<XClassName> rootComponentAnnotations() {
return ROOT_COMPONENT_ANNOTATIONS;
}

/** The subcomponent annotation types. */
public static ImmutableSet<ClassName> subcomponentAnnotations() {
public static ImmutableSet<XClassName> subcomponentAnnotations() {
return SUBCOMPONENT_ANNOTATIONS;
}

/** All component annotation types. */
public static ImmutableSet<ClassName> allComponentAnnotations() {
public static ImmutableSet<XClassName> allComponentAnnotations() {
return ALL_COMPONENT_ANNOTATIONS;
}

/** All component and creator annotation types. */
public static ImmutableSet<ClassName> allComponentAndCreatorAnnotations() {
public static ImmutableSet<XClassName> allComponentAndCreatorAnnotations() {
return ALL_COMPONENT_AND_CREATOR_ANNOTATIONS;
}
}
64 changes: 35 additions & 29 deletions java/dagger/internal/codegen/base/ComponentCreatorAnnotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,55 +21,59 @@
import static dagger.internal.codegen.extension.DaggerStreams.valuesOf;
import static java.util.stream.Collectors.mapping;

import androidx.room.compiler.codegen.XClassName;
import androidx.room.compiler.processing.XTypeElement;
import com.google.common.collect.ImmutableSet;
import com.squareup.javapoet.ClassName;
import dagger.internal.codegen.javapoet.TypeNames;
import dagger.internal.codegen.xprocessing.XTypeNames;
import java.util.stream.Collector;
import java.util.stream.Stream;

/** Simple representation of a component creator annotation type. */
public enum ComponentCreatorAnnotation {
COMPONENT_BUILDER(TypeNames.COMPONENT_BUILDER),
COMPONENT_FACTORY(TypeNames.COMPONENT_FACTORY),
SUBCOMPONENT_BUILDER(TypeNames.SUBCOMPONENT_BUILDER),
SUBCOMPONENT_FACTORY(TypeNames.SUBCOMPONENT_FACTORY),
PRODUCTION_COMPONENT_BUILDER(TypeNames.PRODUCTION_COMPONENT_BUILDER),
PRODUCTION_COMPONENT_FACTORY(TypeNames.PRODUCTION_COMPONENT_FACTORY),
PRODUCTION_SUBCOMPONENT_BUILDER(TypeNames.PRODUCTION_SUBCOMPONENT_BUILDER),
PRODUCTION_SUBCOMPONENT_FACTORY(TypeNames.PRODUCTION_SUBCOMPONENT_FACTORY),
COMPONENT_BUILDER(XTypeNames.COMPONENT_BUILDER),
COMPONENT_FACTORY(XTypeNames.COMPONENT_FACTORY),
SUBCOMPONENT_BUILDER(XTypeNames.SUBCOMPONENT_BUILDER),
SUBCOMPONENT_FACTORY(XTypeNames.SUBCOMPONENT_FACTORY),
PRODUCTION_COMPONENT_BUILDER(XTypeNames.PRODUCTION_COMPONENT_BUILDER),
PRODUCTION_COMPONENT_FACTORY(XTypeNames.PRODUCTION_COMPONENT_FACTORY),
PRODUCTION_SUBCOMPONENT_BUILDER(XTypeNames.PRODUCTION_SUBCOMPONENT_BUILDER),
PRODUCTION_SUBCOMPONENT_FACTORY(XTypeNames.PRODUCTION_SUBCOMPONENT_FACTORY),
;

private final ClassName annotation;
@SuppressWarnings("ImmutableEnumChecker")
private final XClassName annotation;

private final ComponentCreatorKind creatorKind;
private final ClassName componentAnnotation;

ComponentCreatorAnnotation(ClassName annotation) {
@SuppressWarnings("ImmutableEnumChecker")
private final XClassName componentAnnotation;

ComponentCreatorAnnotation(XClassName annotation) {
this.annotation = annotation;
this.creatorKind = ComponentCreatorKind.valueOf(toUpperCase(annotation.simpleName()));
this.componentAnnotation = annotation.enclosingClassName();
this.creatorKind = ComponentCreatorKind.valueOf(toUpperCase(XTypeNames.simpleName(annotation)));
this.componentAnnotation = XTypeNames.enclosingClassName(annotation);
}

/** The actual annotation type. */
public ClassName annotation() {
public XClassName annotation() {
return annotation;
}

/** The component annotation type that encloses this creator annotation type. */
public final ClassName componentAnnotation() {
public final XClassName componentAnnotation() {
return componentAnnotation;
}

/** Returns {@code true} if the creator annotation is for a subcomponent. */
public final boolean isSubcomponentCreatorAnnotation() {
return componentAnnotation().simpleName().endsWith("Subcomponent");
return XTypeNames.simpleName(componentAnnotation()).endsWith("Subcomponent");
}

/**
* Returns {@code true} if the creator annotation is for a production component or subcomponent.
*/
public final boolean isProductionCreatorAnnotation() {
return componentAnnotation().simpleName().startsWith("Production");
return XTypeNames.simpleName(componentAnnotation()).startsWith("Production");
}

/** The creator kind the annotation is associated with. */
Expand All @@ -80,16 +84,20 @@ public ComponentCreatorKind creatorKind() {

@Override
public final String toString() {
return annotation().canonicalName();
return annotation().getCanonicalName();
}

public final String simpleName() {
return XTypeNames.simpleName(annotation());
}

/** Returns all component creator annotations. */
public static ImmutableSet<ClassName> allCreatorAnnotations() {
public static ImmutableSet<XClassName> allCreatorAnnotations() {
return stream().collect(toAnnotationClasses());
}

/** Returns all root component creator annotations. */
public static ImmutableSet<ClassName> rootComponentCreatorAnnotations() {
public static ImmutableSet<XClassName> rootComponentCreatorAnnotations() {
return stream()
.filter(
componentCreatorAnnotation ->
Expand All @@ -98,7 +106,7 @@ public static ImmutableSet<ClassName> rootComponentCreatorAnnotations() {
}

/** Returns all subcomponent creator annotations. */
public static ImmutableSet<ClassName> subcomponentCreatorAnnotations() {
public static ImmutableSet<XClassName> subcomponentCreatorAnnotations() {
return stream()
.filter(
componentCreatorAnnotation ->
Expand All @@ -107,7 +115,7 @@ public static ImmutableSet<ClassName> subcomponentCreatorAnnotations() {
}

/** Returns all production component creator annotations. */
public static ImmutableSet<ClassName> productionCreatorAnnotations() {
public static ImmutableSet<XClassName> productionCreatorAnnotations() {
return stream()
.filter(
componentCreatorAnnotation ->
Expand All @@ -116,14 +124,12 @@ public static ImmutableSet<ClassName> productionCreatorAnnotations() {
}

/** Returns the legal creator annotations for the given {@code componentAnnotation}. */
public static ImmutableSet<ClassName> creatorAnnotationsFor(
public static ImmutableSet<XClassName> creatorAnnotationsFor(
ComponentAnnotation componentAnnotation) {
return stream()
.filter(
creatorAnnotation ->
creatorAnnotation
.componentAnnotation()
.simpleName()
XTypeNames.simpleName(creatorAnnotation.componentAnnotation())
.equals(componentAnnotation.simpleName()))
.collect(toAnnotationClasses());
}
Expand All @@ -137,7 +143,7 @@ private static Stream<ComponentCreatorAnnotation> stream() {
return valuesOf(ComponentCreatorAnnotation.class);
}

private static Collector<ComponentCreatorAnnotation, ?, ImmutableSet<ClassName>>
private static Collector<ComponentCreatorAnnotation, ?, ImmutableSet<XClassName>>
toAnnotationClasses() {
return mapping(ComponentCreatorAnnotation::annotation, toImmutableSet());
}
Expand Down
25 changes: 13 additions & 12 deletions java/dagger/internal/codegen/base/ComponentKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@
import static dagger.internal.codegen.extension.DaggerStreams.valuesOf;
import static java.util.EnumSet.allOf;

import androidx.room.compiler.codegen.XClassName;
import androidx.room.compiler.processing.XTypeElement;
import com.google.common.collect.ImmutableSet;
import com.squareup.javapoet.ClassName;
import dagger.internal.codegen.javapoet.TypeNames;
import dagger.internal.codegen.xprocessing.XTypeNames;
import java.util.Optional;

/** Enumeration of the different kinds of components. */
public enum ComponentKind {
COMPONENT(TypeNames.COMPONENT),
SUBCOMPONENT(TypeNames.SUBCOMPONENT),
PRODUCTION_COMPONENT(TypeNames.PRODUCTION_COMPONENT),
PRODUCTION_SUBCOMPONENT(TypeNames.PRODUCTION_SUBCOMPONENT),
MODULE(TypeNames.MODULE),
PRODUCER_MODULE(TypeNames.PRODUCER_MODULE);
COMPONENT(XTypeNames.COMPONENT),
SUBCOMPONENT(XTypeNames.SUBCOMPONENT),
PRODUCTION_COMPONENT(XTypeNames.PRODUCTION_COMPONENT),
PRODUCTION_SUBCOMPONENT(XTypeNames.PRODUCTION_SUBCOMPONENT),
MODULE(XTypeNames.MODULE),
PRODUCER_MODULE(XTypeNames.PRODUCER_MODULE);

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) {
public static ImmutableSet<XClassName> annotationsFor(Iterable<ComponentKind> kinds) {
return stream(kinds).map(ComponentKind::annotation).collect(toImmutableSet());
}

Expand All @@ -68,14 +68,15 @@ public static Optional<ComponentKind> forAnnotatedElement(XTypeElement element)
return kinds.stream().findAny();
}

private final ClassName annotation;
@SuppressWarnings("ImmutableEnumChecker")
private final XClassName annotation;

ComponentKind(ClassName annotation) {
ComponentKind(XClassName annotation) {
this.annotation = annotation;
}

/** Returns the annotation that marks a component of this kind. */
public ClassName annotation() {
public XClassName annotation() {
return annotation;
}

Expand Down
Loading

0 comments on commit 5cfd6eb

Please sign in to comment.