本文整理了Java中com.google.inject.Key.getAnnotationType()
方法的一些代码示例,展示了Key.getAnnotationType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Key.getAnnotationType()
方法的具体详情如下:
包路径:com.google.inject.Key
类名称:Key
方法名:getAnnotationType
[英]Gets the annotation type.
[中]获取批注类型。
代码示例来源:origin: com.google.inject/guice
protected void checkNotAnnotated() {
if (key.getAnnotationType() != null) {
binder.addError(AbstractBindingBuilder.ANNOTATION_ALREADY_SPECIFIED);
}
}
代码示例来源:origin: com.google.inject/guice
/** Returns true if the key type is MembersInjector (but not a subclass of MembersInjector). */
private static boolean isMembersInjector(Key<?> key) {
return key.getTypeLiteral().getRawType().equals(MembersInjector.class)
&& key.getAnnotationType() == null;
}
代码示例来源:origin: apache/incubator-druid
@SuppressWarnings("unchecked")
public static <T> void bindInstance(
Binder binder,
Key<T> bindKey,
T instance
)
{
binder.bind(bindKey).toInstance(instance);
final ParameterizedType supType = Types.newParameterizedType(Supplier.class, bindKey.getTypeLiteral().getType());
final Key supplierKey;
if (bindKey.getAnnotationType() != null) {
supplierKey = Key.get(supType, bindKey.getAnnotationType());
} else if (bindKey.getAnnotation() != null) {
supplierKey = Key.get(supType, bindKey.getAnnotation());
} else {
supplierKey = Key.get(supType);
}
binder.bind(supplierKey).toInstance(Suppliers.ofInstance(instance));
}
代码示例来源: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
protected void checkNotAnnotated() {
if (binding.getKey().getAnnotationType() != null) {
binder.addError(ANNOTATION_ALREADY_SPECIFIED);
}
}
代码示例来源:origin: apache/incubator-druid
/**
* Binds an option for a specific choice. The choice must already be registered on the injector for this to work.
*
* @param binder the binder for the injector that is being configured
* @param interfaceKey the interface that will have an option added to it. This must equal the
* Key provided to createChoice
* @param <T> interface type
* @return A MapBinder that can be used to create the actual option bindings.
*/
public static <T> MapBinder<String, T> optionBinder(Binder binder, Key<T> interfaceKey)
{
final TypeLiteral<T> interfaceType = interfaceKey.getTypeLiteral();
if (interfaceKey.getAnnotation() != null) {
return MapBinder.newMapBinder(binder, TypeLiteral.get(String.class), interfaceType, interfaceKey.getAnnotation());
} else if (interfaceKey.getAnnotationType() != null) {
Class<? extends Annotation> annotationType = interfaceKey.getAnnotationType();
return MapBinder.newMapBinder(binder, TypeLiteral.get(String.class), interfaceType, annotationType);
} else {
return MapBinder.newMapBinder(binder, TypeLiteral.get(String.class), interfaceType);
}
}
代码示例来源:origin: com.google.inject/guice
/**
* Returns a key that doesn't hold any references to parent classes. This is necessary for
* anonymous keys, so ensure we don't hold a ref to the containing module (or class) forever.
*/
public static <T> Key<T> canonicalizeKey(Key<T> key) {
// If we know this isn't a subclass, return as-is.
// Otherwise, recreate the key to avoid the subclass
if (key.getClass() == Key.class) {
return key;
} else if (key.getAnnotation() != null) {
return Key.get(key.getTypeLiteral(), key.getAnnotation());
} else if (key.getAnnotationType() != null) {
return Key.get(key.getTypeLiteral(), key.getAnnotationType());
} else {
return Key.get(key.getTypeLiteral());
}
}
代码示例来源:origin: com.google.inject/guice
@Override
public String toString(Key key) {
if (key.getAnnotationType() != null) {
return key.getTypeLiteral()
+ " annotated with "
+ (key.getAnnotation() != null ? key.getAnnotation() : key.getAnnotationType());
} else {
return key.getTypeLiteral().toString();
}
}
});
代码示例来源:origin: apache/incubator-druid
if (key.getAnnotation() != null) {
implsMap = (Map<String, Provider<T>>) injector.getInstance(Key.get(mapType, key.getAnnotation()));
} else if (key.getAnnotationType() != null) {
implsMap = (Map<String, Provider<T>>) injector.getInstance(Key.get(mapType, key.getAnnotationType()));
} else {
implsMap = (Map<String, Provider<T>>) injector.getInstance(Key.get(mapType));
代码示例来源:origin: com.google.inject/guice
private void toConstant(Class<?> type, Object instance) {
// this type will define T, so these assignments are safe
@SuppressWarnings("unchecked")
Class<T> typeAsClassT = (Class<T>) type;
@SuppressWarnings("unchecked")
T instanceAsT = (T) instance;
if (keyTypeIsSet()) {
binder.addError(CONSTANT_VALUE_ALREADY_SET);
return;
}
BindingImpl<T> base = getBinding();
Key<T> key;
if (base.getKey().getAnnotation() != null) {
key = Key.get(typeAsClassT, base.getKey().getAnnotation());
} else if (base.getKey().getAnnotationType() != null) {
key = Key.get(typeAsClassT, base.getKey().getAnnotationType());
} else {
key = Key.get(typeAsClassT);
}
if (instanceAsT == null) {
binder.addError(BINDING_TO_NULL);
}
setBinding(
new InstanceBindingImpl<T>(
base.getSource(),
key,
base.getScoping(),
ImmutableSet.<InjectionPoint>of(),
instanceAsT));
}
代码示例来源:origin: com.google.inject/guice
@Override
public Boolean visit(UntargettedBinding<? extends T> untargetted) {
prepareBinding();
// Error: Missing implementation.
// Example: bind(Date.class).annotatedWith(Red.class);
// We can't assume abstract types aren't injectable. They may have an
// @ImplementedBy annotation or something.
if (key.getAnnotationType() != null) {
errors.missingImplementationWithHint(key, injector);
putBinding(invalidBinding(injector, key, source));
return true;
}
// This cast is safe after the preceeding check.
try {
BindingImpl<T> binding =
injector.createUninitializedBinding(key, scoping, source, errors, false);
scheduleInitialization(binding);
putBinding(binding);
} catch (ErrorsException e) {
errors.merge(e.getErrors());
putBinding(invalidBinding(injector, key, source));
}
return true;
}
代码示例来源:origin: com.google.inject/guice
if (key.getAnnotationType() != null) {
代码示例来源:origin: org.sonatype.sisu/sisu-guice
protected void checkNotAnnotated() {
if (key.getAnnotationType() != null) {
binder.addError(AbstractBindingBuilder.ANNOTATION_ALREADY_SPECIFIED);
}
}
代码示例来源:origin: com.google.inject.extensions/guice-assistedinject
/** Return all non-assisted dependencies. */
private Set<Dependency<?>> removeAssistedDeps(Set<Dependency<?>> deps) {
ImmutableSet.Builder<Dependency<?>> builder = ImmutableSet.builder();
for (Dependency<?> dep : deps) {
Class<?> annotationType = dep.getKey().getAnnotationType();
if (annotationType == null || !annotationType.equals(Assisted.class)) {
builder.add(dep);
}
}
return builder.build();
}
代码示例来源:origin: com.google/inject
/** Returns true if the key type is MembersInjector (but not a subclass of MembersInjector). */
private static boolean isMembersInjector(Key<?> key) {
return key.getTypeLiteral().getRawType().equals(MembersInjector.class)
&& !(key.getAnnotationType() != null);
}
代码示例来源:origin: com.google/inject
protected void checkNotAnnotated() {
if (key.getAnnotationType() != null) {
binder.addError(AbstractBindingBuilder.ANNOTATION_ALREADY_SPECIFIED);
}
}
代码示例来源:origin: com.google/inject
protected void checkNotAnnotated() {
if (binding.getKey().getAnnotationType() != null) {
binder.addError(ANNOTATION_ALREADY_SPECIFIED);
}
}
代码示例来源:origin: org.sonatype.sisu/sisu-guice
protected void checkNotAnnotated() {
if (binding.getKey().getAnnotationType() != null) {
binder.addError(ANNOTATION_ALREADY_SPECIFIED);
}
}
代码示例来源:origin: com.atlassian.org.eclipse.sisu/org.eclipse.sisu.inject
@Override
public Boolean visit( final LinkedKeyBinding<?> binding )
{
final Key<?> linkedKey = binding.getLinkedKey();
if ( linkedKey.getAnnotationType() == null )
{
return verifyImplementation( linkedKey.getTypeLiteral() );
}
return Boolean.TRUE; // indirect binding, don't scan
}
代码示例来源:origin: com.atlassian.org.eclipse.sisu/org.eclipse.sisu.inject
@Override
public Boolean visit( final ProviderKeyBinding<?> binding )
{
final Key<?> providerKey = binding.getProviderKey();
if ( providerKey.getAnnotationType() == null )
{
return analyzeImplementation( providerKey.getTypeLiteral(), true );
}
return Boolean.TRUE; // indirect binding, don't scan
}
内容来源于网络,如有侵权,请联系作者删除!