Skip to content

Commit c0ea341

Browse files
bcorsoDagger Team
authored and
Dagger Team
committed
Upgrade XProcessing jars.
RELNOTES=N/A PiperOrigin-RevId: 720198398
1 parent c63e003 commit c0ea341

File tree

7 files changed

+142
-179
lines changed

7 files changed

+142
-179
lines changed

java/dagger/internal/codegen/base/SourceFileGenerator.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import androidx.room.compiler.processing.XFiler;
3131
import androidx.room.compiler.processing.XMessager;
3232
import androidx.room.compiler.processing.XProcessingEnv;
33+
import androidx.room.compiler.processing.XTypeElement;
3334
import com.google.common.collect.ImmutableList;
3435
import com.google.common.collect.ImmutableSet;
3536
import com.squareup.javapoet.AnnotationSpec;
@@ -79,7 +80,7 @@ private JavaFile buildJavaFile(T input, TypeSpec.Builder typeSpecBuilder) {
7980
addOriginatingElement(typeSpecBuilder, originatingElement);
8081
typeSpecBuilder.addAnnotation(DaggerGenerated.class);
8182
Optional<AnnotationSpec> generatedAnnotation =
82-
Optional.ofNullable(processingEnv.findGeneratedAnnotation())
83+
Optional.ofNullable(findGeneratedAnnotation())
8384
.map(
8485
annotation ->
8586
AnnotationSpec.builder(annotation.getClassName())
@@ -105,6 +106,14 @@ private JavaFile buildJavaFile(T input, TypeSpec.Builder typeSpecBuilder) {
105106
return javaFileBuilder.build();
106107
}
107108

109+
private XTypeElement findGeneratedAnnotation() {
110+
XTypeElement generatedAnnotation =
111+
processingEnv.findTypeElement("javax.annotation.processing.Generated");
112+
return generatedAnnotation != null
113+
? generatedAnnotation
114+
: processingEnv.findTypeElement("javax.annotation.Generated");
115+
}
116+
108117
/** Returns the originating element of the generating type. */
109118
public abstract XElement originatingElement(T input);
110119

Binary file not shown.

javatests/dagger/hilt/processor/internal/generatesrootinput/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ compiler_test(
3232
"//java/dagger/hilt/android/testing/compile",
3333
"//java/dagger/hilt/processor/internal:base_processor",
3434
"//java/dagger/hilt/processor/internal/generatesrootinput:generates_root_inputs",
35+
"//java/dagger/internal/codegen/extension",
3536
"//java/dagger/internal/codegen/xprocessing",
3637
"//java/dagger/internal/codegen/xprocessing:xprocessing-testing",
3738
"//third_party/java/javapoet",

javatests/dagger/hilt/processor/internal/generatesrootinput/GeneratesRootInputProcessorTest.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
package dagger.hilt.processor.internal.generatesrootinput;
1818

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

21-
import androidx.room.compiler.processing.XElement;
2222
import androidx.room.compiler.processing.XFiler.Mode;
2323
import androidx.room.compiler.processing.XProcessingEnv;
2424
import androidx.room.compiler.processing.XRoundEnv;
2525
import androidx.room.compiler.processing.util.Source;
26-
import com.google.common.truth.Correspondence;
2726
import com.squareup.javapoet.ClassName;
2827
import com.squareup.javapoet.JavaFile;
2928
import com.squareup.javapoet.TypeSpec;
@@ -43,7 +42,7 @@ public final class GeneratesRootInputProcessorTest {
4342
private static final int GENERATED_CLASSES = 5;
4443
private static final ClassName TEST_ANNOTATION = ClassName.get("test", "TestAnnotation");
4544

46-
private final List<XElement> elementsToWaitFor = new ArrayList<>();
45+
private final List<String> elementsToWaitFor = new ArrayList<>();
4746
private int generatedClasses = 0;
4847

4948
public final class TestAnnotationStep extends BaseProcessingStep {
@@ -57,7 +56,10 @@ public TestAnnotationStep(XProcessingEnv env) {
5756
@Override
5857
public void postProcess(XProcessingEnv processingEnv, XRoundEnv round) {
5958
if (generatedClasses > 0) {
60-
elementsToWaitFor.addAll(generatesRootInputs.getElementsToWaitFor(round));
59+
elementsToWaitFor.addAll(
60+
generatesRootInputs.getElementsToWaitFor(round).stream()
61+
.map(element -> XElements.asTypeElement(element).getQualifiedName())
62+
.collect(toImmutableList()));
6163
}
6264
if (generatedClasses < GENERATED_CLASSES) {
6365
TypeSpec typeSpec =
@@ -84,10 +86,6 @@ public void succeeds_ComponentProcessorWaitsForAnnotationsWithGeneratesRootInput
8486
subject -> {
8587
subject.hasErrorCount(0);
8688
assertThat(elementsToWaitFor)
87-
.comparingElementsUsing(
88-
Correspondence.<XElement, String>transforming(
89-
element -> XElements.asTypeElement(element).getQualifiedName(),
90-
"has qualified name of"))
9189
.containsExactly("foo.Foo0", "foo.Foo1", "foo.Foo2", "foo.Foo3", "foo.Foo4")
9290
.inOrder();
9391
elementsToWaitFor.clear();

javatests/dagger/internal/codegen/BindsMethodValidationTest.java

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static dagger.internal.codegen.DaggerModuleMethodSubject.Factory.assertThatModuleMethod;
2121
import static java.lang.annotation.RetentionPolicy.RUNTIME;
2222

23-
import androidx.room.compiler.processing.XProcessingEnv;
2423
import androidx.room.compiler.processing.util.Source;
2524
import com.google.common.collect.ImmutableList;
2625
import dagger.Module;
@@ -253,27 +252,21 @@ public void bindsMissingTypeInParameterHierarchy() {
253252
subject.hasErrorCount(2);
254253
break;
255254
}
256-
// TODO(b/248552462): Javac and KSP should match once this bug is fixed.
257-
boolean isJavac = CompilerTests.backend(subject) == XProcessingEnv.Backend.JAVAC;
258255
subject.hasErrorContaining(
259-
String.format(
260-
"ModuleProcessingStep was unable to process 'test.TestModule' because '%s' "
261-
+ "could not be resolved.",
262-
isJavac ? "MissingType" : "error.NonExistentClass"));
256+
"ModuleProcessingStep was unable to process 'test.TestModule' because "
257+
+ "'MissingType' could not be resolved.");
263258
subject.hasErrorContaining(
264-
String.format(
265-
"BindingMethodProcessingStep was unable to process"
266-
+ " 'bindObject(test.Child<java.lang.String>)' because '%1$s' could not "
267-
+ "be resolved."
268-
+ "\n "
269-
+ "\n Dependency trace:"
270-
+ "\n => element (INTERFACE): test.TestModule"
271-
+ "\n => element (METHOD): bindObject(test.Child<java.lang.String>)"
272-
+ "\n => element (PARAMETER): child"
273-
+ "\n => type (DECLARED parameter): test.Child<java.lang.String>"
274-
+ "\n => type (DECLARED supertype): test.Parent<java.lang.String>"
275-
+ "\n => type (ERROR supertype): %1$s",
276-
isJavac ? "MissingType" : "error.NonExistentClass"));
259+
"BindingMethodProcessingStep was unable to process "
260+
+ "'bindObject(test.Child<java.lang.String>)' because 'MissingType' could "
261+
+ "not be resolved."
262+
+ "\n "
263+
+ "\n Dependency trace:"
264+
+ "\n => element (INTERFACE): test.TestModule"
265+
+ "\n => element (METHOD): bindObject(test.Child<java.lang.String>)"
266+
+ "\n => element (PARAMETER): child"
267+
+ "\n => type (DECLARED parameter): test.Child<java.lang.String>"
268+
+ "\n => type (DECLARED supertype): test.Parent<java.lang.String>"
269+
+ "\n => type (ERROR supertype): MissingType");
277270
});
278271
}
279272

@@ -319,26 +312,19 @@ public void bindsMissingTypeInReturnTypeHierarchy() {
319312
subject.hasErrorCount(2);
320313
break;
321314
}
322-
// TODO(b/248552462): Javac and KSP should match once this bug is fixed.
323-
boolean isJavac = CompilerTests.backend(subject) == XProcessingEnv.Backend.JAVAC;
324315
subject.hasErrorContaining(
325-
String.format(
326-
"ModuleProcessingStep was unable to process 'test.TestModule' because '%s' "
327-
+ "could not be resolved.",
328-
isJavac ? "MissingType" : "error.NonExistentClass"));
316+
"ModuleProcessingStep was unable to process 'test.TestModule' because "
317+
+ "'MissingType' could not be resolved.");
329318
subject.hasErrorContaining(
330-
String.format(
331-
"BindingMethodProcessingStep was unable to process "
332-
+ "'bindChild(java.lang.String)' because '%1$s' could not be"
333-
+ " resolved."
334-
+ "\n "
335-
+ "\n Dependency trace:"
336-
+ "\n => element (INTERFACE): test.TestModule"
337-
+ "\n => element (METHOD): bindChild(java.lang.String)"
338-
+ "\n => type (DECLARED return type): test.Child<java.lang.String>"
339-
+ "\n => type (DECLARED supertype): test.Parent<java.lang.String>"
340-
+ "\n => type (ERROR supertype): %1$s",
341-
isJavac ? "MissingType" : "error.NonExistentClass"));
319+
"BindingMethodProcessingStep was unable to process 'bindChild(java.lang.String)' "
320+
+ "because 'MissingType' could not be resolved."
321+
+ "\n "
322+
+ "\n Dependency trace:"
323+
+ "\n => element (INTERFACE): test.TestModule"
324+
+ "\n => element (METHOD): bindChild(java.lang.String)"
325+
+ "\n => type (DECLARED return type): test.Child<java.lang.String>"
326+
+ "\n => type (DECLARED supertype): test.Parent<java.lang.String>"
327+
+ "\n => type (ERROR supertype): MissingType");
342328
});
343329
}
344330

0 commit comments

Comments
 (0)