Java Code Examples for org.springframework.expression.spel.CodeFlow#areBoxingCompatible()

The following examples show how to use org.springframework.expression.spel.CodeFlow#areBoxingCompatible() . 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: Operator.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Return an object that indicates whether the input descriptors are compatible.
 * <p>A declared descriptor is what could statically be determined (e.g. from looking
 * at the return value of a property accessor method) whilst an actual descriptor
 * is the type of an actual object that was returned, which may differ.
 * <p>For generic types with unbound type variables, the declared descriptor
 * discovered may be 'Object' but from the actual descriptor it is possible to
 * observe that the objects are really numeric values (e.g. ints).
 * @param leftDeclaredDescriptor the statically determinable left descriptor
 * @param rightDeclaredDescriptor the statically determinable right descriptor
 * @param leftActualDescriptor the dynamic/runtime left object descriptor
 * @param rightActualDescriptor the dynamic/runtime right object descriptor
 * @return a DescriptorComparison object indicating the type of compatibility, if any
 */
public static DescriptorComparison checkNumericCompatibility(
		@Nullable String leftDeclaredDescriptor, @Nullable String rightDeclaredDescriptor,
		@Nullable String leftActualDescriptor, @Nullable String rightActualDescriptor) {

	String ld = leftDeclaredDescriptor;
	String rd = rightDeclaredDescriptor;

	boolean leftNumeric = CodeFlow.isPrimitiveOrUnboxableSupportedNumberOrBoolean(ld);
	boolean rightNumeric = CodeFlow.isPrimitiveOrUnboxableSupportedNumberOrBoolean(rd);

	// If the declared descriptors aren't providing the information, try the actual descriptors
	if (!leftNumeric && !ObjectUtils.nullSafeEquals(ld, leftActualDescriptor)) {
		ld = leftActualDescriptor;
		leftNumeric = CodeFlow.isPrimitiveOrUnboxableSupportedNumberOrBoolean(ld);
	}
	if (!rightNumeric && !ObjectUtils.nullSafeEquals(rd, rightActualDescriptor)) {
		rd = rightActualDescriptor;
		rightNumeric = CodeFlow.isPrimitiveOrUnboxableSupportedNumberOrBoolean(rd);
	}

	if (leftNumeric && rightNumeric) {
		if (CodeFlow.areBoxingCompatible(ld, rd)) {
			return new DescriptorComparison(true, true, CodeFlow.toPrimitiveTargetDesc(ld));
		}
		else {
			return DescriptorComparison.INCOMPATIBLE_NUMBERS;
		}
	}
	else {
		return DescriptorComparison.NOT_NUMBERS;
	}
}
 
Example 2
Source File: Operator.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Return an object that indicates whether the input descriptors are compatible.
 * <p>A declared descriptor is what could statically be determined (e.g. from looking
 * at the return value of a property accessor method) whilst an actual descriptor
 * is the type of an actual object that was returned, which may differ.
 * <p>For generic types with unbound type variables, the declared descriptor
 * discovered may be 'Object' but from the actual descriptor it is possible to
 * observe that the objects are really numeric values (e.g. ints).
 * @param leftDeclaredDescriptor the statically determinable left descriptor
 * @param rightDeclaredDescriptor the statically determinable right descriptor
 * @param leftActualDescriptor the dynamic/runtime left object descriptor
 * @param rightActualDescriptor the dynamic/runtime right object descriptor
 * @return a DescriptorComparison object indicating the type of compatibility, if any
 */
public static DescriptorComparison checkNumericCompatibility(
		@Nullable String leftDeclaredDescriptor, @Nullable String rightDeclaredDescriptor,
		@Nullable String leftActualDescriptor, @Nullable String rightActualDescriptor) {

	String ld = leftDeclaredDescriptor;
	String rd = rightDeclaredDescriptor;

	boolean leftNumeric = CodeFlow.isPrimitiveOrUnboxableSupportedNumberOrBoolean(ld);
	boolean rightNumeric = CodeFlow.isPrimitiveOrUnboxableSupportedNumberOrBoolean(rd);

	// If the declared descriptors aren't providing the information, try the actual descriptors
	if (!leftNumeric && !ObjectUtils.nullSafeEquals(ld, leftActualDescriptor)) {
		ld = leftActualDescriptor;
		leftNumeric = CodeFlow.isPrimitiveOrUnboxableSupportedNumberOrBoolean(ld);
	}
	if (!rightNumeric && !ObjectUtils.nullSafeEquals(rd, rightActualDescriptor)) {
		rd = rightActualDescriptor;
		rightNumeric = CodeFlow.isPrimitiveOrUnboxableSupportedNumberOrBoolean(rd);
	}

	if (leftNumeric && rightNumeric) {
		if (CodeFlow.areBoxingCompatible(ld, rd)) {
			return new DescriptorComparison(true, true, CodeFlow.toPrimitiveTargetDesc(ld));
		}
		else {
			return DescriptorComparison.INCOMPATIBLE_NUMBERS;
		}
	}
	else {
		return DescriptorComparison.NOT_NUMBERS;
	}
}
 
Example 3
Source File: Operator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return an object that indicates whether the input descriptors are compatible.
 * <p>A declared descriptor is what could statically be determined (e.g. from looking
 * at the return value of a property accessor method) whilst an actual descriptor
 * is the type of an actual object that was returned, which may differ.
 * <p>For generic types with unbound type variables, the declared descriptor
 * discovered may be 'Object' but from the actual descriptor it is possible to
 * observe that the objects are really numeric values (e.g. ints).
 * @param leftDeclaredDescriptor the statically determinable left descriptor
 * @param rightDeclaredDescriptor the statically determinable right descriptor
 * @param leftActualDescriptor the dynamic/runtime left object descriptor
 * @param rightActualDescriptor the dynamic/runtime right object descriptor
 * @return a DescriptorComparison object indicating the type of compatibility, if any
 */
public static DescriptorComparison checkNumericCompatibility(String leftDeclaredDescriptor,
		String rightDeclaredDescriptor, String leftActualDescriptor, String rightActualDescriptor) {

	String ld = leftDeclaredDescriptor;
	String rd = rightDeclaredDescriptor;

	boolean leftNumeric = CodeFlow.isPrimitiveOrUnboxableSupportedNumberOrBoolean(ld);
	boolean rightNumeric = CodeFlow.isPrimitiveOrUnboxableSupportedNumberOrBoolean(rd);
	
	// If the declared descriptors aren't providing the information, try the actual descriptors
	if (!leftNumeric && !ObjectUtils.nullSafeEquals(ld, leftActualDescriptor)) {
		ld = leftActualDescriptor;
		leftNumeric = CodeFlow.isPrimitiveOrUnboxableSupportedNumberOrBoolean(ld);
	}
	if (!rightNumeric && !ObjectUtils.nullSafeEquals(rd, rightActualDescriptor)) {
		rd = rightActualDescriptor;
		rightNumeric = CodeFlow.isPrimitiveOrUnboxableSupportedNumberOrBoolean(rd);
	}
	
	if (leftNumeric && rightNumeric) {
		if (CodeFlow.areBoxingCompatible(ld, rd)) {
			return new DescriptorComparison(true, true, CodeFlow.toPrimitiveTargetDesc(ld));
		}
		else {
			return DescriptorComparison.INCOMPATIBLE_NUMBERS;
		}
	}
	else {
		return DescriptorComparison.NOT_NUMBERS;
	}		
}
 
Example 4
Source File: Operator.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an object that indicates whether the input descriptors are compatible. A declared descriptor
 * is what could statically be determined (e.g. from looking at the return value of a property accessor
 * method) whilst an actual descriptor is the type of an actual object that was returned, which may differ.
 * For generic types with unbound type variables the declared descriptor discovered may be 'Object' but
 * from the actual descriptor it is possible to observe that the objects are really numeric values (e.g.
 * ints).
 * @param leftDeclaredDescriptor the statically determinable left descriptor
 * @param rightDeclaredDescriptor the statically determinable right descriptor
 * @param leftActualDescriptor the dynamic/runtime left object descriptor
 * @param rightActualDescriptor the dynamic/runtime right object descriptor
 * @return a DescriptorComparison object indicating the type of compatibility, if any
 */
public static DescriptorComparison checkNumericCompatibility(String leftDeclaredDescriptor,
		String rightDeclaredDescriptor, String leftActualDescriptor, String rightActualDescriptor) {

	String ld = leftDeclaredDescriptor;
	String rd = rightDeclaredDescriptor;

	boolean leftNumeric = CodeFlow.isPrimitiveOrUnboxableSupportedNumberOrBoolean(ld);
	boolean rightNumeric = CodeFlow.isPrimitiveOrUnboxableSupportedNumberOrBoolean(rd);
	
	// If the declared descriptors aren't providing the information, try the actual descriptors
	if (!leftNumeric && !ld.equals(leftActualDescriptor)) {
		ld = leftActualDescriptor;
		leftNumeric = CodeFlow.isPrimitiveOrUnboxableSupportedNumberOrBoolean(ld);
	}
	if (!rightNumeric && !rd.equals(rightActualDescriptor)) {
		rd = rightActualDescriptor;
		rightNumeric = CodeFlow.isPrimitiveOrUnboxableSupportedNumberOrBoolean(rd);
	}
	
	if (leftNumeric && rightNumeric) {
		if (CodeFlow.areBoxingCompatible(ld, rd)) {
			return new DescriptorComparison(true, true, CodeFlow.toPrimitiveTargetDesc(ld));
		}
		else {
			return DescriptorComparison.INCOMPATIBLE_NUMBERS;
		}
	}
	else {
		return DescriptorComparison.NOT_NUMBERS;
	}		
}