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


Java Annotations.findBindingAnnotation方法代码示例

本文整理汇总了Java中com.google.inject.internal.Annotations.findBindingAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java Annotations.findBindingAnnotation方法的具体用法?Java Annotations.findBindingAnnotation怎么用?Java Annotations.findBindingAnnotation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.inject.internal.Annotations的用法示例。


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

示例1: checkForMisplacedBindingAnnotations

import com.google.inject.internal.Annotations; //导入方法依赖的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

示例2: checkForMisplacedBindingAnnotations

import com.google.inject.internal.Annotations; //导入方法依赖的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

示例3: InjectableMethod

import com.google.inject.internal.Annotations; //导入方法依赖的package包/类
private <D> InjectableMethod(@Nullable TypeLiteral<D> targetType, @Nullable D target, Method method, @Nullable T result) {
    final Errors errors = new Errors(method);

    if(Members.isStatic(method)) {
        checkArgument(target == null);
    } else {
        checkArgument(target != null);
    }

    targetType = targetType(targetType, target, method);

    checkArgument(method.getDeclaringClass().isAssignableFrom(targetType.getRawType()));

    this.method = method;
    this.dependencies = ImmutableSet.copyOf(InjectionPoint.forMethod(method, targetType).getDependencies());

    if(result != null) {
        this.result = result;
        this.providedKey = Keys.forInstance(result);
    } else {
        final TypeLiteral<T> returnType = (TypeLiteral<T>) targetType.getReturnType(method);
        if(!Void.class.equals(returnType.getRawType())) {
            final Annotation qualifier = Annotations.findBindingAnnotation(errors, method, method.getAnnotations());
            this.result = null;
            this.providedKey = Keys.get(returnType, qualifier);
        } else {
            this.result = (T) this;
            this.providedKey = Keys.forInstance(this.result);
        }
    }

    this.scope = Annotations.findScopeAnnotation(errors, method.getAnnotations());

    MethodHandle handle = MethodHandleUtils.privateUnreflect(method);
    if(target != null) {
        handle = handle.bindTo(target);
    }
    this.handle = handle;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:40,代码来源:InjectableMethod.java

示例4: providerFor

import com.google.inject.internal.Annotations; //导入方法依赖的package包/类
private EventualProvider<?> providerFor(Invokable<T, ?> method, Errors methodErrors) {
  Annotation[] annotations = method.getAnnotations();

  verifyMethodAccessibility(methodErrors, method, source);

  @Nullable Annotation bindingAnnotation =
      Annotations.findBindingAnnotation(methodErrors, method, annotations);

  verifyAbsenseOfScopeAnnotation(methodErrors, annotations, source);

  List<Dependency<ListenableFuture<?>>> dependencies =
      Lists.newArrayListWithCapacity(method.getParameters().size());

  for (Parameter parameter : method.getParameters()) {
    dependencies.add(extractDependency(methodErrors, parameter));
  }

  Key<ListenableFuture<?>> bindingKey;
  boolean exposedBinding = method.isAnnotationPresent(Exposed.class);

  if (isVoid(method)) {
    bindingKey = futureKey(TypeToken.of(Boolean.class), new BlackholedAnnotation());
    exposedBinding = false;
  } else {
    bindingKey = futureKey(method.getReturnType(), bindingAnnotation);
  }

  return new EventualProvider<>(
      method,
      exposedBinding,
      dependencies,
      bindingKey,
      scopeAnnotation,
      source);
}
 
开发者ID:immutables,项目名称:miscellaneous,代码行数:36,代码来源:Providers.java

示例5: extractDependency

import com.google.inject.internal.Annotations; //导入方法依赖的package包/类
Dependency<ListenableFuture<?>> extractDependency(Errors methodErrors, Parameter parameter) {
  @Nullable Annotation bindingAnnotation =
      Annotations.findBindingAnnotation(
          methodErrors,
          parameter.getDeclaringInvokable(),
          parameter.getAnnotations());

  return Dependency.get(futureKey(
      parameter.getType(),
      bindingAnnotation));
}
 
开发者ID:immutables,项目名称:miscellaneous,代码行数:12,代码来源:Providers.java

示例6: findThrowingConstructor

import com.google.inject.internal.Annotations; //导入方法依赖的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;
}
 
开发者ID:google,项目名称:guice,代码行数:37,代码来源:CheckedProvideUtils.java

示例7: findThrowingConstructor

import com.google.inject.internal.Annotations; //导入方法依赖的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;
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:34,代码来源:CheckedProvideUtils.java

示例8: getKey

import com.google.inject.internal.Annotations; //导入方法依赖的package包/类
<T> Key<T> getKey(Errors errors, TypeLiteral<T> type, Member member, Annotation[] annotations) {
  Annotation bindingAnnotation = Annotations.findBindingAnnotation(errors, member, annotations);
  return bindingAnnotation == null ? Key.get(type) : Key.get(type, bindingAnnotation);
}
 
开发者ID:google,项目名称:guice,代码行数:5,代码来源:CheckedProviderMethodsModule.java


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