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


Java Errors.throwConfigurationExceptionIfErrorsExist方法代码示例

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


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

示例1: configure

import com.google.inject.internal.Errors; //导入方法依赖的package包/类
@Override
protected void configure()
{
	final Errors errors = new Errors(testClass);

	for (FrameworkField field : fields)
	{
		try
		{
			final Field f = field.getField();
			final Key key = Annotations.getKey(TypeLiteral.get(f.getGenericType()), f, field.getAnnotations(), errors);

			bindMock(key, f.getType(), "Automock[" + field.getName() + "] " + key);
		}
		catch (ErrorsException e)
		{
			// Add it to the error list and hold them all until the end
			errors.merge(e.getErrors());
		}
	}

	errors.throwConfigurationExceptionIfErrorsExist();
}
 
开发者ID:petergeneric,项目名称:stdlib,代码行数:24,代码来源:AutomockAnnotatedMockModule.java

示例2: matchMethods

import com.google.inject.internal.Errors; //导入方法依赖的package包/类
private void matchMethods(Key<?> factoryKey) throws ErrorsException {
    Errors errors = new Errors();
    dependencies.add(new Dependency(Dependency.GINJECTOR, factoryKey, getContext()));
    Class<?> factoryRawType = factoryType.getRawType();

    // getMethods() includes inherited methods from super-interfaces.
    for (Method method : factoryRawType.getMethods()) {
        Key<?> returnType = getKey(factoryType.getReturnType(method), method, method.getAnnotations(), errors);

        // Get parameters with annotations.
        List<TypeLiteral<?>> params = factoryType.getParameterTypes(method);
        Annotation[][] paramAnnotations = method.getParameterAnnotations();
        int p = 0;
        List<Key<?>> paramList = new ArrayList<Key<?>>();
        for (TypeLiteral<?> param : params) {
            Key<?> paramKey = getKey(param, method, paramAnnotations[p++], errors);
            paramList.add(assistKey(method, paramKey, errors));
        }

        // Try to match up the method to the constructor.
        TypeLiteral<?> implementation = collector.get(returnType);
        if (implementation == null) {
            implementation = returnType.getTypeLiteral();
        }
        Constructor<?> constructor = findMatchingConstructor(method, implementation, paramList, errors);

        if (constructor == null) {
            continue; // Errors are collected and thrown below.
        }

        // Calculate a map from method to constructor parameters and required
        // keys.
        String[] parameterNames = extractConstructorParameters(factoryKey, implementation, constructor, paramList, errors, dependencies);

        TypeLiteral<?> methodDeclaringType = factoryType.getSupertype(method.getDeclaringClass());
        assistData.add(new AssistData(implementation, MethodLiteral.get(constructor, implementation), MethodLiteral.get(method, methodDeclaringType),
                parameterNames));
        implementations.add(implementation);

        dependencies.addAll(guiceUtil.getMemberInjectionDependencies(factoryKey, implementation));
    }

    errors.throwConfigurationExceptionIfErrorsExist();
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:45,代码来源:FactoryBinding.java

示例3: matchMethods

import com.google.inject.internal.Errors; //导入方法依赖的package包/类
private void matchMethods(Key<?> factoryKey) throws ErrorsException {
  Errors errors = new Errors();
  dependencies.add(new Dependency(Dependency.GINJECTOR, factoryKey, getContext()));
  Class<?> factoryRawType = factoryType.getRawType();

  // getMethods() includes inherited methods from super-interfaces.
  for (Method method : factoryRawType.getMethods()) {
    Key<?> returnType = getKey(factoryType.getReturnType(method), method,
        method.getAnnotations(), errors);

    // Get parameters with annotations.
    List<TypeLiteral<?>> params = factoryType.getParameterTypes(method);
    Annotation[][] paramAnnotations = method.getParameterAnnotations();
    int p = 0;
    List<Key<?>> paramList = new ArrayList<Key<?>>();
    for (TypeLiteral<?> param : params) {
      Key<?> paramKey = getKey(param, method, paramAnnotations[p++], errors);
      paramList.add(assistKey(method, paramKey, errors));
    }

    // Try to match up the method to the constructor.
    TypeLiteral<?> implementation = collector.get(returnType);
    if (implementation == null) {
      implementation = returnType.getTypeLiteral();
    }
    Constructor<?> constructor =
        findMatchingConstructor(method, implementation, paramList, errors);

    if (constructor == null) {
      continue; // Errors are collected and thrown below.
    }

    // Calculate a map from method to constructor parameters and required
    // keys.
    String[] parameterNames = extractConstructorParameters(factoryKey, 
        implementation, constructor, paramList, errors, dependencies);

    TypeLiteral<?> methodDeclaringType = factoryType.getSupertype(method.getDeclaringClass());
    assistData.add(new AssistData(implementation, MethodLiteral.get(constructor, implementation),
        MethodLiteral.get(method, methodDeclaringType), parameterNames));
    implementations.add(implementation);

    dependencies.addAll(guiceUtil.getMemberInjectionDependencies(factoryKey, implementation));
  }

  errors.throwConfigurationExceptionIfErrorsExist();
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:48,代码来源:FactoryBinding.java

示例4: forConstructorOf

import com.google.inject.internal.Errors; //导入方法依赖的package包/类
/**
 * Returns a new injection point for the injectable constructor of {@code type}.
 *
 * @param type a concrete type with exactly one constructor annotated {@literal @}{@link Inject},
 *     or a no-arguments constructor that is not private.
 * @throws ConfigurationException if there is no injectable constructor, more than one injectable
 *     constructor, or if parameters of the injectable constructor are malformed, such as a
 *     parameter with multiple binding annotations.
 */
public static InjectionPoint forConstructorOf(TypeLiteral<?> type) {
  Class<?> rawType = getRawType(type.getType());
  Errors errors = new Errors(rawType);

  Constructor<?> injectableConstructor = null;
  for (Constructor<?> constructor : rawType.getDeclaredConstructors()) {

    boolean optional;
    Inject guiceInject = constructor.getAnnotation(Inject.class);
    if (guiceInject == null) {
      javax.inject.Inject javaxInject = constructor.getAnnotation(javax.inject.Inject.class);
      if (javaxInject == null) {
        continue;
      }
      optional = false;
    } else {
      optional = guiceInject.optional();
    }

    if (optional) {
      errors.optionalConstructor(constructor);
    }

    if (injectableConstructor != null) {
      errors.tooManyConstructors(rawType);
    }

    injectableConstructor = constructor;
    checkForMisplacedBindingAnnotations(injectableConstructor, errors);
  }

  errors.throwConfigurationExceptionIfErrorsExist();

  if (injectableConstructor != null) {
    return new InjectionPoint(type, injectableConstructor);
  }

  // If no annotated constructor is found, look for a no-arg constructor instead.
  try {
    Constructor<?> noArgConstructor = rawType.getDeclaredConstructor();

    // Disallow private constructors on non-private classes (unless they have @Inject)
    if (Modifier.isPrivate(noArgConstructor.getModifiers())
        && !Modifier.isPrivate(rawType.getModifiers())) {
      errors.missingConstructor(rawType);
      throw new ConfigurationException(errors.getMessages());
    }

    checkForMisplacedBindingAnnotations(noArgConstructor, errors);
    return new InjectionPoint(type, noArgConstructor);
  } catch (NoSuchMethodException e) {
    errors.missingConstructor(rawType);
    throw new ConfigurationException(errors.getMessages());
  }
}
 
开发者ID:google,项目名称:guice,代码行数:65,代码来源:InjectionPoint.java


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