All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.inject.spi.StaticInjectionRequest Maven / Gradle / Ivy

package com.google.inject.spi;

import com.google.inject.Binder;
import com.google.inject.ConfigurationException;

import java.util.Set;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * A request to inject the static fields and methods of a type. Requests are created
 * explicitly in a module using {@link com.google.inject.Binder#requestStaticInjection(Class[])
 * requestStaticInjection()} statements:
 * 
 *     requestStaticInjection(MyLegacyService.class);
* */ public final class StaticInjectionRequest implements Element { private final Object source; private final Class type; StaticInjectionRequest(Object source, Class type) { this.source = checkNotNull(source, "source"); this.type = checkNotNull(type, "type"); } public Object getSource() { return source; } public Class getType() { return type; } /** * Returns the static methods and fields of {@code type} that will be injected to fulfill this * request. * * @return a possibly empty set of injection points. The set has a specified iteration order. All * fields are returned and then all methods. Within the fields, supertype fields are returned * before subtype fields. Similarly, supertype methods are returned before subtype methods. * @throws ConfigurationException if there is a malformed injection point on {@code type}, such as * a field with multiple binding annotations. The exception's {@link * ConfigurationException#getPartialValue() partial value} is a {@code * Set} * of the valid injection points. */ public Set getInjectionPoints() throws ConfigurationException { return InjectionPoint.forStaticMethodsAndFields(type); } public void applyTo(Binder binder) { binder.withSource(getSource()).requestStaticInjection(type); } public T acceptVisitor(ElementVisitor visitor) { return visitor.visit(this); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy