1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
40
40
public abstract class Operator extends SpelNodeImpl {
41
41
42
42
private final String operatorName ;
43
-
43
+
44
44
// The descriptors of the runtime operand values are used if the discovered declared
45
45
// descriptors are not providing enough information (for example a generic type
46
46
// whose accessors seem to only be returning 'Object' - the actual descriptors may
@@ -70,7 +70,8 @@ public final String getOperatorName() {
70
70
}
71
71
72
72
/**
73
- * String format for all operators is the same '(' [operand] [operator] [operand] ')'
73
+ * String format for all operators is the same
74
+ * {@code '(' [operand] [operator] [operand] ')'}.
74
75
*/
75
76
@ Override
76
77
public String toStringAST () {
@@ -100,8 +101,8 @@ protected boolean isCompilableOperatorUsingNumerics() {
100
101
return (dc .areNumbers && dc .areCompatible );
101
102
}
102
103
103
- /**
104
- * Numeric comparison operators share very similar generated code, only differing in
104
+ /**
105
+ * Numeric comparison operators share very similar generated code, only differing in
105
106
* two comparison instructions.
106
107
*/
107
108
protected void generateComparisonCode (MethodVisitor mv , CodeFlow cf , int compInstruction1 , int compInstruction2 ) {
@@ -113,14 +114,14 @@ protected void generateComparisonCode(MethodVisitor mv, CodeFlow cf, int compIns
113
114
DescriptorComparison dc = DescriptorComparison .checkNumericCompatibility (
114
115
leftDesc , rightDesc , this .leftActualDescriptor , this .rightActualDescriptor );
115
116
char targetType = dc .compatibleType ; // CodeFlow.toPrimitiveTargetDesc(leftDesc);
116
-
117
+
117
118
cf .enterCompilationScope ();
118
119
getLeftOperand ().generateCode (mv , cf );
119
120
cf .exitCompilationScope ();
120
121
if (unboxLeft ) {
121
122
CodeFlow .insertUnboxInsns (mv , targetType , leftDesc );
122
123
}
123
-
124
+
124
125
cf .enterCompilationScope ();
125
126
getRightOperand ().generateCode (mv , cf );
126
127
cf .exitCompilationScope ();
@@ -136,11 +137,11 @@ protected void generateComparisonCode(MethodVisitor mv, CodeFlow cf, int compIns
136
137
mv .visitJumpInsn (compInstruction1 , elseTarget );
137
138
}
138
139
else if (targetType == 'F' ) {
139
- mv .visitInsn (FCMPG );
140
+ mv .visitInsn (FCMPG );
140
141
mv .visitJumpInsn (compInstruction1 , elseTarget );
141
142
}
142
143
else if (targetType == 'J' ) {
143
- mv .visitInsn (LCMP );
144
+ mv .visitInsn (LCMP );
144
145
mv .visitJumpInsn (compInstruction1 , elseTarget );
145
146
}
146
147
else if (targetType == 'I' ) {
@@ -212,6 +213,10 @@ else if (leftNumber instanceof Byte || rightNumber instanceof Byte) {
212
213
return left .toString ().equals (right .toString ());
213
214
}
214
215
216
+ if (left instanceof Boolean && right instanceof Boolean ) {
217
+ return left .equals (right );
218
+ }
219
+
215
220
if (ObjectUtils .nullSafeEquals (left , right )) {
216
221
return true ;
217
222
}
@@ -225,7 +230,7 @@ else if (leftNumber instanceof Byte || rightNumber instanceof Byte) {
225
230
226
231
return false ;
227
232
}
228
-
233
+
229
234
230
235
/**
231
236
* A descriptor comparison encapsulates the result of comparing descriptor
@@ -248,7 +253,7 @@ private DescriptorComparison(boolean areNumbers, boolean areCompatible, char com
248
253
this .areCompatible = areCompatible ;
249
254
this .compatibleType = compatibleType ;
250
255
}
251
-
256
+
252
257
/**
253
258
* Return an object that indicates whether the input descriptors are compatible.
254
259
* <p>A declared descriptor is what could statically be determined (e.g. from looking
@@ -271,7 +276,7 @@ public static DescriptorComparison checkNumericCompatibility(String leftDeclared
271
276
272
277
boolean leftNumeric = CodeFlow .isPrimitiveOrUnboxableSupportedNumberOrBoolean (ld );
273
278
boolean rightNumeric = CodeFlow .isPrimitiveOrUnboxableSupportedNumberOrBoolean (rd );
274
-
279
+
275
280
// If the declared descriptors aren't providing the information, try the actual descriptors
276
281
if (!leftNumeric && !ObjectUtils .nullSafeEquals (ld , leftActualDescriptor )) {
277
282
ld = leftActualDescriptor ;
@@ -281,7 +286,7 @@ public static DescriptorComparison checkNumericCompatibility(String leftDeclared
281
286
rd = rightActualDescriptor ;
282
287
rightNumeric = CodeFlow .isPrimitiveOrUnboxableSupportedNumberOrBoolean (rd );
283
288
}
284
-
289
+
285
290
if (leftNumeric && rightNumeric ) {
286
291
if (CodeFlow .areBoxingCompatible (ld , rd )) {
287
292
return new DescriptorComparison (true , true , CodeFlow .toPrimitiveTargetDesc (ld ));
@@ -292,7 +297,7 @@ public static DescriptorComparison checkNumericCompatibility(String leftDeclared
292
297
}
293
298
else {
294
299
return DescriptorComparison .NOT_NUMBERS ;
295
- }
300
+ }
296
301
}
297
302
}
298
303
0 commit comments