Java Code Examples for org.springframework.expression.spel.support.ReflectiveMethodExecutor

The following examples show how to use org.springframework.expression.spel.support.ReflectiveMethodExecutor. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-analysis-note   Source File: MethodReference.java    License: MIT License 6 votes vote down vote up
/**
 * 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.hasProxyTarget() ||
			!(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;
	}
	Class<?> clazz = executor.getMethod().getDeclaringClass();
	if (!Modifier.isPublic(clazz.getModifiers()) && executor.getPublicDeclaringClass() == null) {
		return false;
	}

	return true;
}
 
Example 2
Source Project: java-technology-stack   Source File: MethodReference.java    License: MIT License 6 votes vote down vote up
/**
 * 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.hasProxyTarget() ||
			!(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;
	}
	Class<?> clazz = executor.getMethod().getDeclaringClass();
	if (!Modifier.isPublic(clazz.getModifiers()) && executor.getPublicDeclaringClass() == null) {
		return false;
	}

	return true;
}
 
Example 3
Source Project: lams   Source File: MethodReference.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source Project: spring4-understanding   Source File: MethodReference.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source Project: spring-analysis-note   Source File: MethodReference.java    License: MIT License 5 votes vote down vote up
private void updateExitTypeDescriptor() {
	CachedMethodExecutor executorToCheck = this.cachedExecutor;
	if (executorToCheck != null && executorToCheck.get() instanceof ReflectiveMethodExecutor) {
		Method method = ((ReflectiveMethodExecutor) executorToCheck.get()).getMethod();
		String descriptor = CodeFlow.toDescriptor(method.getReturnType());
		if (this.nullSafe && CodeFlow.isPrimitive(descriptor)) {
			this.originalPrimitiveExitTypeDescriptor = descriptor;
			this.exitTypeDescriptor = CodeFlow.toBoxedDescriptor(descriptor);
		}
		else {
			this.exitTypeDescriptor = descriptor;
		}
	}
}
 
Example 6
Source Project: java-technology-stack   Source File: MethodReference.java    License: MIT License 5 votes vote down vote up
private void updateExitTypeDescriptor() {
	CachedMethodExecutor executorToCheck = this.cachedExecutor;
	if (executorToCheck != null && executorToCheck.get() instanceof ReflectiveMethodExecutor) {
		Method method = ((ReflectiveMethodExecutor) executorToCheck.get()).getMethod();
		String descriptor = CodeFlow.toDescriptor(method.getReturnType());
		if (this.nullSafe && CodeFlow.isPrimitive(descriptor)) {
			this.originalPrimitiveExitTypeDescriptor = descriptor;
			this.exitTypeDescriptor = CodeFlow.toBoxedDescriptor(descriptor);
		}
		else {
			this.exitTypeDescriptor = descriptor;
		}
	}
}
 
Example 7
Source Project: lams   Source File: MethodReference.java    License: GNU General Public License v2.0 5 votes vote down vote up
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());
	}
}
 
Example 8
Source Project: spring4-understanding   Source File: MethodReference.java    License: Apache License 2.0 5 votes vote down vote up
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());
	}
}
 
Example 9
Source Project: lams   Source File: MethodReference.java    License: GNU General Public License v2.0 4 votes vote down vote up
@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);
}
 
Example 10
Source Project: spring4-understanding   Source File: MethodReference.java    License: Apache License 2.0 4 votes vote down vote up
@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);
}