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


Java Errors类代码示例

本文整理汇总了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;
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:33,代码来源:FactoryBinding.java

示例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());
}
 
开发者ID:bootique,项目名称:bootique-jersey-client,代码行数:22,代码来源:ClientGuiceInjectInjector.java

示例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;
}
 
开发者ID:skuzzle,项目名称:guice-scoped-proxy-extension,代码行数:23,代码来源:InstanceBuilder.java

示例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();
}
 
开发者ID:immutables,项目名称:miscellaneous,代码行数:21,代码来源:Providers.java

示例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();
}
 
开发者ID:immutables,项目名称:miscellaneous,代码行数:24,代码来源:Providers.java

示例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;
}
 
开发者ID:google,项目名称:guice,代码行数:31,代码来源:Elements.java

示例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;
}
 
开发者ID:google,项目名称:guice,代码行数:29,代码来源:InjectionPoint.java

示例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;
}
 
开发者ID:google,项目名称:guice,代码行数:24,代码来源:InjectionPoint.java

示例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;
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:29,代码来源:InjectionPoint.java

示例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;
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:25,代码来源:InjectionPoint.java

示例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;
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:17,代码来源:InjectionPoint.java

示例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());
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:22,代码来源:ProvisionExceptionsTest.java

示例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());
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:22,代码来源:ProvisionExceptionsTest.java

示例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());
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:25,代码来源:ProvisionExceptionsTest.java

示例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());
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:23,代码来源:ProvisionExceptionsTest.java


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