Skip to content

Commit

Permalink
Migrate to the new JavaPoetExtKt#toAnnotationSpec(XAnnotation) API …
Browse files Browse the repository at this point in the history
…in XProcessing.

RELNOTES=N/A
PiperOrigin-RevId: 463664244
  • Loading branch information
bcorso authored and Dagger Team committed Jul 27, 2022
1 parent 56335c1 commit 2cce0be
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
3 changes: 2 additions & 1 deletion java/dagger/internal/codegen/writing/GwtCompatibility.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.google.common.base.Preconditions.checkArgument;

import androidx.room.compiler.processing.JavaPoetExtKt;
import androidx.room.compiler.processing.XAnnotation;
import androidx.room.compiler.processing.XElement;
import com.squareup.javapoet.AnnotationSpec;
Expand All @@ -38,7 +39,7 @@ static Optional<AnnotationSpec> gwtIncompatibleAnnotation(Binding binding) {
Optional<AnnotationSpec> gwtIncompatible =
element.getAllAnnotations().stream()
.filter(GwtCompatibility::isGwtIncompatible)
.map(XAnnotations::getAnnotationSpec)
.map(JavaPoetExtKt::toAnnotationSpec)
.findFirst();
if (gwtIncompatible.isPresent()) {
return gwtIncompatible;
Expand Down
4 changes: 2 additions & 2 deletions java/dagger/internal/codegen/writing/InjectionMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import static javax.lang.model.element.Modifier.PUBLIC;
import static javax.lang.model.element.Modifier.STATIC;

import androidx.room.compiler.processing.JavaPoetExtKt;
import androidx.room.compiler.processing.XAnnotation;
import androidx.room.compiler.processing.XConstructorElement;
import androidx.room.compiler.processing.XExecutableElement;
Expand All @@ -78,7 +79,6 @@
import dagger.internal.codegen.compileroption.CompilerOptions;
import dagger.internal.codegen.extension.DaggerCollectors;
import dagger.internal.codegen.javapoet.TypeNames;
import dagger.internal.codegen.xprocessing.XAnnotations;
import dagger.spi.model.DaggerAnnotation;
import dagger.spi.model.DependencyRequest;
import java.util.List;
Expand Down Expand Up @@ -434,7 +434,7 @@ private static MethodSpec fieldProxy(
.build())
.addTypeVariables(typeVariableNames(enclosingType));

qualifier.map(XAnnotations::getAnnotationSpec).ifPresent(builder::addAnnotation);
qualifier.map(JavaPoetExtKt::toAnnotationSpec).ifPresent(builder::addAnnotation);

boolean useObject = !isRawTypePubliclyAccessible(enclosingType.getType());
UniqueNameSet parameterNameSet = new UniqueNameSet();
Expand Down
6 changes: 0 additions & 6 deletions java/dagger/internal/codegen/xprocessing/XAnnotations.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,13 @@
import androidx.room.compiler.processing.XAnnotation;
import com.google.auto.common.AnnotationMirrors;
import com.google.common.base.Equivalence;
import com.squareup.javapoet.AnnotationSpec;
import com.squareup.javapoet.ClassName;
import java.util.Arrays;

// TODO(bcorso): Consider moving these methods into XProcessing library.
/** A utility class for {@link XAnnotation} helper methods. */
public final class XAnnotations {

/** Returns the {@link AnnotationSpec} for the given annotation */
public static AnnotationSpec getAnnotationSpec(XAnnotation annotation) {
return AnnotationSpec.get(toJavac(annotation));
}

/** Returns the string representation of the given annotation. */
public static String toString(XAnnotation annotation) {
return AnnotationMirrors.toString(toJavac(annotation));
Expand Down

0 comments on commit 2cce0be

Please sign in to comment.