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


Java Parameter类代码示例

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


Parameter类属于com.google.common.reflect包,在下文中一共展示了Parameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildParamList

import com.google.common.reflect.Parameter; //导入依赖的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: generateEqualFactoryArguments

import com.google.common.reflect.Parameter; //导入依赖的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

示例3: getDummyArguments

import com.google.common.reflect.Parameter; //导入依赖的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

示例4: bind

import com.google.common.reflect.Parameter; //导入依赖的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

示例5: testAllAuroraSchedulerManagerIfaceMethodsHaveAuthorizingParam

import com.google.common.reflect.Parameter; //导入依赖的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

示例6: addExposedTypes

import com.google.common.reflect.Parameter; //导入依赖的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

示例7: eligibilityVerified

import com.google.common.reflect.Parameter; //导入依赖的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

示例8: generateEqualFactoryArguments

import com.google.common.reflect.Parameter; //导入依赖的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:google,项目名称:guava,代码行数:29,代码来源:ClassSanityTester.java

示例9: getDummyArguments

import com.google.common.reflect.Parameter; //导入依赖的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

示例10: handleInvocation

import com.google.common.reflect.Parameter; //导入依赖的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

示例11: hasInstanceMethodToTestNulls

import com.google.common.reflect.Parameter; //导入依赖的package包/类
private boolean hasInstanceMethodToTestNulls(Class<?> c, Visibility visibility) {
  for (Method method : nullPointerTester.getInstanceMethodsToTest(c, visibility)) {
    for (Parameter param : Invokable.from(method).getParameters()) {
      if (!NullPointerTester.isPrimitiveOrNullable(param)) {
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:11,代码来源:ClassSanityTester.java

示例12: testEqualsUsing

import com.google.common.reflect.Parameter; //导入依赖的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

示例13: generateDummyArg

import com.google.common.reflect.Parameter; //导入依赖的package包/类
@Nullable private static Object generateDummyArg(Parameter param, FreshValueGenerator generator)
    throws ParameterNotInstantiableException {
  if (param.isAnnotationPresent(Nullable.class)) {
    return null;
  }
  Object arg = generator.generateFresh(param.getType());
  if (arg == null) {
    throw new ParameterNotInstantiableException(param);
  }
  return arg;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:ClassSanityTester.java

示例14: of

import com.google.common.reflect.Parameter; //导入依赖的package包/类
public static GenericMethodType<?> of(Invokable<?, ?> invokable) {
    return new GenericMethodType<>(invokable.getReturnType(),
                                   invokable.getParameters()
                                            .stream()
                                            .map(Parameter::getType)
                                            .collect(Collectors.toImmutableList()));
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:8,代码来源:GenericMethodType.java

示例15: getArgumentTypes

import com.google.common.reflect.Parameter; //导入依赖的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


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