Skip to content

Commit

Permalink
Use new XProcessing APIs to get TypeVariableNames from XTypeElements.
Browse files Browse the repository at this point in the history
RELNOTES=N/A
PiperOrigin-RevId: 462246463
  • Loading branch information
bcorso authored and Dagger Team committed Jul 20, 2022
1 parent b838876 commit 4a96bbe
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions java/dagger/internal/codegen/xprocessing/XTypeElements.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

package dagger.internal.codegen.xprocessing;

import static androidx.room.compiler.processing.compat.XConverters.toJavac;
import static com.google.common.base.Preconditions.checkNotNull;
import static dagger.internal.codegen.extension.DaggerStreams.toImmutableList;
import static kotlin.streams.jdk8.StreamsKt.asStream;

import androidx.room.compiler.processing.XHasModifiers;
import androidx.room.compiler.processing.XMethodElement;
import androidx.room.compiler.processing.XTypeElement;
import androidx.room.compiler.processing.XTypeParameterElement;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.squareup.javapoet.TypeVariableName;
Expand Down Expand Up @@ -52,8 +52,8 @@ private static Visibility of(XTypeElement element) {
// TODO(bcorso): Consider XParameterizable interface to handle both methods and types.
/** Returns the type arguments for the given type as a list of {@link TypeVariableName}. */
public static ImmutableList<TypeVariableName> typeVariableNames(XTypeElement typeElement) {
return toJavac(typeElement).getTypeParameters().stream()
.map(TypeVariableName::get)
return typeElement.getTypeParameters().stream()
.map(XTypeParameterElement::getTypeVariableName)
.collect(toImmutableList());
}

Expand All @@ -63,11 +63,8 @@ public static boolean isNested(XTypeElement typeElement) {
}

/** Returns {@code true} if the given {@code type} has type parameters. */
public static boolean hasTypeParameters(XTypeElement type) {
// TODO(bcorso): Add support for XTypeElement#getTypeParameters() or at least
// XTypeElement#hasTypeParameters() in XProcessing. XTypes#getTypeArguments() isn't quite the
// same -- it tells you if the declared type has parameters rather than the element itself.
return !toJavac(type).getTypeParameters().isEmpty();
public static boolean hasTypeParameters(XTypeElement typeElement) {
return !typeElement.getTypeParameters().isEmpty();
}

/** Returns all non-private, non-static, abstract methods in {@code type}. */
Expand Down

0 comments on commit 4a96bbe

Please sign in to comment.