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


Java Errors.addMessage方法代码示例

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


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

示例1: eligibilityVerified

import com.google.inject.internal.Errors; //导入方法依赖的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

示例2: verifyAbsenseOfScopeAnnotation

import com.google.inject.internal.Errors; //导入方法依赖的package包/类
private void verifyAbsenseOfScopeAnnotation(Errors methodErrors, Annotation[] annotations, Object source) {
  @Nullable Class<? extends Annotation> methodScopeAnnotation =
      Annotations.findScopeAnnotation(methodErrors, annotations);
  if (methodScopeAnnotation != null) {
    methodErrors.addMessage(
        "Misplaced scope annotation @%s on method @%s %s."
            + "\n\tScope annotation will only be inherited from enclosing class %s",
        methodScopeAnnotation.getSimpleName(),
        Eventually.Provides.class.getSimpleName(),
        source,
        providersClass.getSimpleName());
  }
}
 
开发者ID:immutables,项目名称:miscellaneous,代码行数:14,代码来源:Providers.java

示例3: verifyMethodAccessibility

import com.google.inject.internal.Errors; //导入方法依赖的package包/类
private void verifyMethodAccessibility(Errors methodErrors, Invokable<T, ?> method, Object source) {
  if (method.isStatic()
      || method.isPrivate()
      || method.isAbstract()
      || method.isSynthetic()) {
    methodErrors.addMessage(
        "Method @%s %s must not be private, static or abstract",
        Eventually.Provides.class.getSimpleName(),
        source);
  } else if (!method.isPublic()) {
    method.setAccessible(true);
  }
}
 
开发者ID:immutables,项目名称:miscellaneous,代码行数:14,代码来源:Providers.java

示例4: validateFactoryReturnType

import com.google.inject.internal.Errors; //导入方法依赖的package包/类
private void validateFactoryReturnType(Errors errors, Class<?> returnType, Class<?> factoryType) {
  if (Modifier.isPublic(factoryType.getModifiers())
      && !Modifier.isPublic(returnType.getModifiers())) {
    errors.addMessage(
        "%s is public, but has a method that returns a non-public type: %s. "
            + "Due to limitations with java.lang.reflect.Proxy, this is not allowed. "
            + "Please either make the factory non-public or the return type public.",
        factoryType, returnType);
  }
}
 
开发者ID:google,项目名称:guice,代码行数:11,代码来源:FactoryProvider2.java

示例5: findThrowingConstructor

import com.google.inject.internal.Errors; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") // safe because it's a constructor of the typeLiteral
static <T> Constructor<? extends T> findThrowingConstructor(
    TypeLiteral<? extends T> typeLiteral, Binder binder) {

  Class<?> rawType = typeLiteral.getRawType();
  Errors errors = new Errors(rawType);
  Constructor<?> cxtor = null;
  for (Constructor<?> constructor : rawType.getDeclaredConstructors()) {
    if (constructor.isAnnotationPresent(ThrowingInject.class)) {
      if (cxtor != null) {
        errors.addMessage(
            "%s has more than one constructor annotated with @ThrowingInject. "
                + CONSTRUCTOR_RULES,
            rawType);
      }

      cxtor = constructor;
      Annotation misplacedBindingAnnotation =
          Annotations.findBindingAnnotation(
              errors, cxtor, ((AnnotatedElement) cxtor).getAnnotations());
      if (misplacedBindingAnnotation != null) {
        errors.misplacedBindingAnnotation(cxtor, misplacedBindingAnnotation);
      }
    }
  }

  if (cxtor == null) {
    errors.addMessage(
        "Could not find a suitable constructor in %s. " + CONSTRUCTOR_RULES, rawType);
  }

  for (Message msg : errors.getMessages()) {
    binder.addError(msg);
  }
  return (Constructor<? extends T>) cxtor;
}
 
开发者ID:google,项目名称:guice,代码行数:37,代码来源:CheckedProvideUtils.java

示例6: validateFactoryReturnType

import com.google.inject.internal.Errors; //导入方法依赖的package包/类
private void validateFactoryReturnType(Errors errors, Class<?> returnType, Class<?> factoryType) {
  if (Modifier.isPublic(factoryType.getModifiers())
      && !Modifier.isPublic(returnType.getModifiers())) {
    errors.addMessage("%s is public, but has a method that returns a non-public type: %s. "
        + "Due to limitations with java.lang.reflect.Proxy, this is not allowed. "
        + "Please either make the factory non-public or the return type public.",
        factoryType, returnType);
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:10,代码来源:FactoryProvider2.java

示例7: findThrowingConstructor

import com.google.inject.internal.Errors; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") // safe because it's a constructor of the typeLiteral
static <T> Constructor<? extends T> findThrowingConstructor(
    TypeLiteral<? extends T> typeLiteral, Binder binder) {
  
  Class<?> rawType = typeLiteral.getRawType();
  Errors errors = new Errors(rawType);
  Constructor<?> cxtor = null;
  for (Constructor<?> constructor : rawType.getDeclaredConstructors()) {
    if (constructor.isAnnotationPresent(ThrowingInject.class)) {
      if (cxtor != null) {
        errors.addMessage("%s has more than one constructor annotated with @ThrowingInject. "
            + CONSTRUCTOR_RULES, rawType);
      }

      cxtor = constructor;
      Annotation misplacedBindingAnnotation = Annotations.findBindingAnnotation(
          errors, cxtor, ((AnnotatedElement) cxtor).getAnnotations());
      if (misplacedBindingAnnotation != null) {
        errors.misplacedBindingAnnotation(cxtor, misplacedBindingAnnotation);
      }
    }
  }
  
  if (cxtor == null) {
    errors.addMessage(
        "Could not find a suitable constructor in %s. " + CONSTRUCTOR_RULES, rawType);
  }

  for (Message msg : errors.getMessages()) {
    binder.addError(msg);
  }
  return (Constructor<? extends T>) cxtor;
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:34,代码来源:CheckedProvideUtils.java

示例8: findMatchingConstructor

import com.google.inject.internal.Errors; //导入方法依赖的package包/类
/**
 * Finds a constructor suitable for the method. If the implementation contained any constructors marked with {@link AssistedInject}, this requires all
 * {@link Assisted} parameters to exactly match the parameters (in any order) listed in the method. Otherwise, if no {@link AssistedInject} constructors
 * exist, this will default to looking for a {@literal @}{@link Inject} constructor.
 */
private Constructor findMatchingConstructor(Method method, TypeLiteral<?> implementation, List<Key<?>> paramList, Errors errors) throws ErrorsException {
    Constructor<?> matchingConstructor = null;
    boolean anyAssistedInjectConstructors = false;

    // Look for AssistedInject constructors...
    for (Constructor<?> constructor : implementation.getRawType().getDeclaredConstructors()) {
        if (constructor.isAnnotationPresent(AssistedInject.class)) {
            anyAssistedInjectConstructors = true;

            if (constructorHasMatchingParams(implementation, constructor, paramList, errors)) {
                if (matchingConstructor != null) {
                    errors.addMessage(PrettyPrinter.format("%s has more than one constructor annotated with @AssistedInject "
                            + "that matches the parameters in method %s.", implementation, method));
                    return null;
                } else {
                    matchingConstructor = constructor;
                }
            }
        }
    }

    if (matchingConstructor != null) {
        return matchingConstructor;
    }

    if (anyAssistedInjectConstructors) {
        errors.addMessage(PrettyPrinter.format("%s has @AssistedInject constructors, but none of them match the " + "parameters in method %s.",
                implementation, method));
        return null;
    }

    // Look for @Inject constructors...
    Constructor<?> injectConstructor = (Constructor) InjectionPoint.forConstructorOf(implementation).getMember();

    if (injectConstructorHasMatchingParams(implementation, injectConstructor, paramList, errors)) {
        return injectConstructor;
    }

    // No matching constructor exists, complain.
    errors.addMessage(PrettyPrinter.format("%s has no constructors matching the parameters in method %s.", implementation, method));
    return null;
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:48,代码来源:FactoryBinding.java

示例9: extractConstructorParameters

import com.google.inject.internal.Errors; //导入方法依赖的package包/类
/**
 * Matches constructor parameters to method parameters for injection and
 * records remaining parameters as required keys.
 */
private String[] extractConstructorParameters(Key<?> factoryKey, TypeLiteral<?> implementation,
    Constructor constructor, List<Key<?>> methodParams, Errors errors,
    Set<Dependency> dependencyCollector) throws ErrorsException {

  // Get parameters with annotations.
  List<TypeLiteral<?>> ctorParams = implementation.getParameterTypes(constructor);
  Annotation[][] ctorParamAnnotations = constructor.getParameterAnnotations();

  int p = 0;
  String[] parameterNames = new String[ctorParams.size()];
  Set<Key<?>> keySet = new LinkedHashSet<Key<?>>();
  for (TypeLiteral<?> ctorParam : ctorParams) {
    Key<?> ctorParamKey = getKey(ctorParam, constructor, ctorParamAnnotations[p], errors);

    if (ctorParamKey.getAnnotationType() == Assisted.class) {
      if (!keySet.add(ctorParamKey)) {
        errors.addMessage(PrettyPrinter.format(
            "%s has more than one parameter of type %s annotated with @Assisted(\"%s\").  " +
            "Please specify a unique value with the annotation to avoid confusion.",
            implementation, ctorParamKey.getTypeLiteral().getType(), 
            ((Assisted) ctorParamKey.getAnnotation()).value()));
      }
      
      int location = methodParams.indexOf(ctorParamKey);

      // This should never happen since the constructor was already checked
      // in #[inject]constructorHasMatchingParams(..).
      Preconditions.checkState(location != -1);

      parameterNames[p] = ReflectUtil.formatParameterName(location);
    } else {
      dependencyCollector.add(new Dependency(factoryKey, ctorParamKey, false, true,
          constructor.toString()));
    }

    p++;
  }

  return parameterNames;
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:45,代码来源:FactoryBinding.java

示例10: findMatchingConstructor

import com.google.inject.internal.Errors; //导入方法依赖的package包/类
/**
 * Finds a constructor suitable for the method. If the implementation
 * contained any constructors marked with {@link AssistedInject}, this
 * requires all {@link Assisted} parameters to exactly match the parameters
 * (in any order) listed in the method. Otherwise, if no
 * {@link AssistedInject} constructors exist, this will default to looking
 * for a {@literal @}{@link Inject} constructor.
 */
private Constructor findMatchingConstructor(Method method, TypeLiteral<?> implementation,
    List<Key<?>> paramList, Errors errors) throws ErrorsException {
  Constructor<?> matchingConstructor = null;
  boolean anyAssistedInjectConstructors = false;

  // Look for AssistedInject constructors...
  for (Constructor<?> constructor : implementation.getRawType().getDeclaredConstructors()) {
    if (constructor.isAnnotationPresent(AssistedInject.class)) {
      anyAssistedInjectConstructors = true;

      if (constructorHasMatchingParams(implementation, constructor, paramList, errors)) {
        if (matchingConstructor != null) {
          errors.addMessage(PrettyPrinter.format(
              "%s has more than one constructor annotated with @AssistedInject "
                  + "that matches the parameters in method %s.",
              implementation, method));
          return null;
        } else {
          matchingConstructor = constructor;
        }
      }
    }
  }

  if (matchingConstructor != null) {
    return matchingConstructor;
  }

  if (anyAssistedInjectConstructors) {
    errors.addMessage(PrettyPrinter.format(
        "%s has @AssistedInject constructors, but none of them match the "
            + "parameters in method %s.", implementation, method));
    return null;
  }

  // Look for @Inject constructors...
  Constructor<?> injectConstructor =
      (Constructor) InjectionPoint.forConstructorOf(implementation).getMember();

  if (injectConstructorHasMatchingParams(implementation, injectConstructor, paramList, errors)) {
    return injectConstructor;
  }

  // No matching constructor exists, complain.
  errors.addMessage(PrettyPrinter.format(
      "%s has no constructors matching the parameters in method %s.",
      implementation, method));
  return null;
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:58,代码来源:FactoryBinding.java

示例11: findMatchingConstructorInjectionPoint

import com.google.inject.internal.Errors; //导入方法依赖的package包/类
/**
 * Finds a constructor suitable for the method. If the implementation contained any constructors
 * marked with {@link AssistedInject}, this requires all {@link Assisted} parameters to exactly
 * match the parameters (in any order) listed in the method. Otherwise, if no {@link
 * AssistedInject} constructors exist, this will default to looking for an {@literal @}{@link
 * Inject} constructor.
 */
private <T> InjectionPoint findMatchingConstructorInjectionPoint(
    Method method, Key<?> returnType, TypeLiteral<T> implementation, List<Key<?>> paramList)
    throws ErrorsException {
  Errors errors = new Errors(method);
  if (returnType.getTypeLiteral().equals(implementation)) {
    errors = errors.withSource(implementation);
  } else {
    errors = errors.withSource(returnType).withSource(implementation);
  }

  Class<?> rawType = implementation.getRawType();
  if (Modifier.isInterface(rawType.getModifiers())) {
    errors.addMessage(
        "%s is an interface, not a concrete class.  Unable to create AssistedInject factory.",
        implementation);
    throw errors.toException();
  } else if (Modifier.isAbstract(rawType.getModifiers())) {
    errors.addMessage(
        "%s is abstract, not a concrete class.  Unable to create AssistedInject factory.",
        implementation);
    throw errors.toException();
  } else if (Classes.isInnerClass(rawType)) {
    errors.cannotInjectInnerClass(rawType);
    throw errors.toException();
  }

  Constructor<?> matchingConstructor = null;
  boolean anyAssistedInjectConstructors = false;
  // Look for AssistedInject constructors...
  for (Constructor<?> constructor : rawType.getDeclaredConstructors()) {
    if (constructor.isAnnotationPresent(AssistedInject.class)) {
      anyAssistedInjectConstructors = true;
      if (constructorHasMatchingParams(implementation, constructor, paramList, errors)) {
        if (matchingConstructor != null) {
          errors.addMessage(
              "%s has more than one constructor annotated with @AssistedInject"
                  + " that matches the parameters in method %s.  Unable to create "
                  + "AssistedInject factory.",
              implementation, method);
          throw errors.toException();
        } else {
          matchingConstructor = constructor;
        }
      }
    }
  }

  if (!anyAssistedInjectConstructors) {
    // If none existed, use @Inject.
    try {
      return InjectionPoint.forConstructorOf(implementation);
    } catch (ConfigurationException e) {
      errors.merge(e.getErrorMessages());
      throw errors.toException();
    }
  } else {
    // Otherwise, use it or fail with a good error message.
    if (matchingConstructor != null) {
      // safe because we got the constructor from this implementation.
      @SuppressWarnings("unchecked")
      InjectionPoint ip =
          InjectionPoint.forConstructor(
              (Constructor<? super T>) matchingConstructor, implementation);
      return ip;
    } else {
      errors.addMessage(
          "%s has @AssistedInject constructors, but none of them match the"
              + " parameters in method %s.  Unable to create AssistedInject factory.",
          implementation, method);
      throw errors.toException();
    }
  }
}
 
开发者ID:google,项目名称:guice,代码行数:81,代码来源:FactoryProvider2.java

示例12: findMatchingConstructorInjectionPoint

import com.google.inject.internal.Errors; //导入方法依赖的package包/类
/**
 * Finds a constructor suitable for the method.  If the implementation contained any constructors
 * marked with {@link AssistedInject}, this requires all {@link Assisted} parameters to exactly
 * match the parameters (in any order) listed in the method.  Otherwise, if no
 * {@link AssistedInject} constructors exist, this will default to looking for an
 * {@literal @}{@link Inject} constructor.
 */
private InjectionPoint findMatchingConstructorInjectionPoint(
    Method method, Key<?> returnType, TypeLiteral<?> implementation, List<Key<?>> paramList)
    throws ErrorsException {
  Errors errors = new Errors(method);
  if(returnType.getTypeLiteral().equals(implementation)) {
    errors = errors.withSource(implementation);
  } else {
    errors = errors.withSource(returnType).withSource(implementation);
  }

  Class<?> rawType = implementation.getRawType();
  if (Modifier.isInterface(rawType.getModifiers())) {
    errors.addMessage(
        "%s is an interface, not a concrete class.  Unable to create AssistedInject factory.",
        implementation);
    throw errors.toException();
  } else if (Modifier.isAbstract(rawType.getModifiers())) {
    errors.addMessage(
        "%s is abstract, not a concrete class.  Unable to create AssistedInject factory.",
        implementation);
    throw errors.toException();
  } else if (Classes.isInnerClass(rawType)) {
    errors.cannotInjectInnerClass(rawType);
    throw errors.toException();
  }

  Constructor<?> matchingConstructor = null;
  boolean anyAssistedInjectConstructors = false;
  // Look for AssistedInject constructors...
  for (Constructor<?> constructor : rawType.getDeclaredConstructors()) {
    if (constructor.isAnnotationPresent(AssistedInject.class)) {
      anyAssistedInjectConstructors = true;
      if (constructorHasMatchingParams(implementation, constructor, paramList, errors)) {
        if (matchingConstructor != null) {
          errors
              .addMessage(
                  "%s has more than one constructor annotated with @AssistedInject"
                      + " that matches the parameters in method %s.  Unable to create AssistedInject factory.",
                  implementation, method);
          throw errors.toException();
        } else {
          matchingConstructor = constructor;
        }
      }
    }
  }

  if(!anyAssistedInjectConstructors) {
    // If none existed, use @Inject.
    try {
      return InjectionPoint.forConstructorOf(implementation);
    } catch(ConfigurationException e) {
      errors.merge(e.getErrorMessages());
      throw errors.toException();
    }
  } else {
    // Otherwise, use it or fail with a good error message.
    if(matchingConstructor != null) {
        // safe because we got the constructor from this implementation.
        @SuppressWarnings("unchecked")
        InjectionPoint ip = InjectionPoint.forConstructor(
            (Constructor)matchingConstructor, implementation);
        return ip;
    } else {
      errors.addMessage(
          "%s has @AssistedInject constructors, but none of them match the"
          + " parameters in method %s.  Unable to create AssistedInject factory.",
          implementation, method);
      throw errors.toException();
    }
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:80,代码来源:FactoryProvider2.java


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