Skip to content

Commit

Permalink
Upgrade XProcessing jars.
Browse files Browse the repository at this point in the history
RELNOTES=N/A
PiperOrigin-RevId: 720198398
  • Loading branch information
bcorso authored and Dagger Team committed Jan 27, 2025
1 parent c63e003 commit c0ea341
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 179 deletions.
11 changes: 10 additions & 1 deletion java/dagger/internal/codegen/base/SourceFileGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import androidx.room.compiler.processing.XFiler;
import androidx.room.compiler.processing.XMessager;
import androidx.room.compiler.processing.XProcessingEnv;
import androidx.room.compiler.processing.XTypeElement;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.squareup.javapoet.AnnotationSpec;
Expand Down Expand Up @@ -79,7 +80,7 @@ private JavaFile buildJavaFile(T input, TypeSpec.Builder typeSpecBuilder) {
addOriginatingElement(typeSpecBuilder, originatingElement);
typeSpecBuilder.addAnnotation(DaggerGenerated.class);
Optional<AnnotationSpec> generatedAnnotation =
Optional.ofNullable(processingEnv.findGeneratedAnnotation())
Optional.ofNullable(findGeneratedAnnotation())
.map(
annotation ->
AnnotationSpec.builder(annotation.getClassName())
Expand All @@ -105,6 +106,14 @@ private JavaFile buildJavaFile(T input, TypeSpec.Builder typeSpecBuilder) {
return javaFileBuilder.build();
}

private XTypeElement findGeneratedAnnotation() {
XTypeElement generatedAnnotation =
processingEnv.findTypeElement("javax.annotation.processing.Generated");
return generatedAnnotation != null
? generatedAnnotation
: processingEnv.findTypeElement("javax.annotation.Generated");
}

/** Returns the originating element of the generating type. */
public abstract XElement originatingElement(T input);

Expand Down
Binary file modified java/dagger/internal/codegen/xprocessing/xprocessing.jar
Binary file not shown.
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
62 changes: 24 additions & 38 deletions javatests/dagger/internal/codegen/BindsMethodValidationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static dagger.internal.codegen.DaggerModuleMethodSubject.Factory.assertThatModuleMethod;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import androidx.room.compiler.processing.XProcessingEnv;
import androidx.room.compiler.processing.util.Source;
import com.google.common.collect.ImmutableList;
import dagger.Module;
Expand Down Expand Up @@ -253,27 +252,21 @@ public void bindsMissingTypeInParameterHierarchy() {
subject.hasErrorCount(2);
break;
}
// TODO(b/248552462): Javac and KSP should match once this bug is fixed.
boolean isJavac = CompilerTests.backend(subject) == XProcessingEnv.Backend.JAVAC;
subject.hasErrorContaining(
String.format(
"ModuleProcessingStep was unable to process 'test.TestModule' because '%s' "
+ "could not be resolved.",
isJavac ? "MissingType" : "error.NonExistentClass"));
"ModuleProcessingStep was unable to process 'test.TestModule' because "
+ "'MissingType' could not be resolved.");
subject.hasErrorContaining(
String.format(
"BindingMethodProcessingStep was unable to process"
+ " 'bindObject(test.Child<java.lang.String>)' because '%1$s' could not "
+ "be resolved."
+ "\n "
+ "\n Dependency trace:"
+ "\n => element (INTERFACE): test.TestModule"
+ "\n => element (METHOD): bindObject(test.Child<java.lang.String>)"
+ "\n => element (PARAMETER): child"
+ "\n => type (DECLARED parameter): test.Child<java.lang.String>"
+ "\n => type (DECLARED supertype): test.Parent<java.lang.String>"
+ "\n => type (ERROR supertype): %1$s",
isJavac ? "MissingType" : "error.NonExistentClass"));
"BindingMethodProcessingStep was unable to process "
+ "'bindObject(test.Child<java.lang.String>)' because 'MissingType' could "
+ "not be resolved."
+ "\n "
+ "\n Dependency trace:"
+ "\n => element (INTERFACE): test.TestModule"
+ "\n => element (METHOD): bindObject(test.Child<java.lang.String>)"
+ "\n => element (PARAMETER): child"
+ "\n => type (DECLARED parameter): test.Child<java.lang.String>"
+ "\n => type (DECLARED supertype): test.Parent<java.lang.String>"
+ "\n => type (ERROR supertype): MissingType");
});
}

Expand Down Expand Up @@ -319,26 +312,19 @@ public void bindsMissingTypeInReturnTypeHierarchy() {
subject.hasErrorCount(2);
break;
}
// TODO(b/248552462): Javac and KSP should match once this bug is fixed.
boolean isJavac = CompilerTests.backend(subject) == XProcessingEnv.Backend.JAVAC;
subject.hasErrorContaining(
String.format(
"ModuleProcessingStep was unable to process 'test.TestModule' because '%s' "
+ "could not be resolved.",
isJavac ? "MissingType" : "error.NonExistentClass"));
"ModuleProcessingStep was unable to process 'test.TestModule' because "
+ "'MissingType' could not be resolved.");
subject.hasErrorContaining(
String.format(
"BindingMethodProcessingStep was unable to process "
+ "'bindChild(java.lang.String)' because '%1$s' could not be"
+ " resolved."
+ "\n "
+ "\n Dependency trace:"
+ "\n => element (INTERFACE): test.TestModule"
+ "\n => element (METHOD): bindChild(java.lang.String)"
+ "\n => type (DECLARED return type): test.Child<java.lang.String>"
+ "\n => type (DECLARED supertype): test.Parent<java.lang.String>"
+ "\n => type (ERROR supertype): %1$s",
isJavac ? "MissingType" : "error.NonExistentClass"));
"BindingMethodProcessingStep was unable to process 'bindChild(java.lang.String)' "
+ "because 'MissingType' could not be resolved."
+ "\n "
+ "\n Dependency trace:"
+ "\n => element (INTERFACE): test.TestModule"
+ "\n => element (METHOD): bindChild(java.lang.String)"
+ "\n => type (DECLARED return type): test.Child<java.lang.String>"
+ "\n => type (DECLARED supertype): test.Parent<java.lang.String>"
+ "\n => type (ERROR supertype): MissingType");
});
}

Expand Down
Loading

0 comments on commit c0ea341

Please sign in to comment.