mirror of
https://github.com/google/guice.git
synced 2024-04-21 12:32:36 +00:00
Remove redundant references to javax.{inject,persistence,servlet} and replace the rest with their jakarta variants.
This required upgrading some test dependencies, because the tests need some impls of the APIs which only exist in newer releases. This also removes the struts2 extension from the maven & bazel build (although it keeps the now-unused source), because struts2 has no release that supports jakarta. For users that want to continue using the struts2 extension, please continue to use the Guice 6.0 release (instead of the 7.0+ line, which will only support the jakarta dependencies). Fixes #1383. (I'll cut the 6.0 candidates/releases from before this commit, and if we need to make further 6.0 changes, I'll manually merge those into the 6.0 branch.) PiperOrigin-RevId: 529504991
This commit is contained in:
@@ -24,7 +24,9 @@ javadoc_library(
|
||||
"//extensions/persist/src/com/google/inject/persist:javadoc-srcs",
|
||||
"//extensions/servlet/src/com/google/inject/servlet:javadoc-srcs",
|
||||
"//extensions/spring/src/com/google/inject/spring:javadoc-srcs",
|
||||
"//extensions/struts2/src/com/google/inject/struts2:javadoc-srcs",
|
||||
# struts2 doesn't work with jakarta.servlet, so we don't include it.
|
||||
# We leave the commented out line as a bread-crumb for the future.
|
||||
# "//extensions/struts2/src/com/google/inject/struts2:javadoc-srcs",
|
||||
"//extensions/testlib/src/com/google/inject/testing/fieldbinder:javadoc-srcs",
|
||||
"//extensions/testlib/src/com/google/inject/testing/throwingproviders:javadoc-srcs",
|
||||
"//extensions/throwingproviders/src/com/google/inject/throwingproviders:javadoc-srcs",
|
||||
@@ -62,7 +64,7 @@ javadoc_library(
|
||||
],
|
||||
"Servlet Extension": ["com.google.inject.servlet"],
|
||||
"Spring Extension": ["com.google.inject.spring"],
|
||||
"Struts2 Extension": ["com.google.inject.struts2"],
|
||||
# "Struts2 Extension": ["com.google.inject.struts2"],
|
||||
"Test Libraries Extension": ["com.google.inject.testing.*"],
|
||||
"ThrowingProviders Extension": ["com.google.inject.throwingproviders"],
|
||||
},
|
||||
@@ -77,7 +79,7 @@ javadoc_library(
|
||||
"//extensions/persist/src/com/google/inject/persist",
|
||||
"//extensions/servlet/src/com/google/inject/servlet",
|
||||
"//extensions/spring/src/com/google/inject/spring",
|
||||
"//extensions/struts2/src/com/google/inject/struts2",
|
||||
# "//extensions/struts2/src/com/google/inject/struts2",
|
||||
"//extensions/testlib/src/com/google/inject/testing/fieldbinder",
|
||||
"//extensions/testlib/src/com/google/inject/testing/throwingproviders",
|
||||
"//extensions/throwingproviders/src/com/google/inject/throwingproviders",
|
||||
|
||||
@@ -35,10 +35,9 @@ maven_install(
|
||||
"com.google.errorprone:error_prone_annotations:2.18.0",
|
||||
"com.google.guava:guava:31.0.1-jre",
|
||||
"commons-logging:commons-logging:1.2",
|
||||
"javax.inject:javax.inject:1",
|
||||
"jakarta.inject:jakarta.inject-api:2.0.1",
|
||||
"javax.persistence:javax.persistence-api:2.2",
|
||||
"javax.servlet:servlet-api:2.5",
|
||||
"jakarta.persistence:jakarta.persistence-api:3.0.0",
|
||||
"jakarta.servlet:jakarta.servlet-api:5.0.0",
|
||||
"org.apache.struts:struts2-core:2.5.30",
|
||||
"org.apache.struts.xwork:xwork-core:2.3.37",
|
||||
"org.ow2.asm:asm:9.5",
|
||||
@@ -70,12 +69,6 @@ maven_install(
|
||||
"1.1.3",
|
||||
testonly = True,
|
||||
),
|
||||
maven.artifact(
|
||||
"javax.inject",
|
||||
"javax.inject-tck",
|
||||
"1",
|
||||
testonly = True,
|
||||
),
|
||||
maven.artifact(
|
||||
"jakarta.inject",
|
||||
"jakarta.inject-tck",
|
||||
@@ -106,16 +99,10 @@ maven_install(
|
||||
"2.2",
|
||||
testonly = True,
|
||||
),
|
||||
maven.artifact(
|
||||
"org.hibernate.javax.persistence",
|
||||
"hibernate-jpa-2.0-api",
|
||||
"1.0.0.Final",
|
||||
testonly = True,
|
||||
),
|
||||
maven.artifact(
|
||||
"org.hibernate",
|
||||
"hibernate-core",
|
||||
"5.6.3.Final",
|
||||
"hibernate-core-jakarta",
|
||||
"5.6.15.Final",
|
||||
testonly = True,
|
||||
),
|
||||
maven.artifact(
|
||||
|
||||
@@ -19,7 +19,9 @@ java_library(
|
||||
"//extensions/persist/src/com/google/inject/persist",
|
||||
"//extensions/servlet/src/com/google/inject/servlet",
|
||||
"//extensions/spring/src/com/google/inject/spring",
|
||||
"//extensions/struts2/src/com/google/inject/struts2",
|
||||
# struts2 doesn't work with jakarta.servlet, so we don't include it.
|
||||
# We leave the commented out line as a bread-crumb for the future.
|
||||
# "//extensions/struts2/src/com/google/inject/struts2",
|
||||
"//extensions/testlib/src/com/google/inject/testing:testlib",
|
||||
"//extensions/throwingproviders/src/com/google/inject/throwingproviders",
|
||||
],
|
||||
|
||||
@@ -68,11 +68,13 @@
|
||||
<artifactId>guice-spring</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<!-- struts2 doesn't support jakarta.servlet yet, so we don't include it.
|
||||
<dependency>
|
||||
<groupId>com.google.inject.extensions</groupId>
|
||||
<artifactId>guice-struts2</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>com.google.inject.extensions</groupId>
|
||||
<artifactId>guice-testlib</artifactId>
|
||||
|
||||
+2
-16
@@ -14,10 +14,6 @@
|
||||
<name>Google Guice - Core Library</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.inject</groupId>
|
||||
<artifactId>javax.inject</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.inject</groupId>
|
||||
<artifactId>jakarta.inject-api</artifactId>
|
||||
@@ -46,8 +42,8 @@
|
||||
| Test dependencies
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>javax.inject</groupId>
|
||||
<artifactId>javax.inject-tck</artifactId>
|
||||
<groupId>jakarta.inject</groupId>
|
||||
<artifactId>jakarta.inject-tck</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -98,16 +94,6 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.11.0</version>
|
||||
<configuration>
|
||||
<testExcludes>
|
||||
<!--
|
||||
Don't compile the jakarta TCK b/c it would clash w/ the javax.inject TCK.
|
||||
We test it with the Bazel build for now, and basic jakarta functionality is tested
|
||||
with the JakartaTest in the same package.
|
||||
-->
|
||||
<testExclude>**/GuiceJakartaTck.java</testExclude>
|
||||
</testExcludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
|
||||
@@ -52,7 +52,7 @@ java_library(
|
||||
srcs = PROVIDED_BY_SRCS,
|
||||
javacopts = JAVAC_OPTS,
|
||||
deps = [
|
||||
"//third_party/java/jsr330_inject",
|
||||
"//third_party/java/jakarta_inject",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -96,7 +96,6 @@ java_library(
|
||||
"//third_party/java/asm",
|
||||
"//third_party/java/error_prone:annotations",
|
||||
"//third_party/java/jsr305_annotations",
|
||||
"//third_party/java/jsr330_inject",
|
||||
"//third_party/java/jakarta_inject",
|
||||
],
|
||||
)
|
||||
@@ -109,7 +108,7 @@ java_library(
|
||||
],
|
||||
deps = [
|
||||
"//third_party/java/error_prone:annotations",
|
||||
"//third_party/java/jsr330_inject",
|
||||
"//third_party/java/jakarta_inject",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.lang.annotation.Target;
|
||||
* The Injector then proceeds to perform field and method injections.
|
||||
* <li>Pre-constructed instances passed to {@link Injector#injectMembers}, {@link
|
||||
* com.google.inject.binder.LinkedBindingBuilder#toInstance(Object)} and {@link
|
||||
* com.google.inject.binder.LinkedBindingBuilder#toProvider(javax.inject.Provider)}. In this
|
||||
* com.google.inject.binder.LinkedBindingBuilder#toProvider(jakarta.inject.Provider)}. In this
|
||||
* case all constructors are, of course, ignored.
|
||||
* <li>Static fields and methods of classes which any {@link Module} has specifically requested
|
||||
* static injection for, using {@link Binder#requestStaticInjection}.
|
||||
|
||||
@@ -32,5 +32,5 @@ import java.lang.annotation.Target;
|
||||
public @interface ProvidedBy {
|
||||
|
||||
/** The implementation type. */
|
||||
Class<? extends javax.inject.Provider<?>> value();
|
||||
Class<? extends jakarta.inject.Provider<?>> value();
|
||||
}
|
||||
|
||||
@@ -38,7 +38,9 @@ package com.google.inject;
|
||||
* @param <T> the type of object this provides
|
||||
* @author crazybob@google.com (Bob Lee)
|
||||
*/
|
||||
public interface Provider<T> extends javax.inject.Provider<T>, jakarta.inject.Provider<T> {
|
||||
public interface Provider<T>
|
||||
extends
|
||||
jakarta.inject.Provider<T> {
|
||||
|
||||
/**
|
||||
* Provides an instance of {@code T}.
|
||||
|
||||
@@ -69,7 +69,6 @@ public class Scopes {
|
||||
@Override
|
||||
public Boolean visitScopeAnnotation(Class<? extends Annotation> scopeAnnotation) {
|
||||
return scopeAnnotation == Singleton.class
|
||||
|| scopeAnnotation == javax.inject.Singleton.class
|
||||
|| scopeAnnotation == jakarta.inject.Singleton.class;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,17 +57,17 @@ public interface LinkedBindingBuilder<T> extends ScopedBindingBuilder {
|
||||
* @see com.google.inject.Injector#injectMembers
|
||||
* @since 4.0
|
||||
*/
|
||||
ScopedBindingBuilder toProvider(javax.inject.Provider<? extends T> provider);
|
||||
ScopedBindingBuilder toProvider(jakarta.inject.Provider<? extends T> provider);
|
||||
|
||||
/** See the EDSL examples at {@link com.google.inject.Binder}. */
|
||||
ScopedBindingBuilder toProvider(Class<? extends javax.inject.Provider<? extends T>> providerType);
|
||||
ScopedBindingBuilder toProvider(Class<? extends jakarta.inject.Provider<? extends T>> providerType);
|
||||
|
||||
/** See the EDSL examples at {@link com.google.inject.Binder}. */
|
||||
ScopedBindingBuilder toProvider(
|
||||
TypeLiteral<? extends javax.inject.Provider<? extends T>> providerType);
|
||||
TypeLiteral<? extends jakarta.inject.Provider<? extends T>> providerType);
|
||||
|
||||
/** See the EDSL examples at {@link com.google.inject.Binder}. */
|
||||
ScopedBindingBuilder toProvider(Key<? extends javax.inject.Provider<? extends T>> providerKey);
|
||||
ScopedBindingBuilder toProvider(Key<? extends jakarta.inject.Provider<? extends T>> providerKey);
|
||||
|
||||
/**
|
||||
* See the EDSL examples at {@link com.google.inject.Binder}.
|
||||
|
||||
@@ -43,7 +43,6 @@ import java.lang.reflect.Proxy;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
/**
|
||||
* Annotation utilities.
|
||||
@@ -347,7 +346,8 @@ public class Annotations {
|
||||
private static final AnnotationChecker scopeChecker =
|
||||
new AnnotationChecker(
|
||||
Arrays.asList(
|
||||
ScopeAnnotation.class, javax.inject.Scope.class, jakarta.inject.Scope.class));
|
||||
ScopeAnnotation.class,
|
||||
jakarta.inject.Scope.class));
|
||||
|
||||
public static boolean isScopeAnnotation(Class<? extends Annotation> annotationType) {
|
||||
return scopeChecker.hasAnnotations(annotationType);
|
||||
@@ -405,7 +405,9 @@ public class Annotations {
|
||||
|
||||
private static final AnnotationChecker bindingAnnotationChecker =
|
||||
new AnnotationChecker(
|
||||
Arrays.asList(BindingAnnotation.class, Qualifier.class, jakarta.inject.Qualifier.class));
|
||||
Arrays.asList(
|
||||
BindingAnnotation.class,
|
||||
jakarta.inject.Qualifier.class));
|
||||
|
||||
/** Returns true if annotations of the specified type are binding annotations. */
|
||||
public static boolean isBindingAnnotation(Class<? extends Annotation> annotationType) {
|
||||
@@ -413,31 +415,27 @@ public class Annotations {
|
||||
}
|
||||
|
||||
/**
|
||||
* If the annotation is an instance of {@code javax.inject.Named}, canonicalizes to
|
||||
* If the annotation is an instance of {@code jakarta.inject.Named}, canonicalizes to
|
||||
* com.google.guice.name.Named. Returns the given annotation otherwise.
|
||||
*/
|
||||
public static Annotation canonicalizeIfNamed(Annotation annotation) {
|
||||
if (annotation instanceof javax.inject.Named) {
|
||||
return Names.named(((javax.inject.Named) annotation).value());
|
||||
} else if (annotation instanceof jakarta.inject.Named) {
|
||||
if (annotation instanceof jakarta.inject.Named) {
|
||||
return Names.named(((jakarta.inject.Named) annotation).value());
|
||||
} else {
|
||||
return annotation;
|
||||
}
|
||||
return annotation;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the annotation is the class {@code javax.inject.Named}, canonicalizes to
|
||||
* If the annotation is the class {@code jakarta.inject.Named}, canonicalizes to
|
||||
* com.google.guice.name.Named. Returns the given annotation class otherwise.
|
||||
*/
|
||||
public static Class<? extends Annotation> canonicalizeIfNamed(
|
||||
Class<? extends Annotation> annotationType) {
|
||||
if (annotationType == javax.inject.Named.class
|
||||
|| annotationType == jakarta.inject.Named.class) {
|
||||
if (
|
||||
annotationType == jakarta.inject.Named.class) {
|
||||
return Named.class;
|
||||
} else {
|
||||
return annotationType;
|
||||
}
|
||||
return annotationType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -104,11 +104,11 @@ public class BindingBuilder<T> extends AbstractBindingBuilder<T>
|
||||
|
||||
@Override
|
||||
public BindingBuilder<T> toProvider(Provider<? extends T> provider) {
|
||||
return toProvider((javax.inject.Provider<? extends T>) provider);
|
||||
return toProvider((jakarta.inject.Provider<? extends T>) provider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BindingBuilder<T> toProvider(javax.inject.Provider<? extends T> provider) {
|
||||
public BindingBuilder<T> toProvider(jakarta.inject.Provider<? extends T> provider) {
|
||||
checkNotNull(provider, "provider");
|
||||
checkNotTargetted();
|
||||
|
||||
@@ -130,19 +130,19 @@ public class BindingBuilder<T> extends AbstractBindingBuilder<T>
|
||||
|
||||
@Override
|
||||
public BindingBuilder<T> toProvider(
|
||||
Class<? extends javax.inject.Provider<? extends T>> providerType) {
|
||||
Class<? extends jakarta.inject.Provider<? extends T>> providerType) {
|
||||
return toProvider(Key.get(providerType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BindingBuilder<T> toProvider(
|
||||
TypeLiteral<? extends javax.inject.Provider<? extends T>> providerType) {
|
||||
TypeLiteral<? extends jakarta.inject.Provider<? extends T>> providerType) {
|
||||
return toProvider(Key.get(providerType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BindingBuilder<T> toProvider(
|
||||
Key<? extends javax.inject.Provider<? extends T>> providerKey) {
|
||||
Key<? extends jakarta.inject.Provider<? extends T>> providerKey) {
|
||||
checkNotNull(providerKey, "providerKey");
|
||||
checkNotTargetted();
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ final class BindingProcessor extends AbstractBindingProcessor {
|
||||
@Override
|
||||
public Boolean visit(ProviderInstanceBinding<? extends T> binding) {
|
||||
prepareBinding();
|
||||
javax.inject.Provider<? extends T> provider = binding.getUserSuppliedProvider();
|
||||
jakarta.inject.Provider<? extends T> provider = binding.getUserSuppliedProvider();
|
||||
if (provider instanceof InternalProviderInstanceBindingImpl.Factory) {
|
||||
@SuppressWarnings("unchecked")
|
||||
InternalProviderInstanceBindingImpl.Factory<T> asProviderMethod =
|
||||
@@ -136,8 +136,8 @@ final class BindingProcessor extends AbstractBindingProcessor {
|
||||
return visitInternalProviderInstanceBindingFactory(asProviderMethod);
|
||||
}
|
||||
Set<InjectionPoint> injectionPoints = binding.getInjectionPoints();
|
||||
Initializable<? extends javax.inject.Provider<? extends T>> initializable =
|
||||
initializer.<javax.inject.Provider<? extends T>>requestInjection(
|
||||
Initializable<? extends jakarta.inject.Provider<? extends T>> initializable =
|
||||
initializer.<jakarta.inject.Provider<? extends T>>requestInjection(
|
||||
injector, /* type= */ null, provider, null, source, injectionPoints, errors);
|
||||
// always visited with Binding<T>
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -157,7 +157,7 @@ final class BindingProcessor extends AbstractBindingProcessor {
|
||||
@Override
|
||||
public Boolean visit(ProviderKeyBinding<? extends T> binding) {
|
||||
prepareBinding();
|
||||
Key<? extends javax.inject.Provider<? extends T>> providerKey =
|
||||
Key<? extends jakarta.inject.Provider<? extends T>> providerKey =
|
||||
binding.getProviderKey();
|
||||
// always visited with Binding<T>
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -19,19 +19,19 @@ package com.google.inject.internal;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.internal.InjectorImpl.JitLimitation;
|
||||
import com.google.inject.spi.Dependency;
|
||||
import javax.inject.Provider;
|
||||
import jakarta.inject.Provider;
|
||||
|
||||
/** Delegates to a custom factory which is also bound in the injector. */
|
||||
final class BoundProviderFactory<T> extends ProviderInternalFactory<T> implements CreationListener {
|
||||
|
||||
private final ProvisionListenerStackCallback<T> provisionCallback;
|
||||
private final InjectorImpl injector;
|
||||
final Key<? extends javax.inject.Provider<? extends T>> providerKey;
|
||||
private InternalFactory<? extends javax.inject.Provider<? extends T>> providerFactory;
|
||||
final Key<? extends jakarta.inject.Provider<? extends T>> providerKey;
|
||||
private InternalFactory<? extends jakarta.inject.Provider<? extends T>> providerFactory;
|
||||
|
||||
BoundProviderFactory(
|
||||
InjectorImpl injector,
|
||||
Key<? extends javax.inject.Provider<? extends T>> providerKey,
|
||||
Key<? extends jakarta.inject.Provider<? extends T>> providerKey,
|
||||
Object source,
|
||||
ProvisionListenerStackCallback<T> provisionCallback) {
|
||||
super(source);
|
||||
@@ -55,7 +55,7 @@ final class BoundProviderFactory<T> extends ProviderInternalFactory<T> implement
|
||||
public T get(InternalContext context, Dependency<?> dependency, boolean linked)
|
||||
throws InternalProvisionException {
|
||||
try {
|
||||
javax.inject.Provider<? extends T> provider = providerFactory.get(context, dependency, true);
|
||||
jakarta.inject.Provider<? extends T> provider = providerFactory.get(context, dependency, true);
|
||||
return circularGet(provider, context, dependency, provisionCallback);
|
||||
} catch (InternalProvisionException ipe) {
|
||||
throw ipe.addSource(providerKey);
|
||||
|
||||
@@ -784,7 +784,7 @@ final class InjectorImpl implements Injector, Lookups {
|
||||
<T> BindingImpl<T> createProvidedByBinding(
|
||||
Key<T> key, Scoping scoping, ProvidedBy providedBy, Errors errors) throws ErrorsException {
|
||||
Class<?> rawType = key.getTypeLiteral().getRawType();
|
||||
Class<? extends javax.inject.Provider<?>> providerType = providedBy.value();
|
||||
Class<? extends jakarta.inject.Provider<?>> providerType = providedBy.value();
|
||||
|
||||
// Make sure it's not the same type. TODO: Can we check for deeper loops?
|
||||
if (providerType == rawType) {
|
||||
|
||||
@@ -338,7 +338,6 @@ final class InjectorShell {
|
||||
public void configure(Binder binder) {
|
||||
binder = binder.withSource(SourceProvider.UNKNOWN_SOURCE);
|
||||
binder.bindScope(Singleton.class, SINGLETON);
|
||||
binder.bindScope(javax.inject.Singleton.class, SINGLETON);
|
||||
binder.bindScope(jakarta.inject.Singleton.class, SINGLETON);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,10 +30,10 @@ import com.google.inject.spi.ProviderInstanceBinding;
|
||||
final class InternalFactoryToInitializableAdapter<T> extends ProviderInternalFactory<T> {
|
||||
|
||||
private final ProvisionListenerStackCallback<T> provisionCallback;
|
||||
private final Initializable<? extends javax.inject.Provider<? extends T>> initializable;
|
||||
private final Initializable<? extends jakarta.inject.Provider<? extends T>> initializable;
|
||||
|
||||
public InternalFactoryToInitializableAdapter(
|
||||
Initializable<? extends javax.inject.Provider<? extends T>> initializable,
|
||||
Initializable<? extends jakarta.inject.Provider<? extends T>> initializable,
|
||||
Object source,
|
||||
ProvisionListenerStackCallback<T> provisionCallback) {
|
||||
super(source);
|
||||
@@ -49,7 +49,7 @@ final class InternalFactoryToInitializableAdapter<T> extends ProviderInternalFac
|
||||
|
||||
@Override
|
||||
protected T provision(
|
||||
javax.inject.Provider<? extends T> provider,
|
||||
jakarta.inject.Provider<? extends T> provider,
|
||||
Dependency<?> dependency,
|
||||
ConstructionContext<T> constructionContext)
|
||||
throws InternalProvisionException {
|
||||
|
||||
@@ -102,7 +102,7 @@ public final class InternalProvisionException extends Exception {
|
||||
}
|
||||
|
||||
public static InternalProvisionException subtypeNotProvided(
|
||||
Class<? extends javax.inject.Provider<?>> providerType, Class<?> type) {
|
||||
Class<? extends jakarta.inject.Provider<?>> providerType, Class<?> type) {
|
||||
return create(
|
||||
ErrorId.SUBTYPE_NOT_PROVIDED, "%s doesn't provide instances of %s.", providerType, type);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.util.Set;
|
||||
final class LinkedProviderBindingImpl<T> extends BindingImpl<T>
|
||||
implements ProviderKeyBinding<T>, HasDependencies, DelayedInitialize {
|
||||
|
||||
final Key<? extends javax.inject.Provider<? extends T>> providerKey;
|
||||
final Key<? extends jakarta.inject.Provider<? extends T>> providerKey;
|
||||
final DelayedInitialize delayedInitializer;
|
||||
|
||||
private LinkedProviderBindingImpl(
|
||||
@@ -42,7 +42,7 @@ final class LinkedProviderBindingImpl<T> extends BindingImpl<T>
|
||||
Object source,
|
||||
InternalFactory<? extends T> internalFactory,
|
||||
Scoping scoping,
|
||||
Key<? extends javax.inject.Provider<? extends T>> providerKey,
|
||||
Key<? extends jakarta.inject.Provider<? extends T>> providerKey,
|
||||
DelayedInitialize delayedInitializer) {
|
||||
super(injector, key, source, internalFactory, scoping);
|
||||
this.providerKey = providerKey;
|
||||
@@ -55,7 +55,7 @@ final class LinkedProviderBindingImpl<T> extends BindingImpl<T>
|
||||
Object source,
|
||||
InternalFactory<? extends T> internalFactory,
|
||||
Scoping scoping,
|
||||
Key<? extends javax.inject.Provider<? extends T>> providerKey) {
|
||||
Key<? extends jakarta.inject.Provider<? extends T>> providerKey) {
|
||||
this(injector, key, source, internalFactory, scoping, providerKey, null);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ final class LinkedProviderBindingImpl<T> extends BindingImpl<T>
|
||||
Object source,
|
||||
Key<T> key,
|
||||
Scoping scoping,
|
||||
Key<? extends javax.inject.Provider<? extends T>> providerKey) {
|
||||
Key<? extends jakarta.inject.Provider<? extends T>> providerKey) {
|
||||
super(source, key, scoping);
|
||||
this.providerKey = providerKey;
|
||||
this.delayedInitializer = null;
|
||||
@@ -75,7 +75,7 @@ final class LinkedProviderBindingImpl<T> extends BindingImpl<T>
|
||||
Object source,
|
||||
InternalFactory<? extends T> internalFactory,
|
||||
Scoping scoping,
|
||||
Key<? extends javax.inject.Provider<? extends T>> providerKey,
|
||||
Key<? extends jakarta.inject.Provider<? extends T>> providerKey,
|
||||
DelayedInitialize delayedInitializer) {
|
||||
return new LinkedProviderBindingImpl<T>(
|
||||
injector, key, source, internalFactory, scoping, providerKey, delayedInitializer);
|
||||
@@ -87,7 +87,7 @@ final class LinkedProviderBindingImpl<T> extends BindingImpl<T>
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key<? extends javax.inject.Provider<? extends T>> getProviderKey() {
|
||||
public Key<? extends jakarta.inject.Provider<? extends T>> getProviderKey() {
|
||||
return providerKey;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ public class MoreTypes {
|
||||
/**
|
||||
* Returns an type that's appropriate for use in a key.
|
||||
*
|
||||
* <p>If the raw type of {@code typeLiteral} is a {@code javax.inject.Provider} or {@code
|
||||
* <p>If the raw type of {@code typeLiteral} is a {@code jakarta.inject.Provider} or {@code
|
||||
* jakarta.inject.Provider}, this returns a {@code com.google.inject.Provider} with the same type
|
||||
* parameters.
|
||||
*
|
||||
@@ -92,12 +92,12 @@ public class MoreTypes {
|
||||
throw new ConfigurationException(errors.getMessages());
|
||||
}
|
||||
|
||||
if (typeLiteral.getRawType() == javax.inject.Provider.class
|
||||
|| typeLiteral.getRawType() == jakarta.inject.Provider.class) {
|
||||
if (
|
||||
typeLiteral.getRawType() == jakarta.inject.Provider.class) {
|
||||
ParameterizedType parameterizedType = (ParameterizedType) type;
|
||||
|
||||
// the following casts are generally unsafe, but com.google.inject.Provider extends
|
||||
// javax.inject.Provider & jakarta.inject.Provider and is covariant
|
||||
// jakarta.inject.Provider & jakarta.inject.Provider and is covariant
|
||||
@SuppressWarnings("unchecked")
|
||||
TypeLiteral<T> guiceProviderType =
|
||||
(TypeLiteral<T>)
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.google.inject.Key;
|
||||
import com.google.inject.ProvidedBy;
|
||||
import com.google.inject.internal.InjectorImpl.JitLimitation;
|
||||
import com.google.inject.spi.Dependency;
|
||||
import javax.inject.Provider;
|
||||
import jakarta.inject.Provider;
|
||||
|
||||
/**
|
||||
* An {@link InternalFactory} for {@literal @}{@link ProvidedBy} bindings.
|
||||
@@ -74,7 +74,7 @@ class ProvidedByInternalFactory<T> extends ProviderInternalFactory<T> implements
|
||||
|
||||
@Override
|
||||
protected T provision(
|
||||
javax.inject.Provider<? extends T> provider,
|
||||
jakarta.inject.Provider<? extends T> provider,
|
||||
Dependency<?> dependency,
|
||||
ConstructionContext<T> constructionContext)
|
||||
throws InternalProvisionException {
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.util.Set;
|
||||
|
||||
class ProviderInstanceBindingImpl<T> extends BindingImpl<T> implements ProviderInstanceBinding<T> {
|
||||
|
||||
final javax.inject.Provider<? extends T> providerInstance;
|
||||
final jakarta.inject.Provider<? extends T> providerInstance;
|
||||
final ImmutableSet<InjectionPoint> injectionPoints;
|
||||
|
||||
public ProviderInstanceBindingImpl(
|
||||
@@ -45,7 +45,7 @@ class ProviderInstanceBindingImpl<T> extends BindingImpl<T> implements ProviderI
|
||||
Object source,
|
||||
InternalFactory<? extends T> internalFactory,
|
||||
Scoping scoping,
|
||||
javax.inject.Provider<? extends T> providerInstance,
|
||||
jakarta.inject.Provider<? extends T> providerInstance,
|
||||
Set<InjectionPoint> injectionPoints) {
|
||||
super(injector, key, source, internalFactory, scoping);
|
||||
this.providerInstance = providerInstance;
|
||||
@@ -57,7 +57,7 @@ class ProviderInstanceBindingImpl<T> extends BindingImpl<T> implements ProviderI
|
||||
Key<T> key,
|
||||
Scoping scoping,
|
||||
Set<InjectionPoint> injectionPoints,
|
||||
javax.inject.Provider<? extends T> providerInstance) {
|
||||
jakarta.inject.Provider<? extends T> providerInstance) {
|
||||
super(source, key, scoping);
|
||||
this.injectionPoints = ImmutableSet.copyOf(injectionPoints);
|
||||
this.providerInstance = providerInstance;
|
||||
@@ -78,7 +78,7 @@ class ProviderInstanceBindingImpl<T> extends BindingImpl<T> implements ProviderI
|
||||
}
|
||||
|
||||
@Override
|
||||
public javax.inject.Provider<? extends T> getUserSuppliedProvider() {
|
||||
public jakarta.inject.Provider<? extends T> getUserSuppliedProvider() {
|
||||
return providerInstance;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.google.inject.internal.ProvisionListenerStackCallback.ProvisionCallback;
|
||||
import com.google.inject.spi.Dependency;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Provider;
|
||||
import jakarta.inject.Provider;
|
||||
|
||||
/**
|
||||
* Base class for InternalFactories that are used by Providers, to handle circular dependencies.
|
||||
|
||||
@@ -136,17 +136,6 @@ public final class RealMapBinder<K, V> implements Module {
|
||||
newParameterizedType(jakarta.inject.Provider.class, valueType.getType())));
|
||||
}
|
||||
|
||||
// provider map <K, V> is safely a Map<K, javax.inject.Provider<V>>>
|
||||
@SuppressWarnings("unchecked")
|
||||
static <K, V> TypeLiteral<Map<K, javax.inject.Provider<V>>> mapOfJavaxProviderOf(
|
||||
TypeLiteral<K> keyType, TypeLiteral<V> valueType) {
|
||||
return (TypeLiteral<Map<K, javax.inject.Provider<V>>>)
|
||||
TypeLiteral.get(
|
||||
Types.mapOf(
|
||||
keyType.getType(),
|
||||
newParameterizedType(javax.inject.Provider.class, valueType.getType())));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") // a provider map <K, Set<V>> is safely a Map<K, Set<Provider<V>>>
|
||||
static <K, V> TypeLiteral<Map<K, Set<Provider<V>>>> mapOfSetOfProviderOf(
|
||||
TypeLiteral<K> keyType, TypeLiteral<V> valueType) {
|
||||
@@ -164,15 +153,6 @@ public final class RealMapBinder<K, V> implements Module {
|
||||
keyType.getType(), Types.setOf(Types.jakartaProviderOf(valueType.getType()))));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") // a provider map <K, Set<V>> is safely a Map<K, Set<Provider<V>>>
|
||||
static <K, V> TypeLiteral<Map<K, Set<javax.inject.Provider<V>>>> mapOfSetOfJavaxProviderOf(
|
||||
TypeLiteral<K> keyType, TypeLiteral<V> valueType) {
|
||||
return (TypeLiteral<Map<K, Set<javax.inject.Provider<V>>>>)
|
||||
TypeLiteral.get(
|
||||
Types.mapOf(
|
||||
keyType.getType(), Types.setOf(Types.javaxProviderOf(valueType.getType()))));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") // a provider map <K, Set<V>> is safely a Map<K, Set<Provider<V>>>
|
||||
static <K, V> TypeLiteral<Map<K, Collection<Provider<V>>>> mapOfCollectionOfProviderOf(
|
||||
TypeLiteral<K> keyType, TypeLiteral<V> valueType) {
|
||||
@@ -193,16 +173,6 @@ public final class RealMapBinder<K, V> implements Module {
|
||||
Types.collectionOf(Types.jakartaProviderOf(valueType.getType()))));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") // a provider map <K, Set<V>> is safely a Map<K, Set<Provider<V>>>
|
||||
static <K, V>
|
||||
TypeLiteral<Map<K, Collection<javax.inject.Provider<V>>>> mapOfCollectionOfJavaxProviderOf(
|
||||
TypeLiteral<K> keyType, TypeLiteral<V> valueType) {
|
||||
return (TypeLiteral<Map<K, Collection<javax.inject.Provider<V>>>>)
|
||||
TypeLiteral.get(
|
||||
Types.mapOf(
|
||||
keyType.getType(), Types.collectionOf(Types.javaxProviderOf(valueType.getType()))));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") // a provider entry <K, V> is safely a Map.Entry<K, Provider<V>>
|
||||
static <K, V> TypeLiteral<Map.Entry<K, Provider<V>>> entryOfProviderOf(
|
||||
TypeLiteral<K> keyType, TypeLiteral<V> valueType) {
|
||||
@@ -235,26 +205,6 @@ public final class RealMapBinder<K, V> implements Module {
|
||||
TypeLiteral.get(Types.setOf(entryOfJakartaProviderOf(keyType, valueType).getType()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") // a provider entry <K, V> is safely a Map.Entry<K, Provider<V>>
|
||||
static <K, V> TypeLiteral<Map.Entry<K, Provider<V>>> entryOfJavaxProviderOf(
|
||||
TypeLiteral<K> keyType, TypeLiteral<V> valueType) {
|
||||
return (TypeLiteral<Map.Entry<K, Provider<V>>>)
|
||||
TypeLiteral.get(
|
||||
newParameterizedTypeWithOwner(
|
||||
Map.class,
|
||||
Map.Entry.class,
|
||||
keyType.getType(),
|
||||
Types.javaxProviderOf(valueType.getType())));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") // a provider entry <K, V> is safely a Map.Entry<K, Provider<V>>
|
||||
static <K, V>
|
||||
TypeLiteral<Set<Map.Entry<K, javax.inject.Provider<V>>>> setOfEntryOfJavaxProviderOf(
|
||||
TypeLiteral<K> keyType, TypeLiteral<V> valueType) {
|
||||
return (TypeLiteral<Set<Map.Entry<K, javax.inject.Provider<V>>>>)
|
||||
TypeLiteral.get(Types.setOf(entryOfJavaxProviderOf(keyType, valueType).getType()));
|
||||
}
|
||||
|
||||
/** Given a {@code Key<T>} will return a {@code Key<Provider<T>>}. */
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> Key<Provider<T>> getKeyOfProvider(Key<T> valueKey) {
|
||||
@@ -357,14 +307,6 @@ public final class RealMapBinder<K, V> implements Module {
|
||||
(Provider) providerMapProvider;
|
||||
binder.bind(bindingSelection.getJakartaProviderMapKey()).toProvider(jakartaProviderMapProvider);
|
||||
|
||||
// The map this exposes is internally an ImmutableMap, so it's OK to massage
|
||||
// the guice Provider to javax Provider in the value (since Guice provider
|
||||
// implements javax Provider).
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
Provider<Map<K, javax.inject.Provider<V>>> javaxProviderMapProvider =
|
||||
(Provider) providerMapProvider;
|
||||
binder.bind(bindingSelection.getJavaxProviderMapKey()).toProvider(javaxProviderMapProvider);
|
||||
|
||||
RealMapProvider<K, V> mapProvider = new RealMapProvider<>(bindingSelection);
|
||||
// Bind Map<K, V> to the provider w/ extension support.
|
||||
binder
|
||||
@@ -379,13 +321,6 @@ public final class RealMapBinder<K, V> implements Module {
|
||||
Key<Set<Map.Entry<K, jakarta.inject.Provider<V>>>> jakartaEntrySetProviderKey =
|
||||
(Key) bindingSelection.getEntrySetBinder().getSetKey();
|
||||
binder.bind(bindingSelection.getEntrySetJakartaProviderKey()).to(jakartaEntrySetProviderKey);
|
||||
|
||||
// The Map.Entries are all ProviderMapEntry instances which do not allow setValue, so it is
|
||||
// safe to massage the return type like this
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
Key<Set<Map.Entry<K, javax.inject.Provider<V>>>> massagedEntrySetProviderKey =
|
||||
(Key) bindingSelection.getEntrySetBinder().getSetKey();
|
||||
binder.bind(bindingSelection.getEntrySetJavaxProviderKey()).to(massagedEntrySetProviderKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -425,20 +360,16 @@ public final class RealMapBinder<K, V> implements Module {
|
||||
private final Key<Map<K, V>> mapKey;
|
||||
|
||||
// Lazily computed
|
||||
private Key<Map<K, jakarta.inject.Provider<V>>> jakartaProviderMapKey;
|
||||
private Key<Map<K, javax.inject.Provider<V>>> javaxProviderMapKey;
|
||||
private Key<Map<K, Provider<V>>> providerMapKey;
|
||||
private Key<Map<K, Set<V>>> multimapKey;
|
||||
private Key<Map<K, Set<Provider<V>>>> providerSetMultimapKey;
|
||||
private Key<Map<K, Set<jakarta.inject.Provider<V>>>> jakartaProviderSetMultimapKey;
|
||||
private Key<Map<K, Set<javax.inject.Provider<V>>>> javaxProviderSetMultimapKey;
|
||||
private Key<Map<K, Collection<Provider<V>>>> providerCollectionMultimapKey;
|
||||
private Key<Map<K, ? extends V>> mapOfKeyExtendsValueKey;
|
||||
private Key<Map<K, jakarta.inject.Provider<V>>> jakartaProviderMapKey;
|
||||
private Key<Map<K, Set<jakarta.inject.Provider<V>>>> jakartaProviderSetMultimapKey;
|
||||
private Key<Map<K, Collection<jakarta.inject.Provider<V>>>>
|
||||
jakartaProviderCollectionMultimapKey;
|
||||
private Key<Map<K, Collection<javax.inject.Provider<V>>>> javaxProviderCollectionMultimapKey;
|
||||
private Key<Set<Map.Entry<K, jakarta.inject.Provider<V>>>> entrySetJakartaProviderKey;
|
||||
private Key<Set<Map.Entry<K, javax.inject.Provider<V>>>> entrySetJavaxProviderKey;
|
||||
private Key<Map<K, ? extends V>> mapOfKeyExtendsValueKey;
|
||||
|
||||
private final RealMultibinder<Map.Entry<K, Provider<V>>> entrySetBinder;
|
||||
|
||||
@@ -604,17 +535,13 @@ public final class RealMapBinder<K, V> implements Module {
|
||||
return key.equals(getMapKey())
|
||||
|| key.equals(getProviderMapKey())
|
||||
|| key.equals(getJakartaProviderMapKey())
|
||||
|| key.equals(getJavaxProviderMapKey())
|
||||
|| key.equals(getMultimapKey())
|
||||
|| key.equals(getProviderSetMultimapKey())
|
||||
|| key.equals(getJakartaProviderSetMultimapKey())
|
||||
|| key.equals(getJavaxProviderSetMultimapKey())
|
||||
|| key.equals(getProviderCollectionMultimapKey())
|
||||
|| key.equals(getJakartaProviderCollectionMultimapKey())
|
||||
|| key.equals(getJavaxProviderCollectionMultimapKey())
|
||||
|| key.equals(entrySetBinder.getSetKey())
|
||||
|| key.equals(getEntrySetJakartaProviderKey())
|
||||
|| key.equals(getEntrySetJavaxProviderKey())
|
||||
|| key.equals(getMapOfKeyExtendsValueKey())
|
||||
|| matchesValueKey(key);
|
||||
}
|
||||
@@ -644,14 +571,6 @@ public final class RealMapBinder<K, V> implements Module {
|
||||
return local;
|
||||
}
|
||||
|
||||
private Key<Map<K, javax.inject.Provider<V>>> getJavaxProviderMapKey() {
|
||||
Key<Map<K, javax.inject.Provider<V>>> local = javaxProviderMapKey;
|
||||
if (local == null) {
|
||||
local = javaxProviderMapKey = mapKey.ofType(mapOfJavaxProviderOf(keyType, valueType));
|
||||
}
|
||||
return local;
|
||||
}
|
||||
|
||||
private Key<Map<K, Set<V>>> getMultimapKey() {
|
||||
Key<Map<K, Set<V>>> local = multimapKey;
|
||||
if (local == null) {
|
||||
@@ -678,16 +597,6 @@ public final class RealMapBinder<K, V> implements Module {
|
||||
return local;
|
||||
}
|
||||
|
||||
private Key<Map<K, Set<javax.inject.Provider<V>>>> getJavaxProviderSetMultimapKey() {
|
||||
Key<Map<K, Set<javax.inject.Provider<V>>>> local = javaxProviderSetMultimapKey;
|
||||
if (local == null) {
|
||||
local =
|
||||
javaxProviderSetMultimapKey =
|
||||
mapKey.ofType(mapOfSetOfJavaxProviderOf(keyType, valueType));
|
||||
}
|
||||
return local;
|
||||
}
|
||||
|
||||
private Key<Map<K, Collection<Provider<V>>>> getProviderCollectionMultimapKey() {
|
||||
Key<Map<K, Collection<Provider<V>>>> local = providerCollectionMultimapKey;
|
||||
if (local == null) {
|
||||
@@ -710,17 +619,6 @@ public final class RealMapBinder<K, V> implements Module {
|
||||
return local;
|
||||
}
|
||||
|
||||
private Key<Map<K, Collection<javax.inject.Provider<V>>>>
|
||||
getJavaxProviderCollectionMultimapKey() {
|
||||
Key<Map<K, Collection<javax.inject.Provider<V>>>> local = javaxProviderCollectionMultimapKey;
|
||||
if (local == null) {
|
||||
local =
|
||||
javaxProviderCollectionMultimapKey =
|
||||
mapKey.ofType(mapOfCollectionOfJavaxProviderOf(keyType, valueType));
|
||||
}
|
||||
return local;
|
||||
}
|
||||
|
||||
private Key<Set<Map.Entry<K, jakarta.inject.Provider<V>>>> getEntrySetJakartaProviderKey() {
|
||||
Key<Set<Map.Entry<K, jakarta.inject.Provider<V>>>> local = entrySetJakartaProviderKey;
|
||||
if (local == null) {
|
||||
@@ -731,16 +629,6 @@ public final class RealMapBinder<K, V> implements Module {
|
||||
return local;
|
||||
}
|
||||
|
||||
private Key<Set<Map.Entry<K, javax.inject.Provider<V>>>> getEntrySetJavaxProviderKey() {
|
||||
Key<Set<Map.Entry<K, javax.inject.Provider<V>>>> local = entrySetJavaxProviderKey;
|
||||
if (local == null) {
|
||||
local =
|
||||
entrySetJavaxProviderKey =
|
||||
mapKey.ofType(setOfEntryOfJavaxProviderOf(keyType, valueType));
|
||||
}
|
||||
return local;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Key<Map<K, ? extends V>> getMapOfKeyExtendsValueKey() {
|
||||
Key<Map<K, ? extends V>> local = mapOfKeyExtendsValueKey;
|
||||
@@ -977,14 +865,11 @@ public final class RealMapBinder<K, V> implements Module {
|
||||
public Set<Key<?>> getAlternateMapKeys() {
|
||||
return ImmutableSet.of(
|
||||
(Key<?>) bindingSelection.getJakartaProviderMapKey(),
|
||||
(Key<?>) bindingSelection.getJavaxProviderMapKey(),
|
||||
(Key<?>) bindingSelection.getProviderMapKey(),
|
||||
(Key<?>) bindingSelection.getProviderSetMultimapKey(),
|
||||
(Key<?>) bindingSelection.getJakartaProviderSetMultimapKey(),
|
||||
(Key<?>) bindingSelection.getJavaxProviderSetMultimapKey(),
|
||||
(Key<?>) bindingSelection.getProviderCollectionMultimapKey(),
|
||||
(Key<?>) bindingSelection.getJakartaProviderCollectionMultimapKey(),
|
||||
(Key<?>) bindingSelection.getJavaxProviderCollectionMultimapKey(),
|
||||
(Key<?>) bindingSelection.getMultimapKey(),
|
||||
(Key<?>) bindingSelection.getMapOfKeyExtendsValueKey());
|
||||
}
|
||||
@@ -1150,14 +1035,6 @@ public final class RealMapBinder<K, V> implements Module {
|
||||
new RealProviderMultimapProvider<K, V>(bindingSelection.getMapKey());
|
||||
binder.bind(bindingSelection.getProviderSetMultimapKey()).toProvider(multimapProvider);
|
||||
|
||||
// Provide links from a few different public keys to the providerMultimapKey.
|
||||
// The collection this exposes is internally an ImmutableMap, so it's OK to massage
|
||||
// the guice Provider to javax Provider in the value (since the guice Provider implements
|
||||
// javax Provider).
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
Provider<Map<K, Set<javax.inject.Provider<V>>>> javaxProvider = (Provider) multimapProvider;
|
||||
binder.bind(bindingSelection.getJavaxProviderSetMultimapKey()).toProvider(javaxProvider);
|
||||
|
||||
// Provide links from a few different public keys to the providerMultimapKey.
|
||||
// The collection this exposes is internally an ImmutableMap, so it's OK to massage
|
||||
// the guice Provider to jakarta Provider in the value (since the guice Provider implements
|
||||
@@ -1180,13 +1057,6 @@ public final class RealMapBinder<K, V> implements Module {
|
||||
.bind(bindingSelection.getJakartaProviderCollectionMultimapKey())
|
||||
.toProvider(collectionJakartaProvider);
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
Provider<Map<K, Collection<javax.inject.Provider<V>>>> collectionJavaxProvider =
|
||||
(Provider) multimapProvider;
|
||||
binder
|
||||
.bind(bindingSelection.getJavaxProviderCollectionMultimapKey())
|
||||
.toProvider(collectionJavaxProvider);
|
||||
|
||||
// Binds a Map<K, Set<V>>
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
Provider<Map<K, Set<V>>> realMultimapProvider =
|
||||
|
||||
@@ -81,15 +81,6 @@ public final class RealMultibinder<T> implements Module {
|
||||
return (TypeLiteral<Collection<jakarta.inject.Provider<T>>>) TypeLiteral.get(type);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <T> TypeLiteral<Collection<javax.inject.Provider<T>>> collectionOfJavaxProvidersOf(
|
||||
TypeLiteral<T> elementType) {
|
||||
Type providerType =
|
||||
Types.newParameterizedType(javax.inject.Provider.class, elementType.getType());
|
||||
Type type = Types.collectionOf(providerType);
|
||||
return (TypeLiteral<Collection<javax.inject.Provider<T>>>) TypeLiteral.get(type);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <T> TypeLiteral<Set<? extends T>> setOfExtendsOf(TypeLiteral<T> elementType) {
|
||||
Type extendsType = Types.subtypeOf(elementType.getType());
|
||||
@@ -132,14 +123,6 @@ public final class RealMultibinder<T> implements Module {
|
||||
Provider<Collection<jakarta.inject.Provider<T>>> jakartaProvider =
|
||||
(Provider) collectionOfProvidersProvider;
|
||||
binder.bind(bindingSelection.getCollectionOfJakartaProvidersKey()).toProvider(jakartaProvider);
|
||||
|
||||
// The collection this exposes is internally an ImmutableList, so it's OK to massage
|
||||
// the guice Provider to javax Provider in the value (since the guice Provider implements
|
||||
// javax Provider).
|
||||
@SuppressWarnings("unchecked")
|
||||
Provider<Collection<javax.inject.Provider<T>>> javaxProvider =
|
||||
(Provider) collectionOfProvidersProvider;
|
||||
binder.bind(bindingSelection.getCollectionOfJavaxProvidersKey()).toProvider(javaxProvider);
|
||||
}
|
||||
|
||||
public void permitDuplicates() {
|
||||
@@ -344,7 +327,6 @@ public final class RealMultibinder<T> implements Module {
|
||||
return ImmutableSet.of(
|
||||
(Key<?>) bindingSelection.getCollectionOfProvidersKey(),
|
||||
(Key<?>) bindingSelection.getCollectionOfJakartaProvidersKey(),
|
||||
(Key<?>) bindingSelection.getCollectionOfJavaxProvidersKey(),
|
||||
(Key<?>) bindingSelection.getSetOfExtendsKey());
|
||||
}
|
||||
|
||||
@@ -409,7 +391,6 @@ public final class RealMultibinder<T> implements Module {
|
||||
private String setName;
|
||||
private Key<Collection<Provider<T>>> collectionOfProvidersKey;
|
||||
private Key<Collection<jakarta.inject.Provider<T>>> collectionOfJakartaProvidersKey;
|
||||
private Key<Collection<javax.inject.Provider<T>>> collectionOfJavaxProvidersKey;
|
||||
private Key<Set<? extends T>> setOfExtendsKey;
|
||||
private Key<Boolean> permitDuplicatesKey;
|
||||
|
||||
@@ -536,16 +517,6 @@ public final class RealMultibinder<T> implements Module {
|
||||
return local;
|
||||
}
|
||||
|
||||
Key<Collection<javax.inject.Provider<T>>> getCollectionOfJavaxProvidersKey() {
|
||||
Key<Collection<javax.inject.Provider<T>>> local = collectionOfJavaxProvidersKey;
|
||||
if (local == null) {
|
||||
local =
|
||||
collectionOfJavaxProvidersKey =
|
||||
setKey.ofType(collectionOfJavaxProvidersOf(elementType));
|
||||
}
|
||||
return local;
|
||||
}
|
||||
|
||||
Key<Set<? extends T>> getSetOfExtendsKey() {
|
||||
Key<Set<? extends T>> local = setOfExtendsKey;
|
||||
if (local == null) {
|
||||
@@ -594,7 +565,6 @@ public final class RealMultibinder<T> implements Module {
|
||||
|| binding.getKey().equals(setKey)
|
||||
|| binding.getKey().equals(collectionOfProvidersKey)
|
||||
|| binding.getKey().equals(collectionOfJakartaProvidersKey)
|
||||
|| binding.getKey().equals(collectionOfJavaxProvidersKey)
|
||||
|| binding.getKey().equals(setOfExtendsKey);
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@@ -46,7 +46,7 @@ import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Set;
|
||||
import javax.inject.Qualifier;
|
||||
import jakarta.inject.Qualifier;
|
||||
|
||||
/**
|
||||
* The actual OptionalBinder plays several roles. It implements Module to hide that fact from the
|
||||
@@ -72,25 +72,6 @@ public final class RealOptionalBinder<T> implements Module {
|
||||
TypeLiteral.get(Types.newParameterizedType(java.util.Optional.class, type.getType()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <T> TypeLiteral<Optional<javax.inject.Provider<T>>> optionalOfJavaxProvider(
|
||||
TypeLiteral<T> type) {
|
||||
return (TypeLiteral<Optional<javax.inject.Provider<T>>>)
|
||||
TypeLiteral.get(
|
||||
Types.newParameterizedType(
|
||||
Optional.class, newParameterizedType(javax.inject.Provider.class, type.getType())));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <T> TypeLiteral<java.util.Optional<javax.inject.Provider<T>>> javaOptionalOfJavaxProvider(
|
||||
TypeLiteral<T> type) {
|
||||
return (TypeLiteral<java.util.Optional<javax.inject.Provider<T>>>)
|
||||
TypeLiteral.get(
|
||||
Types.newParameterizedType(
|
||||
java.util.Optional.class,
|
||||
newParameterizedType(javax.inject.Provider.class, type.getType())));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <T> TypeLiteral<Optional<jakarta.inject.Provider<T>>> optionalOfJakartaProvider(
|
||||
TypeLiteral<T> type) {
|
||||
@@ -209,7 +190,6 @@ public final class RealOptionalBinder<T> implements Module {
|
||||
TypeLiteral<T> typeLiteral = key.getTypeLiteral();
|
||||
// Every OptionalBinder gets the following types bound
|
||||
// * {cgcb,ju}.Optional<Provider<T>>
|
||||
// * {cgcb,ju}.Optional<javax.inject.Provider<T>>
|
||||
// * {cgcb,ju}.Optional<jakarta.inject.Provider<T>>
|
||||
// * {cgcb,ju}.Optional<T>
|
||||
// If setDefault() or setBinding() is called then also
|
||||
@@ -226,29 +206,8 @@ public final class RealOptionalBinder<T> implements Module {
|
||||
.bind(key.ofType(javaOptionalOfProvider(typeLiteral)))
|
||||
.toProvider(javaOptionalProviderFactory);
|
||||
|
||||
// Provider is assignable to javax.inject.Provider and the provider that the factory contains
|
||||
// cannot be modified so we can use some rawtypes hackery to share the same implementation.
|
||||
|
||||
// cgcb.Optional<javax.inject.Provider<T>>
|
||||
@SuppressWarnings("unchecked")
|
||||
InternalProviderInstanceBindingImpl.Factory<Optional<javax.inject.Provider<T>>>
|
||||
optionalJavaxProviderFactory =
|
||||
(InternalProviderInstanceBindingImpl.Factory) optionalProviderFactory;
|
||||
binder
|
||||
.bind(key.ofType(optionalOfJavaxProvider(typeLiteral)))
|
||||
.toProvider(optionalJavaxProviderFactory);
|
||||
// ju.Optional<javax.inject.Provider<T>>
|
||||
@SuppressWarnings("unchecked")
|
||||
InternalProviderInstanceBindingImpl.Factory<java.util.Optional<javax.inject.Provider<T>>>
|
||||
javaOptionalJavaxProviderFactory =
|
||||
(InternalProviderInstanceBindingImpl.Factory) javaOptionalProviderFactory;
|
||||
binder
|
||||
.bind(key.ofType(javaOptionalOfJavaxProvider(typeLiteral)))
|
||||
.toProvider(javaOptionalJavaxProviderFactory);
|
||||
|
||||
// Provider is assignable to jakarta.inject.Provider and the provider that the factory contains
|
||||
// cannot be modified so we can use some rawtypes hackery to share the same implementation.
|
||||
|
||||
// cgcb.Optional<jakarta.inject.Provider<T>>
|
||||
@SuppressWarnings("unchecked")
|
||||
InternalProviderInstanceBindingImpl.Factory<Optional<jakarta.inject.Provider<T>>>
|
||||
@@ -366,7 +325,6 @@ public final class RealOptionalBinder<T> implements Module {
|
||||
TypeLiteral<?> typeLiteral = key.getTypeLiteral();
|
||||
return ImmutableSet.of(
|
||||
(Key<?>) key.ofType(javaOptionalOfProvider(typeLiteral)),
|
||||
(Key<?>) key.ofType(javaOptionalOfJavaxProvider(typeLiteral)),
|
||||
(Key<?>) key.ofType(javaOptionalOfJakartaProvider(typeLiteral)));
|
||||
}
|
||||
}
|
||||
@@ -539,7 +497,6 @@ public final class RealOptionalBinder<T> implements Module {
|
||||
TypeLiteral<?> typeLiteral = key.getTypeLiteral();
|
||||
return ImmutableSet.of(
|
||||
(Key<?>) key.ofType(optionalOfProvider(typeLiteral)),
|
||||
(Key<?>) key.ofType(optionalOfJavaxProvider(typeLiteral)),
|
||||
(Key<?>) key.ofType(optionalOfJakartaProvider(typeLiteral)));
|
||||
}
|
||||
|
||||
@@ -707,7 +664,7 @@ public final class RealOptionalBinder<T> implements Module {
|
||||
// All of our bindings are ProviderInstanceBindings whose providers extend
|
||||
// RealOptionalBinderProviderWithDependencies and have 'this' as its binding selection.
|
||||
if (element instanceof ProviderInstanceBinding) {
|
||||
javax.inject.Provider<?> providerInstance =
|
||||
jakarta.inject.Provider<?> providerInstance =
|
||||
((ProviderInstanceBinding<?>) element).getUserSuppliedProvider();
|
||||
if (providerInstance instanceof RealOptionalBinderProviderWithDependencies) {
|
||||
return ((RealOptionalBinderProviderWithDependencies<?, ?>) providerInstance)
|
||||
|
||||
@@ -161,7 +161,6 @@ public abstract class Scoping {
|
||||
|
||||
public static Scoping forAnnotation(final Class<? extends Annotation> scopingAnnotation) {
|
||||
if (scopingAnnotation == Singleton.class
|
||||
|| scopingAnnotation == javax.inject.Singleton.class
|
||||
|| scopingAnnotation == jakarta.inject.Singleton.class) {
|
||||
return SINGLETON_ANNOTATION;
|
||||
}
|
||||
|
||||
@@ -49,10 +49,10 @@ public interface MapBinderBinding<T> {
|
||||
|
||||
/**
|
||||
* Returns the keys of other bindings that represent this map. This will return an entry for
|
||||
* {@code Map<K, com.google.inject.Provider<V>>}, {@code Map<K, javax.inject.Provider<V>>}, {@code
|
||||
* Map<K, Set<com.google.inject.Provider<V>>>}, {@code Map<K, Set<javax.inject.Provider<V>>>},
|
||||
* {@code Map<K, com.google.inject.Provider<V>>}, {@code Map<K, jakarta.inject.Provider<V>>}, {@code
|
||||
* Map<K, Set<com.google.inject.Provider<V>>>}, {@code Map<K, Set<jakarta.inject.Provider<V>>>},
|
||||
* {@code Map<K, Collection<com.google.inject.Provider<V>>>}, {@code Map<K,
|
||||
* Collection<javax.inject.Provider<V>>>}, {@code Map<K, Set<V>}, and {@code Map<K, ? extends V>}.
|
||||
* Collection<jakarta.inject.Provider<V>>>}, {@code Map<K, Set<V>}, and {@code Map<K, ? extends V>}.
|
||||
*
|
||||
* @since 4.2.3
|
||||
*/
|
||||
|
||||
@@ -47,7 +47,7 @@ public interface MultibinderBinding<T> {
|
||||
/**
|
||||
* Returns the keys of other bindings that represent this set. This will return an entry for
|
||||
* {@code Collection<com.google.inject.Provider<V>>}, {@code
|
||||
* Collection<javax.inject.Provider<V>>}, and {@code Set<? extends V>}.
|
||||
* Collection<jakarta.inject.Provider<V>>}, and {@code Set<? extends V>}.
|
||||
*
|
||||
* @since 4.2.3
|
||||
*/
|
||||
|
||||
@@ -45,7 +45,7 @@ public interface OptionalBinderBinding<T> {
|
||||
/**
|
||||
* Returns the keys of other bindings that represent this OptionalBinder. This will return an
|
||||
* entry for {@code Optional<com.google.inject.Provider<V>>} and {@code
|
||||
* Optional<javax.inject.Provider<V>>}.
|
||||
* Optional<jakarta.inject.Provider<V>>}.
|
||||
*
|
||||
* @since 4.2.3
|
||||
*/
|
||||
|
||||
@@ -297,11 +297,7 @@ public final class InjectionPoint {
|
||||
|
||||
List<Constructor<?>> atInjectConstructors =
|
||||
Arrays.stream(rawType.getDeclaredConstructors())
|
||||
.filter(
|
||||
constructor ->
|
||||
constructor.isAnnotationPresent(Inject.class)
|
||||
|| constructor.isAnnotationPresent(javax.inject.Inject.class)
|
||||
|| constructor.isAnnotationPresent(jakarta.inject.Inject.class))
|
||||
.filter(InjectionPoint::isInjectableConstructor)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Constructor<?> injectableConstructor = null;
|
||||
@@ -346,6 +342,11 @@ public final class InjectionPoint {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isInjectableConstructor(Constructor<?> constructor) {
|
||||
return constructor.isAnnotationPresent(Inject.class)
|
||||
|| constructor.isAnnotationPresent(jakarta.inject.Inject.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new injection point for the injectable constructor of {@code type}.
|
||||
*
|
||||
@@ -485,8 +486,7 @@ public final class InjectionPoint {
|
||||
InjectableMember(TypeLiteral<?> declaringType, Annotation atInject) {
|
||||
this.declaringType = declaringType;
|
||||
|
||||
if (atInject.annotationType() == javax.inject.Inject.class
|
||||
|| atInject.annotationType() == jakarta.inject.Inject.class) {
|
||||
if ( atInject.annotationType() == jakarta.inject.Inject.class) {
|
||||
optional = false;
|
||||
specInject = true;
|
||||
return;
|
||||
@@ -517,7 +517,7 @@ public final class InjectionPoint {
|
||||
final Method method;
|
||||
/**
|
||||
* true if this method overrode a method that was annotated with com.google.inject.Inject. used
|
||||
* to allow different override behavior for guice inject vs javax.inject.Inject
|
||||
* to allow different override behavior for guice inject vs jsr330 Inject
|
||||
*/
|
||||
boolean overrodeGuiceInject;
|
||||
|
||||
@@ -537,10 +537,7 @@ public final class InjectionPoint {
|
||||
}
|
||||
|
||||
static Annotation getAtInject(AnnotatedElement member) {
|
||||
Annotation a = member.getAnnotation(javax.inject.Inject.class);
|
||||
if (a == null) {
|
||||
a = member.getAnnotation(jakarta.inject.Inject.class);
|
||||
}
|
||||
Annotation a = member.getAnnotation(jakarta.inject.Inject.class);
|
||||
return a == null ? member.getAnnotation(Inject.class) : a;
|
||||
}
|
||||
|
||||
@@ -780,7 +777,7 @@ public final class InjectionPoint {
|
||||
logger.log(
|
||||
Level.WARNING,
|
||||
"Method: {0} is not annotated with @Inject but "
|
||||
+ "is overriding a method that is annotated with @javax.inject.Inject."
|
||||
+ "is overriding a method that is annotated with @jakarta.inject.Inject."
|
||||
+ "Because it is not annotated with @Inject, the method will not be "
|
||||
+ "injected. To fix this, annotate the method with @Inject.",
|
||||
method);
|
||||
@@ -824,7 +821,7 @@ public final class InjectionPoint {
|
||||
*
|
||||
* <p>Prior to Java8, javac would generate these methods in subclasses without annotations, which
|
||||
* means this would accidentally stop injecting a method annotated with {@link
|
||||
* javax.inject.Inject}, since the spec says to stop injecting if a subclass isn't annotated with
|
||||
* jakarta.inject.Inject}, since the spec says to stop injecting if a subclass isn't annotated with
|
||||
* it.
|
||||
*
|
||||
* <p>Starting at Java8, javac copies the annotations to the generated subclass method, except it
|
||||
|
||||
@@ -43,7 +43,7 @@ public interface ProviderInstanceBinding<T> extends Binding<T>, HasDependencies
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
javax.inject.Provider<? extends T> getUserSuppliedProvider();
|
||||
jakarta.inject.Provider<? extends T> getUserSuppliedProvider();
|
||||
|
||||
/**
|
||||
* Returns the field and method injection points of the provider, injected at injector-creation
|
||||
|
||||
@@ -33,5 +33,5 @@ public interface ProviderKeyBinding<T> extends Binding<T> {
|
||||
* injector using {@link com.google.inject.Injector#getBinding(Key)
|
||||
* Injector.getBinding(providerKey)}
|
||||
*/
|
||||
Key<? extends javax.inject.Provider<? extends T>> getProviderKey();
|
||||
Key<? extends jakarta.inject.Provider<? extends T>> getProviderKey();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.errorprone.annotations.CheckReturnValue;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
@@ -96,35 +95,6 @@ public final class Providers {
|
||||
return provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Guice-friendly {@code com.google.inject.Provider} for the given JSR-330 {@code
|
||||
* javax.inject.Provider}. The converse method is unnecessary, since Guice providers directly
|
||||
* implement the JSR-330 interface.
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
public static <T> Provider<T> guicify(javax.inject.Provider<T> provider) {
|
||||
if (provider instanceof Provider) {
|
||||
return (Provider<T>) provider;
|
||||
}
|
||||
|
||||
final javax.inject.Provider<T> delegate = checkNotNull(provider, "provider");
|
||||
|
||||
// Ensure that we inject all injection points from the delegate provider.
|
||||
Set<InjectionPoint> injectionPoints =
|
||||
InjectionPoint.forInstanceMethodsAndFields(provider.getClass());
|
||||
if (injectionPoints.isEmpty()) {
|
||||
return new GuicifiedJSR330Provider<T>(delegate);
|
||||
} else {
|
||||
Set<Dependency<?>> mutableDeps = Sets.newHashSet();
|
||||
for (InjectionPoint ip : injectionPoints) {
|
||||
mutableDeps.addAll(ip.getDependencies());
|
||||
}
|
||||
final Set<Dependency<?>> dependencies = ImmutableSet.copyOf(mutableDeps);
|
||||
return new GuicifiedJSR330ProviderWithDependencies<T>(dependencies, delegate);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Guice-friendly {@code com.google.inject.Provider} for the given {@code
|
||||
* jakarta.inject.Provider}. The converse method is unnecessary, since Guice providers directly
|
||||
@@ -153,35 +123,6 @@ public final class Providers {
|
||||
}
|
||||
}
|
||||
|
||||
private static class GuicifiedJSR330Provider<T> implements Provider<T> {
|
||||
protected final javax.inject.Provider<T> delegate;
|
||||
|
||||
private GuicifiedJSR330Provider(javax.inject.Provider<T> delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
return delegate.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "guicified(" + delegate + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return (obj instanceof GuicifiedJSR330Provider)
|
||||
&& Objects.equal(delegate, ((GuicifiedJSR330Provider<?>) obj).delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(delegate);
|
||||
}
|
||||
}
|
||||
|
||||
private static class GuicifiedJakartaProvider<T> implements Provider<T> {
|
||||
protected final jakarta.inject.Provider<T> delegate;
|
||||
|
||||
@@ -211,28 +152,6 @@ public final class Providers {
|
||||
}
|
||||
}
|
||||
|
||||
private static final class GuicifiedJSR330ProviderWithDependencies<T>
|
||||
extends GuicifiedJSR330Provider<T> implements ProviderWithDependencies<T> {
|
||||
private final Set<Dependency<?>> dependencies;
|
||||
|
||||
private GuicifiedJSR330ProviderWithDependencies(
|
||||
Set<Dependency<?>> dependencies, javax.inject.Provider<T> delegate) {
|
||||
super(delegate);
|
||||
this.dependencies = dependencies;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Inject
|
||||
void initialize(Injector injector) {
|
||||
injector.injectMembers(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Dependency<?>> getDependencies() {
|
||||
return dependencies;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class GuicifiedJakartaProviderWithDependencies<T>
|
||||
extends GuicifiedJakartaProvider<T> implements ProviderWithDependencies<T> {
|
||||
private final Set<Dependency<?>> dependencies;
|
||||
|
||||
@@ -135,16 +135,6 @@ public final class Types {
|
||||
return newParameterizedType(Provider.class, providedType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a type modelling a {@link javax.inject.Provider} that provides elements of type {@code
|
||||
* elementType}.
|
||||
*
|
||||
* @return a {@link java.io.Serializable serializable} parameterized type.
|
||||
*/
|
||||
public static Type javaxProviderOf(Type type) {
|
||||
return Types.newParameterizedType(javax.inject.Provider.class, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a type modelling a {@link jakarta.inject.Provider} that provides elements of type
|
||||
* {@code elementType}.
|
||||
|
||||
@@ -43,7 +43,6 @@ import com.google.inject.util.NoopOverrideTest;
|
||||
import com.google.inject.util.OverrideModuleTest;
|
||||
import com.google.inject.util.ProvidersTest;
|
||||
import com.google.inject.util.TypesTest;
|
||||
import com.googlecode.guice.Jsr330Test;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
@@ -125,9 +124,6 @@ public class AllTests {
|
||||
suite.addTestSuite(ProvidersTest.class);
|
||||
suite.addTestSuite(TypesTest.class);
|
||||
|
||||
// googlecode.guice
|
||||
suite.addTestSuite(Jsr330Test.class);
|
||||
|
||||
// multibindings tests
|
||||
suite.addTestSuite(MapBinderTest.class);
|
||||
suite.addTestSuite(MultibinderTest.class);
|
||||
|
||||
@@ -58,7 +58,6 @@ java_library(
|
||||
"//third_party/java/guava/testing",
|
||||
"//third_party/java/guava/util/concurrent",
|
||||
"//third_party/java/jakarta_inject",
|
||||
"//third_party/java/jsr330_inject",
|
||||
"//third_party/java/junit",
|
||||
"//third_party/java/truth",
|
||||
],
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.google.inject;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import javax.inject.Inject;
|
||||
import jakarta.inject.Inject;
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import javax.inject.Named;
|
||||
import jakarta.inject.Named;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.Before;
|
||||
|
||||
@@ -23,8 +23,8 @@ import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Qualifier;
|
||||
import jakarta.inject.Named;
|
||||
import jakarta.inject.Qualifier;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
@@ -19,7 +19,7 @@ java_library(
|
||||
"//third_party/java/guava/annotations",
|
||||
"//third_party/java/guava/collect",
|
||||
"//third_party/java/guava/io",
|
||||
"//third_party/java/jsr330_inject",
|
||||
"//third_party/java/jakarta_inject",
|
||||
"//third_party/java/junit",
|
||||
"//third_party/java/truth",
|
||||
],
|
||||
|
||||
@@ -14,8 +14,8 @@ import com.google.inject.PrivateModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.internal.InternalFlags;
|
||||
import com.google.inject.internal.InternalFlags.IncludeStackTraceOption;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -17,7 +17,7 @@ import com.google.inject.multibindings.ProvidesIntoSet;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import javax.inject.Qualifier;
|
||||
import jakarta.inject.Qualifier;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -17,7 +17,7 @@ import com.google.inject.multibindings.MapBinder;
|
||||
import com.google.inject.multibindings.ProvidesIntoMap;
|
||||
import com.google.inject.multibindings.StringMapKey;
|
||||
import java.lang.annotation.Retention;
|
||||
import javax.inject.Qualifier;
|
||||
import jakarta.inject.Qualifier;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -12,7 +12,7 @@ import com.google.inject.Provides;
|
||||
import com.google.inject.internal.InternalFlags;
|
||||
import com.google.inject.internal.InternalFlags.IncludeStackTraceOption;
|
||||
import java.lang.annotation.Retention;
|
||||
import javax.inject.Qualifier;
|
||||
import jakarta.inject.Qualifier;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -10,7 +10,7 @@ import com.google.inject.Guice;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.internal.InternalFlags;
|
||||
import com.google.inject.internal.InternalFlags.IncludeStackTraceOption;
|
||||
import javax.inject.Inject;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -14,8 +14,8 @@ import com.google.inject.internal.InternalFlags;
|
||||
import com.google.inject.internal.InternalFlags.IncludeStackTraceOption;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Qualifier;
|
||||
import jakarta.inject.Provider;
|
||||
import jakarta.inject.Qualifier;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -15,8 +15,8 @@ import com.google.inject.internal.InternalFlags.IncludeStackTraceOption;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.reflect.Field;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Qualifier;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Qualifier;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -92,8 +92,6 @@ public class MapBinderTest extends TestCase {
|
||||
|
||||
final TypeLiteral<Map<String, jakarta.inject.Provider<String>>> mapOfStringJakartaProvider =
|
||||
new TypeLiteral<Map<String, jakarta.inject.Provider<String>>>() {};
|
||||
final TypeLiteral<Map<String, javax.inject.Provider<String>>> mapOfStringJavaxProvider =
|
||||
new TypeLiteral<Map<String, javax.inject.Provider<String>>>() {};
|
||||
final TypeLiteral<Map<String, Provider<String>>> mapOfStringProvider =
|
||||
new TypeLiteral<Map<String, Provider<String>>>() {};
|
||||
final TypeLiteral<Map<String, String>> mapOfString = new TypeLiteral<Map<String, String>>() {};
|
||||
@@ -106,10 +104,6 @@ public class MapBinderTest extends TestCase {
|
||||
private final TypeLiteral<String> stringType = TypeLiteral.get(String.class);
|
||||
private final TypeLiteral<Integer> intType = TypeLiteral.get(Integer.class);
|
||||
|
||||
private Type javaxProviderOf(Type type) {
|
||||
return Types.javaxProviderOf(type);
|
||||
}
|
||||
|
||||
private Type mapEntryOf(Type keyType, Type valueType) {
|
||||
return Types.newParameterizedTypeWithOwner(Map.class, Map.Entry.class, keyType, valueType);
|
||||
}
|
||||
@@ -166,23 +160,6 @@ public class MapBinderTest extends TestCase {
|
||||
"Multibinder<java.util.Map$Entry<java.lang.String, "
|
||||
+ "com.google.inject.Provider<java.lang.String>>> permits duplicates")),
|
||||
|
||||
// Map<K, javax.inject.Provider<V>>
|
||||
Key.get(Types.mapOf(String.class, javaxProviderOf(String.class))),
|
||||
// Map<K, Set<javax.inject.Provider<V>>
|
||||
Key.get(
|
||||
Types.mapOf(String.class, Types.setOf(Types.javaxProviderOf(String.class)))),
|
||||
// Map<K, Collection<javax.inject.Provider<V>>
|
||||
Key.get(
|
||||
Types.mapOf(
|
||||
String.class, Types.collectionOf(Types.javaxProviderOf(String.class)))),
|
||||
// Set<Map.Entry<K, javax.inject.Provider<V>>>
|
||||
Key.get(Types.setOf(mapEntryOf(String.class, Types.javaxProviderOf(String.class)))),
|
||||
// Collection<javax.inject.Provider<Map.Entry<K, Provider<V>>>>
|
||||
Key.get(
|
||||
collectionOf(
|
||||
Types.javaxProviderOf(
|
||||
mapEntryOf(String.class, Types.providerOf(String.class))))),
|
||||
|
||||
// Map<K, jakarta.inject.Provider<V>>
|
||||
Key.get(Types.mapOf(String.class, Types.jakartaProviderOf(String.class))),
|
||||
// Map<K, Set<jakarta.inject.Provider<V>>
|
||||
@@ -256,7 +233,6 @@ public class MapBinderTest extends TestCase {
|
||||
|
||||
// just make sure these succeed
|
||||
injector.getInstance(Key.get(mapOfStringProvider));
|
||||
injector.getInstance(Key.get(mapOfStringJavaxProvider));
|
||||
injector.getInstance(Key.get(mapOfStringJakartaProvider));
|
||||
}
|
||||
|
||||
@@ -294,7 +270,6 @@ public class MapBinderTest extends TestCase {
|
||||
|
||||
// just make sure these succeed
|
||||
injector.getInstance(Key.get(mapOfStringProvider, Names.named("abc")));
|
||||
injector.getInstance(Key.get(mapOfStringJavaxProvider, Names.named("abc")));
|
||||
injector.getInstance(Key.get(mapOfStringJakartaProvider, Names.named("abc")));
|
||||
}
|
||||
|
||||
@@ -331,7 +306,6 @@ public class MapBinderTest extends TestCase {
|
||||
|
||||
// just make sure these succeed
|
||||
injector.getInstance(Key.get(mapOfStringProvider, Abc.class));
|
||||
injector.getInstance(Key.get(mapOfStringJavaxProvider, Abc.class));
|
||||
injector.getInstance(Key.get(mapOfStringJakartaProvider, Abc.class));
|
||||
}
|
||||
|
||||
@@ -384,10 +358,8 @@ public class MapBinderTest extends TestCase {
|
||||
|
||||
// just make sure these succeed
|
||||
injector.getInstance(Key.get(mapOfStringProvider, named("abc")));
|
||||
injector.getInstance(Key.get(mapOfStringJavaxProvider, named("abc")));
|
||||
injector.getInstance(Key.get(mapOfStringJakartaProvider, named("abc")));
|
||||
injector.getInstance(Key.get(mapOfStringProvider, named("de")));
|
||||
injector.getInstance(Key.get(mapOfStringJavaxProvider, named("de")));
|
||||
injector.getInstance(Key.get(mapOfStringJakartaProvider, named("de")));
|
||||
}
|
||||
|
||||
@@ -440,10 +412,8 @@ public class MapBinderTest extends TestCase {
|
||||
|
||||
// just make sure these succeed
|
||||
injector.getInstance(Key.get(mapOfStringProvider, Abc.class));
|
||||
injector.getInstance(Key.get(mapOfStringJavaxProvider, Abc.class));
|
||||
injector.getInstance(Key.get(mapOfStringJakartaProvider, Abc.class));
|
||||
injector.getInstance(Key.get(mapOfStringProvider, De.class));
|
||||
injector.getInstance(Key.get(mapOfStringJavaxProvider, De.class));
|
||||
injector.getInstance(Key.get(mapOfStringJakartaProvider, De.class));
|
||||
}
|
||||
|
||||
@@ -1529,7 +1499,7 @@ public class MapBinderTest extends TestCase {
|
||||
Object kToFind, Iterable<com.google.inject.spi.Element> elements) {
|
||||
for (com.google.inject.spi.Element element : elements) {
|
||||
if (element instanceof ProviderInstanceBinding) {
|
||||
javax.inject.Provider<?> usp =
|
||||
jakarta.inject.Provider<?> usp =
|
||||
((ProviderInstanceBinding<?>) element).getUserSuppliedProvider();
|
||||
if (usp instanceof ProviderMapEntry) {
|
||||
ProviderMapEntry<?, ?> pme = (ProviderMapEntry<?, ?>) usp;
|
||||
|
||||
@@ -20,7 +20,6 @@ import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static com.google.common.collect.MoreCollectors.onlyElement;
|
||||
import static com.google.inject.Asserts.assertContains;
|
||||
import static com.google.inject.internal.RealMultibinder.collectionOfJakartaProvidersOf;
|
||||
import static com.google.inject.internal.RealMultibinder.collectionOfJavaxProvidersOf;
|
||||
import static com.google.inject.internal.SpiUtils.VisitType.BOTH;
|
||||
import static com.google.inject.internal.SpiUtils.VisitType.MODULE;
|
||||
import static com.google.inject.internal.SpiUtils.assertSetVisitor;
|
||||
@@ -1423,10 +1422,6 @@ public class MultibinderTest extends TestCase {
|
||||
Collection<jakarta.inject.Provider<String>> jakartaProviders =
|
||||
injector.getInstance(Key.get(collectionOfJakartaProvidersOf(stringType)));
|
||||
assertEquals(expectedValues, collectValuesJakarta(jakartaProviders));
|
||||
|
||||
Collection<javax.inject.Provider<String>> javaxProviders =
|
||||
injector.getInstance(Key.get(collectionOfJavaxProvidersOf(stringType)));
|
||||
assertEquals(expectedValues, collectValuesJavax(javaxProviders));
|
||||
}
|
||||
|
||||
public void testMultibinderCanInjectCollectionOfProvidersWithAnnotation() {
|
||||
@@ -1454,10 +1449,6 @@ public class MultibinderTest extends TestCase {
|
||||
Collection<jakarta.inject.Provider<String>> jakartaProviders =
|
||||
injector.getInstance(Key.get(collectionOfJakartaProvidersOf(stringType), ann));
|
||||
assertEquals(expectedValues, collectValuesJakarta(jakartaProviders));
|
||||
|
||||
Collection<javax.inject.Provider<String>> javaxProviders =
|
||||
injector.getInstance(Key.get(collectionOfJavaxProvidersOf(stringType), ann));
|
||||
assertEquals(expectedValues, collectValuesJavax(javaxProviders));
|
||||
}
|
||||
|
||||
public void testMultibindingProviderDependencies() {
|
||||
@@ -1637,13 +1628,4 @@ public class MultibinderTest extends TestCase {
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
private <T> Collection<T> collectValuesJavax(
|
||||
Collection<? extends javax.inject.Provider<T>> providers) {
|
||||
Collection<T> values = Lists.newArrayList();
|
||||
for (javax.inject.Provider<T> provider : providers) {
|
||||
values.add(provider.get());
|
||||
}
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,11 +78,6 @@ public class OptionalBinderTest extends TestCase {
|
||||
new TypeLiteral<Optional<Provider<String>>>() {};
|
||||
final TypeLiteral<java.util.Optional<Provider<String>>> javaOptionalOfProviderString =
|
||||
new TypeLiteral<java.util.Optional<Provider<String>>>() {};
|
||||
final TypeLiteral<Optional<javax.inject.Provider<String>>> optionalOfJavaxProviderString =
|
||||
new TypeLiteral<Optional<javax.inject.Provider<String>>>() {};
|
||||
final TypeLiteral<java.util.Optional<javax.inject.Provider<String>>>
|
||||
javaOptionalOfJavaxProviderString =
|
||||
new TypeLiteral<java.util.Optional<javax.inject.Provider<String>>>() {};
|
||||
final TypeLiteral<Optional<jakarta.inject.Provider<String>>> optionalOfJakartaProviderString =
|
||||
new TypeLiteral<Optional<jakarta.inject.Provider<String>>>() {};
|
||||
final TypeLiteral<java.util.Optional<jakarta.inject.Provider<String>>>
|
||||
@@ -97,11 +92,6 @@ public class OptionalBinderTest extends TestCase {
|
||||
new TypeLiteral<Optional<Provider<Integer>>>() {};
|
||||
final TypeLiteral<java.util.Optional<Provider<Integer>>> javaOptionalOfProviderInteger =
|
||||
new TypeLiteral<java.util.Optional<Provider<Integer>>>() {};
|
||||
final TypeLiteral<Optional<javax.inject.Provider<Integer>>> optionalOfJavaxProviderInteger =
|
||||
new TypeLiteral<Optional<javax.inject.Provider<Integer>>>() {};
|
||||
final TypeLiteral<java.util.Optional<javax.inject.Provider<Integer>>>
|
||||
javaOptionalOfJavaxProviderInteger =
|
||||
new TypeLiteral<java.util.Optional<javax.inject.Provider<Integer>>>() {};
|
||||
final TypeLiteral<Optional<jakarta.inject.Provider<Integer>>> optionalOfJakartaProviderInteger =
|
||||
new TypeLiteral<Optional<jakarta.inject.Provider<Integer>>>() {};
|
||||
final TypeLiteral<java.util.Optional<jakarta.inject.Provider<Integer>>>
|
||||
@@ -227,20 +217,6 @@ public class OptionalBinderTest extends TestCase {
|
||||
assertThat(optionalP.get().get()).isEqualTo(expectedValueIfPresent);
|
||||
}
|
||||
|
||||
Optional<javax.inject.Provider<String>> optionalJxP =
|
||||
injector.getInstance(keyFor(optionalOfJavaxProviderString, annotation));
|
||||
assertThat(optionalJxP.isPresent()).isEqualTo(expectedPresent);
|
||||
if (expectedPresent) {
|
||||
assertThat(optionalJxP.get().get()).isEqualTo(expectedValueIfPresent);
|
||||
}
|
||||
optionalJxP =
|
||||
Optional.fromJavaUtil(
|
||||
injector.getInstance(keyFor(javaOptionalOfJavaxProviderString, annotation)));
|
||||
assertThat(optionalJxP.isPresent()).isEqualTo(expectedPresent);
|
||||
if (expectedPresent) {
|
||||
assertThat(optionalJxP.get().get()).isEqualTo(expectedValueIfPresent);
|
||||
}
|
||||
|
||||
Optional<jakarta.inject.Provider<String>> optionalJkP =
|
||||
injector.getInstance(keyFor(optionalOfJakartaProviderString, annotation));
|
||||
assertThat(optionalJkP.isPresent()).isEqualTo(expectedPresent);
|
||||
@@ -671,8 +647,6 @@ public class OptionalBinderTest extends TestCase {
|
||||
|
||||
Optional<Provider<Integer>> optionalP =
|
||||
injector.getInstance(Key.get(optionalOfProviderInteger));
|
||||
Optional<javax.inject.Provider<Integer>> optionalJxP =
|
||||
injector.getInstance(Key.get(optionalOfJavaxProviderInteger));
|
||||
Optional<jakarta.inject.Provider<Integer>> optionalJkP =
|
||||
injector.getInstance(Key.get(optionalOfJakartaProviderInteger));
|
||||
|
||||
@@ -708,14 +682,6 @@ public class OptionalBinderTest extends TestCase {
|
||||
Optional.fromJavaUtil(injector.getInstance(Key.get(javaOptionalOfJakartaProviderInteger)));
|
||||
assertEquals(13, optionalJkP.get().get().intValue());
|
||||
assertEquals(14, optionalJkP.get().get().intValue());
|
||||
|
||||
// Same with javax.provider
|
||||
optionalJxP =
|
||||
Optional.fromJavaUtil(injector.getInstance(Key.get(javaOptionalOfJavaxProviderInteger)));
|
||||
assertEquals(15, optionalJxP.get().get().intValue());
|
||||
assertEquals(16, optionalJxP.get().get().intValue());
|
||||
assertEquals(17, optionalJxP.get().get().intValue());
|
||||
assertEquals(18, optionalJxP.get().get().intValue());
|
||||
}
|
||||
|
||||
public void testLinkedToNullProvidersMakeAbsentValuesAndPresentProviders_default()
|
||||
|
||||
@@ -18,20 +18,15 @@ package com.google.inject.internal;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.inject.internal.RealMapBinder.entryOfJakartaProviderOf;
|
||||
import static com.google.inject.internal.RealMapBinder.entryOfJavaxProviderOf;
|
||||
import static com.google.inject.internal.RealMapBinder.entryOfProviderOf;
|
||||
import static com.google.inject.internal.RealMapBinder.mapOf;
|
||||
import static com.google.inject.internal.RealMapBinder.mapOfCollectionOfJakartaProviderOf;
|
||||
import static com.google.inject.internal.RealMapBinder.mapOfCollectionOfJavaxProviderOf;
|
||||
import static com.google.inject.internal.RealMapBinder.mapOfCollectionOfProviderOf;
|
||||
import static com.google.inject.internal.RealMapBinder.mapOfJakartaProviderOf;
|
||||
import static com.google.inject.internal.RealMapBinder.mapOfJavaxProviderOf;
|
||||
import static com.google.inject.internal.RealMapBinder.mapOfProviderOf;
|
||||
import static com.google.inject.internal.RealMapBinder.mapOfSetOfJakartaProviderOf;
|
||||
import static com.google.inject.internal.RealMapBinder.mapOfSetOfJavaxProviderOf;
|
||||
import static com.google.inject.internal.RealMapBinder.mapOfSetOfProviderOf;
|
||||
import static com.google.inject.internal.RealMultibinder.collectionOfJakartaProvidersOf;
|
||||
import static com.google.inject.internal.RealMultibinder.collectionOfJavaxProvidersOf;
|
||||
import static com.google.inject.internal.RealMultibinder.collectionOfProvidersOf;
|
||||
import static com.google.inject.internal.RealMultibinder.setOf;
|
||||
import static com.google.inject.internal.RealMultibinder.setOfExtendsOf;
|
||||
@@ -209,25 +204,14 @@ public class SpiUtils {
|
||||
Key<?> collectionOfJakartaProvidersOfEntryOfProvider =
|
||||
mapKey.ofType(collectionOfJakartaProvidersOf(entryOfProviderOf(keyType, valueType)));
|
||||
|
||||
Key<?> mapOfJavaxProvider = mapKey.ofType(mapOfJavaxProviderOf(keyType, valueType));
|
||||
Key<?> mapOfSetOfJavaxProvider = mapKey.ofType(mapOfSetOfJavaxProviderOf(keyType, valueType));
|
||||
Key<?> mapOfCollectionOfJavaxProvider =
|
||||
mapKey.ofType(mapOfCollectionOfJavaxProviderOf(keyType, valueType));
|
||||
Key<?> setOfJavaxEntry = mapKey.ofType(setOf(entryOfJavaxProviderOf(keyType, valueType)));
|
||||
Key<?> collectionOfJavaxProvidersOfEntryOfProvider =
|
||||
mapKey.ofType(collectionOfJavaxProvidersOf(entryOfProviderOf(keyType, valueType)));
|
||||
|
||||
assertEquals(
|
||||
ImmutableSet.of(
|
||||
mapOfJakartaProvider,
|
||||
mapOfJavaxProvider,
|
||||
mapOfProvider,
|
||||
mapOfSetOfProvider,
|
||||
mapOfSetOfJakartaProvider,
|
||||
mapOfSetOfJavaxProvider,
|
||||
mapOfCollectionOfProvider,
|
||||
mapOfCollectionOfJakartaProvider,
|
||||
mapOfCollectionOfJavaxProvider,
|
||||
mapOfSet,
|
||||
mapOfKeyExtendsValueKey),
|
||||
mapbinder.getAlternateMapKeys());
|
||||
@@ -247,12 +231,6 @@ public class SpiUtils {
|
||||
boolean mapCollectionJakartaProviderMatch = false;
|
||||
boolean collectionOfJakartaProvidersOfEntryOfProviderMatch = false;
|
||||
|
||||
boolean javaxEntrySetMatch = false;
|
||||
boolean mapJavaxProviderMatch = false;
|
||||
boolean mapSetJavaxProviderMatch = false;
|
||||
boolean mapCollectionJavaxProviderMatch = false;
|
||||
boolean collectionOfJavaxProvidersOfEntryOfProviderMatch = false;
|
||||
|
||||
List<Object> otherMapBindings = Lists.newArrayList();
|
||||
List<Binding<?>> otherMatches = Lists.newArrayList();
|
||||
Multimap<Object, IndexedBinding> indexedEntries =
|
||||
@@ -310,21 +288,6 @@ public class SpiUtils {
|
||||
} else if (b.getKey().equals(collectionOfJakartaProvidersOfEntryOfProvider)) {
|
||||
assertTrue(contains);
|
||||
collectionOfJakartaProvidersOfEntryOfProviderMatch = true;
|
||||
} else if (b.getKey().equals(mapOfJavaxProvider)) {
|
||||
assertTrue(contains);
|
||||
mapJavaxProviderMatch = true;
|
||||
} else if (b.getKey().equals(mapOfSetOfJavaxProvider)) {
|
||||
assertTrue(contains);
|
||||
mapSetJavaxProviderMatch = true;
|
||||
} else if (b.getKey().equals(mapOfCollectionOfJavaxProvider)) {
|
||||
assertTrue(contains);
|
||||
mapCollectionJavaxProviderMatch = true;
|
||||
} else if (b.getKey().equals(setOfJavaxEntry)) {
|
||||
assertTrue(contains);
|
||||
javaxEntrySetMatch = true;
|
||||
} else if (b.getKey().equals(collectionOfJavaxProvidersOfEntryOfProvider)) {
|
||||
assertTrue(contains);
|
||||
collectionOfJavaxProvidersOfEntryOfProviderMatch = true;
|
||||
} else if (contains) {
|
||||
if (b instanceof ProviderInstanceBinding) {
|
||||
ProviderInstanceBinding<?> pib = (ProviderInstanceBinding<?>) b;
|
||||
@@ -361,11 +324,6 @@ public class SpiUtils {
|
||||
assertTrue(jakartaEntrySetMatch);
|
||||
assertTrue(mapJakartaProviderMatch);
|
||||
assertTrue(collectionOfJakartaProvidersOfEntryOfProviderMatch);
|
||||
assertTrue(javaxEntrySetMatch);
|
||||
assertTrue(mapJavaxProviderMatch);
|
||||
assertTrue(collectionOfJavaxProvidersOfEntryOfProviderMatch);
|
||||
assertEquals(allowDuplicates, mapSetJavaxProviderMatch);
|
||||
assertEquals(allowDuplicates, mapCollectionJavaxProviderMatch);
|
||||
assertEquals(allowDuplicates, mapSetMatch);
|
||||
assertEquals(allowDuplicates, mapSetProviderMatch);
|
||||
assertEquals(allowDuplicates, mapCollectionProviderMatch);
|
||||
@@ -456,25 +414,14 @@ public class SpiUtils {
|
||||
Key<?> collectionOfJakartaProvidersOfEntryOfProvider =
|
||||
mapKey.ofType(collectionOfJakartaProvidersOf(entryOfProviderOf(keyType, valueType)));
|
||||
|
||||
Key<?> mapOfJavaxProvider = mapKey.ofType(mapOfJavaxProviderOf(keyType, valueType));
|
||||
Key<?> mapOfSetOfJavaxProvider = mapKey.ofType(mapOfSetOfJavaxProviderOf(keyType, valueType));
|
||||
Key<?> mapOfCollectionOfJavaxProvider =
|
||||
mapKey.ofType(mapOfCollectionOfJavaxProviderOf(keyType, valueType));
|
||||
Key<?> setOfJavaxEntry = mapKey.ofType(setOf(entryOfJavaxProviderOf(keyType, valueType)));
|
||||
Key<?> collectionOfJavaxProvidersOfEntryOfProvider =
|
||||
mapKey.ofType(collectionOfJavaxProvidersOf(entryOfProviderOf(keyType, valueType)));
|
||||
|
||||
assertEquals(
|
||||
ImmutableSet.of(
|
||||
mapOfProvider,
|
||||
mapOfJakartaProvider,
|
||||
mapOfJavaxProvider,
|
||||
mapOfSetOfProvider,
|
||||
mapOfSetOfJakartaProvider,
|
||||
mapOfSetOfJavaxProvider,
|
||||
mapOfCollectionOfProvider,
|
||||
mapOfCollectionOfJakartaProvider,
|
||||
mapOfCollectionOfJavaxProvider,
|
||||
mapOfSet,
|
||||
mapOfKeyExtendsValueKey),
|
||||
mapbinder.getAlternateMapKeys());
|
||||
@@ -494,12 +441,6 @@ public class SpiUtils {
|
||||
boolean mapCollectionJakartaProviderMatch = false;
|
||||
boolean collectionOfJakartaProvidersOfEntryOfProviderMatch = false;
|
||||
|
||||
boolean entrySetJavaxMatch = false;
|
||||
boolean mapJavaxProviderMatch = false;
|
||||
boolean mapSetJavaxProviderMatch = false;
|
||||
boolean mapCollectionJavaxProviderMatch = false;
|
||||
boolean collectionOfJavaxProvidersOfEntryOfProviderMatch = false;
|
||||
|
||||
List<Object> otherMapBindings = Lists.newArrayList();
|
||||
List<Element> otherMatches = Lists.newArrayList();
|
||||
List<Element> otherElements = Lists.newArrayList();
|
||||
@@ -602,26 +543,6 @@ public class SpiUtils {
|
||||
matched = true;
|
||||
assertTrue(contains);
|
||||
collectionOfJakartaProvidersOfEntryOfProviderMatch = true;
|
||||
} else if (key.equals(mapOfJavaxProvider)) {
|
||||
matched = true;
|
||||
assertTrue(contains);
|
||||
mapJavaxProviderMatch = true;
|
||||
} else if (key.equals(mapOfSetOfJavaxProvider)) {
|
||||
matched = true;
|
||||
assertTrue(contains);
|
||||
mapSetJavaxProviderMatch = true;
|
||||
} else if (key.equals(mapOfCollectionOfJavaxProvider)) {
|
||||
matched = true;
|
||||
assertTrue(contains);
|
||||
mapCollectionJavaxProviderMatch = true;
|
||||
} else if (key.equals(setOfJavaxEntry)) {
|
||||
matched = true;
|
||||
assertTrue(contains);
|
||||
entrySetJavaxMatch = true;
|
||||
} else if (key.equals(collectionOfJavaxProvidersOfEntryOfProvider)) {
|
||||
matched = true;
|
||||
assertTrue(contains);
|
||||
collectionOfJavaxProvidersOfEntryOfProviderMatch = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -649,11 +570,6 @@ public class SpiUtils {
|
||||
assertTrue(entrySetJakartaMatch);
|
||||
assertTrue(mapJakartaProviderMatch);
|
||||
assertTrue(collectionOfJakartaProvidersOfEntryOfProviderMatch);
|
||||
assertTrue(entrySetJavaxMatch);
|
||||
assertTrue(mapJavaxProviderMatch);
|
||||
assertTrue(collectionOfJavaxProvidersOfEntryOfProviderMatch);
|
||||
assertEquals(allowDuplicates, mapSetJavaxProviderMatch);
|
||||
assertEquals(allowDuplicates, mapCollectionJavaxProviderMatch);
|
||||
assertEquals(allowDuplicates, mapSetMatch);
|
||||
assertEquals(allowDuplicates, mapSetProviderMatch);
|
||||
assertEquals(allowDuplicates, mapCollectionProviderMatch);
|
||||
@@ -714,7 +630,6 @@ public class SpiUtils {
|
||||
Key<?> collectionOfProvidersKey = setKey.ofType(collectionOfProvidersOf(elementType));
|
||||
Key<?> collectionOfJakartaProvidersKey =
|
||||
setKey.ofType(collectionOfJakartaProvidersOf(elementType));
|
||||
Key<?> collectionOfJavaxProvidersKey = setKey.ofType(collectionOfJavaxProvidersOf(elementType));
|
||||
Key<?> setOfExtendsKey = setKey.ofType(setOfExtendsOf(elementType));
|
||||
Injector injector = Guice.createInjector(modules);
|
||||
Visitor<Set<T>> visitor = new Visitor<>();
|
||||
@@ -729,7 +644,6 @@ public class SpiUtils {
|
||||
ImmutableSet.of(
|
||||
collectionOfProvidersKey,
|
||||
collectionOfJakartaProvidersKey,
|
||||
collectionOfJavaxProvidersKey,
|
||||
setOfExtendsKey),
|
||||
multibinder.getAlternateSetKeys());
|
||||
List<Binding<?>> elements = Lists.newArrayList(multibinder.getElements());
|
||||
@@ -769,7 +683,6 @@ public class SpiUtils {
|
||||
List<Binding<?>> otherContains = Lists.newArrayList();
|
||||
boolean collectionOfProvidersMatch = false;
|
||||
boolean collectionOfJakartaProvidersMatch = false;
|
||||
boolean collectionOfJavaxProvidersMatch = false;
|
||||
boolean setOfExtendsKeyMatch = false;
|
||||
for (Binding<?> b : injector.getAllBindings().values()) {
|
||||
boolean contains = multibinder.containsElement(b);
|
||||
@@ -789,9 +702,6 @@ public class SpiUtils {
|
||||
} else if (key.equals(collectionOfJakartaProvidersKey)) {
|
||||
assertTrue(contains);
|
||||
collectionOfJakartaProvidersMatch = true;
|
||||
} else if (key.equals(collectionOfJavaxProvidersKey)) {
|
||||
assertTrue(contains);
|
||||
collectionOfJavaxProvidersMatch = true;
|
||||
} else if (key.equals(setOfExtendsKey)) {
|
||||
assertTrue(contains);
|
||||
setOfExtendsKeyMatch = true;
|
||||
@@ -804,7 +714,6 @@ public class SpiUtils {
|
||||
|
||||
assertTrue(collectionOfProvidersMatch);
|
||||
assertTrue(collectionOfJakartaProvidersMatch);
|
||||
assertTrue(collectionOfJavaxProvidersMatch);
|
||||
assertTrue(setOfExtendsKeyMatch);
|
||||
|
||||
if (allowDuplicates) {
|
||||
@@ -829,7 +738,6 @@ public class SpiUtils {
|
||||
Key<?> collectionOfProvidersKey = setKey.ofType(collectionOfProvidersOf(elementType));
|
||||
Key<?> collectionOfJakartaProvidersKey =
|
||||
setKey.ofType(collectionOfJakartaProvidersOf(elementType));
|
||||
Key<?> collectionOfJavaxProvidersKey = setKey.ofType(collectionOfJavaxProvidersOf(elementType));
|
||||
Key<?> setOfExtendsKey = setKey.ofType(setOfExtendsOf(elementType));
|
||||
List<BindResult<?>> bindResults = Lists.newArrayList(results);
|
||||
List<Element> elements = Elements.getElements(modules);
|
||||
@@ -849,7 +757,6 @@ public class SpiUtils {
|
||||
ImmutableSet.of(
|
||||
collectionOfProvidersKey,
|
||||
collectionOfJakartaProvidersKey,
|
||||
collectionOfJavaxProvidersKey,
|
||||
setOfExtendsKey),
|
||||
multibinder.getAlternateSetKeys());
|
||||
List<Object> otherMultibinders = Lists.newArrayList();
|
||||
@@ -860,7 +767,6 @@ public class SpiUtils {
|
||||
Indexer indexer = new Indexer(null);
|
||||
boolean collectionOfProvidersMatch = false;
|
||||
boolean collectionOfJakartaProvidersMatch = false;
|
||||
boolean collectionOfJavaxProvidersMatch = false;
|
||||
boolean setOfExtendsMatch = false;
|
||||
for (Element element : elements) {
|
||||
boolean contains = multibinder.containsElement(element);
|
||||
@@ -895,10 +801,6 @@ public class SpiUtils {
|
||||
assertTrue(contains);
|
||||
assertFalse(matched);
|
||||
collectionOfJakartaProvidersMatch = true;
|
||||
} else if (collectionOfJavaxProvidersKey.equals(key)) {
|
||||
assertTrue(contains);
|
||||
assertFalse(matched);
|
||||
collectionOfJavaxProvidersMatch = true;
|
||||
} else if (setOfExtendsKey.equals(key)) {
|
||||
assertTrue(contains);
|
||||
assertFalse(matched);
|
||||
@@ -926,7 +828,6 @@ public class SpiUtils {
|
||||
otherMultibinders.size());
|
||||
assertTrue(collectionOfProvidersMatch);
|
||||
assertTrue(collectionOfJakartaProvidersMatch);
|
||||
assertTrue(collectionOfJavaxProvidersMatch);
|
||||
assertTrue(setOfExtendsMatch);
|
||||
|
||||
// Validate that we can construct an injector out of the remaining bindings.
|
||||
@@ -1064,10 +965,6 @@ public class SpiUtils {
|
||||
matches(javaOptionalBinder.getActualBinding(), expectedUserLinkedActual));
|
||||
}
|
||||
|
||||
Key<Optional<javax.inject.Provider<T>>> optionalJavaxProviderKey =
|
||||
keyType.ofType(RealOptionalBinder.optionalOfJavaxProvider(keyType.getTypeLiteral()));
|
||||
Key<?> javaOptionalJavaxProviderKey =
|
||||
keyType.ofType(RealOptionalBinder.javaOptionalOfJavaxProvider(keyType.getTypeLiteral()));
|
||||
Key<Optional<jakarta.inject.Provider<T>>> optionalJakartaProviderKey =
|
||||
keyType.ofType(RealOptionalBinder.optionalOfJakartaProvider(keyType.getTypeLiteral()));
|
||||
Key<?> javaOptionalJakartaProviderKey =
|
||||
@@ -1077,18 +974,19 @@ public class SpiUtils {
|
||||
Key<?> javaOptionalProviderKey =
|
||||
keyType.ofType(RealOptionalBinder.javaOptionalOfProvider(keyType.getTypeLiteral()));
|
||||
assertEquals(
|
||||
ImmutableSet.of(optionalJavaxProviderKey, optionalJakartaProviderKey, optionalProviderKey),
|
||||
ImmutableSet.of(
|
||||
optionalProviderKey,
|
||||
optionalJakartaProviderKey),
|
||||
optionalBinder.getAlternateKeys());
|
||||
assertEquals(
|
||||
ImmutableSet.of(
|
||||
javaOptionalJavaxProviderKey, javaOptionalJakartaProviderKey, javaOptionalProviderKey),
|
||||
javaOptionalProviderKey,
|
||||
javaOptionalJakartaProviderKey),
|
||||
javaOptionalBinder.getAlternateKeys());
|
||||
|
||||
boolean keyMatch = false;
|
||||
boolean optionalKeyMatch = false;
|
||||
boolean javaOptionalKeyMatch = false;
|
||||
boolean optionalJavaxProviderKeyMatch = false;
|
||||
boolean javaOptionalJavaxProviderKeyMatch = false;
|
||||
boolean optionalJakartaProviderKeyMatch = false;
|
||||
boolean javaOptionalJakartaProviderKeyMatch = false;
|
||||
boolean optionalProviderKeyMatch = false;
|
||||
@@ -1124,12 +1022,6 @@ public class SpiUtils {
|
||||
} else if (b.getKey().equals(javaOptionalKey)) {
|
||||
assertTrue(contains);
|
||||
javaOptionalKeyMatch = true;
|
||||
} else if (b.getKey().equals(optionalJavaxProviderKey)) {
|
||||
assertTrue(contains);
|
||||
optionalJavaxProviderKeyMatch = true;
|
||||
} else if (b.getKey().equals(javaOptionalJavaxProviderKey)) {
|
||||
assertTrue(contains);
|
||||
javaOptionalJavaxProviderKeyMatch = true;
|
||||
} else if (b.getKey().equals(optionalJakartaProviderKey)) {
|
||||
assertTrue(contains);
|
||||
optionalJakartaProviderKeyMatch = true;
|
||||
@@ -1157,11 +1049,9 @@ public class SpiUtils {
|
||||
// only expect a keymatch if either default or actual are set
|
||||
assertEquals(expectedDefault != null || expectedActual != null, keyMatch);
|
||||
assertTrue(optionalKeyMatch);
|
||||
assertTrue(optionalJavaxProviderKeyMatch);
|
||||
assertTrue(optionalJakartaProviderKeyMatch);
|
||||
assertTrue(optionalProviderKeyMatch);
|
||||
assertTrue(javaOptionalKeyMatch);
|
||||
assertTrue(javaOptionalJavaxProviderKeyMatch);
|
||||
assertTrue(javaOptionalJakartaProviderKeyMatch);
|
||||
assertTrue(javaOptionalProviderKeyMatch);
|
||||
assertEquals(expectedDefault != null, defaultMatch);
|
||||
@@ -1219,10 +1109,6 @@ public class SpiUtils {
|
||||
assertEquals(expectedDefault == null, defaultKey == null);
|
||||
assertEquals(expectedActual == null, actualKey == null);
|
||||
|
||||
Key<Optional<javax.inject.Provider<T>>> optionalJavaxProviderKey =
|
||||
keyType.ofType(RealOptionalBinder.optionalOfJavaxProvider(keyType.getTypeLiteral()));
|
||||
Key<?> javaOptionalJavaxProviderKey =
|
||||
keyType.ofType(RealOptionalBinder.javaOptionalOfJavaxProvider(keyType.getTypeLiteral()));
|
||||
Key<Optional<jakarta.inject.Provider<T>>> optionalJakartaProviderKey =
|
||||
keyType.ofType(RealOptionalBinder.optionalOfJakartaProvider(keyType.getTypeLiteral()));
|
||||
Key<?> javaOptionalJakartaProviderKey =
|
||||
@@ -1234,8 +1120,6 @@ public class SpiUtils {
|
||||
boolean keyMatch = false;
|
||||
boolean optionalKeyMatch = false;
|
||||
boolean javaOptionalKeyMatch = false;
|
||||
boolean optionalJavaxProviderKeyMatch = false;
|
||||
boolean javaOptionalJavaxProviderKeyMatch = false;
|
||||
boolean optionalJakartaProviderKeyMatch = false;
|
||||
boolean javaOptionalJakartaProviderKeyMatch = false;
|
||||
boolean optionalProviderKeyMatch = false;
|
||||
@@ -1284,12 +1168,6 @@ public class SpiUtils {
|
||||
} else if (key != null && key.equals(javaOptionalKey)) {
|
||||
assertTrue(contains);
|
||||
javaOptionalKeyMatch = true;
|
||||
} else if (key != null && key.equals(optionalJavaxProviderKey)) {
|
||||
assertTrue(contains);
|
||||
optionalJavaxProviderKeyMatch = true;
|
||||
} else if (key != null && key.equals(javaOptionalJavaxProviderKey)) {
|
||||
assertTrue(contains);
|
||||
javaOptionalJavaxProviderKeyMatch = true;
|
||||
} else if (key != null && key.equals(optionalJakartaProviderKey)) {
|
||||
assertTrue(contains);
|
||||
optionalJakartaProviderKeyMatch = true;
|
||||
@@ -1323,11 +1201,9 @@ public class SpiUtils {
|
||||
// only expect a keymatch if either default or actual are set
|
||||
assertEquals(expectedDefault != null || expectedActual != null, keyMatch);
|
||||
assertTrue(optionalKeyMatch);
|
||||
assertTrue(optionalJavaxProviderKeyMatch);
|
||||
assertTrue(optionalJakartaProviderKeyMatch);
|
||||
assertTrue(optionalProviderKeyMatch);
|
||||
assertTrue(javaOptionalKeyMatch);
|
||||
assertTrue(javaOptionalJavaxProviderKeyMatch);
|
||||
assertTrue(javaOptionalJakartaProviderKeyMatch);
|
||||
assertTrue(javaOptionalProviderKeyMatch);
|
||||
assertEquals(expectedDefault != null, defaultMatch);
|
||||
|
||||
@@ -28,7 +28,7 @@ import com.google.inject.Injector;
|
||||
import com.google.inject.internal.InternalFlags;
|
||||
import com.google.inject.matcher.Matchers;
|
||||
import java.lang.reflect.Modifier;
|
||||
import javax.inject.Inject;
|
||||
import jakarta.inject.Inject;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -34,11 +34,11 @@ import java.io.Serializable;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.util.Properties;
|
||||
import javax.inject.Qualifier;
|
||||
import jakarta.inject.Qualifier;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests that {@code javax.inject.Named}, {@code jakarta.inject.Named} and {@code
|
||||
* Tests that {@code jakarta.inject.Named}, {@code jakarta.inject.Named} and {@code
|
||||
* com.google.inject.name.Named} are completely interchangeable: bindings for one can be used to
|
||||
* inject the other.
|
||||
*
|
||||
@@ -75,7 +75,7 @@ public class NamedEquivalanceTest extends TestCase {
|
||||
new EqualsTester()
|
||||
.addEqualityGroup(
|
||||
keyForAnnotationType(com.google.inject.name.Named.class),
|
||||
keyForAnnotationType(javax.inject.Named.class),
|
||||
keyForAnnotationType(jakarta.inject.Named.class),
|
||||
keyForAnnotationType(jakarta.inject.Named.class))
|
||||
.addEqualityGroup(keyForAnnotationType(NotNamed.class));
|
||||
}
|
||||
@@ -234,7 +234,7 @@ public class NamedEquivalanceTest extends TestCase {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
@javax.inject.Named("foo")
|
||||
@jakarta.inject.Named("foo")
|
||||
String provideFoo() {
|
||||
return "bar";
|
||||
}
|
||||
@@ -261,7 +261,7 @@ public class NamedEquivalanceTest extends TestCase {
|
||||
|
||||
private static class Jsr330NamedClient {
|
||||
@Inject
|
||||
@javax.inject.Named("foo")
|
||||
@jakarta.inject.Named("foo")
|
||||
String foo;
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ public class NamedEquivalanceTest extends TestCase {
|
||||
private static final long serialVersionUID = 0;
|
||||
}
|
||||
|
||||
private static class JsrNamed implements javax.inject.Named, Serializable {
|
||||
private static class JsrNamed implements jakarta.inject.Named, Serializable {
|
||||
private final String value;
|
||||
|
||||
public JsrNamed(String value) {
|
||||
@@ -336,18 +336,18 @@ public class NamedEquivalanceTest extends TestCase {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof javax.inject.Named)) {
|
||||
if (!(o instanceof jakarta.inject.Named)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
javax.inject.Named other = (javax.inject.Named) o;
|
||||
jakarta.inject.Named other = (jakarta.inject.Named) o;
|
||||
return value.equals(other.value());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "@"
|
||||
+ javax.inject.Named.class.getName()
|
||||
+ jakarta.inject.Named.class.getName()
|
||||
+ "(value="
|
||||
+ Annotations.memberValueString("value", value)
|
||||
+ ")";
|
||||
@@ -355,7 +355,7 @@ public class NamedEquivalanceTest extends TestCase {
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> annotationType() {
|
||||
return javax.inject.Named.class;
|
||||
return jakarta.inject.Named.class;
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 0;
|
||||
|
||||
@@ -10,7 +10,7 @@ import com.google.inject.RestrictedBindingSource;
|
||||
import com.google.inject.util.Modules;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import javax.inject.Named;
|
||||
import jakarta.inject.Named;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
@@ -380,17 +380,17 @@ public class ElementsTest extends TestCase {
|
||||
}
|
||||
};
|
||||
|
||||
final javax.inject.Provider<Integer> intSpecProvider =
|
||||
new javax.inject.Provider<Integer>() {
|
||||
final jakarta.inject.Provider<Integer> intSpecProvider =
|
||||
new jakarta.inject.Provider<Integer>() {
|
||||
@Override
|
||||
public Integer get() {
|
||||
return 42;
|
||||
}
|
||||
};
|
||||
|
||||
final javax.inject.Provider<Double> doubleSpecProvider =
|
||||
new javax.inject.Provider<Double>() {
|
||||
@javax.inject.Inject String string;
|
||||
final jakarta.inject.Provider<Double> doubleSpecProvider =
|
||||
new jakarta.inject.Provider<Double>() {
|
||||
@jakarta.inject.Inject String string;
|
||||
|
||||
@Override
|
||||
public Double get() {
|
||||
|
||||
@@ -406,7 +406,7 @@ public class InjectionPointTest extends TestCase {
|
||||
// Superclass still has all the injection points it did before..
|
||||
assertPoints(points, Super.class, "privateAtAndPublicG", "privateGAndPublicAt", "gInject");
|
||||
// Subclass is missing the privateGAndPublicAt because it first became public with
|
||||
// javax.inject.Inject and was overrode without an annotation, which means it
|
||||
// jakarta.inject.Inject and was overrode without an annotation, which means it
|
||||
// disappears. (It was guice @Inject in Super, but it was private there, so it doesn't
|
||||
// effect the annotations of the subclasses.)
|
||||
assertPoints(points, Sub.class, "privateAtAndPublicG", "atFirstThenG", "gFirstThenAt");
|
||||
@@ -414,7 +414,7 @@ public class InjectionPointTest extends TestCase {
|
||||
|
||||
/**
|
||||
* This test serves two purposes: 1) It makes sure that the bridge methods javax generates don't
|
||||
* stop us from injecting superclass methods in the case of javax.inject.Inject. This would happen
|
||||
* stop us from injecting superclass methods in the case of jakarta.inject.Inject. This would happen
|
||||
* prior to java8 (where javac didn't copy annotations from the superclass into the subclass
|
||||
* method when it generated the bridge methods).
|
||||
*
|
||||
@@ -460,19 +460,19 @@ public class InjectionPointTest extends TestCase {
|
||||
}
|
||||
|
||||
static class Super {
|
||||
@javax.inject.Inject
|
||||
@jakarta.inject.Inject
|
||||
public void atInject() {}
|
||||
|
||||
@com.google.inject.Inject
|
||||
public void gInject() {}
|
||||
|
||||
@javax.inject.Inject
|
||||
@jakarta.inject.Inject
|
||||
private void privateAtAndPublicG() {}
|
||||
|
||||
@com.google.inject.Inject
|
||||
private void privateGAndPublicAt() {}
|
||||
|
||||
@javax.inject.Inject
|
||||
@jakarta.inject.Inject
|
||||
public void atFirstThenG() {}
|
||||
|
||||
@com.google.inject.Inject
|
||||
@@ -491,14 +491,14 @@ public class InjectionPointTest extends TestCase {
|
||||
@com.google.inject.Inject
|
||||
public void privateAtAndPublicG() {}
|
||||
|
||||
@javax.inject.Inject
|
||||
@jakarta.inject.Inject
|
||||
public void privateGAndPublicAt() {}
|
||||
|
||||
@com.google.inject.Inject
|
||||
@Override
|
||||
public void atFirstThenG() {}
|
||||
|
||||
@javax.inject.Inject
|
||||
@jakarta.inject.Inject
|
||||
@Override
|
||||
public void gFirstThenAt() {}
|
||||
}
|
||||
@@ -525,7 +525,7 @@ public class InjectionPointTest extends TestCase {
|
||||
@com.google.inject.Inject
|
||||
public void gInject(Provider<String> p) {}
|
||||
|
||||
@javax.inject.Inject
|
||||
@jakarta.inject.Inject
|
||||
public void jInject(Provider<String> p) {}
|
||||
}
|
||||
|
||||
|
||||
@@ -126,8 +126,8 @@ public class InjectorSpiTest extends TestCase {
|
||||
}
|
||||
assertThat(actualKeys)
|
||||
.containsExactly(Key.get(Stage.class), Key.get(Injector.class), Key.get(Logger.class));
|
||||
// singleton for javax.inject.Singleton, jakarta.inject.Singleton & c.g.i.Singleton
|
||||
assertThat(scopes).hasSize(3);
|
||||
// singleton for jakarta.inject.Singleton & c.g.i.Singleton
|
||||
assertThat(scopes).hasSize(2);
|
||||
assertThat(typeConverters).hasSize(10); // all the built-in converters.
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Set;
|
||||
import javax.inject.Qualifier;
|
||||
import jakarta.inject.Qualifier;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
@@ -434,7 +434,7 @@ public class ProviderMethodsTest implements Module {
|
||||
element instanceof ProviderInstanceBinding);
|
||||
|
||||
ProviderInstanceBinding<?> binding = (ProviderInstanceBinding<?>) element;
|
||||
javax.inject.Provider<?> provider = binding.getUserSuppliedProvider();
|
||||
jakarta.inject.Provider<?> provider = binding.getUserSuppliedProvider();
|
||||
assertTrue(provider instanceof ProviderMethod);
|
||||
assertEquals(methodsObject, ((ProviderMethod) provider).getInstance());
|
||||
assertSame(provider, binding.getProviderInstance());
|
||||
|
||||
@@ -19,7 +19,7 @@ package com.google.inject.util;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.testing.EqualsTester;
|
||||
import com.google.inject.Provider;
|
||||
import javax.inject.Inject;
|
||||
import jakarta.inject.Inject;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
@@ -50,13 +50,6 @@ public class ProvidersTest extends TestCase {
|
||||
|
||||
public void testGuicifyEquality() {
|
||||
new EqualsTester()
|
||||
.addEqualityGroup(
|
||||
Providers.guicify(new JavaxProvider(10)), Providers.guicify(new JavaxProvider(10)))
|
||||
.addEqualityGroup(
|
||||
Providers.guicify(new JavaxProvider(11)), Providers.guicify(new JavaxProvider(11)))
|
||||
.addEqualityGroup(
|
||||
Providers.guicify(new JavaxProviderWithDependencies()),
|
||||
Providers.guicify(new JavaxProviderWithDependencies()))
|
||||
.addEqualityGroup(
|
||||
Providers.guicify(new JakartaProvider(10)), Providers.guicify(new JakartaProvider(10)))
|
||||
.addEqualityGroup(
|
||||
@@ -67,29 +60,6 @@ public class ProvidersTest extends TestCase {
|
||||
.testEquals();
|
||||
}
|
||||
|
||||
private static class JavaxProvider implements javax.inject.Provider<Integer> {
|
||||
private final int value;
|
||||
|
||||
public JavaxProvider(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer get() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return (obj instanceof JavaxProvider) && (value == ((JavaxProvider) obj).value);
|
||||
}
|
||||
}
|
||||
|
||||
private static class JakartaProvider implements jakarta.inject.Provider<Integer> {
|
||||
private final int value;
|
||||
|
||||
@@ -113,30 +83,6 @@ public class ProvidersTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private static class JavaxProviderWithDependencies implements javax.inject.Provider<Integer> {
|
||||
private int value;
|
||||
|
||||
@Inject
|
||||
void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer get() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return (obj instanceof JavaxProviderWithDependencies);
|
||||
}
|
||||
}
|
||||
|
||||
private static class JakartaProviderWithDependencies implements jakarta.inject.Provider<Integer> {
|
||||
private int value;
|
||||
|
||||
|
||||
@@ -20,27 +20,12 @@ java_library(
|
||||
"//third_party/java/aopalliance",
|
||||
"//third_party/java/guava/testing",
|
||||
"//third_party/java/jakarta_inject",
|
||||
"//third_party/java/jsr330_inject",
|
||||
"//third_party/java/junit",
|
||||
"@maven//:biz_aQute_bnd",
|
||||
"@maven//:org_apache_felix_org_apache_felix_framework",
|
||||
],
|
||||
)
|
||||
|
||||
# We split the TCK tests out from the normal libraries, because the jakarta.inject TCK uses the same
|
||||
# packages as the javax.inject TCK, so the two cannot be in the same classloader.
|
||||
|
||||
java_library(
|
||||
name = "javax_inject_tck_test",
|
||||
srcs = ["GuiceTck.java"],
|
||||
deps = [
|
||||
"//core/src/com/google/inject",
|
||||
"//third_party/java/jsr330_inject",
|
||||
"//third_party/java/jsr330_inject:tck",
|
||||
"//third_party/java/junit",
|
||||
],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "jakarta_tck_test",
|
||||
srcs = ["GuiceJakartaTck.java"],
|
||||
@@ -103,11 +88,3 @@ guice_test_suites(
|
||||
suffix = "_jakarta_tck",
|
||||
deps = [":jakarta_tck_test"],
|
||||
)
|
||||
|
||||
guice_test_suites(
|
||||
name = "gen_javax_inject_tck_tests",
|
||||
srcs = ["GuiceTck.java"],
|
||||
sizes = ["small"],
|
||||
suffix = "_javax_inject_tck",
|
||||
deps = [":javax_inject_tck_test"],
|
||||
)
|
||||
|
||||
@@ -39,7 +39,7 @@ import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URLClassLoader;
|
||||
import javax.inject.Inject;
|
||||
import jakarta.inject.Inject;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.Before;
|
||||
@@ -422,7 +422,6 @@ public class BytecodeGenTest {
|
||||
}
|
||||
|
||||
if (name.startsWith("java.")
|
||||
|| name.startsWith("javax.")
|
||||
|| name.startsWith("jakarta.")
|
||||
|| name.equals(LogCreator.class.getName())
|
||||
|| (!name.startsWith("com.google.inject.") && !name.startsWith("com.googlecode.guice"))) {
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2009 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.googlecode.guice;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Provides;
|
||||
import javax.inject.Named;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import org.atinject.tck.Tck;
|
||||
import org.atinject.tck.auto.Car;
|
||||
import org.atinject.tck.auto.Convertible;
|
||||
import org.atinject.tck.auto.Drivers;
|
||||
import org.atinject.tck.auto.DriversSeat;
|
||||
import org.atinject.tck.auto.Engine;
|
||||
import org.atinject.tck.auto.FuelTank;
|
||||
import org.atinject.tck.auto.Seat;
|
||||
import org.atinject.tck.auto.Tire;
|
||||
import org.atinject.tck.auto.V8Engine;
|
||||
import org.atinject.tck.auto.accessories.Cupholder;
|
||||
import org.atinject.tck.auto.accessories.SpareTire;
|
||||
|
||||
public class GuiceTck extends TestCase {
|
||||
|
||||
public static Test suite() {
|
||||
return Tck.testsFor(
|
||||
Guice.createInjector(
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(Car.class).to(Convertible.class);
|
||||
bind(Seat.class).annotatedWith(Drivers.class).to(DriversSeat.class);
|
||||
bind(Engine.class).to(V8Engine.class);
|
||||
bind(Cupholder.class);
|
||||
bind(Tire.class);
|
||||
bind(FuelTank.class);
|
||||
requestStaticInjection(Convertible.class, SpareTire.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("spare")
|
||||
Tire provideSpareTire(SpareTire spare) {
|
||||
return spare;
|
||||
}
|
||||
})
|
||||
.getInstance(Car.class),
|
||||
true,
|
||||
true);
|
||||
}
|
||||
}
|
||||
@@ -1,535 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2009 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.googlecode.guice;
|
||||
|
||||
import static com.google.inject.Asserts.assertContains;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Binding;
|
||||
import com.google.inject.CreationException;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Scope;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.Stage;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.name.Names;
|
||||
import com.google.inject.spi.Dependency;
|
||||
import com.google.inject.spi.HasDependencies;
|
||||
import com.google.inject.util.Providers;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.util.Set;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Qualifier;
|
||||
import javax.inject.Singleton;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class Jsr330Test extends TestCase {
|
||||
|
||||
private final B b = new B();
|
||||
private final C c = new C();
|
||||
private final D d = new D();
|
||||
private final E e = new E();
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
J.nextInstanceId = 0;
|
||||
K.nextInstanceId = 0;
|
||||
}
|
||||
|
||||
public void testInject() {
|
||||
Injector injector =
|
||||
Guice.createInjector(
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(B.class).toInstance(b);
|
||||
bind(C.class).toInstance(c);
|
||||
bind(D.class).toInstance(d);
|
||||
bind(E.class).toInstance(e);
|
||||
bind(A.class);
|
||||
}
|
||||
});
|
||||
|
||||
A a = injector.getInstance(A.class);
|
||||
assertSame(b, a.b);
|
||||
assertSame(c, a.c);
|
||||
assertSame(d, a.d);
|
||||
assertSame(e, a.e);
|
||||
}
|
||||
|
||||
public void testQualifiedInject() {
|
||||
Injector injector =
|
||||
Guice.createInjector(
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(B.class).annotatedWith(Names.named("jodie")).toInstance(b);
|
||||
bind(C.class).annotatedWith(Red.class).toInstance(c);
|
||||
bind(D.class).annotatedWith(RED).toInstance(d);
|
||||
bind(E.class).annotatedWith(Names.named("jesse")).toInstance(e);
|
||||
bind(F.class);
|
||||
}
|
||||
});
|
||||
|
||||
F f = injector.getInstance(F.class);
|
||||
assertSame(b, f.b);
|
||||
assertSame(c, f.c);
|
||||
assertSame(d, f.d);
|
||||
assertSame(e, f.e);
|
||||
}
|
||||
|
||||
public void testProviderInject() {
|
||||
Injector injector =
|
||||
Guice.createInjector(
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(B.class).annotatedWith(Names.named("jodie")).toInstance(b);
|
||||
bind(C.class).toInstance(c);
|
||||
bind(D.class).annotatedWith(RED).toInstance(d);
|
||||
bind(E.class).toInstance(e);
|
||||
bind(G.class);
|
||||
}
|
||||
});
|
||||
|
||||
G g = injector.getInstance(G.class);
|
||||
assertSame(b, g.bProvider.get());
|
||||
assertSame(c, g.cProvider.get());
|
||||
assertSame(d, g.dProvider.get());
|
||||
assertSame(e, g.eProvider.get());
|
||||
}
|
||||
|
||||
public void testScopeAnnotation() {
|
||||
final TestScope scope = new TestScope();
|
||||
|
||||
Injector injector =
|
||||
Guice.createInjector(
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(B.class).in(scope);
|
||||
bind(C.class).in(TestScoped.class);
|
||||
bindScope(TestScoped.class, scope);
|
||||
}
|
||||
});
|
||||
|
||||
B b = injector.getInstance(B.class);
|
||||
assertSame(b, injector.getInstance(B.class));
|
||||
assertSame(b, injector.getInstance(B.class));
|
||||
|
||||
C c = injector.getInstance(C.class);
|
||||
assertSame(c, injector.getInstance(C.class));
|
||||
assertSame(c, injector.getInstance(C.class));
|
||||
|
||||
H h = injector.getInstance(H.class);
|
||||
assertSame(h, injector.getInstance(H.class));
|
||||
assertSame(h, injector.getInstance(H.class));
|
||||
|
||||
scope.reset();
|
||||
|
||||
assertNotSame(b, injector.getInstance(B.class));
|
||||
assertNotSame(c, injector.getInstance(C.class));
|
||||
assertNotSame(h, injector.getInstance(H.class));
|
||||
}
|
||||
|
||||
public void testSingleton() {
|
||||
Injector injector =
|
||||
Guice.createInjector(
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(B.class).in(Singleton.class);
|
||||
}
|
||||
});
|
||||
|
||||
B b = injector.getInstance(B.class);
|
||||
assertSame(b, injector.getInstance(B.class));
|
||||
assertSame(b, injector.getInstance(B.class));
|
||||
|
||||
J j = injector.getInstance(J.class);
|
||||
assertSame(j, injector.getInstance(J.class));
|
||||
assertSame(j, injector.getInstance(J.class));
|
||||
}
|
||||
|
||||
public void testEagerSingleton() {
|
||||
Guice.createInjector(
|
||||
Stage.PRODUCTION,
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(J.class);
|
||||
bind(K.class).in(Singleton.class);
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(1, J.nextInstanceId);
|
||||
assertEquals(1, K.nextInstanceId);
|
||||
}
|
||||
|
||||
public void testScopesIsSingleton() {
|
||||
Injector injector =
|
||||
Guice.createInjector(
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(J.class);
|
||||
bind(K.class).in(Singleton.class);
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue(Scopes.isSingleton(injector.getBinding(J.class)));
|
||||
assertTrue(Scopes.isSingleton(injector.getBinding(K.class)));
|
||||
}
|
||||
|
||||
public void testInjectingFinalFieldsIsForbidden() {
|
||||
try {
|
||||
Guice.createInjector(
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(L.class);
|
||||
}
|
||||
});
|
||||
fail();
|
||||
} catch (CreationException expected) {
|
||||
assertContains(expected.getMessage(), "Injected field Jsr330Test$L.b cannot be final.");
|
||||
}
|
||||
}
|
||||
|
||||
public void testInjectingAbstractMethodsIsForbidden() {
|
||||
try {
|
||||
Guice.createInjector(
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(M.class);
|
||||
}
|
||||
});
|
||||
fail();
|
||||
} catch (CreationException expected) {
|
||||
assertContains(
|
||||
expected.getMessage(), "Injected method Jsr330Test$AbstractM.setB() cannot be abstract.");
|
||||
}
|
||||
}
|
||||
|
||||
public void testInjectingMethodsWithTypeParametersIsForbidden() {
|
||||
try {
|
||||
Guice.createInjector(
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(N.class);
|
||||
}
|
||||
});
|
||||
fail();
|
||||
} catch (CreationException expected) {
|
||||
assertContains(
|
||||
expected.getMessage(), "Injected method Jsr330Test$N.setB() cannot declare type ");
|
||||
}
|
||||
}
|
||||
|
||||
public void testInjectingMethodsWithNonVoidReturnTypes() {
|
||||
Guice.createInjector(
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(P.class);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* This test verifies that we can compile bindings to provider instances whose compile-time type
|
||||
* implements javax.inject.Provider but not com.google.inject.Provider. For binary compatibility,
|
||||
* we don't (and won't) support binding to instances of javax.inject.Provider.
|
||||
*/
|
||||
public void testBindProviderClass() {
|
||||
Injector injector =
|
||||
Guice.createInjector(
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(B.class).toProvider(BProvider.class);
|
||||
bind(B.class).annotatedWith(Names.named("1")).toProvider(BProvider.class);
|
||||
bind(B.class).annotatedWith(Names.named("2")).toProvider(Key.get(BProvider.class));
|
||||
bind(B.class)
|
||||
.annotatedWith(Names.named("3"))
|
||||
.toProvider(TypeLiteral.get(BProvider.class));
|
||||
}
|
||||
});
|
||||
|
||||
injector.getInstance(Key.get(B.class));
|
||||
injector.getInstance(Key.get(B.class, Names.named("1")));
|
||||
injector.getInstance(Key.get(B.class, Names.named("2")));
|
||||
injector.getInstance(Key.get(B.class, Names.named("3")));
|
||||
}
|
||||
|
||||
public void testGuicify330Provider() {
|
||||
Provider<String> jsr330Provider =
|
||||
new Provider<String>() {
|
||||
@Override
|
||||
public String get() {
|
||||
return "A";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "jsr330Provider";
|
||||
}
|
||||
};
|
||||
|
||||
com.google.inject.Provider<String> guicified = Providers.guicify(jsr330Provider);
|
||||
assertEquals("guicified(jsr330Provider)", guicified.toString());
|
||||
assertEquals("A", guicified.get());
|
||||
|
||||
// when you guicify the Guice-friendly, it's a no-op
|
||||
assertSame(guicified, Providers.guicify(guicified));
|
||||
|
||||
assertFalse(guicified instanceof HasDependencies);
|
||||
}
|
||||
|
||||
public void testGuicifyWithDependencies() {
|
||||
Provider<String> jsr330Provider =
|
||||
new Provider<String>() {
|
||||
@Inject double d;
|
||||
int i;
|
||||
|
||||
@Inject
|
||||
void injectMe(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
return d + "-" + i;
|
||||
}
|
||||
};
|
||||
|
||||
final com.google.inject.Provider<String> guicified = Providers.guicify(jsr330Provider);
|
||||
assertTrue(guicified instanceof HasDependencies);
|
||||
Set<Dependency<?>> actual = ((HasDependencies) guicified).getDependencies();
|
||||
validateDependencies(actual, jsr330Provider.getClass());
|
||||
|
||||
Injector injector =
|
||||
Guice.createInjector(
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(String.class).toProvider(guicified);
|
||||
bind(int.class).toInstance(1);
|
||||
bind(double.class).toInstance(2.0d);
|
||||
}
|
||||
});
|
||||
|
||||
Binding<String> binding = injector.getBinding(String.class);
|
||||
assertEquals("2.0-1", binding.getProvider().get());
|
||||
validateDependencies(actual, jsr330Provider.getClass());
|
||||
}
|
||||
|
||||
private void validateDependencies(Set<Dependency<?>> actual, Class<?> owner) {
|
||||
assertEquals(actual.toString(), 2, actual.size());
|
||||
Dependency<?> dDep = null;
|
||||
Dependency<?> iDep = null;
|
||||
for (Dependency<?> dep : actual) {
|
||||
if (dep.getKey().equals(Key.get(Double.class))) {
|
||||
dDep = dep;
|
||||
} else if (dep.getKey().equals(Key.get(Integer.class))) {
|
||||
iDep = dep;
|
||||
}
|
||||
}
|
||||
assertNotNull(dDep);
|
||||
assertNotNull(iDep);
|
||||
assertEquals(TypeLiteral.get(owner), dDep.getInjectionPoint().getDeclaringType());
|
||||
assertEquals("d", dDep.getInjectionPoint().getMember().getName());
|
||||
assertEquals(-1, dDep.getParameterIndex());
|
||||
|
||||
assertEquals(TypeLiteral.get(owner), iDep.getInjectionPoint().getDeclaringType());
|
||||
assertEquals("injectMe", iDep.getInjectionPoint().getMember().getName());
|
||||
assertEquals(0, iDep.getParameterIndex());
|
||||
}
|
||||
|
||||
static class A {
|
||||
final B b;
|
||||
@Inject C c;
|
||||
D d;
|
||||
E e;
|
||||
|
||||
@Inject
|
||||
A(B b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
@Inject
|
||||
void injectD(D d, E e) {
|
||||
this.d = d;
|
||||
this.e = e;
|
||||
}
|
||||
}
|
||||
|
||||
static class B {}
|
||||
|
||||
static class C {}
|
||||
|
||||
static class D {}
|
||||
|
||||
static class E {}
|
||||
|
||||
static class F {
|
||||
final B b;
|
||||
@Inject @Red C c;
|
||||
D d;
|
||||
E e;
|
||||
|
||||
@Inject
|
||||
F(@Named("jodie") B b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
@Inject
|
||||
void injectD(@Red D d, @Named("jesse") E e) {
|
||||
this.d = d;
|
||||
this.e = e;
|
||||
}
|
||||
}
|
||||
|
||||
@Qualifier
|
||||
@Retention(RUNTIME)
|
||||
@interface Red {}
|
||||
|
||||
public static final Red RED =
|
||||
new Red() {
|
||||
@Override
|
||||
public Class<? extends Annotation> annotationType() {
|
||||
return Red.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof Red;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
static class G {
|
||||
final Provider<B> bProvider;
|
||||
@Inject Provider<C> cProvider;
|
||||
Provider<D> dProvider;
|
||||
Provider<E> eProvider;
|
||||
|
||||
@Inject
|
||||
G(@Named("jodie") Provider<B> bProvider) {
|
||||
this.bProvider = bProvider;
|
||||
}
|
||||
|
||||
@Inject
|
||||
void injectD(@Red Provider<D> dProvider, Provider<E> eProvider) {
|
||||
this.dProvider = dProvider;
|
||||
this.eProvider = eProvider;
|
||||
}
|
||||
}
|
||||
|
||||
@javax.inject.Scope
|
||||
@Retention(RUNTIME)
|
||||
@interface TestScoped {}
|
||||
|
||||
static class TestScope implements Scope {
|
||||
private int now = 0;
|
||||
|
||||
@Override
|
||||
public <T> com.google.inject.Provider<T> scope(
|
||||
Key<T> key, final com.google.inject.Provider<T> unscoped) {
|
||||
return new com.google.inject.Provider<T>() {
|
||||
private T value;
|
||||
private int snapshotTime = -1;
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
if (snapshotTime != now) {
|
||||
value = unscoped.get();
|
||||
snapshotTime = now;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
now++;
|
||||
}
|
||||
}
|
||||
|
||||
@TestScoped
|
||||
static class H {}
|
||||
|
||||
@Singleton
|
||||
static class J {
|
||||
static int nextInstanceId = 0;
|
||||
int instanceId = nextInstanceId++;
|
||||
}
|
||||
|
||||
static class K {
|
||||
static int nextInstanceId = 0;
|
||||
int instanceId = nextInstanceId++;
|
||||
}
|
||||
|
||||
static class L {
|
||||
@SuppressWarnings("InjectJavaxInjectOnFinalField")
|
||||
@Inject
|
||||
final B b = null;
|
||||
}
|
||||
|
||||
abstract static class AbstractM {
|
||||
@SuppressWarnings("JavaxInjectOnAbstractMethod")
|
||||
@Inject
|
||||
abstract void setB(B b);
|
||||
}
|
||||
|
||||
static class M extends AbstractM {
|
||||
@Override
|
||||
@SuppressWarnings("OverridesJavaxInjectableMethod")
|
||||
void setB(B b) {}
|
||||
}
|
||||
|
||||
static class N {
|
||||
@Inject
|
||||
<T> void setB(B b) {}
|
||||
}
|
||||
|
||||
static class P {
|
||||
@Inject
|
||||
B setB(B b) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
static class BProvider implements Provider<B> {
|
||||
@Override
|
||||
public B get() {
|
||||
return new B();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public class OSGiContainerTest {
|
||||
static final String AOPALLIANCE_JAR =
|
||||
System.getProperty("aopalliance.jar", "lib/aopalliance.jar");
|
||||
static final String JAVAX_INJECT_JAR =
|
||||
System.getProperty("javax.inject.jar", "lib/javax.inject.jar");
|
||||
System.getProperty("jakarta.inject.jar", "lib/jakarta.inject.jar");
|
||||
static final String GUAVA_JAR = System.getProperty("guava.jar", "lib/guava-25.1-android.jar");
|
||||
|
||||
// dynamically build test bundles
|
||||
@@ -78,9 +78,9 @@ public class OSGiContainerTest {
|
||||
buildBundle("aopalliance", instructions, AOPALLIANCE_JAR);
|
||||
instructions.clear();
|
||||
|
||||
// javax.inject is an API bundle --> export the full API
|
||||
instructions.setProperty("Export-Package", "javax.inject.*");
|
||||
buildBundle("javax.inject", instructions, JAVAX_INJECT_JAR);
|
||||
// jakarta.inject is an API bundle --> export the full API
|
||||
instructions.setProperty("Export-Package", "jakarta.inject.*");
|
||||
buildBundle("jakarta.inject", instructions, JAVAX_INJECT_JAR);
|
||||
instructions.clear();
|
||||
|
||||
// early versions of guava did not ship with OSGi metadata
|
||||
@@ -143,7 +143,7 @@ public class OSGiContainerTest {
|
||||
|
||||
// load all the necessary bundles and start the OSGi test bundle
|
||||
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/aopalliance.jar");
|
||||
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/javax.inject.jar");
|
||||
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/jakarta.inject.jar");
|
||||
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/guava.jar");
|
||||
systemContext.installBundle("reference:file:" + GUICE_JAR);
|
||||
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/osgitests.jar").start();
|
||||
|
||||
@@ -5,8 +5,8 @@ import com.google.inject.Guice;
|
||||
import com.google.inject.Provides;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Qualifier;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Qualifier;
|
||||
|
||||
/** Hello world, Guice! */
|
||||
public class App {
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.google.inject.testing.fieldbinder.Bind;
|
||||
import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -25,7 +25,6 @@ java_library(
|
||||
"//third_party/java/guava/base",
|
||||
"//third_party/java/guava/collect",
|
||||
"//third_party/java/jakarta_inject",
|
||||
"//third_party/java/jsr330_inject",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -304,7 +304,6 @@ final class FactoryProvider2<F>
|
||||
Key<?> paramKey = Annotations.getKey(param, method, paramAnnotations[p++], errors);
|
||||
Class<?> underlylingType = paramKey.getTypeLiteral().getRawType();
|
||||
if (underlylingType.equals(Provider.class)
|
||||
|| underlylingType.equals(javax.inject.Provider.class)
|
||||
|| underlylingType.equals(jakarta.inject.Provider.class)) {
|
||||
errors.addMessage(
|
||||
"A Provider may not be a type in a factory method of an AssistedInject."
|
||||
|
||||
@@ -23,7 +23,6 @@ java_library(
|
||||
"//third_party/java/guava/base",
|
||||
"//third_party/java/guava/collect",
|
||||
"//third_party/java/jakarta_inject",
|
||||
"//third_party/java/jsr330_inject",
|
||||
"//third_party/java/junit",
|
||||
"//third_party/java/truth",
|
||||
],
|
||||
@@ -41,7 +40,7 @@ java_library(
|
||||
"//extensions/assistedinject/src/com/google/inject/assistedinject",
|
||||
"//third_party/java/guava/base",
|
||||
"//third_party/java/guava/collect",
|
||||
"//third_party/java/jsr330_inject",
|
||||
"//third_party/java/jakarta_inject",
|
||||
"//third_party/java/junit",
|
||||
"//third_party/java/truth",
|
||||
],
|
||||
|
||||
+2
-2
@@ -709,9 +709,9 @@ public class FactoryProvider2Test {
|
||||
|
||||
interface JavaxProviderBasedColoredCarFactory {
|
||||
Car createCar(
|
||||
javax.inject.Provider<Color> colorProvider, javax.inject.Provider<String> stringProvider);
|
||||
jakarta.inject.Provider<Color> colorProvider, jakarta.inject.Provider<String> stringProvider);
|
||||
|
||||
Mustang createMustang(@Assisted("color") javax.inject.Provider<Color> colorProvider);
|
||||
Mustang createMustang(@Assisted("color") jakarta.inject.Provider<Color> colorProvider);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ import java.util.List;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
import javax.inject.Inject;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
import javax.inject.Inject;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -25,7 +25,6 @@ java_library(
|
||||
"//third_party/java/guava/base",
|
||||
"//third_party/java/guava/collect",
|
||||
"//third_party/java/jakarta_inject",
|
||||
"//third_party/java/jsr330_inject",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
+2
-1
@@ -94,7 +94,8 @@ final class DaggerMethodScanner extends ModuleAnnotatedMethodScanner {
|
||||
}
|
||||
|
||||
private static final ImmutableSet<Class<? extends Annotation>> SCOPE_ANNOTATIONS =
|
||||
ImmutableSet.of(javax.inject.Scope.class, jakarta.inject.Scope.class);
|
||||
ImmutableSet.of(
|
||||
jakarta.inject.Scope.class);
|
||||
|
||||
private <T> void configureBindsKey(Binder binder, Method method, Key<T> key) {
|
||||
// the Dagger processor already validates the assignability of these two keys. parameterKey()
|
||||
|
||||
@@ -28,7 +28,8 @@ import java.util.Optional;
|
||||
/** Utility methods for creating {@link Key}s. */
|
||||
final class Keys {
|
||||
private static final ImmutableSet<Class<? extends Annotation>> QUALIFIERS =
|
||||
ImmutableSet.of(javax.inject.Qualifier.class, jakarta.inject.Qualifier.class);
|
||||
ImmutableSet.of(
|
||||
jakarta.inject.Qualifier.class);
|
||||
|
||||
static Key<?> parameterKey(Parameter parameter) {
|
||||
Optional<Annotation> qualifier = getAnnotatedAnnotation(parameter, QUALIFIERS);
|
||||
|
||||
@@ -19,7 +19,6 @@ java_library(
|
||||
"//third_party/java/guava/base",
|
||||
"//third_party/java/guava/collect",
|
||||
"//third_party/java/jakarta_inject",
|
||||
"//third_party/java/jsr330_inject",
|
||||
"//third_party/java/junit",
|
||||
"//third_party/java/truth",
|
||||
],
|
||||
|
||||
@@ -95,38 +95,6 @@ public class BindsTest extends TestCase {
|
||||
.isEqualTo(ImmutableSet.of("multibound-3", "multibound-4"));
|
||||
}
|
||||
|
||||
@Module
|
||||
interface JavaxScopedMultibindingBindsModule {
|
||||
@Binds
|
||||
@IntoSet
|
||||
@javax.inject.Singleton
|
||||
Object fromString(String string);
|
||||
|
||||
@Binds
|
||||
CharSequence toCharSequence(String string);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
@javax.inject.Singleton
|
||||
Object fromCharSequence(CharSequence charSequence);
|
||||
}
|
||||
|
||||
public void testJavaxScopedMultibindings() {
|
||||
Injector injector =
|
||||
Guice.createInjector(
|
||||
DaggerAdapter.from(
|
||||
new CountingMultibindingProviderModule(),
|
||||
JavaxScopedMultibindingBindsModule.class));
|
||||
|
||||
Binding<Set<Object>> binding = injector.getBinding(new Key<Set<Object>>() {});
|
||||
assertThat(binding)
|
||||
.hasProvidedValueThat()
|
||||
.isEqualTo(ImmutableSet.of("multibound-1", "multibound-2"));
|
||||
assertThat(binding)
|
||||
.hasProvidedValueThat()
|
||||
.isEqualTo(ImmutableSet.of("multibound-1", "multibound-2"));
|
||||
}
|
||||
|
||||
@Module
|
||||
interface JakartaScopedMultibindingBindsModule {
|
||||
@Binds
|
||||
@@ -159,45 +127,6 @@ public class BindsTest extends TestCase {
|
||||
.isEqualTo(ImmutableSet.of("multibound-1", "multibound-2"));
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@javax.inject.Qualifier
|
||||
@interface JavaxProvidesQualifier {}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@javax.inject.Qualifier
|
||||
@interface JavaxBindsQualifier {}
|
||||
|
||||
@Module
|
||||
interface JavaxQualifiedBinds {
|
||||
@Provides
|
||||
@JavaxProvidesQualifier
|
||||
static String provides() {
|
||||
return "qualifiers";
|
||||
}
|
||||
|
||||
@Binds
|
||||
@JavaxBindsQualifier
|
||||
String bindsToProvides(@JavaxProvidesQualifier String provides);
|
||||
|
||||
@Binds
|
||||
String unqualifiedToBinds(@JavaxBindsQualifier String binds);
|
||||
}
|
||||
|
||||
public void testJavaxQualifiers() {
|
||||
Injector injector = Guice.createInjector(DaggerAdapter.from(JavaxQualifiedBinds.class));
|
||||
|
||||
Binding<String> stringBinding = injector.getBinding(String.class);
|
||||
assertThat(stringBinding).hasProvidedValueThat().isEqualTo("qualifiers");
|
||||
assertThat(stringBinding)
|
||||
.hasSource(JavaxQualifiedBinds.class, "unqualifiedToBinds", String.class);
|
||||
|
||||
Binding<String> qualifiedBinds =
|
||||
injector.getBinding(Key.get(String.class, JavaxBindsQualifier.class));
|
||||
assertThat(qualifiedBinds).hasProvidedValueThat().isEqualTo("qualifiers");
|
||||
assertThat(qualifiedBinds)
|
||||
.hasSource(JavaxQualifiedBinds.class, "bindsToProvides", String.class);
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@jakarta.inject.Qualifier
|
||||
@interface JakartaProvidesQualifier {}
|
||||
|
||||
+2
-2
@@ -39,8 +39,8 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Set;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Qualifier;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Qualifier;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,7 +34,7 @@ import dagger.multibindings.IntoMap;
|
||||
import dagger.multibindings.StringKey;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.util.Map;
|
||||
import javax.inject.Qualifier;
|
||||
import jakarta.inject.Qualifier;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/** {@link IntoMap} tests for {@link DaggerAdapter}. */
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.inject.Qualifier;
|
||||
import jakarta.inject.Qualifier;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/** Tests of {@link Multibinds} support in {@link DaggerAdapter}. */
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import dagger.Module;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.Optional;
|
||||
import javax.inject.Qualifier;
|
||||
import jakarta.inject.Qualifier;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/** Tests of {@link BindsOptionalOf} support in {@link DaggerAdapter}. */
|
||||
|
||||
@@ -15,15 +15,15 @@
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.persistence</groupId>
|
||||
<artifactId>javax.persistence-api</artifactId>
|
||||
<version>2.2</version>
|
||||
<groupId>jakarta.persistence</groupId>
|
||||
<artifactId>jakarta.persistence-api</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>2.5</version>
|
||||
<groupId>jakarta.servlet</groupId>
|
||||
<artifactId>jakarta.servlet-api</artifactId>
|
||||
<version>5.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -34,8 +34,8 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>5.6.3.Final</version>
|
||||
<artifactId>hibernate-core-jakarta</artifactId>
|
||||
<version>5.6.15.Final</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -26,9 +26,8 @@ java_library(
|
||||
"//third_party/java/guava/base",
|
||||
"//third_party/java/guava/collect",
|
||||
"//third_party/java/jakarta_inject",
|
||||
"//third_party/java/javax_persistence",
|
||||
"//third_party/java/jsr330_inject",
|
||||
"//third_party/java/servlet/servlet_api",
|
||||
"//third_party/java/jakarta_persistence",
|
||||
"//third_party/java/jakarta_servlet_api",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -19,18 +19,18 @@ package com.google.inject.persist;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import jakarta.servlet.Filter;
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.FilterConfig;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.ServletRequest;
|
||||
import jakarta.servlet.ServletResponse;
|
||||
|
||||
/**
|
||||
* Apply this filter to enable the HTTP Request unit of work and to have guice-persist manage the
|
||||
* lifecycle of active units of work. The filter automatically starts and stops the relevant {@link
|
||||
* PersistService} upon {@link javax.servlet.Filter#init(javax.servlet.FilterConfig)} and {@link
|
||||
* javax.servlet.Filter#destroy()} respectively.
|
||||
* PersistService} upon {@link jakarta.servlet.Filter#init(jakarta.servlet.FilterConfig)} and {@link
|
||||
* jakarta.servlet.Filter#destroy()} respectively.
|
||||
*
|
||||
* <p>To be able to use the open session-in-view pattern (i.e. work per request), register this
|
||||
* filter <b>once</b> in your Guice {@code ServletModule}. It is important that you register this
|
||||
|
||||
@@ -31,8 +31,8 @@ import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Query;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
@@ -121,8 +121,8 @@ class JpaFinderProxy implements MethodInterceptor {
|
||||
} else if (annotation instanceof Named) {
|
||||
Named named = (Named) annotation;
|
||||
jpaQuery.setParameter(named.value(), argument);
|
||||
} else if (annotation instanceof javax.inject.Named) {
|
||||
javax.inject.Named named = (javax.inject.Named) annotation;
|
||||
} else if (annotation instanceof jakarta.inject.Named) {
|
||||
jakarta.inject.Named named = (jakarta.inject.Named) annotation;
|
||||
jpaQuery.setParameter(named.value(), argument);
|
||||
} else if (annotation instanceof jakarta.inject.Named) {
|
||||
jakarta.inject.Named named = (jakarta.inject.Named) annotation;
|
||||
@@ -186,7 +186,7 @@ class JpaFinderProxy implements MethodInterceptor {
|
||||
//discover the named, first or max annotations then break out
|
||||
Class<? extends Annotation> annotationType = annotation.annotationType();
|
||||
if (Named.class.equals(annotationType)
|
||||
|| javax.inject.Named.class.equals(annotationType)
|
||||
|| jakarta.inject.Named.class.equals(annotationType)
|
||||
|| jakarta.inject.Named.class.equals(annotationType)) {
|
||||
discoveredAnnotations[i] = annotation;
|
||||
finderDescriptor.isBindAsRawParameters = false;
|
||||
|
||||
@@ -20,8 +20,8 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.persist.Transactional;
|
||||
import com.google.inject.persist.UnitOfWork;
|
||||
import java.lang.reflect.Method;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityTransaction;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
|
||||
@@ -29,9 +29,9 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.Map;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.Persistence;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.Persistence;
|
||||
|
||||
/**
|
||||
* @author Dhanji R. Prasanna (dhanji@gmail.com)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<!-- JPA test "unit" -->
|
||||
<persistence-unit name="testUnit" transaction-type="RESOURCE_LOCAL">
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
|
||||
<class>com.google.inject.persist.jpa.JpaTestEntity</class>
|
||||
<class>com.google.inject.persist.jpa.JpaParentTestEntity</class>
|
||||
@@ -26,7 +26,7 @@
|
||||
</persistence-unit>
|
||||
|
||||
<persistence-unit name="testProperties" transaction-type="RESOURCE_LOCAL">
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
|
||||
<class>com.google.inject.persist.jpa.JpaTestEntity</class>
|
||||
<class>com.google.inject.persist.jpa.JpaParentTestEntity</class>
|
||||
|
||||
@@ -26,8 +26,8 @@ java_library(
|
||||
"//third_party/java/hamcrest",
|
||||
"//third_party/java/hibernate:hibernate5",
|
||||
"//third_party/java/hsqldb:hsqldb2",
|
||||
"//third_party/java/javax_persistence",
|
||||
"//third_party/java/jsr330_inject",
|
||||
"//third_party/java/jakarta_inject",
|
||||
"//third_party/java/jakarta_persistence",
|
||||
"//third_party/java/junit",
|
||||
"//third_party/java/mockito",
|
||||
],
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<!-- JPA test "unit" -->
|
||||
<persistence-unit name="testUnit" transaction-type="RESOURCE_LOCAL">
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
|
||||
<class>com.google.inject.persist.jpa.JpaTestEntity</class>
|
||||
<class>com.google.inject.persist.jpa.JpaParentTestEntity</class>
|
||||
@@ -26,7 +26,7 @@
|
||||
</persistence-unit>
|
||||
|
||||
<persistence-unit name="testProperties" transaction-type="RESOURCE_LOCAL">
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
|
||||
<class>com.google.inject.persist.jpa.JpaTestEntity</class>
|
||||
<class>com.google.inject.persist.jpa.JpaParentTestEntity</class>
|
||||
|
||||
+3
-3
@@ -26,9 +26,9 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import javax.inject.Provider;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import jakarta.inject.Provider;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
|
||||
+2
-2
@@ -21,8 +21,8 @@ import com.google.inject.Injector;
|
||||
import com.google.inject.persist.PersistService;
|
||||
import com.google.inject.persist.UnitOfWork;
|
||||
import java.util.Properties;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/** @author Dhanji R. Prasanna (dhanji@gmail.com) */
|
||||
|
||||
@@ -28,7 +28,7 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
|
||||
+2
-2
@@ -21,8 +21,8 @@ import com.google.inject.persist.PersistService;
|
||||
import com.google.inject.persist.UnitOfWork;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.PersistenceException;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.PersistenceException;
|
||||
import javax.sql.DataSource;
|
||||
import junit.framework.TestCase;
|
||||
import org.hibernate.cfg.Environment;
|
||||
|
||||
+2
-2
@@ -20,8 +20,8 @@ import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.persist.PersistService;
|
||||
import com.google.inject.persist.UnitOfWork;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/** @author Dhanji R. Prasanna (dhanji@gmail.com) */
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user