Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
final class DelegateAndroidProcessor {
static final XProcessingEnvConfig PROCESSING_ENV_CONFIG =
new XProcessingEnvConfig.Builder()
// TODO: b/526607713 - Remove this once we properly handle property annotations in KSP.
.includePropertyAnnotationsInFields(true)
.build();
static final String FLAG_EXPERIMENTAL_USE_STRING_KEYS =
"dagger.android.experimentalUseStringKeys";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static javax.tools.Diagnostic.Kind.ERROR;

import androidx.room3.compiler.processing.XAnnotation;
import androidx.room3.compiler.processing.XProcessingEnv;
import androidx.room3.compiler.processing.XType;
import androidx.room3.compiler.processing.XTypeArgument;
import com.google.auto.service.AutoService;
Expand Down Expand Up @@ -56,11 +57,19 @@
*/
@AutoService(BindingGraphPlugin.class)
public final class DuplicateAndroidInjectorsChecker implements BindingGraphPlugin {
private DaggerProcessingEnv processingEnv;
private DaggerProcessingEnv daggerProcessingEnv;
private XProcessingEnv processingEnv;

@Override
public void init(DaggerProcessingEnv processingEnv, Map<String, String> options) {
this.processingEnv = processingEnv;
public void init(DaggerProcessingEnv daggerProcessingEnv, Map<String, String> options) {
this.daggerProcessingEnv = daggerProcessingEnv;
}

@Override
public void onProcessingRoundBegin() {
// The XProcessingEnv must be reconstructed each round to ensure it uses the Resolver from the
// current round.
this.processingEnv = DaggerElements.toXProcessing(daggerProcessingEnv);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
public final class KspProguardProcessor extends KspBasicAnnotationProcessor {
private static final XProcessingEnvConfig PROCESSING_ENV_CONFIG =
new XProcessingEnvConfig.Builder()
// TODO: b/526607713 - Remove this once we properly handle property annotations in KSP.
.includePropertyAnnotationsInFields(true)
.build();
private XProcessingEnv env;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
final class DelegateComponentProcessor {
static final XProcessingEnvConfig PROCESSING_ENV_CONFIG =
new XProcessingEnvConfig.Builder()
// TODO: b/526607713 - Remove this once we properly handle property annotations in KSP.
.includePropertyAnnotationsInFields(true)
.disableAnnotatedElementValidation(true)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import androidx.room3.compiler.processing.XElement;
import androidx.room3.compiler.processing.XProcessingEnv;
import androidx.room3.compiler.processing.XType;
import androidx.room3.compiler.processing.XTypeElement;
import androidx.room3.compiler.processing.compat.XConverters;
import com.google.devtools.ksp.symbol.KSClassDeclaration;
import com.google.devtools.ksp.symbol.KSFunctionDeclaration;
Expand All @@ -27,12 +28,11 @@
import dagger.spi.model.DaggerElement;
import dagger.spi.model.DaggerProcessingEnv;
import dagger.spi.model.DaggerType;
import dagger.spi.model.DaggerTypeElement;

/** Convert Dagger model types to XProcessing types. */
public final class DaggerElements {
public static XElement toXProcessing(
DaggerElement element, DaggerProcessingEnv daggerProcessingEnv) {
XProcessingEnv processingEnv = toXProcessing(daggerProcessingEnv);
public static XElement toXProcessing(DaggerElement element, XProcessingEnv processingEnv) {
switch (element.backend()) {
case JAVAC:
return XConverters.toXProcessing(element.javac(), processingEnv);
Expand All @@ -53,8 +53,7 @@ public static XElement toXProcessing(
String.format("Backend %s not supported yet.", element.backend()));
}

public static XType toXProcessing(DaggerType type, DaggerProcessingEnv daggerProcessingEnv) {
XProcessingEnv processingEnv = toXProcessing(daggerProcessingEnv);
public static XType toXProcessing(DaggerType type, XProcessingEnv processingEnv) {
switch (type.backend()) {
case JAVAC:
return XConverters.toXProcessing(type.javac(), processingEnv);
Expand All @@ -64,6 +63,25 @@ public static XType toXProcessing(DaggerType type, DaggerProcessingEnv daggerPro
throw new IllegalStateException(String.format("Backend %s not supported yet.", type.backend()));
}

public static XTypeElement toXProcessing(
DaggerTypeElement element, XProcessingEnv processingEnv) {
switch (element.backend()) {
case JAVAC:
return XConverters.toXProcessing(element.javac(), processingEnv);
case KSP:
return XConverters.toXProcessing(element.ksp(), processingEnv);
}
throw new IllegalStateException(
String.format("Backend %s not supported yet.", element.backend()));
}

/**
* Returns a new {@link XProcessingEnv} for the given {@link DaggerProcessingEnv}.
*
* <p>Callers should invoke this method once per processing round and pass the resulting {@link
* XProcessingEnv} to the other {@code toXProcessing} methods so that element and type wrappers
* are cached across conversions within the round.
*/
public static XProcessingEnv toXProcessing(DaggerProcessingEnv processingEnv) {
switch (processingEnv.backend()) {
case JAVAC:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static androidx.room3.compiler.processing.XElementKt.isField;
import static androidx.room3.compiler.processing.XElementKt.isMethod;
import static androidx.room3.compiler.processing.XElementKt.isMethodParameter;
import static androidx.room3.compiler.processing.XElementKt.isProperty;
import static androidx.room3.compiler.processing.XElementKt.isTypeElement;
import static androidx.room3.compiler.processing.XElementKt.isVariableElement;
import static androidx.room3.compiler.processing.compat.XConverters.getProcessingEnv;
Expand All @@ -45,6 +46,7 @@
import androidx.room3.compiler.processing.XMemberContainer;
import androidx.room3.compiler.processing.XMethodElement;
import androidx.room3.compiler.processing.XProcessingEnv;
import androidx.room3.compiler.processing.XPropertyElement;
import androidx.room3.compiler.processing.XTypeElement;
import androidx.room3.compiler.processing.XTypeParameterElement;
import androidx.room3.compiler.processing.XVariableElement;
Expand Down Expand Up @@ -254,6 +256,11 @@ public static XFieldElement asField(XElement element) {
return (XFieldElement) element;
}

public static XPropertyElement asProperty(XElement element) {
checkState(isProperty(element));
return (XPropertyElement) element;
}

public static XEnumEntry asEnumEntry(XElement element) {
return (XEnumEntry) element;
}
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
public final class HiltProcessingEnvConfigs {
public static final XProcessingEnvConfig CONFIGS =
new XProcessingEnvConfig.Builder()
// TODO: b/526607713 - Remove this once we properly handle property annotations in KSP.
.includePropertyAnnotationsInFields(true)
// In Hilt we disable the default element validation because we would otherwise run into a
// cycle where our Hilt processors are waiting on the "Hilt_Foo" classes to be generated
// before processing "Foo", but "Hilt_Foo" can't be generated until "Foo" is processed.
Expand Down
2 changes: 2 additions & 0 deletions java/dagger/testing/compile/CompilerTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public final class CompilerTests {
// dagger-compiler/main/java/dagger/internal/codegen/DelegateComponentProcessor.java
static final XProcessingEnvConfig PROCESSING_ENV_CONFIG =
new XProcessingEnvConfig.Builder()
// TODO: b/526607713 - Remove this once we properly handle property annotations in KSP.
.includePropertyAnnotationsInFields(true)
.disableAnnotatedElementValidation(true)
.build();

Expand Down
Loading