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

The following examples show how to use org.springframework.expression.spel.support.ReflectiveMethodExecutor. 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 File: MethodReference.java    From spring-analysis-note with 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 File: MethodReference.java    From java-technology-stack with 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 File: MethodReference.java    From lams with 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 File: MethodReference.java    From spring4-understanding with 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 File: MethodReference.java    From spring-analysis-note with 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 File: MethodReference.java    From java-technology-stack with 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 File: MethodReference.java    From lams with 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 File: MethodReference.java    From spring4-understanding with 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 File: MethodReference.java    From lams with 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 File: MethodReference.java    From spring4-understanding with 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);
}