本文整理了Java中com.google.inject.internal.Annotations
类的一些代码示例,展示了Annotations
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Annotations
类的具体详情如下:
包路径:com.google.inject.internal.Annotations
类名称:Annotations
[英]Annotation utilities.
[中]注释实用程序。
代码示例来源:origin: com.google.inject/guice
InjectionPoint(TypeLiteral<?> declaringType, Field field, boolean optional) {
this.member = field;
this.declaringType = declaringType;
this.optional = optional;
Annotation[] annotations = field.getAnnotations();
Errors errors = new Errors(field);
Key<?> key = null;
try {
key = Annotations.getKey(declaringType.getFieldType(field), field, annotations, errors);
} catch (ConfigurationException e) {
errors.merge(e.getErrorMessages());
} catch (ErrorsException e) {
errors.merge(e.getErrors());
}
errors.throwConfigurationExceptionIfErrorsExist();
this.dependencies =
ImmutableList.<Dependency<?>>of(
newDependency(key, Nullability.allowsNull(annotations), -1));
}
代码示例来源:origin: com.google.inject/guice
private static void ensureIsBindingAnnotation(Class<? extends Annotation> annotationType) {
checkArgument(
Annotations.isBindingAnnotation(annotationType),
"%s is not a binding annotation. Please annotate it with @BindingAnnotation.",
annotationType.getName());
}
代码示例来源:origin: com.google.inject/guice
boolean failIfNotExplicit)
throws ErrorsException {
int numErrors = errors.size();
? key.getTypeLiteral().getRawType()
: (Class) constructorInjector.getDeclaringType().getRawType();
errors.missingImplementationWithHint(key, injector);
errors.cannotInjectInnerClass(rawType);
constructorInjector = InjectionPoint.forConstructorOf(key.getTypeLiteral());
if (failIfNotExplicit && !hasAtInject((Constructor) constructorInjector.getMember())) {
errors.atInjectRequired(rawType);
Class<? extends Annotation> scopeAnnotation = findScopeAnnotation(errors, annotatedType);
if (scopeAnnotation != null) {
scoping =
代码示例来源:origin: com.google.inject/guice
/** Gets the strategy for an annotation type. */
static AnnotationStrategy strategyFor(Class<? extends Annotation> annotationType) {
annotationType = Annotations.canonicalizeIfNamed(annotationType);
if (isAllDefaultMethods(annotationType)) {
return strategyFor(generateAnnotation(annotationType));
}
checkNotNull(annotationType, "annotation type");
ensureRetainedAtRuntime(annotationType);
ensureIsBindingAnnotation(annotationType);
return new AnnotationTypeStrategy(annotationType, null);
}
代码示例来源:origin: com.google.inject/guice
/**
* Adds an error if there is a misplaced annotations on {@code type}. Scoping annotations are not
* allowed on abstract classes or interfaces.
*/
public static void checkForMisplacedScopeAnnotations(
Class<?> type, Object source, Errors errors) {
if (Classes.isConcrete(type)) {
return;
}
Class<? extends Annotation> scopeAnnotation = findScopeAnnotation(errors, type);
if (scopeAnnotation != null
// We let Dagger Components through to aid migrations.
&& !containsComponentAnnotation(type.getAnnotations())) {
errors.withSource(type).scopeAnnotationOnAbstractType(scopeAnnotation, type, source);
}
}
代码示例来源:origin: com.google.inject/guice
/** Gets the strategy for an annotation. */
static AnnotationStrategy strategyFor(Annotation annotation) {
checkNotNull(annotation, "annotation");
Class<? extends Annotation> annotationType = annotation.annotationType();
ensureRetainedAtRuntime(annotationType);
ensureIsBindingAnnotation(annotationType);
if (Annotations.isMarker(annotationType)) {
return new AnnotationTypeStrategy(annotationType, annotation);
}
return new AnnotationInstanceStrategy(Annotations.canonicalizeIfNamed(annotation));
}
代码示例来源:origin: com.google.inject/guice
/** Gets a key for the given type, member and annotations. */
public static Key<?> getKey(
TypeLiteral<?> type, Member member, Annotation[] annotations, Errors errors)
throws ErrorsException {
int numErrorsBefore = errors.size();
Annotation found = findBindingAnnotation(errors, member, annotations);
errors.throwIfNewErrors(numErrorsBefore);
return found == null ? Key.get(type) : Key.get(type, found);
}
代码示例来源:origin: com.google.inject.extensions/guice-assistedinject
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);
}
}
代码示例来源:origin: com.mycila.guice.extensions/mycila-guice-injection
@Override
public Key<?> getKey(TypeLiteral<?> injectedType, Field injectedMember, A resourceAnnotation) {
for (Annotation annotation : injectedMember.getAnnotations())
if (Annotations.isBindingAnnotation(annotation.annotationType()))
return Key.get(injectedType.getFieldType(injectedMember), annotation);
return Key.get(injectedType.getFieldType(injectedMember));
}
代码示例来源:origin: com.google.inject/guice
private <T> void validateKey(Object source, Key<T> key) {
Annotations.checkForMisplacedScopeAnnotations(
key.getTypeLiteral().getRawType(), source, errors);
}
代码示例来源:origin: com.google.inject/guice
<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);
}
代码示例来源:origin: com.mycila.guice.extensions/mycila-guice-injection
private static Key<?> buildKey(TypeLiteral<?> type, Annotation[] annotations) {
for (Annotation annotation : annotations)
if (Annotations.isBindingAnnotation(annotation.annotationType()))
return Key.get(type, annotation);
return Key.get(type);
}
代码示例来源:origin: com.google.inject.extensions/guice-grapher
public void testGetAnnotationName_annotationInstanceWithParameters() throws Exception {
Key<?> key = Key.get(String.class, Names.named("name"));
assertEquals(
"@Named(value=" + Annotations.memberValueString("name") + ")",
nameFactory.getAnnotationName(key));
}
代码示例来源:origin: com.google/inject
Class<?> rawType = key.getTypeLiteral().getRawType();
throw errors.missingImplementation(key).toException();
Annotations.checkForMisplacedScopeAnnotations(rawType, source, errors);
return createImplementedByBinding(key, scoping, implementedBy, errors);
Annotations.checkForMisplacedScopeAnnotations(rawType, source, errors);
return createProvidedByBinding(key, scoping, providedBy, errors);
代码示例来源:origin: com.google.inject/guice
Key<T> key, Scoping scoping, Object source, Errors errors, boolean jitBinding)
throws ErrorsException {
Class<?> rawType = key.getTypeLiteral().getRawType();
throw errors.missingImplementationWithHint(key, this).toException();
Annotations.checkForMisplacedScopeAnnotations(rawType, source, errors);
return createImplementedByBinding(key, scoping, implementedBy, errors);
Annotations.checkForMisplacedScopeAnnotations(rawType, source, errors);
return createProvidedByBinding(key, scoping, providedBy, errors);
代码示例来源:origin: io.bootique.jersey/bootique-jersey
@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());
}
代码示例来源:origin: ArcBees/Jukito
public static List<Key<?>> getMethodKeys(Method method, Errors errors) {
Annotation allParameterAnnotations[][] = method.getParameterAnnotations();
List<Key<?>> result = new ArrayList<Key<?>>(allParameterAnnotations.length);
Iterator<Annotation[]> annotationsIterator = Arrays.asList(allParameterAnnotations).iterator();
TypeLiteral<?> type = TypeLiteral.get(method.getDeclaringClass());
for (TypeLiteral<?> parameterType : type.getParameterTypes(method)) {
try {
Annotation[] parameterAnnotations = annotationsIterator.next();
result.add(Annotations.getKey(parameterType, method, parameterAnnotations, errors));
} catch (ConfigurationException e) {
errors.merge(e.getErrorMessages());
} catch (ErrorsException e) {
errors.merge(e.getErrors());
}
}
return result;
}
}
代码示例来源:origin: info.magnolia/magnolia-core
private Key<?> getKey(ParameterInfo parameter) {
try {
// Get TypeLiteral for this parameter
TypeLiteral<?> declaringType = TypeLiteral.get(parameter.getDeclaringClass());
List<TypeLiteral<?>> parameterTypes = declaringType.getParameterTypes(parameter.getConstructor());
TypeLiteral<?> parameterType = parameterTypes.get(parameter.getParameterIndex());
// Create Key object for this parameter
Errors errors = new Errors(parameter.getConstructor());
return Annotations.getKey(
parameterType,
parameter.getConstructor(),
parameter.getParameterAnnotations(),
errors);
} catch (ErrorsException e) {
throw new MgnlInstantiationException(e.getMessage(), e);
}
}
}
代码示例来源:origin: com.google.inject/guice
/**
* Returns the name the binding should use. This is based on the annotation. If the annotation has
* an instance and is not a marker annotation, we ask the annotation for its toString. If it was a
* marker annotation or just an annotation type, we use the annotation's name. Otherwise, the name
* is the empty string.
*/
public static String nameOf(Key<?> key) {
Annotation annotation = key.getAnnotation();
Class<? extends Annotation> annotationType = key.getAnnotationType();
if (annotation != null && !isMarker(annotationType)) {
return key.getAnnotation().toString();
} else if (key.getAnnotationType() != null) {
return "@" + key.getAnnotationType().getName();
} else {
return "";
}
}
}
代码示例来源:origin: com.google.inject/guice
private ImmutableList<Dependency<?>> forMember(
Member member, TypeLiteral<?> type, Annotation[][] paramterAnnotations) {
Errors errors = new Errors(member);
List<Dependency<?>> dependencies = Lists.newArrayList();
int index = 0;
for (TypeLiteral<?> parameterType : type.getParameterTypes(member)) {
try {
Annotation[] parameterAnnotations = paramterAnnotations[index];
Key<?> key = Annotations.getKey(parameterType, member, parameterAnnotations, errors);
dependencies.add(newDependency(key, Nullability.allowsNull(parameterAnnotations), index));
index++;
} catch (ConfigurationException e) {
errors.merge(e.getErrorMessages());
} catch (ErrorsException e) {
errors.merge(e.getErrors());
}
}
errors.throwConfigurationExceptionIfErrorsExist();
return ImmutableList.copyOf(dependencies);
}
内容来源于网络,如有侵权,请联系作者删除!