本文整理了Java中org.elasticsearch.common.inject.Key.getTypeLiteral()
方法的一些代码示例,展示了Key.getTypeLiteral()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Key.getTypeLiteral()
方法的具体详情如下:
包路径:org.elasticsearch.common.inject.Key
类名称:Key
方法名:getTypeLiteral
[英]Gets the key type.
[中]获取密钥类型。
代码示例来源:origin: org.elasticsearch/elasticsearch
@Override
public String toString() {
return "Provider<" + lookup.key.getTypeLiteral() + ">";
}
代码示例来源:origin: org.elasticsearch/elasticsearch
/**
* Returns true if the key type is Provider (but not a subclass of Provider).
*/
static boolean isProvider(Key<?> key) {
return key.getTypeLiteral().getRawType().equals(Provider.class);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
@Override
public void annotatedWith(Class<? extends Annotation> annotationType) {
Objects.requireNonNull(annotationType, "annotationType");
checkNotAnnotated();
key = Key.get(key.getTypeLiteral(), annotationType);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
@Override
public void annotatedWith(Annotation annotation) {
Objects.requireNonNull(annotation, "annotation");
checkNotAnnotated();
key = Key.get(key.getTypeLiteral(), annotation);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
/**
* Returns true if the key type is MembersInjector (but not a subclass of MembersInjector).
*/
static boolean isMembersInjector(Key<?> key) {
return key.getTypeLiteral().getRawType().equals(MembersInjector.class)
&& !key.hasAnnotationType();
}
代码示例来源:origin: org.elasticsearch/elasticsearch
protected boolean keyTypeIsSet() {
return !Void.class.equals(binding.getKey().getTypeLiteral().getType());
}
代码示例来源:origin: org.elasticsearch/elasticsearch
@Override
public String toString() {
return "BindingBuilder<" + getBinding().getKey().getTypeLiteral() + ">";
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
<T> void index(Binding<T> binding) {
bindingsMultimap.put(binding.getKey().getTypeLiteral(), binding);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
public void initialize(InjectorImpl injector, Errors errors) throws ErrorsException {
factory.constructorInjector = injector.constructors.get(getKey().getTypeLiteral(), errors);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
@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: org.elasticsearch/elasticsearch
private boolean keyMatches(Key<?> key) {
return key.getTypeLiteral().equals(elementType)
&& key.getAnnotation() instanceof Element
&& ((Element) key.getAnnotation()).setName().equals(setName);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
/**
* Sets the binding to a copy with the specified annotation on the bound key
*/
protected BindingImpl<T> annotatedWithInternal(Class<? extends Annotation> annotationType) {
Objects.requireNonNull(annotationType, "annotationType");
checkNotAnnotated();
return setBinding(binding.withKey(
Key.get(this.binding.getKey().getTypeLiteral(), annotationType)));
}
代码示例来源:origin: org.elasticsearch/elasticsearch
/**
* Sets the binding to a copy with the specified annotation on the bound key
*/
protected BindingImpl<T> annotatedWithInternal(Annotation annotation) {
Objects.requireNonNull(annotation, "annotation");
checkNotAnnotated();
return setBinding(binding.withKey(
Key.get(this.binding.getKey().getTypeLiteral(), annotation)));
}
代码示例来源:origin: org.elasticsearch/elasticsearch
private <T> BindingImpl<MembersInjector<T>> createMembersInjectorBinding(
Key<MembersInjector<T>> key, Errors errors) throws ErrorsException {
Type membersInjectorType = key.getTypeLiteral().getType();
if (!(membersInjectorType instanceof ParameterizedType)) {
throw errors.cannotInjectRawMembersInjector().toException();
}
@SuppressWarnings("unchecked") // safe because T came from Key<MembersInjector<T>>
TypeLiteral<T> instanceType = (TypeLiteral<T>) TypeLiteral.get(
((ParameterizedType) membersInjectorType).getActualTypeArguments()[0]);
MembersInjector<T> membersInjector = membersInjectorStore.get(instanceType, errors);
InternalFactory<MembersInjector<T>> factory = new ConstantFactory<>(
Initializables.of(membersInjector));
return new InstanceBindingImpl<>(this, key, SourceProvider.UNKNOWN_SOURCE,
factory, emptySet(), membersInjector);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
/**
* Creates a synthetic binding to {@code Provider<T>}, i.e. a binding to the provider from
* {@code Binding<T>}.
*/
private <T> BindingImpl<Provider<T>> createProviderBinding(Key<Provider<T>> key, Errors errors)
throws ErrorsException {
Type providerType = key.getTypeLiteral().getType();
// If the Provider has no type parameter (raw Provider)...
if (!(providerType instanceof ParameterizedType)) {
throw errors.cannotInjectRawProvider().toException();
}
Type entryType = ((ParameterizedType) providerType).getActualTypeArguments()[0];
@SuppressWarnings("unchecked") // safe because T came from Key<Provider<T>>
Key<T> providedKey = (Key<T>) key.ofType(entryType);
BindingImpl<T> delegate = getBindingOrThrow(providedKey, errors);
return new ProviderBindingImpl<>(this, key, delegate);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
/**
* Converts a binding for a {@code Key<TypeLiteral<T>>} to the value {@code TypeLiteral<T>}. It's
* a bit awkward because we have to pull out the inner type in the type literal.
*/
private <T> BindingImpl<TypeLiteral<T>> createTypeLiteralBinding(
Key<TypeLiteral<T>> key, Errors errors) throws ErrorsException {
Type typeLiteralType = key.getTypeLiteral().getType();
if (!(typeLiteralType instanceof ParameterizedType)) {
throw errors.cannotInjectRawTypeLiteral().toException();
}
ParameterizedType parameterizedType = (ParameterizedType) typeLiteralType;
Type innerType = parameterizedType.getActualTypeArguments()[0];
// this is unfortunate. We don't support building TypeLiterals for type variable like 'T'. If
// this proves problematic, we can probably fix TypeLiteral to support type variables
if (!(innerType instanceof Class)
&& !(innerType instanceof GenericArrayType)
&& !(innerType instanceof ParameterizedType)) {
throw errors.cannotInjectTypeLiteralOf(innerType).toException();
}
@SuppressWarnings("unchecked") // by definition, innerType == T, so this is safe
TypeLiteral<T> value = (TypeLiteral<T>) TypeLiteral.get(innerType);
InternalFactory<TypeLiteral<T>> factory = new ConstantFactory<>(
Initializables.of(value));
return new InstanceBindingImpl<>(this, key, SourceProvider.UNKNOWN_SOURCE,
factory, emptySet(), value);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
Class<?> rawType = key.getTypeLiteral().getRawType();
代码示例来源:origin: org.elasticsearch/elasticsearch
ImplementedBy implementedBy, Errors errors)
throws ErrorsException {
Class<?> rawType = key.getTypeLiteral().getRawType();
Class<?> implementationType = implementedBy.value();
代码示例来源:origin: org.elasticsearch/elasticsearch
final Class<?> rawType = key.getTypeLiteral().getRawType();
final Class<? extends Provider<?>> providerType = providedBy.value();
代码示例来源:origin: org.elasticsearch/elasticsearch
TypeLiteral<T> type = key.getTypeLiteral();
MatcherAndConverter matchingConverter = state.getConverter(stringValue, type, errors, source);
内容来源于网络,如有侵权,请联系作者删除!