use of org.springframework.expression.spel.support.ReflectiveMethodExecutor in project spring-framework by spring-projects.
the class MethodReference method generateCode.
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
CachedMethodExecutor executorToCheck = this.cachedExecutor;
if (executorToCheck == null || !(executorToCheck.get() instanceof ReflectiveMethodExecutor)) {
throw new IllegalStateException("No applicable cached executor found: " + executorToCheck);
}
ReflectiveMethodExecutor methodExecutor = (ReflectiveMethodExecutor) executorToCheck.get();
Method method = methodExecutor.getMethod();
boolean isStaticMethod = Modifier.isStatic(method.getModifiers());
String descriptor = cf.lastDescriptor();
if (descriptor == null) {
if (!isStaticMethod) {
// Nothing on the stack but something is needed
cf.loadTarget(mv);
}
} else {
if (isStaticMethod) {
// Something on the stack when nothing is needed
mv.visitInsn(POP);
}
}
if (CodeFlow.isPrimitive(descriptor)) {
CodeFlow.insertBoxIfNecessary(mv, descriptor.charAt(0));
}
String classDesc = (Modifier.isPublic(method.getDeclaringClass().getModifiers()) ? method.getDeclaringClass().getName().replace('.', '/') : methodExecutor.getPublicDeclaringClass().getName().replace('.', '/'));
if (!isStaticMethod) {
if (descriptor == null || !descriptor.substring(1).equals(classDesc)) {
CodeFlow.insertCheckCast(mv, "L" + classDesc);
}
}
generateCodeForArguments(mv, cf, method, this.children);
mv.visitMethodInsn((isStaticMethod ? INVOKESTATIC : INVOKEVIRTUAL), classDesc, method.getName(), CodeFlow.createSignatureDescriptor(method), method.getDeclaringClass().isInterface());
cf.pushDescriptor(this.exitTypeDescriptor);
}
use of org.springframework.expression.spel.support.ReflectiveMethodExecutor in project spring-framework by spring-projects.
the class MethodReference method updateExitTypeDescriptor.
private void updateExitTypeDescriptor() {
CachedMethodExecutor executorToCheck = this.cachedExecutor;
if (executorToCheck != null && executorToCheck.get() instanceof ReflectiveMethodExecutor) {
Method method = ((ReflectiveMethodExecutor) executorToCheck.get()).getMethod();
this.exitTypeDescriptor = CodeFlow.toDescriptor(method.getReturnType());
}
}
use of org.springframework.expression.spel.support.ReflectiveMethodExecutor in project spring-framework by spring-projects.
the class MethodReference method isCompilable.
/**
* A method reference is compilable if it has been resolved to a reflectively accessible method
* and the child nodes (arguments to the method) are also compilable.
*/
@Override
public boolean isCompilable() {
CachedMethodExecutor executorToCheck = this.cachedExecutor;
if (executorToCheck == null || !(executorToCheck.get() instanceof ReflectiveMethodExecutor)) {
return false;
}
for (SpelNodeImpl child : this.children) {
if (!child.isCompilable()) {
return false;
}
}
ReflectiveMethodExecutor executor = (ReflectiveMethodExecutor) executorToCheck.get();
if (executor.didArgumentConversionOccur()) {
return false;
}
Method method = executor.getMethod();
Class<?> clazz = method.getDeclaringClass();
if (!Modifier.isPublic(clazz.getModifiers()) && executor.getPublicDeclaringClass() == null) {
return false;
}
return true;
}
Aggregations