本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
示例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));
}
示例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;
}
示例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;
}
示例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);
}