Skip to content

Commit

Permalink
Don't store XElement outside of processing rounds.
Browse files Browse the repository at this point in the history
`GeneratesRootInputProcessorTest` stores the `List<XElement>` returned by `GeneratesRootInputs.getElementsToWaitFor()` to test the output. However, this causes an issue with the latest XProcessing drop when trying to access the fully qualified name of the element outside of the actual processing rounds. This is fixed if we replaced the `List<XElement>` with `List<String>` and calculate the qualified name immediately inside the processing round.

RELNOTES=N/A
PiperOrigin-RevId: 720687140
  • Loading branch information
bcorso authored and Dagger Team committed Jan 28, 2025
1 parent 550c6f8 commit 81ea86a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ compiler_test(
"//java/dagger/hilt/android/testing/compile",
"//java/dagger/hilt/processor/internal:base_processor",
"//java/dagger/hilt/processor/internal/generatesrootinput:generates_root_inputs",
"//java/dagger/internal/codegen/extension",
"//java/dagger/internal/codegen/xprocessing",
"//java/dagger/internal/codegen/xprocessing:xprocessing-testing",
"//third_party/java/javapoet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
package dagger.hilt.processor.internal.generatesrootinput;

import static com.google.common.truth.Truth.assertThat;
import static dagger.internal.codegen.extension.DaggerStreams.toImmutableList;

import androidx.room.compiler.processing.XElement;
import androidx.room.compiler.processing.XFiler.Mode;
import androidx.room.compiler.processing.XProcessingEnv;
import androidx.room.compiler.processing.XRoundEnv;
import androidx.room.compiler.processing.util.Source;
import com.google.common.truth.Correspondence;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.TypeSpec;
Expand All @@ -43,7 +42,7 @@ public final class GeneratesRootInputProcessorTest {
private static final int GENERATED_CLASSES = 5;
private static final ClassName TEST_ANNOTATION = ClassName.get("test", "TestAnnotation");

private final List<XElement> elementsToWaitFor = new ArrayList<>();
private final List<String> elementsToWaitFor = new ArrayList<>();
private int generatedClasses = 0;

public final class TestAnnotationStep extends BaseProcessingStep {
Expand All @@ -57,7 +56,10 @@ public TestAnnotationStep(XProcessingEnv env) {
@Override
public void postProcess(XProcessingEnv processingEnv, XRoundEnv round) {
if (generatedClasses > 0) {
elementsToWaitFor.addAll(generatesRootInputs.getElementsToWaitFor(round));
elementsToWaitFor.addAll(
generatesRootInputs.getElementsToWaitFor(round).stream()
.map(element -> XElements.asTypeElement(element).getQualifiedName())
.collect(toImmutableList()));
}
if (generatedClasses < GENERATED_CLASSES) {
TypeSpec typeSpec =
Expand All @@ -84,10 +86,6 @@ public void succeeds_ComponentProcessorWaitsForAnnotationsWithGeneratesRootInput
subject -> {
subject.hasErrorCount(0);
assertThat(elementsToWaitFor)
.comparingElementsUsing(
Correspondence.<XElement, String>transforming(
element -> XElements.asTypeElement(element).getQualifiedName(),
"has qualified name of"))
.containsExactly("foo.Foo0", "foo.Foo1", "foo.Foo2", "foo.Foo3", "foo.Foo4")
.inOrder();
elementsToWaitFor.clear();
Expand Down

0 comments on commit 81ea86a

Please sign in to comment.