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));
}
}
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;
}
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);
}
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;
}
Aggregations