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


Java TypeLiteral类代码示例

本文整理汇总了Java中org.elasticsearch.common.inject.TypeLiteral的典型用法代码示例。如果您正苦于以下问题:Java TypeLiteral类的具体用法?Java TypeLiteral怎么用?Java TypeLiteral使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: InjectionPoint

import org.elasticsearch.common.inject.TypeLiteral; //导入依赖的package包/类
InjectionPoint(TypeLiteral<?> type, Field field) {
    this.member = field;

    Inject inject = field.getAnnotation(Inject.class);
    this.optional = inject.optional();

    Annotation[] annotations = field.getAnnotations();

    Errors errors = new Errors(field);
    Key<?> key = null;
    try {
        key = Annotations.getKey(type.getFieldType(field), field, annotations, errors);
    } catch (ErrorsException e) {
        errors.merge(e.getErrors());
    }
    errors.throwConfigurationExceptionIfErrorsExist();

    this.dependencies = Collections.<Dependency<?>>singletonList(
        newDependency(key, Nullability.allowsNull(annotations), -1));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:InjectionPoint.java

示例2: forMember

import org.elasticsearch.common.inject.TypeLiteral; //导入依赖的package包/类
private List<Dependency<?>> forMember(Member member, TypeLiteral<?> type,
                                               Annotation[][] parameterAnnotations) {
    Errors errors = new Errors(member);
    Iterator<Annotation[]> annotationsIterator = Arrays.asList(parameterAnnotations).iterator();

    List<Dependency<?>> dependencies = new ArrayList<>();
    int index = 0;

    for (TypeLiteral<?> parameterType : type.getParameterTypes(member)) {
        try {
            Annotation[] paramAnnotations = annotationsIterator.next();
            Key<?> key = Annotations.getKey(parameterType, member, paramAnnotations, errors);
            dependencies.add(newDependency(key, Nullability.allowsNull(paramAnnotations), index));
            index++;
        } catch (ErrorsException e) {
            errors.merge(e.getErrors());
        }
    }

    errors.throwConfigurationExceptionIfErrorsExist();
    return Collections.unmodifiableList(dependencies);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:InjectionPoint.java

示例3: addInjectorsForMembers

import org.elasticsearch.common.inject.TypeLiteral; //导入依赖的package包/类
private static <M extends Member & AnnotatedElement> void addInjectorsForMembers(
        TypeLiteral<?> typeLiteral, Factory<M> factory, boolean statics,
        Collection<InjectionPoint> injectionPoints, Errors errors) {
    for (M member : factory.getMembers(getRawType(typeLiteral.getType()))) {
        if (isStatic(member) != statics) {
            continue;
        }

        Inject inject = member.getAnnotation(Inject.class);
        if (inject == null) {
            continue;
        }

        try {
            injectionPoints.add(factory.create(typeLiteral, member, errors));
        } catch (ConfigurationException ignorable) {
            if (!inject.optional()) {
                errors.merge(ignorable.getErrorMessages());
            }
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:InjectionPoint.java

示例4: AssistedConstructor

import org.elasticsearch.common.inject.TypeLiteral; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public AssistedConstructor(Constructor<T> constructor, List<TypeLiteral<?>> parameterTypes) {
    this.constructor = constructor;

    Annotation[][] annotations = constructor.getParameterAnnotations();

    List<Type> typeList = new ArrayList<>();
    allParameters = new ArrayList<>();

    // categorize params as @Assisted or @Injected
    for (int i = 0; i < parameterTypes.size(); i++) {
        Parameter parameter = new Parameter(parameterTypes.get(i).getType(), annotations[i]);
        allParameters.add(parameter);
        if (parameter.isProvidedByFactory()) {
            typeList.add(parameter.getType());
        }
    }
    this.assistedParameters = new ParameterListKey(typeList);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:20,代码来源:AssistedConstructor.java

示例5: forStaticMethodsAndFields

import org.elasticsearch.common.inject.TypeLiteral; //导入依赖的package包/类
/**
 * Returns all static method and field injection points on {@code type}.
 *
 * @return a possibly empty set of injection points. The set has a specified iteration order. All
 *         fields are returned and then all methods. Within the fields, supertype fields are returned
 *         before subtype fields. Similarly, supertype methods are returned before subtype methods.
 * @throws ConfigurationException if there is a malformed injection point on {@code type}, such as
 *                                a field with multiple binding annotations. The exception's {@link
 *                                ConfigurationException#getPartialValue() partial value} is a {@code Set<InjectionPoint>}
 *                                of the valid injection points.
 */
public static Set<InjectionPoint> forStaticMethodsAndFields(TypeLiteral type) {
    Set<InjectionPoint> result = new HashSet<>();
    Errors errors = new Errors();

    addInjectionPoints(type, Factory.FIELDS, true, result, errors);
    addInjectionPoints(type, Factory.METHODS, true, result, errors);

    result = unmodifiableSet(result);
    if (errors.hasErrors()) {
        throw new ConfigurationException(errors.getMessages()).withPartialValue(result);
    }
    return result;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:InjectionPoint.java

示例6: forInstanceMethodsAndFields

import org.elasticsearch.common.inject.TypeLiteral; //导入依赖的package包/类
/**
 * Returns all instance method and field injection points on {@code type}.
 *
 * @return a possibly empty set of injection points. The set has a specified iteration order. All
 *         fields are returned and then all methods. Within the fields, supertype fields are returned
 *         before subtype fields. Similarly, supertype methods are returned before subtype methods.
 * @throws ConfigurationException if there is a malformed injection point on {@code type}, such as
 *                                a field with multiple binding annotations. The exception's {@link
 *                                ConfigurationException#getPartialValue() partial value} is a {@code Set<InjectionPoint>}
 *                                of the valid injection points.
 */
public static Set<InjectionPoint> forInstanceMethodsAndFields(TypeLiteral<?> type) {
    Set<InjectionPoint> result = new HashSet<>();
    Errors errors = new Errors();

    // TODO (crazybob): Filter out overridden members.
    addInjectionPoints(type, Factory.FIELDS, false, result, errors);
    addInjectionPoints(type, Factory.METHODS, false, result, errors);

    result = unmodifiableSet(result);
    if (errors.hasErrors()) {
        throw new ConfigurationException(errors.getMessages()).withPartialValue(result);
    }
    return result;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:InjectionPoint.java

示例7: newSetBinder

import org.elasticsearch.common.inject.TypeLiteral; //导入依赖的package包/类
/**
 * Returns a new multibinder that collects instances of {@code type} in a {@link Set} that is
 * itself bound with no binding annotation.
 */
public static <T> Multibinder<T> newSetBinder(Binder binder, TypeLiteral<T> type) {
    binder = binder.skipSources(RealMultibinder.class, Multibinder.class);
    RealMultibinder<T> result = new RealMultibinder<>(binder, type, "",
            Key.get(Multibinder.<T>setOf(type)));
    binder.install(result);
    return result;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:12,代码来源:Multibinder.java

示例8: getKey

import org.elasticsearch.common.inject.TypeLiteral; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:Annotations.java

示例9: errorNotifyingTypeListener

import org.elasticsearch.common.inject.TypeLiteral; //导入依赖的package包/类
public Errors errorNotifyingTypeListener(TypeListenerBinding listener,
                                         TypeLiteral<?> type, Throwable cause) {
    return errorInUserCode(cause,
            "Error notifying TypeListener %s (bound at %s) of %s.%n"
                    + " Reason: %s",
            listener.getListener(), convert(listener.getSource()), type, cause);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:8,代码来源:Errors.java

示例10: conversionError

import org.elasticsearch.common.inject.TypeLiteral; //导入依赖的package包/类
public Errors conversionError(String stringValue, Object source,
                              TypeLiteral<?> type, MatcherAndConverter matchingConverter, RuntimeException cause) {
    return errorInUserCode(cause, "Error converting '%s' (bound at %s) to %s%n"
            + " using %s.%n"
            + " Reason: %s",
            stringValue, convert(source), type, matchingConverter, cause);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:Errors.java

示例11: ambiguousTypeConversion

import org.elasticsearch.common.inject.TypeLiteral; //导入依赖的package包/类
public Errors ambiguousTypeConversion(String stringValue, Object source, TypeLiteral<?> type,
                                      MatcherAndConverter a, MatcherAndConverter b) {
    return addMessage("Multiple converters can convert '%s' (bound at %s) to %s:%n"
            + " %s and%n"
            + " %s.%n"
            + " Please adjust your type converter configuration to avoid overlapping matches.",
            stringValue, convert(source), type, a, b);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:Errors.java

示例12: formatSource

import org.elasticsearch.common.inject.TypeLiteral; //导入依赖的package包/类
public static void formatSource(Formatter formatter, Object source) {
    if (source instanceof Dependency) {
        Dependency<?> dependency = (Dependency<?>) source;
        InjectionPoint injectionPoint = dependency.getInjectionPoint();
        if (injectionPoint != null) {
            formatInjectionPoint(formatter, dependency, injectionPoint);
        } else {
            formatSource(formatter, dependency.getKey());
        }

    } else if (source instanceof InjectionPoint) {
        formatInjectionPoint(formatter, null, (InjectionPoint) source);

    } else if (source instanceof Class) {
        formatter.format("  at %s%n", StackTraceElements.forType((Class<?>) source));

    } else if (source instanceof Member) {
        formatter.format("  at %s%n", StackTraceElements.forMember((Member) source));

    } else if (source instanceof TypeLiteral) {
        formatter.format("  while locating %s%n", source);

    } else if (source instanceof Key) {
        Key<?> key = (Key<?>) source;
        formatter.format("  while locating %s%n", convert(key));

    } else {
        formatter.format("  at %s%n", source);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:31,代码来源:Errors.java

示例13: addInjectionPoints

import org.elasticsearch.common.inject.TypeLiteral; //导入依赖的package包/类
private static <M extends Member & AnnotatedElement> void addInjectionPoints(TypeLiteral<?> type,
                                                                             Factory<M> factory, boolean statics, Collection<InjectionPoint> injectionPoints,
                                                                             Errors errors) {
    if (type.getType() == Object.class) {
        return;
    }

    // Add injectors for superclass first.
    TypeLiteral<?> superType = type.getSupertype(type.getRawType().getSuperclass());
    addInjectionPoints(superType, factory, statics, injectionPoints, errors);

    // Add injectors for all members next
    addInjectorsForMembers(type, factory, statics, injectionPoints, errors);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:15,代码来源:InjectionPoint.java

示例14: newMapBinder

import org.elasticsearch.common.inject.TypeLiteral; //导入依赖的package包/类
/**
 * Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} in a
 * {@link Map} that is itself bound with {@code annotation}.
 */
public static <K, V> MapBinder<K, V> newMapBinder(Binder binder,
                                                  TypeLiteral<K> keyType, TypeLiteral<V> valueType, Annotation annotation) {
    binder = binder.skipSources(MapBinder.class, RealMapBinder.class);
    return newMapBinder(binder, valueType,
            Key.get(mapOf(keyType, valueType), annotation),
            Key.get(mapOfProviderOf(keyType, valueType), annotation),
            Multibinder.newSetBinder(binder, entryOfProviderOf(keyType, valueType), annotation));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:MapBinder.java

示例15: hear

import org.elasticsearch.common.inject.TypeLiteral; //导入依赖的package包/类
@Override
public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
    encounter.register(new InjectionListener<I>() {
        @Override
        public void afterInjection(I injectee) {
            instanceFuture.set((CrateRestMainAction)injectee);
        }
    });
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:10,代码来源:CrateCoreModule.java


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