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


Java ImplementedBy类代码示例

本文整理汇总了Java中com.google.inject.ImplementedBy的典型用法代码示例。如果您正苦于以下问题:Java ImplementedBy类的具体用法?Java ImplementedBy怎么用?Java ImplementedBy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: addImplementedByConstructionRule

import com.google.inject.ImplementedBy; //导入依赖的package包/类
private void addImplementedByConstructionRule() {
    // rule for @ImplementedBy
    config.construction.constructionRules
            .add(new ImplementedByConstructionRuleBase() {

                @Override
                protected DependencyKey<?> getImplementorKey(
                        TypeToken<?> type) {
                    ImplementedBy implementedBy = type.getRawType()
                            .getAnnotation(ImplementedBy.class);
                    if (implementedBy != null) {

                        if (type.getRawType()
                                .equals(implementedBy.value())) {
                            throw new SaltaException(
                                    "@ImplementedBy points to the same class it annotates. type: "
                                            + type);
                        }
                        return DependencyKey.of(implementedBy.value());
                    }
                    return null;
                }
            });
}
 
开发者ID:ruediste,项目名称:salta,代码行数:25,代码来源:GuiceModule.java

示例2: createImplementedByBinding

import com.google.inject.ImplementedBy; //导入依赖的package包/类
private BindClassBinding createImplementedByBinding(Key<?> key, ImplementedBy implementedBy)
    throws BindingCreationException {
  Class<?> rawType = key.getTypeLiteral().getRawType();
  Class<?> implementationType = implementedBy.value();

  if (implementationType == rawType) {
    throw new BindingCreationException(
        "@ImplementedBy points to the same class it annotates: %s", rawType);
  }

  if (!rawType.isAssignableFrom(implementationType)) {
    throw new BindingCreationException("%s doesn't extend %s (while resolving @ImplementedBy)",
        implementationType, rawType);
  }

  return bindingFactory.getBindClassBinding(Key.get(implementationType), key,
      Context.forText("@ImplementedBy annotation"));
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:19,代码来源:ImplicitBindingCreator.java

示例3: configure

import com.google.inject.ImplementedBy; //导入依赖的package包/类
@Override
protected void configure() {
    final ImplementedBy implementedBy = type.getRawType().getAnnotation(ImplementedBy.class);

    bind(parserKey).toInstance(new ReflectiveParserImpl(
        implementedBy != null ? implementedBy.value() : this.baseClass,
        Members.annotations(Parseable.Property.class, Methods.declaredMethodsInAncestors(type.getRawType()))
               .merge(this::createProperty)
               .collect(Collectors.toImmutableList())
    ));
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:12,代码来源:ReflectiveParserManifest.java

示例4: createImplementedByBinding

import com.google.inject.ImplementedBy; //导入依赖的package包/类
/** Creates a binding for a type annotated with @ImplementedBy. */
private <T> BindingImpl<T> createImplementedByBinding(
    Key<T> key, Scoping scoping, ImplementedBy implementedBy, Errors errors)
    throws ErrorsException {
  Class<?> rawType = key.getTypeLiteral().getRawType();
  Class<?> implementationType = implementedBy.value();

  // Make sure it's not the same type. TODO: Can we check for deeper cycles?
  if (implementationType == rawType) {
    throw errors.recursiveImplementationType().toException();
  }

  // Make sure implementationType extends type.
  if (!rawType.isAssignableFrom(implementationType)) {
    throw errors.notASubtype(implementationType, rawType).toException();
  }

  @SuppressWarnings("unchecked") // After the preceding check, this cast is safe.
  Class<? extends T> subclass = (Class<? extends T>) implementationType;

  // Look up the target binding.
  final Key<? extends T> targetKey = Key.get(subclass);
  Object source = rawType;
  FactoryProxy<T> factory = new FactoryProxy<>(this, key, targetKey, source);
  factory.notify(errors); // causes the factory to initialize itself internally
  return new LinkedBindingImpl<T>(
      this,
      key,
      source,
      Scoping.<T>scope(key, this, factory, source, scoping),
      scoping,
      targetKey);
}
 
开发者ID:google,项目名称:guice,代码行数:34,代码来源:InjectorImpl.java

示例5: create

import com.google.inject.ImplementedBy; //导入依赖的package包/类
/**
 * Creates the implicit binding
 */
public Binding create(Key<?> key) throws BindingCreationException {
  TypeLiteral<?> type = key.getTypeLiteral();

  // All steps per:
  // http://code.google.com/p/google-guice/wiki/BindingResolution

  // 1. Explicit binding - already finished at this point.

  // 2. Ask parent injector.
  // 3. Ask child injector.
  // These bindings are created in BindingResolver and are not necessary here.

  // 4. Provider injections.
  if (isProviderKey(key)) {
    return bindingFactory.getImplicitProviderBinding(key);
    // TODO(bstoler): Scope the provider binding like the thing being provided?
  }

  // 4b. AsyncProvider injections.
  if (isAsyncProviderKey(key)) {
    return bindingFactory.getAsyncProviderBinding(key);
  }

  // 5. Convert constants.
  // Already covered by resolving explicit bindings.
  if (BindConstantBinding.isConstantKey(key)) {
    throw new BindingCreationException(
        "Binding requested for constant key '%s' but no explicit binding was found", key);
  }

  // 6. If the dependency has a binding annotation, give up.
  if (key.getAnnotation() != null || key.getAnnotationType() != null) {
    throw new BindingCreationException("No implementation bound for '%s' and an implicit binding"
        + " cannot be created because the type is annotated.", key);
  }

  // 7. If the dependency is an array or enum, give up.
  // Covered by step 5 (enum) and 11 (array).

  // 8. Handle TypeLiteral injections.
  // TODO(schmitt): Implement TypeLiteral injections.

  // 9. Use resolution annotations (@ImplementedBy, @ProvidedBy)
  ImplementedBy implementedBy = type.getRawType().getAnnotation(ImplementedBy.class);
  if (implementedBy != null) {
    return createImplementedByBinding(key, implementedBy);
  }

  ProvidedBy providedBy = type.getRawType().getAnnotation(ProvidedBy.class);
  if (providedBy != null) {
    return createProvidedByBinding(key, providedBy);
  }

  // 10. If the dependency is abstract or a non-static inner class, give up.
  // Abstract classes are handled by GWT.create.
  // TODO(schmitt): Introduce check.

  // 11. Use a single @Inject or public no-arguments constructor.
  return createImplicitBindingForClass(type);
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:64,代码来源:ImplicitBindingCreator.java

示例6: createUninitializedBinding

import com.google.inject.ImplementedBy; //导入依赖的package包/类
/**
 * Creates a binding for an injectable type with the given scope. Looks for a scope on the type if
 * none is specified.
 */
<T> BindingImpl<T> createUninitializedBinding(
    Key<T> key, Scoping scoping, Object source, Errors errors, boolean jitBinding)
    throws ErrorsException {
  Class<?> rawType = key.getTypeLiteral().getRawType();

  ImplementedBy implementedBy = rawType.getAnnotation(ImplementedBy.class);

  // Don't try to inject arrays or enums annotated with @ImplementedBy.
  if (rawType.isArray() || (rawType.isEnum() && implementedBy != null)) {
    throw errors.missingImplementationWithHint(key, this).toException();
  }

  // Handle TypeLiteral<T> by binding the inner type
  if (rawType == TypeLiteral.class) {
    @SuppressWarnings("unchecked") // we have to fudge the inner type as Object
    BindingImpl<T> binding =
        (BindingImpl<T>) createTypeLiteralBinding((Key<TypeLiteral<Object>>) key, errors);
    return binding;
  }

  // Handle @ImplementedBy
  if (implementedBy != null) {
    Annotations.checkForMisplacedScopeAnnotations(rawType, source, errors);
    return createImplementedByBinding(key, scoping, implementedBy, errors);
  }

  // Handle @ProvidedBy.
  ProvidedBy providedBy = rawType.getAnnotation(ProvidedBy.class);
  if (providedBy != null) {
    Annotations.checkForMisplacedScopeAnnotations(rawType, source, errors);
    return createProvidedByBinding(key, scoping, providedBy, errors);
  }

  return ConstructorBindingImpl.create(
      this,
      key,
      null, /* use default constructor */
      source,
      scoping,
      errors,
      jitBinding && options.jitDisabled,
      options.atInjectRequired);
}
 
开发者ID:google,项目名称:guice,代码行数:48,代码来源:InjectorImpl.java

示例7: createUninitializedBinding

import com.google.inject.ImplementedBy; //导入依赖的package包/类
/**
 * Creates a binding for an injectable type with the given scope. Looks for a scope on the type if
 * none is specified.
 */
<T> BindingImpl<T> createUninitializedBinding(Key<T> key, Scoping scoping, Object source,
    Errors errors, boolean jitBinding) throws ErrorsException {
  Class<?> rawType = key.getTypeLiteral().getRawType();

  // Don't try to inject arrays, or enums.
  if (rawType.isArray() || rawType.isEnum()) {
    throw errors.missingImplementation(key).toException();
  }

  // Handle TypeLiteral<T> by binding the inner type
  if (rawType == TypeLiteral.class) {
    @SuppressWarnings("unchecked") // we have to fudge the inner type as Object
    BindingImpl<T> binding = (BindingImpl<T>) createTypeLiteralBinding(
        (Key<TypeLiteral<Object>>) key, errors);
    return binding;
  }

  // Handle @ImplementedBy
  ImplementedBy implementedBy = rawType.getAnnotation(ImplementedBy.class);
  if (implementedBy != null) {
    Annotations.checkForMisplacedScopeAnnotations(rawType, source, errors);
    return createImplementedByBinding(key, scoping, implementedBy, errors);
  }

  // Handle @ProvidedBy.
  ProvidedBy providedBy = rawType.getAnnotation(ProvidedBy.class);
  if (providedBy != null) {
    Annotations.checkForMisplacedScopeAnnotations(rawType, source, errors);
    return createProvidedByBinding(key, scoping, providedBy, errors);
  }


  return ConstructorBindingImpl.create(this,
      key,
      null, /* use default constructor */
      source,
      scoping,
      errors,
      jitBinding && options.jitDisabled,
      options.atInjectRequired);
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:46,代码来源:InjectorImpl.java

示例8: autobind

import com.google.inject.ImplementedBy; //导入依赖的package包/类
private <T> void autobind(Class<T> clazz)
{
	// If the class is a regular class (or an interface annotated with @ImplementedBy)...
	if (!clazz.isInterface() || clazz.isAnnotationPresent(ImplementedBy.class))
	{
		// Guice knows how to bind this already so no need to search for an implementation, just expose it via JAX-RS
		RestResourceRegistry.register(clazz);
	}
	else
	{
		// Search for implementations
		final List<Class<? extends T>> implementations = scannerFactory.getInstance().getImplementations(clazz);

		if (implementations.size() == 1)
		{
			RestResourceRegistry.register(clazz);

			bind(clazz).to(implementations.get(0));
		}
		else if (implementations.size() == 0)
		{
			if (ResteasyProxyClientFactoryImpl.getConfiguredBoundServiceName(config, clazz) != null)
			{
				log.debug(
						"Found JAX-RS interface with no implementation but a service.{name}.endpoint config. Auto-binding a client: " +
						clazz);

				TypeLiteral typeLiteral = TypeLiteral.<JAXRSClientProvider<T>>get(Types.newParameterizedType(
						JAXRSClientProvider.class,
						clazz));
				bind(clazz).toProvider(typeLiteral);
			}
			else
			{
				log.debug("Found JAX-RS interface with no implementation and no service.{name}.endpoint config. Ignoring: " +
				          clazz);
			}
		}
		else
		{
			// Too many interfaces
			throw new IllegalArgumentException("Expected 0 or 1 implementation for auto-discovered REST interface " +
			                                   clazz +
			                                   " but found " +
			                                   implementations +
			                                   ". Auto-binding REST interfaces is not possible.");
		}
	}
}
 
开发者ID:petergeneric,项目名称:stdlib,代码行数:50,代码来源:JAXRSAutoRegisterServicesModule.java

示例9: createUninitializedBinding

import com.google.inject.ImplementedBy; //导入依赖的package包/类
/**
 * Creates a binding for an injectable type with the given scope. Looks for a scope on the type if
 * none is specified.
 */
<T> BindingImpl<T> createUninitializedBinding(Key<T> key, Scoping scoping, Object source,
    Errors errors, boolean jitBinding) throws ErrorsException {
  Class<?> rawType = key.getTypeLiteral().getRawType();

  // Don't try to inject arrays, or enums.
  if (rawType.isArray() || rawType.isEnum()) {
    throw errors.missingImplementation(key).toException();
  }

  // Handle TypeLiteral<T> by binding the inner type
  if (rawType == TypeLiteral.class) {
    @SuppressWarnings("unchecked") // we have to fudge the inner type as Object
    BindingImpl<T> binding = (BindingImpl<T>) createTypeLiteralBinding(
        (Key<TypeLiteral<Object>>) key, errors);
    return binding;
  }

  // Handle @ImplementedBy
  ImplementedBy implementedBy = rawType.getAnnotation(ImplementedBy.class);
  if (implementedBy != null) {
    Annotations.checkForMisplacedScopeAnnotations(rawType, source, errors);
    return createImplementedByBinding(key, scoping, implementedBy, errors);
  }

  // Handle @ProvidedBy.
  ProvidedBy providedBy = rawType.getAnnotation(ProvidedBy.class);
  if (providedBy != null) {
    Annotations.checkForMisplacedScopeAnnotations(rawType, source, errors);
    return createProvidedByBinding(key, scoping, providedBy, errors);
  }

  
  return ConstructorBindingImpl.create(this,
      key,
      null, /* use default constructor */
      source,
      scoping,
      errors,
      jitBinding && options.jitDisabled,
      options.atInjectRequired);
}
 
开发者ID:utopiazh,项目名称:google-guice,代码行数:46,代码来源:InjectorImpl.java


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