本文整理汇总了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();
}
示例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());
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
}
示例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();
}
}
}