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 @@ -16,6 +16,7 @@

package dagger.internal.codegen.binding;

import androidx.room3.compiler.processing.XMethodElement;
import com.google.auto.value.AutoValue;
import com.google.auto.value.extension.memoized.Memoized;
import com.google.common.collect.ImmutableSet;
Expand All @@ -24,6 +25,7 @@
import dagger.internal.codegen.model.BindingKind;
import dagger.internal.codegen.model.DependencyRequest;
import dagger.internal.codegen.xprocessing.Nullability;
import dagger.internal.codegen.xprocessing.XTypeNames;
import java.util.Optional;

/** A binding for a {@link BindingKind#DELEGATE}. */
Expand All @@ -49,6 +51,11 @@ public boolean requiresModuleInstance() {
return false;
}

public static boolean hasDelegateAnnotation(XMethodElement method) {
return method.hasAnnotation(XTypeNames.BINDS)
;
}

@Override
public abstract Builder toBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@
import dagger.internal.codegen.base.ContributionType.HasContributionType;
import dagger.internal.codegen.model.DaggerAnnotation;
import dagger.internal.codegen.model.DependencyRequest;
import dagger.internal.codegen.xprocessing.XTypeNames;
import java.util.Optional;
import javax.inject.Inject;

/** The declaration for a delegate binding established by a {@link Binds} method. */
/**
* The declaration for a delegate binding established by a {@link Binds}
* <!-- copybara:strip_begin -->
* or {@link Alias}
* <!-- copybara:strip_end -->
* method.
*/
@AutoValue
public abstract class DelegateDeclaration extends Declaration
implements HasContributionType {
public abstract class DelegateDeclaration extends Declaration implements HasContributionType {
abstract DependencyRequest delegateRequest();

// Note: We're using DaggerAnnotation instead of XAnnotation for its equals/hashcode
Expand All @@ -64,20 +68,20 @@ public static final class Factory {
this.dependencyRequestFactory = dependencyRequestFactory;
}

public DelegateDeclaration create(XMethodElement bindsMethod, XTypeElement contributingModule) {
checkArgument(bindsMethod.hasAnnotation(XTypeNames.BINDS));
XMethodType resolvedMethod = bindsMethod.asMemberOf(contributingModule.getType());
public DelegateDeclaration create(XMethodElement method, XTypeElement contributingModule) {
checkArgument(DelegateBinding.hasDelegateAnnotation(method));
XMethodType resolvedMethod = method.asMemberOf(contributingModule.getType());
DependencyRequest delegateRequest =
dependencyRequestFactory.forRequiredResolvedVariable(
Iterables.getOnlyElement(bindsMethod.getParameters()),
Iterables.getOnlyElement(method.getParameters()),
Iterables.getOnlyElement(resolvedMethod.getParameterTypes()));
return new AutoValue_DelegateDeclaration(
ContributionType.fromBindingElement(bindsMethod),
keyFactory.forBindsMethod(bindsMethod, contributingModule),
Optional.<XElement>of(bindsMethod),
ContributionType.fromBindingElement(method),
keyFactory.forDelegateDeclaration(method, contributingModule),
Optional.<XElement>of(method),
Optional.of(contributingModule),
delegateRequest,
getMapKey(bindsMethod).map(DaggerAnnotation::from));
getMapKey(method).map(DaggerAnnotation::from));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import androidx.room3.compiler.processing.XProcessingEnv;
import androidx.room3.compiler.processing.XType;
import androidx.room3.compiler.processing.XTypeElement;
import dagger.Binds;
import dagger.BindsOptionalOf;
import dagger.internal.codegen.base.ContributionType;
import dagger.internal.codegen.base.FrameworkTypes;
Expand Down Expand Up @@ -138,9 +137,8 @@ public Key forProducesMethod(XMethodElement method, XTypeElement contributingMod
return forBindingMethod(method, contributingModule, Optional.of(XTypeNames.PRODUCER));
}

/** Returns the key bound by a {@link Binds} method. */
Key forBindsMethod(XMethodElement method, XTypeElement contributingModule) {
checkArgument(method.hasAnnotation(XTypeNames.BINDS));
Key forDelegateDeclaration(XMethodElement method, XTypeElement contributingModule) {
checkArgument(DelegateBinding.hasDelegateAnnotation(method));
return forBindingMethod(method, contributingModule, Optional.empty());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public ModuleDescriptor createUncached(XTypeElement moduleElement) {
if (moduleMethod.hasAnnotation(XTypeNames.PRODUCES)) {
bindings.add(bindingFactory.producesMethodBinding(moduleMethod, moduleElement));
}
if (moduleMethod.hasAnnotation(XTypeNames.BINDS)) {
if (DelegateBinding.hasDelegateAnnotation(moduleMethod)) {
delegates.add(
bindingDelegateDeclarationFactory.create(moduleMethod, moduleElement));
}
Expand Down
66 changes: 0 additions & 66 deletions javatests/dagger/functional/asalias/AsAliasTest.java

This file was deleted.

61 changes: 0 additions & 61 deletions javatests/dagger/functional/asalias/BUILD

This file was deleted.

78 changes: 0 additions & 78 deletions javatests/dagger/functional/asalias/ChainOfAsAliasTest.java

This file was deleted.

Loading
Loading