本文整理汇总了Java中com.google.common.reflect.Invokable类的典型用法代码示例。如果您正苦于以下问题:Java Invokable类的具体用法?Java Invokable怎么用?Java Invokable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Invokable类属于com.google.common.reflect包,在下文中一共展示了Invokable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildParamList
import com.google.common.reflect.Invokable; //导入依赖的package包/类
private Object[] buildParamList(Invokable<?, ?> invokable, int indexOfParamToSetToNull) {
ImmutableList<Parameter> params = invokable.getParameters();
Object[] args = new Object[params.size()];
for (int i = 0; i < args.length; i++) {
Parameter param = params.get(i);
if (i != indexOfParamToSetToNull) {
args[i] = getDefaultValue(param.getType());
Assert.assertTrue(
"Can't find or create a sample instance for type '"
+ param.getType()
+ "'; please provide one using NullPointerTester.setDefault()",
args[i] != null || isNullable(param));
}
}
return args;
}
示例2: testNulls
import com.google.common.reflect.Invokable; //导入依赖的package包/类
/**
* Tests null checks against the instance methods of the return values, if any.
*
* <p>Test fails if default value cannot be determined for a constructor or factory method
* parameter, or if the constructor or factory method throws exception.
*
* @return this tester
*/
public FactoryMethodReturnValueTester testNulls() throws Exception {
for (Invokable<?, ?> factory : getFactoriesToTest()) {
Object instance = instantiate(factory);
if (instance != null
&& packagesToTest.contains(Reflection.getPackageName(instance.getClass()))) {
try {
nullPointerTester.testAllPublicInstanceMethods(instance);
} catch (AssertionError e) {
AssertionError error = new AssertionFailedError(
"Null check failed on return value of " + factory);
error.initCause(e);
throw error;
}
}
}
return this;
}
示例3: testSerializable
import com.google.common.reflect.Invokable; //导入依赖的package包/类
/**
* Runs serialization test on the return values of the static methods.
*
* <p>Test fails if default value cannot be determined for a constructor or factory method
* parameter, or if the constructor or factory method throws exception.
*
* @return this tester
*/
public FactoryMethodReturnValueTester testSerializable() throws Exception {
for (Invokable<?, ?> factory : getFactoriesToTest()) {
Object instance = instantiate(factory);
if (instance != null) {
try {
SerializableTester.reserialize(instance);
} catch (RuntimeException e) {
AssertionError error = new AssertionFailedError(
"Serialization failed on return value of " + factory);
error.initCause(e.getCause());
throw error;
}
}
}
return this;
}
示例4: generateEqualFactoryArguments
import com.google.common.reflect.Invokable; //导入依赖的package包/类
/**
* Returns dummy factory arguments that are equal to {@code args} but may be different instances,
* to be used to construct a second instance of the same equality group.
*/
private List<Object> generateEqualFactoryArguments(
Invokable<?, ?> factory, List<Parameter> params, List<Object> args)
throws ParameterNotInstantiableException, FactoryMethodReturnsNullException,
InvocationTargetException, IllegalAccessException {
List<Object> equalArgs = Lists.newArrayList(args);
for (int i = 0; i < args.size(); i++) {
Parameter param = params.get(i);
Object arg = args.get(i);
// Use new fresh value generator because 'args' were populated with new fresh generator each.
// Two newFreshValueGenerator() instances should normally generate equal value sequence.
Object shouldBeEqualArg = generateDummyArg(param, newFreshValueGenerator());
if (arg != shouldBeEqualArg
&& Objects.equal(arg, shouldBeEqualArg)
&& hashCodeInsensitiveToArgReference(factory, args, i, shouldBeEqualArg)
&& hashCodeInsensitiveToArgReference(
factory, args, i, generateDummyArg(param, newFreshValueGenerator()))) {
// If the implementation uses identityHashCode(), referential equality is
// probably intended. So no point in using an equal-but-different factory argument.
// We check twice to avoid confusion caused by accidental hash collision.
equalArgs.set(i, shouldBeEqualArg);
}
}
return equalArgs;
}
示例5: getDummyArguments
import com.google.common.reflect.Invokable; //导入依赖的package包/类
private List<Object> getDummyArguments(Invokable<?, ?> invokable)
throws ParameterNotInstantiableException {
List<Object> args = Lists.newArrayList();
for (Parameter param : invokable.getParameters()) {
if (param.isAnnotationPresent(Nullable.class)) {
args.add(null);
continue;
}
Object defaultValue = getDummyValue(param.getType());
if (defaultValue == null) {
throw new ParameterNotInstantiableException(param);
}
args.add(defaultValue);
}
return args;
}
示例6: invocationFailureReason
import com.google.common.reflect.Invokable; //导入依赖的package包/类
private static @Nullable String invocationFailureReason(Invokable<?, ?> to, Invokable<?, ?> from) {
final String reason = invocationFailureReason(methodType(to), methodType(from));
if(reason != null) return reason;
thrownLoop: for(TypeToken<? extends Throwable> thrown : from.getExceptionTypes()) {
final Class<?> thrownRaw = thrown.getRawType();
if(Error.class.isAssignableFrom(thrownRaw)) continue;
if(RuntimeException.class.isAssignableFrom(thrownRaw)) continue ;
for(TypeToken<? extends Throwable> caught : to.getExceptionTypes()) {
if(caught.getRawType().isAssignableFrom(thrownRaw)) continue thrownLoop;
}
return "unhandled exception " + thrown.getRawType().getName();
}
return null;
}
示例7: createHandle
import com.google.common.reflect.Invokable; //导入依赖的package包/类
@Override
MethodHandle createHandle(Method rawProxyMethod, Invokable<T, ?> proxyMethod) throws ReflectiveOperationException {
if(proxyMethod.getReturnType().getRawType().equals(void.class)) {
if(proxyMethod.getParameters().size() == 1) {
return lookup.findStaticSetter(targetType,
proxyMethod.getName(),
proxyMethod.getParameters().get(0).getType().getRawType());
}
} else {
if(proxyMethod.getParameters().isEmpty()) {
return lookup.findStaticGetter(targetType,
proxyMethod.getName(),
proxyMethod.getReturnType().getRawType());
}
}
throw new MethodFormException(rawProxyMethod, "Field delegate method does not have a getter or setter signature");
}
示例8: methods
import com.google.common.reflect.Invokable; //导入依赖的package包/类
private static void methods() {
Methods ms1 = Scanner.paths("/io/ytcode/reflect/").scan().classes().methods();
Methods ms2 =
ms1.filter(
new Predicate<Method>() {
@Override
public boolean apply(Method m) {
return Invokable.from(m).isPublic();
}
});
System.out.println(ms2);
Methods ms3 = ms1.modifiers(Modifier.PUBLIC, Modifier.STATIC);
System.out.println(ms3);
}
示例9: bind
import com.google.common.reflect.Invokable; //导入依赖的package包/类
@Override
protected void bind(Object target, String key, FixtureMap fixtureMap) {
List<Method> candidates = findSetterCandidates(target, key);
for (Method candidate : candidates) {
ImmutableList<Parameter> paramTypes = Invokable.from(candidate).getParameters();
if (paramTypes.size() != 1) continue;
TypeToken<?> paramType = paramTypes.get(0).getType();
try {
Object candidateParam = getFixtureConverter().convert(fixtureMap, paramType);
if (candidateParam != null) {
candidate.invoke(target, candidateParam);
return;
}
} catch (Exception e) {
throw new FixtureMappingException(e);
}
}
bindByField(target, key, fixtureMap);
}
示例10: testAllAuroraSchedulerManagerIfaceMethodsHaveAuthorizingParam
import com.google.common.reflect.Invokable; //导入依赖的package包/类
@Test
public void testAllAuroraSchedulerManagerIfaceMethodsHaveAuthorizingParam() throws Exception {
for (Method declaredMethod : AuroraSchedulerManager.Iface.class.getDeclaredMethods()) {
Invokable<?, ?> invokable = Invokable.from(declaredMethod);
Collection<Parameter> parameters = invokable.getParameters();
Invokable<?, ?> annotatedInvokable = Invokable.from(
AnnotatedAuroraAdmin.class.getDeclaredMethod(
invokable.getName(),
FluentIterable.from(parameters)
.transform(input -> input.getType().getRawType())
.toList()
.toArray(new Class<?>[0])));
Collection<Parameter> annotatedParameters = Collections2.filter(
annotatedInvokable.getParameters(),
input -> input.getAnnotation(AuthorizingParam.class) != null);
assertFalse(
"Method " + invokable + " should have at least 1 " + AuthorizingParam.class.getName()
+ " annotation but none were found.",
annotatedParameters.isEmpty());
}
}
示例11: addExposedTypes
import com.google.common.reflect.Invokable; //导入依赖的package包/类
private void addExposedTypes(Invokable<?, ?> invokable, Class<?> cause) {
addExposedTypes(invokable.getReturnType(), cause);
for (Annotation annotation : invokable.getAnnotations()) {
LOG.debug(
"Adding exposed types from {}, which is an annotation on invokable {}",
annotation,
invokable);
addExposedTypes(annotation.annotationType(), cause);
}
for (Parameter parameter : invokable.getParameters()) {
LOG.debug(
"Adding exposed types from {}, which is a parameter on invokable {}",
parameter,
invokable);
addExposedTypes(parameter, cause);
}
for (TypeToken<?> exceptionType : invokable.getExceptionTypes()) {
LOG.debug(
"Adding exposed types from {}, which is an exception type on invokable {}",
exceptionType,
invokable);
addExposedTypes(exceptionType, cause);
}
}
示例12: getExposedInvokables
import com.google.common.reflect.Invokable; //导入依赖的package包/类
/** Returns an {@link Invokable} for each public methods or constructors of a type. */
private Set<Invokable> getExposedInvokables(TypeToken<?> type) {
Set<Invokable> invokables = Sets.newHashSet();
for (Constructor constructor : type.getRawType().getConstructors()) {
if (0 != (constructor.getModifiers() & (Modifier.PUBLIC | Modifier.PROTECTED))) {
invokables.add(type.constructor(constructor));
}
}
for (Method method : type.getRawType().getMethods()) {
if (0 != (method.getModifiers() & (Modifier.PUBLIC | Modifier.PROTECTED))) {
invokables.add(type.method(method));
}
}
return invokables;
}
示例13: introspectProviders
import com.google.common.reflect.Invokable; //导入依赖的package包/类
private ImmutableList<EventualProvider<?>> introspectProviders() {
ImmutableList.Builder<EventualProvider<?>> builder = ImmutableList.builder();
// FIXME handle method overriding?
for (Class<?> t : type.getTypes().classes().rawTypes()) {
if (t != Object.class) {
for (Method m : t.getDeclaredMethods()) {
if (m.isAnnotationPresent(Eventually.Provides.class)) {
Errors methodErrors = errors.withSource(StackTraceElements.forMember(m));
Invokable<T, Object> invokable = type.method(m);
if (eligibilityVerified(invokable, methodErrors)) {
builder.add(providerFor(invokable, methodErrors));
}
}
}
}
}
return builder.build();
}
示例14: eligibilityVerified
import com.google.common.reflect.Invokable; //导入依赖的package包/类
private boolean eligibilityVerified(Invokable<T, Object> method, Errors errors) {
List<TypeToken<?>> primitiveTypes = Lists.newArrayList();
for (Parameter parameter : method.getParameters()) {
if (parameter.getType().isPrimitive()) {
primitiveTypes.add(parameter.getType());
}
}
if (method.getReturnType().isPrimitive() && !isVoid(method)) {
primitiveTypes.add(method.getReturnType());
}
if (!primitiveTypes.isEmpty()) {
errors.addMessage("Incompartible eventual provider method '%s'"
+ "\n\tSignature has primitive types: %s."
+ " Please use boxed types instead",
method.getName(),
Joiner.on(", ").join(primitiveTypes));
}
return primitiveTypes.isEmpty();
}
示例15: EventualProvider
import com.google.common.reflect.Invokable; //导入依赖的package包/类
EventualProvider(
Invokable<T, ?> method,
boolean exposedBinding,
List<Dependency<ListenableFuture<?>>> dependencies,
Key<ListenableFuture<?>> bindingKey,
@Nullable Class<? extends Annotation> scopeAnnotation,
Object source) {
this.method = method;
this.source = source;
this.exposedBinding = exposedBinding;
this.bindingKey = bindingKey;
this.scopeAnnotation = scopeAnnotation;
this.dependencies = ImmutableList.copyOf(dependencies);
this.dependencySet = ImmutableSet.<Dependency<?>>builder()
.addAll(dependencies)
.add(Dependency.get(Key.get(Injector.class)))
.add(Dependency.get(Key.get(type.getRawType())))
.build();
}