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


Java Invokable.getParameters方法代码示例

本文整理汇总了Java中com.google.common.reflect.Invokable.getParameters方法的典型用法代码示例。如果您正苦于以下问题:Java Invokable.getParameters方法的具体用法?Java Invokable.getParameters怎么用?Java Invokable.getParameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.reflect.Invokable的用法示例。


在下文中一共展示了Invokable.getParameters方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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 (isNullable(param)) {
      args.add(null);
      continue;
    }
    Object defaultValue = getDummyValue(param.getType());
    if (defaultValue == null) {
      throw new ParameterNotInstantiableException(param);
    }
    args.add(defaultValue);
  }
  return args;
}
 
开发者ID:google,项目名称:guava,代码行数:17,代码来源:ClassSanityTester.java

示例7: handleInvocation

import com.google.common.reflect.Invokable; //导入方法依赖的package包/类
@Override protected Object handleInvocation(
    Object proxy, Method method, Object[] args) {
  Invokable<?, ?> invokable = interfaceType.method(method);
  ImmutableList<Parameter> params = invokable.getParameters();
  for (int i = 0; i < args.length; i++) {
    Parameter param = params.get(i);
    if (!param.isAnnotationPresent(Nullable.class)) {
      checkNotNull(args[i]);
    }
  }
  return dummyReturnValue(interfaceType.resolveType(method.getGenericReturnType()));
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:13,代码来源:DummyProxy.java

示例8: testEqualsUsing

import com.google.common.reflect.Invokable; //导入方法依赖的package包/类
private void testEqualsUsing(final Invokable<?, ?> factory)

      throws ParameterNotInstantiableException, ParameterHasNoDistinctValueException,
             IllegalAccessException, InvocationTargetException, FactoryMethodReturnsNullException {
    List<Parameter> params = factory.getParameters();
    List<FreshValueGenerator> argGenerators = Lists.newArrayListWithCapacity(params.size());
    List<Object> args = Lists.newArrayListWithCapacity(params.size());
    for (Parameter param : params) {
      FreshValueGenerator generator = newFreshValueGenerator();
      argGenerators.add(generator);
      args.add(generateDummyArg(param, generator));
    }
    Object instance = createInstance(factory, args);
    List<Object> equalArgs = generateEqualFactoryArguments(factory, params, args);
    // Each group is a List of items, each item has a list of factory args.
    final List<List<List<Object>>> argGroups = Lists.newArrayList();
    argGroups.add(ImmutableList.of(args, equalArgs));
    EqualsTester tester = new EqualsTester(new ItemReporter() {
      @Override String reportItem(Item<?> item) {
        List<Object> factoryArgs = argGroups.get(item.groupNumber).get(item.itemNumber);
        return factory.getName() + "(" + Joiner.on(", ").useForNull("null").join(factoryArgs) + ")";
      }
    });
    tester.addEqualityGroup(instance, createInstance(factory, equalArgs));
    for (int i = 0; i < params.size(); i++) {
      List<Object> newArgs = Lists.newArrayList(args);
      Object newArg = argGenerators.get(i).generateFresh(params.get(i).getType());

      if (newArg == null || Objects.equal(args.get(i), newArg)) {
        if (params.get(i).getType().getRawType().isEnum()) {
          continue; // Nothing better we can do if it's single-value enum
        }
        throw new ParameterHasNoDistinctValueException(params.get(i));
      }
      newArgs.set(i, newArg);
      tester.addEqualityGroup(createInstance(factory, newArgs));
      argGroups.add(ImmutableList.of(newArgs));
    }
    tester.testEquals();
  }
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:41,代码来源:ClassSanityTester.java

示例9: getArgumentTypes

import com.google.common.reflect.Invokable; //导入方法依赖的package包/类
/**
 * Returns a list of argument types for the given method, which must
 * be a part of the class.
 */
public List<TypeDescriptor<?>> getArgumentTypes(Method method) {
  Invokable<?, ?> typedMethod = token.method(method);

  List<TypeDescriptor<?>> argTypes = Lists.newArrayList();
  for (Parameter parameter : typedMethod.getParameters()) {
    argTypes.add(new SimpleTypeDescriptor<>(parameter.getType()));
  }
  return argTypes;
}
 
开发者ID:apache,项目名称:beam,代码行数:14,代码来源:TypeDescriptor.java

示例10: providerFor

import com.google.common.reflect.Invokable; //导入方法依赖的package包/类
private EventualProvider<?> providerFor(Invokable<T, ?> method, Errors methodErrors) {
  Annotation[] annotations = method.getAnnotations();

  verifyMethodAccessibility(methodErrors, method, source);

  @Nullable Annotation bindingAnnotation =
      Annotations.findBindingAnnotation(methodErrors, method, annotations);

  verifyAbsenseOfScopeAnnotation(methodErrors, annotations, source);

  List<Dependency<ListenableFuture<?>>> dependencies =
      Lists.newArrayListWithCapacity(method.getParameters().size());

  for (Parameter parameter : method.getParameters()) {
    dependencies.add(extractDependency(methodErrors, parameter));
  }

  Key<ListenableFuture<?>> bindingKey;
  boolean exposedBinding = method.isAnnotationPresent(Exposed.class);

  if (isVoid(method)) {
    bindingKey = futureKey(TypeToken.of(Boolean.class), new BlackholedAnnotation());
    exposedBinding = false;
  } else {
    bindingKey = futureKey(method.getReturnType(), bindingAnnotation);
  }

  return new EventualProvider<>(
      method,
      exposedBinding,
      dependencies,
      bindingKey,
      scopeAnnotation,
      source);
}
 
开发者ID:immutables,项目名称:miscellaneous,代码行数:36,代码来源:Providers.java

示例11: MethodBinder

import com.google.common.reflect.Invokable; //导入方法依赖的package包/类
public MethodBinder(Invokable<T, R> from)
{

  this.method = from;
  int positional = 0;

  for (Parameter p : from.getParameters())
  {
    if (p.getAnnotation(GQLContext.class) != null)
    {
      this.contextual.put(p.getType(), p);
      args.add((generator) -> generator.context(p));
    }
    else if (p.getAnnotation(GQLArg.class) != null)
    {
      final GQLArg arg = p.getAnnotation(GQLArg.class);
      named.put(arg.value(), p);
      args.add((generator) -> generator.named(arg.value(), p));
    }
    else
    {
      final int mpos = positional;
      this.positional.add(p);
      args.add((generator) -> generator.positional(mpos, p));
    }
  }

}
 
开发者ID:zourzouvillys,项目名称:graphql,代码行数:29,代码来源:MethodBinder.java

示例12: handleInvocation

import com.google.common.reflect.Invokable; //导入方法依赖的package包/类
@Override
protected Object handleInvocation(Object proxy, Method method, Object[] args) {
  Invokable<?, ?> invokable = interfaceType.method(method);
  ImmutableList<Parameter> params = invokable.getParameters();
  for (int i = 0; i < args.length; i++) {
    Parameter param = params.get(i);
    if (!isNullable(param)) {
      checkNotNull(args[i]);
    }
  }
  return dummyReturnValue(interfaceType.resolveType(method.getGenericReturnType()));
}
 
开发者ID:google,项目名称:guava,代码行数:13,代码来源:DummyProxy.java

示例13: allNonDeprecatedMethodsTakeOptions

import com.google.common.reflect.Invokable; //导入方法依赖的package包/类
@Test
public void allNonDeprecatedMethodsTakeOptions() throws IOException, NoSuchMethodException {
	for (Class aClass : getAllModels()) {
		HashSet<Class<?>> interfaces = new HashSet<Class<?>>(Arrays.<Class<?>>asList(aClass.getInterfaces()));
		for (Method method : aClass.getMethods()) {
			// Skip methods not declared on the base class.
			if (method.getDeclaringClass() != aClass) {
				continue;
			}
			// Skip equals
			if (method.getName().equals("equals")) {
				continue;
			}
			// Skip setters
			if (method.getName().startsWith("set")) {
				continue;
			}
			// Skip getters
			if (method.getName().startsWith("get")) {
				continue;
			}

			// If more than one method with the same parameter types is declared in a class, and one of these
			// methods has a return type that is more specific than any of the others, that method is returned;
			// otherwise one of the methods is chosen arbitrarily.
			Method mostSpecificMethod = aClass.getDeclaredMethod(method.getName(), method.getParameterTypes());
			if (!method.equals(mostSpecificMethod)) {
				continue;
			}

			Invokable<?, Object> invokable = Invokable.from(method);
			// Skip private methods.
			if (invokable.isPrivate()) {
				continue;
			}
			// Skip deprecated methods - we need to keep them around, but aren't asserting their type.
			if (invokable.isAnnotationPresent(Deprecated.class)) {
				continue;
			}
			ImmutableList<Parameter> parameters = invokable.getParameters();
			// Skip empty parameter lists - assume the author is using default values for the RequestOptions
			if (parameters.isEmpty()) {
				continue;
			}
			Parameter lastParam = parameters.get(parameters.size() - 1);
			Class<?> finalParamType = lastParam.getType().getRawType();

			// Skip methods that have exactly one param which is a map.
			if (Map.class.equals(finalParamType) && parameters.size() == 1) {
				continue;
			}

			// Skip `public static Foo retrieve(String id) {...` helper methods
			if (String.class.equals(finalParamType) && parameters.size() == 1 && "retrieve".equals(method.getName())) {
				continue;
			}

			// Skip the `public static Card createCard(String id) {...` helper method on Customer.
			if (String.class.equals(finalParamType) && parameters.size() == 1 && "createCard".equals(method.getName())) {
				continue;
			}

			if (RequestOptions.class.isAssignableFrom(finalParamType)) {
				continue;
			}
			Assert.assertTrue(
					String.format("Methods on %ss like %s.%s should take a final parameter as a %s parameter.%n", APIResource.class.getSimpleName(), aClass.getSimpleName(), method.getName(), RequestOptions.class.getSimpleName()),
					RequestOptions.class.isAssignableFrom(finalParamType));
		}
	}
}
 
开发者ID:payjp,项目名称:payjp-java,代码行数:72,代码来源:StandardizationTest.java

示例14: testEqualsUsing

import com.google.common.reflect.Invokable; //导入方法依赖的package包/类
private void testEqualsUsing(final Invokable<?, ?> factory)
    throws ParameterNotInstantiableException, ParameterHasNoDistinctValueException,
        IllegalAccessException, InvocationTargetException, FactoryMethodReturnsNullException {
  List<Parameter> params = factory.getParameters();
  List<FreshValueGenerator> argGenerators = Lists.newArrayListWithCapacity(params.size());
  List<Object> args = Lists.newArrayListWithCapacity(params.size());
  for (Parameter param : params) {
    FreshValueGenerator generator = newFreshValueGenerator();
    argGenerators.add(generator);
    args.add(generateDummyArg(param, generator));
  }
  Object instance = createInstance(factory, args);
  List<Object> equalArgs = generateEqualFactoryArguments(factory, params, args);
  // Each group is a List of items, each item has a list of factory args.
  final List<List<List<Object>>> argGroups = Lists.newArrayList();
  argGroups.add(ImmutableList.of(args, equalArgs));
  EqualsTester tester =
      new EqualsTester(
          new ItemReporter() {
            @Override
            String reportItem(Item<?> item) {
              List<Object> factoryArgs = argGroups.get(item.groupNumber).get(item.itemNumber);
              return factory.getName()
                  + "("
                  + Joiner.on(", ").useForNull("null").join(factoryArgs)
                  + ")";
            }
          });
  tester.addEqualityGroup(instance, createInstance(factory, equalArgs));
  for (int i = 0; i < params.size(); i++) {
    List<Object> newArgs = Lists.newArrayList(args);
    Object newArg = argGenerators.get(i).generateFresh(params.get(i).getType());

    if (newArg == null || Objects.equal(args.get(i), newArg)) {
      if (params.get(i).getType().getRawType().isEnum()) {
        continue; // Nothing better we can do if it's single-value enum
      }
      throw new ParameterHasNoDistinctValueException(params.get(i));
    }
    newArgs.set(i, newArg);
    tester.addEqualityGroup(createInstance(factory, newArgs));
    argGroups.add(ImmutableList.of(newArgs));
  }
  tester.testEquals();
}
 
开发者ID:google,项目名称:guava,代码行数:46,代码来源:ClassSanityTester.java


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