Search in sources :

Example 1 with ParamInfo

use of ru.vyarus.guice.persist.orient.repository.core.spi.parameter.ParamInfo in project guice-persist-orient by xvik.

the class ParamsService method processParameter.

@SuppressWarnings("unchecked")
private void processParameter(final ProcessingContext context, final Class<? extends RepositoryMethodDescriptor> descriptorType, final int pos, final Class<?> type, final Annotation... annotations) {
    final Annotation ext = ExtUtils.findParameterExtension(annotations);
    if (ext != null) {
        final Class<? extends MethodParamExtension> extension = ext.annotationType().getAnnotation(MethodParam.class).value();
        ExtCompatibilityUtils.checkParamExtensionCompatibility(descriptorType, extension);
        if (!context.extensionMap.containsKey(extension)) {
            final MethodParamExtension instance = injector.getInstance(extension);
            context.extensionMap.put(extension, instance);
        }
        context.extParams.put(extension, new ParamInfo(ext, pos, type));
    } else {
        context.ordinal.add(new ParamInfo(pos, type));
    }
}
Also used : MethodParamExtension(ru.vyarus.guice.persist.orient.repository.core.spi.parameter.MethodParamExtension) MethodParam(ru.vyarus.guice.persist.orient.repository.core.spi.parameter.MethodParam) Annotation(java.lang.annotation.Annotation) ParamInfo(ru.vyarus.guice.persist.orient.repository.core.spi.parameter.ParamInfo)

Example 2 with ParamInfo

use of ru.vyarus.guice.persist.orient.repository.core.spi.parameter.ParamInfo in project guice-persist-orient by xvik.

the class TargetMethodAnalyzer method analyzeMethod.

@SuppressWarnings({ "unchecked", "PMD.AvoidInstantiatingObjectsInLoops" })
private static MatchedMethod analyzeMethod(final Method method, final List<Class<?>> params, final GenericsContext targetGenerics) {
    final List<ParamInfo> ordinalParamsInfo = Lists.newArrayList();
    final List<Class<?>> types = targetGenerics.method(method).resolveParameters();
    final Annotation[][] annotations = method.getParameterAnnotations();
    boolean extended = false;
    for (int i = 0; i < types.size(); i++) {
        // ignore extensions (they always add value)
        try {
            if (ExtUtils.findParameterExtension(annotations[i]) == null) {
                ordinalParamsInfo.add(new ParamInfo(i, types.get(i)));
            } else {
                extended = true;
            }
        } catch (Exception ex) {
            throw new IllegalStateException(String.format("Error analysing method %s parameter %s", RepositoryUtils.methodToString(method), i), ex);
        }
    }
    MatchedMethod res = null;
    if (isParametersCompatible(params, ordinalParamsInfo)) {
        res = new MatchedMethod(method, ordinalParamsInfo, extended);
    }
    return res;
}
Also used : ParamInfo(ru.vyarus.guice.persist.orient.repository.core.spi.parameter.ParamInfo)

Example 3 with ParamInfo

use of ru.vyarus.guice.persist.orient.repository.core.spi.parameter.ParamInfo in project guice-persist-orient by xvik.

the class GenericParamExtension method createParam.

@SuppressWarnings("unchecked")
private ParamInfo createParam(final ParamInfo<Generic> paramInfo, final DelegateParamsContext context) {
    final Class<?> requiredType = paramInfo.annotation.genericHolder();
    final GenericsContext generics = requiredType == Object.class ? context.getCallerContext().generics : context.getCallerContext().generics.type(requiredType);
    final String generic = paramInfo.annotation.value();
    final int position = paramInfo.position;
    final Method method = context.getDescriptorContext().method;
    check(method.getParameterTypes()[position].equals(Class.class), "Generic type parameter must be Class, but it's %s", paramInfo.type.getSimpleName());
    final Class<?> type = generics.generic(generic);
    check(type != null, "Generic type name '%s' not found in %s", generic, generics.currentClass());
    return new ParamInfo(paramInfo.position, type);
}
Also used : GenericsContext(ru.vyarus.java.generics.resolver.context.GenericsContext) Method(java.lang.reflect.Method) ParamInfo(ru.vyarus.guice.persist.orient.repository.core.spi.parameter.ParamInfo)

Example 4 with ParamInfo

use of ru.vyarus.guice.persist.orient.repository.core.spi.parameter.ParamInfo in project guice-persist-orient by xvik.

the class TargetMethodAnalyzer method isParametersCompatible.

/**
 * Checking method parameters compatibility.
 *
 * @param params            repository method params to check against
 * @param ordinalParamInfos target method ordinal params (excluding extension parameters)
 * @return true if method is compatible, false otherwise
 */
@SuppressWarnings("unchecked")
private static boolean isParametersCompatible(final List<Class<?>> params, final List<ParamInfo> ordinalParamInfos) {
    boolean resolution = params.size() == ordinalParamInfos.size();
    if (resolution && !params.isEmpty()) {
        final Iterator<Class<?>> paramsIt = params.iterator();
        final Iterator<ParamInfo> targetIt = ordinalParamInfos.iterator();
        while (paramsIt.hasNext()) {
            final Class<?> type = paramsIt.next();
            final ParamInfo paramInfo = targetIt.next();
            if (!paramInfo.type.isAssignableFrom(type)) {
                resolution = false;
                break;
            }
        }
    }
    return resolution;
}
Also used : ParamInfo(ru.vyarus.guice.persist.orient.repository.core.spi.parameter.ParamInfo)

Aggregations

ParamInfo (ru.vyarus.guice.persist.orient.repository.core.spi.parameter.ParamInfo)4 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 MethodParam (ru.vyarus.guice.persist.orient.repository.core.spi.parameter.MethodParam)1 MethodParamExtension (ru.vyarus.guice.persist.orient.repository.core.spi.parameter.MethodParamExtension)1 GenericsContext (ru.vyarus.java.generics.resolver.context.GenericsContext)1