mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
extracted MethodEvaluator
This commit is contained in:
parent
29054a66fa
commit
45abdbfae0
@ -10,7 +10,6 @@ import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Arrays;
|
||||
@ -133,24 +132,7 @@ public class EvaluatorFactory {
|
||||
}
|
||||
|
||||
final Method method = clazz.getMethod("eval", types);
|
||||
return new Evaluator<T>() {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public T evaluate(Object... args) {
|
||||
try {
|
||||
return (T) method.invoke(object, args);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends T> getType() {
|
||||
return projectionType;
|
||||
}
|
||||
};
|
||||
return new MethodEvaluator<T>(method, object, projectionType);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new CodegenException(e);
|
||||
} catch (SecurityException e) {
|
||||
|
||||
44
src/main/java/com/mysema/codegen/MethodEvaluator.java
Normal file
44
src/main/java/com/mysema/codegen/MethodEvaluator.java
Normal file
@ -0,0 +1,44 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.mysema.codegen;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @author tiwe
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public final class MethodEvaluator<T> implements Evaluator<T> {
|
||||
|
||||
private final Method method;
|
||||
|
||||
private final Object object;
|
||||
|
||||
private final Class<? extends T> projectionType;
|
||||
|
||||
MethodEvaluator(Method method, Object object, Class<? extends T> projectionType) {
|
||||
this.method = method;
|
||||
this.object = object;
|
||||
this.projectionType = projectionType;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public T evaluate(Object... args) {
|
||||
try {
|
||||
return (T) method.invoke(object, args);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends T> getType() {
|
||||
return projectionType;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user