Browse Source

Remove more unused inject code (#106211)

Removing a couple assertions that we do not use together with their supporting code.
Armin Braun 1 year ago
parent
commit
04110202ea
22 changed files with 29 additions and 684 deletions
  1. 1 5
      server/src/main/java/org/elasticsearch/common/inject/Binder.java
  2. 1 3
      server/src/main/java/org/elasticsearch/common/inject/Binding.java
  3. 1 7
      server/src/main/java/org/elasticsearch/common/inject/BindingProcessor.java
  4. 0 30
      server/src/main/java/org/elasticsearch/common/inject/ConstructionProxyFactory.java
  5. 24 3
      server/src/main/java/org/elasticsearch/common/inject/ConstructorInjectorStore.java
  6. 0 65
      server/src/main/java/org/elasticsearch/common/inject/DefaultConstructionProxyFactory.java
  7. 0 37
      server/src/main/java/org/elasticsearch/common/inject/Exposed.java
  8. 0 38
      server/src/main/java/org/elasticsearch/common/inject/ImplementedBy.java
  9. 0 91
      server/src/main/java/org/elasticsearch/common/inject/InjectorImpl.java
  10. 1 7
      server/src/main/java/org/elasticsearch/common/inject/Module.java
  11. 0 5
      server/src/main/java/org/elasticsearch/common/inject/PrivateBinder.java
  12. 0 38
      server/src/main/java/org/elasticsearch/common/inject/ProvidedBy.java
  13. 0 37
      server/src/main/java/org/elasticsearch/common/inject/Provides.java
  14. 0 13
      server/src/main/java/org/elasticsearch/common/inject/TypeLiteral.java
  15. 0 7
      server/src/main/java/org/elasticsearch/common/inject/binder/ScopedBindingBuilder.java
  16. 0 8
      server/src/main/java/org/elasticsearch/common/inject/internal/AbstractBindingBuilder.java
  17. 0 21
      server/src/main/java/org/elasticsearch/common/inject/internal/Errors.java
  18. 0 97
      server/src/main/java/org/elasticsearch/common/inject/internal/ProviderMethod.java
  19. 0 130
      server/src/main/java/org/elasticsearch/common/inject/internal/ProviderMethodsModule.java
  20. 0 8
      server/src/main/java/org/elasticsearch/common/inject/spi/Elements.java
  21. 1 2
      server/src/main/java/org/elasticsearch/common/inject/spi/InjectionPoint.java
  22. 0 32
      server/src/main/java/org/elasticsearch/common/inject/util/Modules.java

+ 1 - 5
server/src/main/java/org/elasticsearch/common/inject/Binder.java

@@ -52,11 +52,7 @@ import java.lang.annotation.Annotation;
  *
  * Specifies that a request for a {@code Service} instance with no binding
  * annotations should be treated as if it were a request for a
- * {@code ServiceImpl} instance. This <i>overrides</i> the function of any
- * {@link ImplementedBy @ImplementedBy} or {@link ProvidedBy @ProvidedBy}
- * annotations found on {@code Service}, since Guice will have already
- * "moved on" to {@code ServiceImpl} before it reaches the point when it starts
- * looking for these annotations.
+ * {@code ServiceImpl} instance.
  *
  * <pre>
  *     bind(Service.class).toProvider(ServiceProvider.class);</pre>

+ 1 - 3
server/src/main/java/org/elasticsearch/common/inject/Binding.java

@@ -31,9 +31,7 @@ import org.elasticsearch.common.inject.spi.Element;
  * <pre>
  *     bind(Service.class).annotatedWith(Red.class).to(ServiceImpl.class);
  *     bindConstant().annotatedWith(ServerHost.class).to(args[0]);</pre></li>
- * <li>Implicitly by the Injector by following a type's {@link ImplementedBy
- * pointer} {@link ProvidedBy annotations} or by using its {@link Inject annotated} or
- * default constructor.</li>
+ * <li>Implicitly by the Injector by using its {@link Inject annotated} or default constructor.</li>
  * <li>By converting a bound instance to a different type.</li>
  * <li>For {@link Provider providers}, by delegating to the binding for the provided type.</li>
  * </ul>

+ 1 - 7
server/src/main/java/org/elasticsearch/common/inject/BindingProcessor.java

@@ -25,7 +25,6 @@ import org.elasticsearch.common.inject.internal.InternalFactory;
 import org.elasticsearch.common.inject.internal.LinkedBindingImpl;
 import org.elasticsearch.common.inject.internal.LinkedProviderBindingImpl;
 import org.elasticsearch.common.inject.internal.ProviderInstanceBindingImpl;
-import org.elasticsearch.common.inject.internal.ProviderMethod;
 import org.elasticsearch.common.inject.internal.Scoping;
 import org.elasticsearch.common.inject.internal.UntargettedBindingImpl;
 import org.elasticsearch.common.inject.spi.BindingTargetVisitor;
@@ -62,12 +61,7 @@ class BindingProcessor extends AbstractProcessor {
         final Object source = command.getSource();
 
         if (Void.class.equals(command.getKey().getRawType())) {
-            if (command instanceof ProviderInstanceBinding
-                && ((ProviderInstanceBinding<?>) command).getProviderInstance() instanceof ProviderMethod) {
-                errors.voidProviderMethod();
-            } else {
-                errors.missingConstantValues();
-            }
+            errors.missingConstantValues();
             return true;
         }
 

+ 0 - 30
server/src/main/java/org/elasticsearch/common/inject/ConstructionProxyFactory.java

@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2006 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 org.elasticsearch.common.inject;
-
-/**
- * Creates {@link ConstructionProxy} instances.
- *
- * @author crazybob@google.com (Bob Lee)
- */
-interface ConstructionProxyFactory<T> {
-
-    /**
-     * Gets a construction proxy for the given constructor.
-     */
-    ConstructionProxy<T> create();
-}

+ 24 - 3
server/src/main/java/org/elasticsearch/common/inject/ConstructorInjectorStore.java

@@ -21,6 +21,9 @@ import org.elasticsearch.common.inject.internal.ErrorsException;
 import org.elasticsearch.common.inject.internal.FailableCache;
 import org.elasticsearch.common.inject.spi.InjectionPoint;
 
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
 /**
  * Constructor injectors by type.
  *
@@ -65,10 +68,28 @@ class ConstructorInjectorStore {
         );
         MembersInjectorImpl<T> membersInjector = injector.membersInjectorStore.get(type, errors);
 
-        ConstructionProxyFactory<T> factory = new DefaultConstructionProxyFactory<>(injectionPoint);
-
         errors.throwIfNewErrors(numErrorsBefore);
 
-        return new ConstructorInjector<>(factory.create(), constructorParameterInjectors, membersInjector);
+        @SuppressWarnings("unchecked") // the injection point is for a constructor of T
+        final Constructor<T> constructor = (Constructor<T>) injectionPoint.getMember();
+        return new ConstructorInjector<>(new ConstructionProxy<>() {
+            @Override
+            public T newInstance(Object... arguments) throws InvocationTargetException {
+                try {
+                    return constructor.newInstance(arguments);
+                } catch (InstantiationException e) {
+                    throw new AssertionError(e); // shouldn't happen, we know this is a concrete type
+                } catch (IllegalAccessException e) {
+                    // a security manager is blocking us, we're hosed
+                    throw new AssertionError("Wrong access modifiers on " + constructor, e);
+                }
+            }
+
+            @Override
+            public InjectionPoint getInjectionPoint() {
+                return injectionPoint;
+            }
+
+        }, constructorParameterInjectors, membersInjector);
     }
 }

+ 0 - 65
server/src/main/java/org/elasticsearch/common/inject/DefaultConstructionProxyFactory.java

@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2006 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 org.elasticsearch.common.inject;
-
-import org.elasticsearch.common.inject.spi.InjectionPoint;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-
-/**
- * Produces construction proxies that invoke the class constructor.
- *
- * @author crazybob@google.com (Bob Lee)
- */
-class DefaultConstructionProxyFactory<T> implements ConstructionProxyFactory<T> {
-
-    private final InjectionPoint injectionPoint;
-
-    /**
-     * @param injectionPoint an injection point whose member is a constructor of {@code T}.
-     */
-    DefaultConstructionProxyFactory(InjectionPoint injectionPoint) {
-        this.injectionPoint = injectionPoint;
-    }
-
-    @Override
-    public ConstructionProxy<T> create() {
-        @SuppressWarnings("unchecked") // the injection point is for a constructor of T
-        final Constructor<T> constructor = (Constructor<T>) injectionPoint.getMember();
-
-        return new ConstructionProxy<>() {
-            @Override
-            public T newInstance(Object... arguments) throws InvocationTargetException {
-                try {
-                    return constructor.newInstance(arguments);
-                } catch (InstantiationException e) {
-                    throw new AssertionError(e); // shouldn't happen, we know this is a concrete type
-                } catch (IllegalAccessException e) {
-                    // a security manager is blocking us, we're hosed
-                    throw new AssertionError("Wrong access modifiers on " + constructor, e);
-                }
-            }
-
-            @Override
-            public InjectionPoint getInjectionPoint() {
-                return injectionPoint;
-            }
-
-        };
-    }
-}

+ 0 - 37
server/src/main/java/org/elasticsearch/common/inject/Exposed.java

@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2008 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 org.elasticsearch.common.inject;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-/**
- * Accompanies a {@literal @}{@link org.elasticsearch.common.inject.Provides Provides} method annotation in a
- * private module to indicate that the provided binding is exposed.
- *
- * @author jessewilson@google.com (Jesse Wilson)
- * @since 2.0
- */
-@Target(ElementType.METHOD)
-@Retention(RUNTIME)
-@Documented
-public @interface Exposed {
-}

+ 0 - 38
server/src/main/java/org/elasticsearch/common/inject/ImplementedBy.java

@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2006 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 org.elasticsearch.common.inject;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-/**
- * A pointer to the default implementation of a type.
- *
- * @author crazybob@google.com (Bob Lee)
- */
-@Retention(RUNTIME)
-@Target(TYPE)
-public @interface ImplementedBy {
-
-    /**
-     * The implementation type.
-     */
-    Class<?> value();
-}

+ 0 - 91
server/src/main/java/org/elasticsearch/common/inject/InjectorImpl.java

@@ -17,15 +17,12 @@
 package org.elasticsearch.common.inject;
 
 import org.elasticsearch.common.Classes;
-import org.elasticsearch.common.inject.internal.Annotations;
 import org.elasticsearch.common.inject.internal.BindingImpl;
 import org.elasticsearch.common.inject.internal.Errors;
 import org.elasticsearch.common.inject.internal.ErrorsException;
 import org.elasticsearch.common.inject.internal.InstanceBindingImpl;
 import org.elasticsearch.common.inject.internal.InternalContext;
 import org.elasticsearch.common.inject.internal.InternalFactory;
-import org.elasticsearch.common.inject.internal.LinkedBindingImpl;
-import org.elasticsearch.common.inject.internal.LinkedProviderBindingImpl;
 import org.elasticsearch.common.inject.internal.MatcherAndConverter;
 import org.elasticsearch.common.inject.internal.Scoping;
 import org.elasticsearch.common.inject.internal.SourceProvider;
@@ -321,20 +318,6 @@ class InjectorImpl implements Injector, Lookups {
             return binding;
         }
 
-        // Handle @ImplementedBy
-        ImplementedBy implementedBy = rawType.getAnnotation(ImplementedBy.class);
-        if (implementedBy != null) {
-            Annotations.checkForMisplacedScopeAnnotations(rawType, source, errors);
-            return createImplementedByBinding(key, scoping, implementedBy, errors);
-        }
-
-        // Handle @ProvidedBy.
-        ProvidedBy providedBy = rawType.getAnnotation(ProvidedBy.class);
-        if (providedBy != null) {
-            Annotations.checkForMisplacedScopeAnnotations(rawType, source, errors);
-            return createProvidedByBinding(key, scoping, providedBy, errors);
-        }
-
         // We can't inject abstract classes.
         // TODO: Method interceptors could actually enable us to implement
         // abstract types. Should we remove this restriction?
@@ -384,80 +367,6 @@ class InjectorImpl implements Injector, Lookups {
         return new InstanceBindingImpl<>(this, key, SourceProvider.UNKNOWN_SOURCE, factory, emptySet(), value);
     }
 
-    /**
-     * Creates a binding for a type annotated with @ProvidedBy.
-     */
-    <T> BindingImpl<T> createProvidedByBinding(Key<T> key, Scoping scoping, ProvidedBy providedBy, Errors errors) throws ErrorsException {
-        final Class<?> rawType = key.getTypeLiteral().getRawType();
-        final Class<? extends Provider<?>> providerType = providedBy.value();
-
-        // Make sure it's not the same type. TODO: Can we check for deeper loops?
-        if (providerType == rawType) {
-            throw errors.recursiveProviderType().toException();
-        }
-
-        // Assume the provider provides an appropriate type. We double check at runtime.
-        @SuppressWarnings("unchecked")
-        final Key<? extends Provider<T>> providerKey = (Key<? extends Provider<T>>) Key.get(providerType);
-        final BindingImpl<? extends Provider<?>> providerBinding = getBindingOrThrow(providerKey, errors);
-
-        InternalFactory<T> internalFactory = (errors1, context, dependency) -> {
-            errors1 = errors1.withSource(providerKey);
-            Provider<?> provider = providerBinding.getInternalFactory().get(errors1, context, dependency);
-            try {
-                Object o = provider.get();
-                if (o != null && rawType.isInstance(o) == false) {
-                    throw errors1.subtypeNotProvided(providerType, rawType).toException();
-                }
-                @SuppressWarnings("unchecked") // protected by isInstance() check above
-                T t = (T) o;
-                return t;
-            } catch (RuntimeException e) {
-                throw errors1.errorInProvider(e).toException();
-            }
-        };
-
-        return new LinkedProviderBindingImpl<>(
-            this,
-            key,
-            rawType /* source */,
-            Scopes.scope(this, internalFactory, scoping),
-            scoping,
-            providerKey
-        );
-    }
-
-    /**
-     * Creates a binding for a type annotated with @ImplementedBy.
-     */
-    <T> BindingImpl<T> createImplementedByBinding(Key<T> key, Scoping scoping, ImplementedBy implementedBy, Errors errors)
-        throws ErrorsException {
-        Class<?> rawType = key.getTypeLiteral().getRawType();
-        Class<?> implementationType = implementedBy.value();
-
-        // Make sure it's not the same type. TODO: Can we check for deeper cycles?
-        if (implementationType == rawType) {
-            throw errors.recursiveImplementationType().toException();
-        }
-
-        // Make sure implementationType extends type.
-        if (rawType.isAssignableFrom(implementationType) == false) {
-            throw errors.notASubtype(implementationType, rawType).toException();
-        }
-
-        @SuppressWarnings("unchecked") // After the preceding check, this cast is safe.
-        Class<? extends T> subclass = (Class<? extends T>) implementationType;
-
-        // Look up the target binding.
-        final Key<? extends T> targetKey = Key.get(subclass);
-        final BindingImpl<? extends T> targetBinding = getBindingOrThrow(targetKey, errors);
-
-        InternalFactory<T> internalFactory = (errors1, context, dependency) -> targetBinding.getInternalFactory()
-            .get(errors1.withSource(targetKey), context, dependency);
-
-        return new LinkedBindingImpl<>(this, key, rawType /* source */, Scopes.scope(this, internalFactory, scoping), scoping, targetKey);
-    }
-
     /**
      * Attempts to create a just-in-time binding for {@code key} in the root injector, falling back to
      * other ancestor injectors until this injector is tried.

+ 1 - 7
server/src/main/java/org/elasticsearch/common/inject/Module.java

@@ -24,11 +24,6 @@ package org.elasticsearch.common.inject;
  * <p>
  * Your Module classes can use a more streamlined syntax by extending
  * {@link AbstractModule} rather than implementing this interface directly.
- * <p>
- * In addition to the bindings configured via {@link #configure}, bindings
- * will be created for all methods annotated with {@literal @}{@link Provides}.
- * Use scope and binding annotations on these methods to configure the
- * bindings.
  */
 public interface Module {
 
@@ -36,8 +31,7 @@ public interface Module {
      * Contributes bindings and other configurations for this module to {@code binder}.
      * <p>
      * <strong>Do not invoke this method directly</strong> to install submodules. Instead use
-     * {@link Binder#install(Module)}, which ensures that {@link Provides provider methods} are
-     * discovered.
+     * {@link Binder#install(Module)}.
      */
     void configure(Binder binder);
 }

+ 0 - 5
server/src/main/java/org/elasticsearch/common/inject/PrivateBinder.java

@@ -24,11 +24,6 @@ package org.elasticsearch.common.inject;
  */
 public interface PrivateBinder extends Binder {
 
-    /**
-     * Makes the binding for {@code key} available to the enclosing environment
-     */
-    void expose(Key<?> key);
-
     @Override
     PrivateBinder withSource(Object source);
 

+ 0 - 38
server/src/main/java/org/elasticsearch/common/inject/ProvidedBy.java

@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2006 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 org.elasticsearch.common.inject;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-/**
- * A pointer to the default provider type for a type.
- *
- * @author crazybob@google.com (Bob Lee)
- */
-@Retention(RUNTIME)
-@Target(TYPE)
-public @interface ProvidedBy {
-
-    /**
-     * The implementation type.
-     */
-    Class<? extends Provider<?>> value();
-}

+ 0 - 37
server/src/main/java/org/elasticsearch/common/inject/Provides.java

@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2007 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 org.elasticsearch.common.inject;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-/**
- * Annotates methods of a {@link Module} to create a provider method binding. The method's return
- * type is bound to its returned value. Guice will pass dependencies to the method as parameters.
- *
- * @author crazybob@google.com (Bob Lee)
- * @since 2.0
- */
-@Documented
-@Target(METHOD)
-@Retention(RUNTIME)
-public @interface Provides {
-}

+ 0 - 13
server/src/main/java/org/elasticsearch/common/inject/TypeLiteral.java

@@ -277,17 +277,4 @@ public class TypeLiteral<T> {
         return resolveAll(genericParameterTypes);
     }
 
-    /**
-     * Returns the resolved generic return type of {@code method}.
-     *
-     * @param method a method defined by this or any supertype.
-     * @since 2.0
-     */
-    public TypeLiteral<?> getReturnType(Method method) {
-        if (method.getDeclaringClass().isAssignableFrom(rawType) == false) {
-            throw new IllegalArgumentException(method + " is not defined by a supertype of " + type);
-        }
-
-        return resolve(method.getGenericReturnType());
-    }
 }

+ 0 - 7
server/src/main/java/org/elasticsearch/common/inject/binder/ScopedBindingBuilder.java

@@ -16,8 +16,6 @@
 
 package org.elasticsearch.common.inject.binder;
 
-import java.lang.annotation.Annotation;
-
 /**
  * See the EDSL examples at {@link org.elasticsearch.common.inject.Binder}.
  *
@@ -25,11 +23,6 @@ import java.lang.annotation.Annotation;
  */
 public interface ScopedBindingBuilder {
 
-    /**
-     * See the EDSL examples at {@link org.elasticsearch.common.inject.Binder}.
-     */
-    void in(Class<? extends Annotation> scopeAnnotation);
-
     /**
      * Instructs the {@link org.elasticsearch.common.inject.Injector} to eagerly initialize this
      * singleton-scoped binding upon creation. Useful for application

+ 0 - 8
server/src/main/java/org/elasticsearch/common/inject/internal/AbstractBindingBuilder.java

@@ -21,9 +21,7 @@ import org.elasticsearch.common.inject.Key;
 import org.elasticsearch.common.inject.spi.Element;
 import org.elasticsearch.common.inject.spi.InstanceBinding;
 
-import java.lang.annotation.Annotation;
 import java.util.List;
-import java.util.Objects;
 
 /**
  * Bind a value or constant.
@@ -61,12 +59,6 @@ public abstract class AbstractBindingBuilder<T> {
         return binding;
     }
 
-    public void in(final Class<? extends Annotation> scopeAnnotation) {
-        Objects.requireNonNull(scopeAnnotation, "scopeAnnotation");
-        checkNotScoped();
-        setBinding(getBinding().withScoping(Scoping.forAnnotation(scopeAnnotation)));
-    }
-
     public void asEagerSingleton() {
         checkNotScoped();
         setBinding(getBinding().withScoping(Scoping.EAGER_SINGLETON));

+ 0 - 21
server/src/main/java/org/elasticsearch/common/inject/internal/Errors.java

@@ -21,7 +21,6 @@ import org.elasticsearch.common.inject.ConfigurationException;
 import org.elasticsearch.common.inject.CreationException;
 import org.elasticsearch.common.inject.Inject;
 import org.elasticsearch.common.inject.Key;
-import org.elasticsearch.common.inject.Provider;
 import org.elasticsearch.common.inject.ProvisionException;
 import org.elasticsearch.common.inject.Scope;
 import org.elasticsearch.common.inject.TypeLiteral;
@@ -197,22 +196,6 @@ public final class Errors {
         return addMessage("Binding to Provider is not allowed.");
     }
 
-    public Errors subtypeNotProvided(Class<? extends Provider<?>> providerType, Class<?> type) {
-        return addMessage("%s doesn't provide instances of %s.", providerType, type);
-    }
-
-    public Errors notASubtype(Class<?> implementationType, Class<?> type) {
-        return addMessage("%s doesn't extend %s.", implementationType, type);
-    }
-
-    public Errors recursiveImplementationType() {
-        return addMessage("@ImplementedBy points to the same class it annotates.");
-    }
-
-    public Errors recursiveProviderType() {
-        return addMessage("@ProvidedBy points to the same class it annotates.");
-    }
-
     public Errors missingRuntimeRetention(Object source) {
         return addMessage("Please annotate with @Retention(RUNTIME).%n" + " Bound at %s.", convert(source));
     }
@@ -266,10 +249,6 @@ public final class Errors {
         return addMessage("Scope %s is already bound to %s. Cannot bind %s.", existing, annotationType, scope);
     }
 
-    public Errors voidProviderMethod() {
-        return addMessage("Provider methods must return a value. Do not return void.");
-    }
-
     public Errors missingConstantValues() {
         return addMessage("Missing constant value. Please call to(...).");
     }

+ 0 - 97
server/src/main/java/org/elasticsearch/common/inject/internal/ProviderMethod.java

@@ -1,97 +0,0 @@
-/*
- * Copyright (C) 2008 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 org.elasticsearch.common.inject.internal;
-
-import org.elasticsearch.common.inject.Binder;
-import org.elasticsearch.common.inject.Exposed;
-import org.elasticsearch.common.inject.Key;
-import org.elasticsearch.common.inject.PrivateBinder;
-import org.elasticsearch.common.inject.Provider;
-import org.elasticsearch.common.inject.spi.ProviderWithDependencies;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.List;
-
-/**
- * A provider that invokes a method and returns its result.
- *
- * @author jessewilson@google.com (Jesse Wilson)
- */
-public class ProviderMethod<T> implements ProviderWithDependencies<T> {
-    private final Key<T> key;
-    private final Class<? extends Annotation> scopeAnnotation;
-    private final Object instance;
-    private final Method method;
-    private final List<Provider<?>> parameterProviders;
-    private final boolean exposed;
-
-    /**
-     * @param method the method to invoke. Its return type must be the same type as {@code key}.
-     */
-    ProviderMethod(
-        Key<T> key,
-        Method method,
-        Object instance,
-        List<Provider<?>> parameterProviders,
-        Class<? extends Annotation> scopeAnnotation
-    ) {
-        this.key = key;
-        this.scopeAnnotation = scopeAnnotation;
-        this.instance = instance;
-        this.method = method;
-        this.parameterProviders = parameterProviders;
-        this.exposed = method.getAnnotation(Exposed.class) != null;
-    }
-
-    public void configure(Binder binder) {
-        binder = binder.withSource(method);
-
-        if (scopeAnnotation != null) {
-            binder.bind(key).toProvider(this).in(scopeAnnotation);
-        } else {
-            binder.bind(key).toProvider(this);
-        }
-
-        if (exposed) {
-            // the cast is safe 'cause the only binder we have implements PrivateBinder. If there's a
-            // misplaced @Exposed, calling this will add an error to the binder's error queue
-            ((PrivateBinder) binder).expose(key);
-        }
-    }
-
-    @Override
-    public T get() {
-        Object[] parameters = new Object[parameterProviders.size()];
-        for (int i = 0; i < parameters.length; i++) {
-            parameters[i] = parameterProviders.get(i).get();
-        }
-
-        try {
-            // We know this cast is safe because T is the method's return type.
-            @SuppressWarnings({ "unchecked" })
-            T result = (T) method.invoke(instance, parameters);
-            return result;
-        } catch (IllegalAccessException e) {
-            throw new AssertionError(e);
-        } catch (InvocationTargetException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-}

+ 0 - 130
server/src/main/java/org/elasticsearch/common/inject/internal/ProviderMethodsModule.java

@@ -1,130 +0,0 @@
-/*
- * Copyright (C) 2008 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 org.elasticsearch.common.inject.internal;
-
-import org.elasticsearch.common.inject.Binder;
-import org.elasticsearch.common.inject.Key;
-import org.elasticsearch.common.inject.Module;
-import org.elasticsearch.common.inject.Provider;
-import org.elasticsearch.common.inject.Provides;
-import org.elasticsearch.common.inject.TypeLiteral;
-import org.elasticsearch.common.inject.spi.Message;
-import org.elasticsearch.common.inject.util.Modules;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Member;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-
-/**
- * Creates bindings to methods annotated with {@literal @}{@link Provides}. Use the scope and
- * binding annotations on the provider method to configure the binding.
- *
- * @author crazybob@google.com (Bob Lee)
- * @author jessewilson@google.com (Jesse Wilson)
- */
-public final class ProviderMethodsModule implements Module {
-    private final Object delegate;
-    private final TypeLiteral<?> typeLiteral;
-
-    private ProviderMethodsModule(Object delegate) {
-        this.delegate = Objects.requireNonNull(delegate, "delegate");
-        this.typeLiteral = TypeLiteral.get(this.delegate.getClass());
-    }
-
-    /**
-     * Returns a module which creates bindings for provider methods from the given module.
-     */
-    public static Module forModule(Module module) {
-        return forObject(module);
-    }
-
-    /**
-     * Returns a module which creates bindings for provider methods from the given object.
-     * This is useful notably for <a href="http://code.google.com/p/google-gin/">GIN</a>
-     */
-    public static Module forObject(Object object) {
-        // avoid infinite recursion, since installing a module always installs itself
-        if (object instanceof ProviderMethodsModule) {
-            return Modules.EMPTY_MODULE;
-        }
-
-        return new ProviderMethodsModule(object);
-    }
-
-    @Override
-    public synchronized void configure(Binder binder) {
-        for (ProviderMethod<?> providerMethod : getProviderMethods(binder)) {
-            providerMethod.configure(binder);
-        }
-    }
-
-    public List<ProviderMethod<?>> getProviderMethods(Binder binder) {
-        List<ProviderMethod<?>> result = new ArrayList<>();
-        for (Class<?> c = delegate.getClass(); c != Object.class; c = c.getSuperclass()) {
-            for (Method method : c.getMethods()) {
-                if (method.getAnnotation(Provides.class) != null) {
-                    result.add(createProviderMethod(binder, method));
-                }
-            }
-        }
-        return result;
-    }
-
-    <T> ProviderMethod<T> createProviderMethod(Binder binder, final Method method) {
-        binder = binder.withSource(method);
-        Errors errors = new Errors(method);
-
-        // prepare the parameter providers
-        List<Provider<?>> parameterProviders = new ArrayList<>();
-        List<TypeLiteral<?>> parameterTypes = typeLiteral.getParameterTypes(method);
-        Annotation[][] parameterAnnotations = method.getParameterAnnotations();
-        for (int i = 0; i < parameterTypes.size(); i++) {
-            Key<?> key = getKey(errors, parameterTypes.get(i), method, parameterAnnotations[i]);
-            parameterProviders.add(binder.getProvider(key));
-        }
-
-        @SuppressWarnings("unchecked") // Define T as the method's return type.
-        TypeLiteral<T> returnType = (TypeLiteral<T>) typeLiteral.getReturnType(method);
-
-        Key<T> key = getKey(errors, returnType, method, method.getAnnotations());
-        Class<? extends Annotation> scopeAnnotation = Annotations.findScopeAnnotation(errors, method.getAnnotations());
-
-        for (Message message : errors.getMessages()) {
-            binder.addError(message);
-        }
-
-        return new ProviderMethod<>(key, method, delegate, parameterProviders, scopeAnnotation);
-    }
-
-    static <T> Key<T> getKey(Errors errors, TypeLiteral<T> type, Member member, Annotation[] annotations) {
-        Annotation bindingAnnotation = Annotations.findBindingAnnotation(errors, member, annotations);
-        return bindingAnnotation == null ? Key.get(type) : Key.get(type, bindingAnnotation);
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        return o instanceof ProviderMethodsModule && ((ProviderMethodsModule) o).delegate == delegate;
-    }
-
-    @Override
-    public int hashCode() {
-        return delegate.hashCode();
-    }
-}

+ 0 - 8
server/src/main/java/org/elasticsearch/common/inject/spi/Elements.java

@@ -31,7 +31,6 @@ import org.elasticsearch.common.inject.binder.AnnotatedBindingBuilder;
 import org.elasticsearch.common.inject.internal.AbstractBindingBuilder;
 import org.elasticsearch.common.inject.internal.BindingBuilder;
 import org.elasticsearch.common.inject.internal.Errors;
-import org.elasticsearch.common.inject.internal.ProviderMethodsModule;
 import org.elasticsearch.common.inject.internal.SourceProvider;
 
 import java.lang.annotation.Annotation;
@@ -135,7 +134,6 @@ public final class Elements {
                         addError(e);
                     }
                 }
-                binder.install(ProviderMethodsModule.forModule(module));
             }
         }
 
@@ -192,12 +190,6 @@ public final class Elements {
             return new RecordingBinder(this, null, newSourceProvider);
         }
 
-        @Override
-        public void expose(Key<?> key) {
-            addError("Cannot expose %s on a standard binder. " + "Exposed bindings are only applicable to private binders.", key);
-
-        }
-
         private static final Logger logger = LogManager.getLogger(Elements.class);
 
         protected Object getSource() {

+ 1 - 2
server/src/main/java/org/elasticsearch/common/inject/spi/InjectionPoint.java

@@ -123,8 +123,7 @@ public final class InjectionPoint {
     /**
      * Returns true if this injection point shall be skipped if the injector cannot resolve bindings
      * for all required dependencies. Both explicit bindings (as specified in a module), and implicit
-     * bindings ({@literal @}{@link org.elasticsearch.common.inject.ImplementedBy ImplementedBy}, default
-     * constructors etc.) may be used to satisfy optional injection points.
+     * bindings by default constructors etc.) may be used to satisfy optional injection points.
      */
     public boolean isOptional() {
         return optional;

+ 0 - 32
server/src/main/java/org/elasticsearch/common/inject/util/Modules.java

@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2008 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 org.elasticsearch.common.inject.util;
-
-import org.elasticsearch.common.inject.Module;
-
-/**
- * Static utility methods for creating and working with instances of {@link Module}.
- *
- * @author jessewilson@google.com (Jesse Wilson)
- * @since 2.0
- */
-public final class Modules {
-    private Modules() {}
-
-    public static final Module EMPTY_MODULE = binder -> {};
-
-}