本文整理汇总了Java中com.google.inject.internal.Errors类的典型用法代码示例。如果您正苦于以下问题:Java Errors类的具体用法?Java Errors怎么用?Java Errors使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Errors类属于com.google.inject.internal包,在下文中一共展示了Errors类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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()];
for (TypeLiteral<?> ctorParam : ctorParams) {
Key<?> ctorParamKey = getKey(ctorParam, constructor, ctorParamAnnotations[p], errors);
if (ctorParamKey.getAnnotationType() == Assisted.class) {
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;
}
示例2: resolve
import com.google.inject.internal.Errors; //导入依赖的package包/类
@Override
public Object resolve(Injectee injectee, ServiceHandle<?> serviceHandle) {
if (injectee.getRequiredType() instanceof Class) {
TypeLiteral<?> typeLiteral = TypeLiteral.get(injectee.getRequiredType());
Errors errors = new Errors(injectee.getParent());
Key<?> key;
try {
key = Annotations.getKey(typeLiteral, (Member) injectee.getParent(),
injectee.getParent().getDeclaredAnnotations(), errors);
} catch (ErrorsException e) {
errors.merge(e.getErrors());
throw new ConfigurationException(errors.getMessages());
}
return injector.getInstance(key);
}
throw new IllegalStateException("Can't process injection point: " + injectee.getRequiredType());
}
示例3: create
import com.google.inject.internal.Errors; //导入依赖的package包/类
/**
* Creates the scoped proxy object using the given provider.
*
* @param injector The injector.
* @return The scoped proxy object.
*/
@SuppressWarnings("unchecked")
public T create(Injector injector) {
Preconditions.checkNotNull(injector, "injector");
Preconditions.checkState(this.dispatcher != null, "no provider set");
this.enhancer.setCallbackType(this.dispatcher.getClass());
final Class<T> enhancedClass = this.enhancer.createClass();
final Errors errors = new Errors();
final T proxyInstance = this.constructionStrategy
.createInstance(enhancedClass, injector, errors);
errors.throwProvisionExceptionIfErrorsExist();
final Factory factory = (Factory) proxyInstance;
factory.setCallback(CALLBACK_INDEX, this.dispatcher);
return proxyInstance;
}
示例4: introspectProviders
import com.google.inject.internal.Errors; //导入依赖的package包/类
private ImmutableList<EventualProvider<?>> introspectProviders() {
ImmutableList.Builder<EventualProvider<?>> builder = ImmutableList.builder();
// FIXME handle method overriding?
for (Class<?> t : type.getTypes().classes().rawTypes()) {
if (t != Object.class) {
for (Method m : t.getDeclaredMethods()) {
if (m.isAnnotationPresent(Eventually.Provides.class)) {
Errors methodErrors = errors.withSource(StackTraceElements.forMember(m));
Invokable<T, Object> invokable = type.method(m);
if (eligibilityVerified(invokable, methodErrors)) {
builder.add(providerFor(invokable, methodErrors));
}
}
}
}
}
return builder.build();
}
示例5: 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();
}
示例6: scanForAnnotatedMethods
import com.google.inject.internal.Errors; //导入依赖的package包/类
/**
* Applies all scanners to the modules we've installed. We skip certain PrivateModules because
* store them in more than one Modules map and only want to process them through one of the
* maps. (They're stored in both maps to prevent a module from being installed more than once.)
*/
void scanForAnnotatedMethods() {
for (ModuleAnnotatedMethodScanner scanner : scanners) {
// Note: we must iterate over a copy of the modules because calling install(..)
// will mutate modules, otherwise causing a ConcurrentModificationException.
for (Map.Entry<Module, ModuleInfo> entry : Maps.newLinkedHashMap(modules).entrySet()) {
Module module = entry.getKey();
ModuleInfo info = entry.getValue();
if (info.skipScanning) {
continue;
}
moduleSource = entry.getValue().moduleSource;
try {
info.binder.install(ProviderMethodsModule.forModule(module, scanner));
} catch (RuntimeException e) {
Collection<Message> messages = Errors.getMessagesFromThrowable(e);
if (!messages.isEmpty()) {
elements.addAll(messages);
} else {
addError(e);
}
}
}
}
moduleSource = null;
}
示例7: forStaticMethodsAndFields
import com.google.inject.internal.Errors; //导入依赖的package包/类
/**
* Returns all static method and field injection points on {@code type}.
*
* @return a possibly empty set of injection points. The set has a specified iteration order. All
* fields are returned and then all methods. Within the fields, supertype fields are returned
* before subtype fields. Similarly, supertype methods are returned before subtype methods.
* @throws ConfigurationException if there is a malformed injection point on {@code type}, such as
* a field with multiple binding annotations. The exception's {@link
* ConfigurationException#getPartialValue() partial value} is a {@code Set<InjectionPoint>} of
* the valid injection points.
*/
public static Set<InjectionPoint> forStaticMethodsAndFields(TypeLiteral<?> type) {
Errors errors = new Errors();
Set<InjectionPoint> result;
if (type.getRawType().isInterface()) {
errors.staticInjectionOnInterface(type.getRawType());
result = null;
} else {
result = getInjectionPoints(type, true, errors);
}
if (errors.hasErrors()) {
throw new ConfigurationException(errors.getMessages()).withPartialValue(result);
}
return result;
}
示例8: checkForMisplacedBindingAnnotations
import com.google.inject.internal.Errors; //导入依赖的package包/类
/** Returns true if the binding annotation is in the wrong place. */
private static boolean checkForMisplacedBindingAnnotations(Member member, Errors errors) {
Annotation misplacedBindingAnnotation =
Annotations.findBindingAnnotation(
errors, member, ((AnnotatedElement) member).getAnnotations());
if (misplacedBindingAnnotation == null) {
return false;
}
// don't warn about misplaced binding annotations on methods when there's a field with the same
// name. In Scala, fields always get accessor methods (that we need to ignore). See bug 242.
if (member instanceof Method) {
try {
if (member.getDeclaringClass().getDeclaredField(member.getName()) != null) {
return false;
}
} catch (NoSuchFieldException ignore) {
}
}
errors.misplacedBindingAnnotation(member, misplacedBindingAnnotation);
return true;
}
示例9: forStaticMethodsAndFields
import com.google.inject.internal.Errors; //导入依赖的package包/类
/**
* Returns all static method and field injection points on {@code type}.
*
* @return a possibly empty set of injection points. The set has a specified iteration order. All
* fields are returned and then all methods. Within the fields, supertype fields are returned
* before subtype fields. Similarly, supertype methods are returned before subtype methods.
* @throws ConfigurationException if there is a malformed injection point on {@code type}, such as
* a field with multiple binding annotations. The exception's {@link
* ConfigurationException#getPartialValue() partial value} is a {@code Set<InjectionPoint>}
* of the valid injection points.
*/
public static Set<InjectionPoint> forStaticMethodsAndFields(TypeLiteral<?> type) {
Errors errors = new Errors();
Set<InjectionPoint> result;
if (type.getRawType().isInterface()) {
errors.staticInjectionOnInterface(type.getRawType());
result = null;
} else {
result = getInjectionPoints(type, true, errors);
}
if (errors.hasErrors()) {
throw new ConfigurationException(errors.getMessages()).withPartialValue(result);
}
return result;
}
示例10: checkForMisplacedBindingAnnotations
import com.google.inject.internal.Errors; //导入依赖的package包/类
/**
* Returns true if the binding annotation is in the wrong place.
*/
private static boolean checkForMisplacedBindingAnnotations(Member member, Errors errors) {
Annotation misplacedBindingAnnotation = Annotations.findBindingAnnotation(
errors, member, ((AnnotatedElement) member).getAnnotations());
if (misplacedBindingAnnotation == null) {
return false;
}
// don't warn about misplaced binding annotations on methods when there's a field with the same
// name. In Scala, fields always get accessor methods (that we need to ignore). See bug 242.
if (member instanceof Method) {
try {
if (member.getDeclaringClass().getDeclaredField(member.getName()) != null) {
return false;
}
} catch (NoSuchFieldException ignore) {
}
}
errors.misplacedBindingAnnotation(member, misplacedBindingAnnotation);
return true;
}
示例11: isValidMethod
import com.google.inject.internal.Errors; //导入依赖的package包/类
private static boolean isValidMethod(InjectableMethod injectableMethod,
Errors errors) {
boolean result = true;
if (injectableMethod.jsr330) {
Method method = injectableMethod.method;
if (Modifier.isAbstract(method.getModifiers())) {
errors.cannotInjectAbstractMethod(method);
result = false;
}
if (method.getTypeParameters().length > 0) {
errors.cannotInjectMethodWithTypeParameters(method);
result = false;
}
}
return result;
}
示例12: testConstructorRuntimeException
import com.google.inject.internal.Errors; //导入依赖的package包/类
public void testConstructorRuntimeException() {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(Names.named("runtime")).to(true);
bind(Exploder.class).to(Explosion.class);
bind(Tracer.class).to(TracerImpl.class);
}
});
try {
injector.getInstance(Tracer.class);
fail();
} catch(ProvisionException pe) {
// Make sure our initial error message gives the user exception.
Asserts.assertContains(pe.getMessage(),
"1) Error injecting constructor", "java.lang.IllegalStateException: boom!");
assertEquals(1, pe.getErrorMessages().size());
assertEquals(IllegalStateException.class, pe.getCause().getClass());
assertEquals(IllegalStateException.class, Errors.getOnlyCause(pe.getErrorMessages()).getClass());
}
}
示例13: testConstructorCheckedException
import com.google.inject.internal.Errors; //导入依赖的package包/类
public void testConstructorCheckedException() {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(Names.named("runtime")).to(false);
bind(Exploder.class).to(Explosion.class);
bind(Tracer.class).to(TracerImpl.class);
}
});
try {
injector.getInstance(Tracer.class);
fail();
} catch(ProvisionException pe) {
// Make sure our initial error message gives the user exception.
Asserts.assertContains(pe.getMessage(),
"1) Error injecting constructor", "java.io.IOException: boom!");
assertEquals(1, pe.getErrorMessages().size());
assertEquals(IOException.class, pe.getCause().getClass());
assertEquals(IOException.class, Errors.getOnlyCause(pe.getErrorMessages()).getClass());
}
}
示例14: testCustomProvidersRuntimeException
import com.google.inject.internal.Errors; //导入依赖的package包/类
public void testCustomProvidersRuntimeException() {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(Exploder.class).toProvider(new Provider<Exploder>() {
public Exploder get() {
return Explosion.createRuntime();
}
});
bind(Tracer.class).to(TracerImpl.class);
}
});
try {
injector.getInstance(Tracer.class);
fail();
} catch(ProvisionException pe) {
// Make sure our initial error message gives the user exception.
Asserts.assertContains(pe.getMessage(),
"1) Error in custom provider", "java.lang.IllegalStateException: boom!");
assertEquals(1, pe.getErrorMessages().size());
assertEquals(IllegalStateException.class, pe.getCause().getClass());
assertEquals(IllegalStateException.class, Errors.getOnlyCause(pe.getErrorMessages()).getClass());
}
}
示例15: testProviderMethodRuntimeException
import com.google.inject.internal.Errors; //导入依赖的package包/类
public void testProviderMethodRuntimeException() {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(Tracer.class).to(TracerImpl.class);
}
@Provides Exploder exploder() {
return Explosion.createRuntime();
}
});
try {
injector.getInstance(Tracer.class);
fail();
} catch(ProvisionException pe) {
// Make sure our initial error message gives the user exception.
Asserts.assertContains(pe.getMessage(),
"1) Error in custom provider", "java.lang.IllegalStateException: boom!");
assertEquals(1, pe.getErrorMessages().size());
assertEquals(IllegalStateException.class, pe.getCause().getClass());
assertEquals(IllegalStateException.class, Errors.getOnlyCause(pe.getErrorMessages()).getClass());
}
}