Search in sources :

Example 1 with ConfigurationException

use of org.elasticsearch.common.inject.ConfigurationException in project crate by crate.

the class InjectionPoint method forStaticMethodsAndFields.

/**
 * 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;
}
Also used : Errors(org.elasticsearch.common.inject.internal.Errors) ConfigurationException(org.elasticsearch.common.inject.ConfigurationException) HashSet(java.util.HashSet)

Example 2 with ConfigurationException

use of org.elasticsearch.common.inject.ConfigurationException in project crate by crate.

the class InjectionPoint method forInstanceMethodsAndFields.

/**
 * 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;
}
Also used : Errors(org.elasticsearch.common.inject.internal.Errors) ConfigurationException(org.elasticsearch.common.inject.ConfigurationException) HashSet(java.util.HashSet)

Example 3 with ConfigurationException

use of org.elasticsearch.common.inject.ConfigurationException in project elasticsearch by elastic.

the class InjectionPoint method forInstanceMethodsAndFields.

/**
     * 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;
}
Also used : Errors(org.elasticsearch.common.inject.internal.Errors) ConfigurationException(org.elasticsearch.common.inject.ConfigurationException) HashSet(java.util.HashSet)

Example 4 with ConfigurationException

use of org.elasticsearch.common.inject.ConfigurationException in project elasticsearch by elastic.

the class InjectionPoint method forStaticMethodsAndFields.

/**
     * 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;
}
Also used : Errors(org.elasticsearch.common.inject.internal.Errors) ConfigurationException(org.elasticsearch.common.inject.ConfigurationException) HashSet(java.util.HashSet)

Example 5 with ConfigurationException

use of org.elasticsearch.common.inject.ConfigurationException in project elasticsearch by elastic.

the class InjectionPoint method forConstructorOf.

/**
     * Returns a new injection point for the injectable constructor of {@code type}.
     *
     * @param type a concrete type with exactly one constructor annotated {@literal @}{@link Inject},
     *             or a no-arguments constructor that is not private.
     * @throws ConfigurationException if there is no injectable constructor, more than one injectable
     *                                constructor, or if parameters of the injectable constructor are malformed, such as a
     *                                parameter with multiple binding annotations.
     */
public static InjectionPoint forConstructorOf(TypeLiteral<?> type) {
    Class<?> rawType = getRawType(type.getType());
    Errors errors = new Errors(rawType);
    Constructor<?> injectableConstructor = null;
    for (Constructor<?> constructor : rawType.getConstructors()) {
        Inject inject = constructor.getAnnotation(Inject.class);
        if (inject != null) {
            if (inject.optional()) {
                errors.optionalConstructor(constructor);
            }
            if (injectableConstructor != null) {
                errors.tooManyConstructors(rawType);
            }
            injectableConstructor = constructor;
            checkForMisplacedBindingAnnotations(injectableConstructor, errors);
        }
    }
    errors.throwConfigurationExceptionIfErrorsExist();
    if (injectableConstructor != null) {
        return new InjectionPoint(type, injectableConstructor);
    }
    // If no annotated constructor is found, look for a no-arg constructor instead.
    try {
        Constructor<?> noArgConstructor = rawType.getConstructor();
        // Disallow private constructors on non-private classes (unless they have @Inject)
        if (Modifier.isPrivate(noArgConstructor.getModifiers()) && !Modifier.isPrivate(rawType.getModifiers())) {
            errors.missingConstructor(rawType);
            throw new ConfigurationException(errors.getMessages());
        }
        checkForMisplacedBindingAnnotations(noArgConstructor, errors);
        return new InjectionPoint(type, noArgConstructor);
    } catch (NoSuchMethodException e) {
        errors.missingConstructor(rawType);
        throw new ConfigurationException(errors.getMessages());
    }
}
Also used : Inject(org.elasticsearch.common.inject.Inject) Errors(org.elasticsearch.common.inject.internal.Errors) ConfigurationException(org.elasticsearch.common.inject.ConfigurationException)

Aggregations

ConfigurationException (org.elasticsearch.common.inject.ConfigurationException)7 Errors (org.elasticsearch.common.inject.internal.Errors)6 HashSet (java.util.HashSet)4 Inject (org.elasticsearch.common.inject.Inject)2 RandomizedContext (com.carrotsearch.randomizedtesting.RandomizedContext)1 Listeners (com.carrotsearch.randomizedtesting.annotations.Listeners)1 TestGroup (com.carrotsearch.randomizedtesting.annotations.TestGroup)1 RandomStrings (com.carrotsearch.randomizedtesting.generators.RandomStrings)1 Constants (io.crate.Constants)1 SQLOperations (io.crate.action.sql.SQLOperations)1 Session (io.crate.action.sql.Session)1 SessionContext (io.crate.action.sql.SessionContext)1 Analyzer (io.crate.analyze.Analyzer)1 ParamTypeHints (io.crate.analyze.ParamTypeHints)1 Lists2 (io.crate.common.collections.Lists2)1 TimeValue (io.crate.common.unit.TimeValue)1 Paging (io.crate.data.Paging)1 Row (io.crate.data.Row)1 TransportShardAction (io.crate.execution.dml.TransportShardAction)1 TransportShardDeleteAction (io.crate.execution.dml.delete.TransportShardDeleteAction)1