Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.google.inject.throwingproviders;
import static com.google.inject.throwingproviders.ProviderChecker.checkInterface;
import com.google.common.base.Optional;
import com.google.inject.TypeLiteral;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;
/**
* Static utility methods for creating and working with instances of {@link CheckedProvider}.
*
* @author [email protected] (Russ Harmon)
* @since 4.2
*/
public final class CheckedProviders {
private abstract static class CheckedProviderInvocationHandler implements InvocationHandler {
private boolean isGetMethod(Method method) {
// Since Java does not allow multiple methods with the same name and number & type of
// arguments, this is all we need to check to see if it is an overriding method of
// CheckedProvider#get().
return method.getName().equals("get") && method.getParameterTypes().length == 0;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getDeclaringClass() == Object.class) {
return method.invoke(this, args);
} else if (isGetMethod(method)) {
return invokeGet(proxy, method);
}
throw new UnsupportedOperationException(
String.format(
"Unsupported method <%s> with args <%s> invoked on <%s>",
method, Arrays.toString(args), proxy));
}
protected abstract T invokeGet(Object proxy, Method method) throws Throwable;
@Override
public abstract String toString();
}
private static final class ReturningHandler extends CheckedProviderInvocationHandler {
private final T returned;
ReturningHandler(T returned) {
this.returned = returned;
}
@Override
protected T invokeGet(Object proxy, Method method) throws Throwable {
return returned;
}
@Override
public String toString() {
return String.format("generated CheckedProvider returning <%s>", returned);
}
}
private static final class ThrowingHandler extends CheckedProviderInvocationHandler