当前位置: 首页>>代码示例>>Java>>正文


Java Invokable类代码示例

本文整理汇总了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;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:18,代码来源:NullPointerTester.java

示例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;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:26,代码来源:ClassSanityTester.java

示例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;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:25,代码来源:ClassSanityTester.java

示例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;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:29,代码来源:ClassSanityTester.java

示例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;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:17,代码来源:ClassSanityTester.java

示例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;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:17,代码来源:Methods.java

示例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");
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:19,代码来源:Delegates.java

示例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);
}
 
开发者ID:wangyuntao,项目名称:reflect,代码行数:17,代码来源:Example.java

示例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);
}
 
开发者ID:keepcosmos,项目名称:beanmother,代码行数:23,代码来源:SetterAndFieldFixtureMapper.java

示例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());
  }
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:24,代码来源:AnnotatedAuroraAdminTest.java

示例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);
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:25,代码来源:ApiSurface.java

示例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;
}
 
开发者ID:apache,项目名称:beam,代码行数:19,代码来源:ApiSurface.java

示例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();
}
 
开发者ID:immutables,项目名称:miscellaneous,代码行数:21,代码来源:Providers.java

示例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();
}
 
开发者ID:immutables,项目名称:miscellaneous,代码行数:24,代码来源:Providers.java

示例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();
}
 
开发者ID:immutables,项目名称:miscellaneous,代码行数:20,代码来源:Providers.java


注:本文中的com.google.common.reflect.Invokable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。