本文整理汇总了Java中com.google.inject.internal.ErrorsException类的典型用法代码示例。如果您正苦于以下问题:Java ErrorsException类的具体用法?Java ErrorsException怎么用?Java ErrorsException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ErrorsException类属于com.google.inject.internal包,在下文中一共展示了ErrorsException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractConstructorParameters
import com.google.inject.internal.ErrorsException; //导入依赖的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.ErrorsException; //导入依赖的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: FactoryBinding
import com.google.inject.internal.ErrorsException; //导入依赖的package包/类
FactoryBinding(Map<Key<?>, TypeLiteral<?>> collector, Key<?> factoryKey, Context context,
GuiceUtil guiceUtil, MethodCallUtil methodCallUtil) {
super(context, factoryKey);
this.collector = Preconditions.checkNotNull(collector);
this.factoryKey = factoryKey;
this.factoryType = factoryKey.getTypeLiteral();
this.guiceUtil = guiceUtil;
this.methodCallUtil = methodCallUtil;
try {
matchMethods(Preconditions.checkNotNull(factoryKey));
} catch (ErrorsException e) {
e.getErrors().throwConfigurationExceptionIfErrorsExist();
}
}
示例4: testFieldInjectionPoint
import com.google.inject.internal.ErrorsException; //导入依赖的package包/类
public void testFieldInjectionPoint() throws NoSuchFieldException, IOException, ErrorsException {
TypeLiteral<?> typeLiteral = TypeLiteral.get(getClass());
Field fooField = getClass().getField("foo");
InjectionPoint injectionPoint = new InjectionPoint(typeLiteral, fooField, false);
assertSame(fooField, injectionPoint.getMember());
assertFalse(injectionPoint.isOptional());
assertEquals(getClass().getName() + ".foo", injectionPoint.toString());
assertEqualsBothWays(injectionPoint, new InjectionPoint(typeLiteral, fooField, false));
assertNotSerializable(injectionPoint);
Dependency<?> dependency = getOnlyElement(injectionPoint.getDependencies());
assertEquals("Key[type=java.lang.String, [email protected](value=a)]@"
+ getClass().getName() + ".foo", dependency.toString());
assertEquals(fooField, dependency.getInjectionPoint().getMember());
assertEquals(-1, dependency.getParameterIndex());
Assert.assertEquals(Key.get(String.class, named("a")), dependency.getKey());
assertEquals(false, dependency.isNullable());
assertNotSerializable(dependency);
assertEqualsBothWays(dependency,
getOnlyElement(new InjectionPoint(typeLiteral, fooField, false).getDependencies()));
}
示例5: testConstructorInjectionPoint
import com.google.inject.internal.ErrorsException; //导入依赖的package包/类
public void testConstructorInjectionPoint() throws NoSuchMethodException, IOException,
ErrorsException {
TypeLiteral<?> typeLiteral = TypeLiteral.get(Constructable.class);
Constructor<?> constructor = Constructable.class.getConstructor(String.class);
InjectionPoint injectionPoint = new InjectionPoint(typeLiteral, constructor);
assertSame(constructor, injectionPoint.getMember());
assertFalse(injectionPoint.isOptional());
assertEquals(Constructable.class.getName() + ".<init>()", injectionPoint.toString());
assertEqualsBothWays(injectionPoint, new InjectionPoint(typeLiteral, constructor));
assertNotSerializable(injectionPoint);
Dependency<?> dependency = getOnlyElement(injectionPoint.getDependencies());
assertEquals("Key[type=java.lang.String, [email protected](value=c)]@"
+ Constructable.class.getName() + ".<init>()[0]", dependency.toString());
assertEquals(constructor, dependency.getInjectionPoint().getMember());
assertEquals(0, dependency.getParameterIndex());
assertEquals(Key.get(String.class, named("c")), dependency.getKey());
assertEquals(false, dependency.isNullable());
assertNotSerializable(dependency);
assertEqualsBothWays(dependency,
getOnlyElement(new InjectionPoint(typeLiteral, constructor).getDependencies()));
}
示例6: configure
import com.google.inject.internal.ErrorsException; //导入依赖的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();
}
示例7: getCollectionParamValue
import com.google.inject.internal.ErrorsException; //导入依赖的package包/类
/**
* Compute the value for a parameter annotated with
*
* @param errors
* @param paramIndex
*
* @return
*
* @throws ErrorsException
*/
private Object getCollectionParamValue(final Errors errors,
final int paramIndex,
final TestEach annotation) throws ErrorsException
{
if (!(method instanceof TestEachFrameworkMethod))
throw new AssertionError("Required a parameterised FrameworkMethod but got " + method);
// The index within the collection to use for this particular invocation
final int collectionIndex = ((TestEachFrameworkMethod) method).getCollectionIndexForParameter(paramIndex);
if (annotation.value() != null && annotation.value().length > 0)
{
final Class<?> desiredType = method.getMethod().getParameterTypes()[paramIndex];
final String val = annotation.value()[collectionIndex];
return convertParamType(val, desiredType);
}
else
{
return getGuiceCollectionParamValue(errors, paramIndex, collectionIndex);
}
}
示例8: FactoryBinding
import com.google.inject.internal.ErrorsException; //导入依赖的package包/类
FactoryBinding(Map<Key<?>, TypeLiteral<?>> collector, Key<?> factoryKey, Context context, GuiceUtil guiceUtil, MethodCallUtil methodCallUtil) {
super(context, factoryKey);
this.collector = Preconditions.checkNotNull(collector);
this.factoryKey = factoryKey;
this.factoryType = factoryKey.getTypeLiteral();
this.guiceUtil = guiceUtil;
this.methodCallUtil = methodCallUtil;
try {
matchMethods(Preconditions.checkNotNull(factoryKey));
} catch (ErrorsException e) {
e.getErrors().throwConfigurationExceptionIfErrorsExist();
}
}
示例9: injectConstructorHasMatchingParams
import com.google.inject.internal.ErrorsException; //导入依赖的package包/类
/**
* Matching logic for {@literal @}{@link Inject} constructor and method parameters.
* <p/>
* This returns true if all assisted parameters required by the constructor are provided by the factory method.
*/
private boolean injectConstructorHasMatchingParams(TypeLiteral<?> type, Constructor<?> constructor, List<Key<?>> paramList, Errors errors)
throws ErrorsException {
List<TypeLiteral<?>> params = type.getParameterTypes(constructor);
Annotation[][] paramAnnotations = constructor.getParameterAnnotations();
int p = 0;
for (TypeLiteral<?> param : params) {
Key<?> paramKey = getKey(param, constructor, paramAnnotations[p++], errors);
if (paramKey.getAnnotationType() == Assisted.class && !paramList.contains(paramKey)) {
return false;
}
}
return true;
}
示例10: assistKey
import com.google.inject.internal.ErrorsException; //导入依赖的package包/类
/**
* Returns a key similar to {@code key}, but with an {@literal @}Assisted binding annotation.
* <p/>
* This fails if another binding annotation is clobbered in the process. If the key already has the {@literal @}Assisted annotation, it is returned as-is to
* preserve any String value.
*/
private <T> Key<T> assistKey(Method method, Key<T> key, Errors errors) throws ErrorsException {
if (key.getAnnotationType() == null) {
return Key.get(key.getTypeLiteral(), DEFAULT_ANNOTATION);
} else if (key.getAnnotationType() == Assisted.class) {
return key;
} else {
errors.withSource(method).addMessage(
PrettyPrinter.format("Only @Assisted is allowed for factory parameters, but found @%s", key.getAnnotationType()));
throw errors.toException();
}
}
示例11: injectConstructorHasMatchingParams
import com.google.inject.internal.ErrorsException; //导入依赖的package包/类
/**
* Matching logic for {@literal @}{@link Inject} constructor and method
* parameters.
*
* This returns true if all assisted parameters required by the constructor
* are provided by the factory method.
*/
private boolean injectConstructorHasMatchingParams(TypeLiteral<?> type,
Constructor<?> constructor, List<Key<?>> paramList, Errors errors) throws ErrorsException {
List<TypeLiteral<?>> params = type.getParameterTypes(constructor);
Annotation[][] paramAnnotations = constructor.getParameterAnnotations();
int p = 0;
for (TypeLiteral<?> param : params) {
Key<?> paramKey = getKey(param, constructor, paramAnnotations[p++], errors);
if(paramKey.getAnnotationType() == Assisted.class && !paramList.contains(paramKey)) {
return false;
}
}
return true;
}
示例12: assistKey
import com.google.inject.internal.ErrorsException; //导入依赖的package包/类
/**
* Returns a key similar to {@code key}, but with an {@literal @}Assisted
* binding annotation.
*
* This fails if another binding annotation is clobbered in the process. If
* the key already has the {@literal @}Assisted annotation, it is returned
* as-is to preserve any String value.
*/
private <T> Key<T> assistKey(Method method, Key<T> key, Errors errors) throws ErrorsException {
if (key.getAnnotationType() == null) {
return Key.get(key.getTypeLiteral(), DEFAULT_ANNOTATION);
} else if (key.getAnnotationType() == Assisted.class) {
return key;
} else {
errors.withSource(method).addMessage(PrettyPrinter.format(
"Only @Assisted is allowed for factory parameters, but found @%s",
key.getAnnotationType()));
throw errors.toException();
}
}
示例13: newFactory
import com.google.inject.internal.ErrorsException; //导入依赖的package包/类
public static <F> Provider<F> newFactory(
TypeLiteral<F> factoryType, TypeLiteral<?> implementationType) {
Map<Method, AssistedConstructor<?>> factoryMethodToConstructor =
createMethodMapping(factoryType, implementationType);
if (!factoryMethodToConstructor.isEmpty()) {
return new FactoryProvider<F>(factoryType, implementationType, factoryMethodToConstructor);
} else {
BindingCollector collector = new BindingCollector();
// Preserving backwards-compatibility: Map all return types in a factory
// interface to the passed implementation type.
Errors errors = new Errors();
Key<?> implementationKey = Key.get(implementationType);
try {
for (Method method : factoryType.getRawType().getMethods()) {
Key<?> returnType =
getKey(factoryType.getReturnType(method), method, method.getAnnotations(), errors);
if (!implementationKey.equals(returnType)) {
collector.addBinding(returnType, implementationType);
}
}
} catch (ErrorsException e) {
throw new ConfigurationException(e.getErrors().getMessages());
}
return new FactoryProvider2<F>(Key.get(factoryType), collector);
}
}
示例14: assistKey
import com.google.inject.internal.ErrorsException; //导入依赖的package包/类
/**
* Returns a key similar to {@code key}, but with an {@literal @}Assisted binding annotation. This
* fails if another binding annotation is clobbered in the process. If the key already has the
* {@literal @}Assisted annotation, it is returned as-is to preserve any String value.
*/
private <T> Key<T> assistKey(Method method, Key<T> key, Errors errors) throws ErrorsException {
if (key.getAnnotationType() == null) {
return Key.get(key.getTypeLiteral(), DEFAULT_ANNOTATION);
} else if (key.getAnnotationType() == Assisted.class) {
return key;
} else {
errors
.withSource(method)
.addMessage(
"Only @Assisted is allowed for factory parameters, but found @%s",
key.getAnnotationType());
throw errors.toException();
}
}
示例15: testFieldInjectionPoint
import com.google.inject.internal.ErrorsException; //导入依赖的package包/类
public void testFieldInjectionPoint() throws NoSuchFieldException, IOException, ErrorsException {
TypeLiteral<?> typeLiteral = TypeLiteral.get(getClass());
Field fooField = getClass().getField("foo");
InjectionPoint injectionPoint = new InjectionPoint(typeLiteral, fooField, false);
assertSame(fooField, injectionPoint.getMember());
assertFalse(injectionPoint.isOptional());
assertEquals(getClass().getName() + ".foo", injectionPoint.toString());
assertEqualsBothWays(injectionPoint, new InjectionPoint(typeLiteral, fooField, false));
assertNotSerializable(injectionPoint);
Dependency<?> dependency = getOnlyElement(injectionPoint.getDependencies());
assertEquals(
"Key[type=java.lang.String, [email protected](value="
+ Annotations.memberValueString("a")
+ ")]@"
+ getClass().getName()
+ ".foo",
dependency.toString());
assertEquals(fooField, dependency.getInjectionPoint().getMember());
assertEquals(-1, dependency.getParameterIndex());
assertEquals(Key.get(String.class, named("a")), dependency.getKey());
assertFalse(dependency.isNullable());
assertNotSerializable(dependency);
assertEqualsBothWays(
dependency,
getOnlyElement(new InjectionPoint(typeLiteral, fooField, false).getDependencies()));
}