(Primitive val, int kind)
| 646 | } |
| 647 | |
| 648 | public static Primitive unaryOperation(Primitive val, int kind) |
| 649 | throws UtilEvalError |
| 650 | { |
| 651 | if (val == NULL) |
| 652 | throw new UtilEvalError( |
| 653 | "illegal use of null object or 'null' literal"); |
| 654 | if (val == VOID) |
| 655 | throw new UtilEvalError( |
| 656 | "illegal use of undefined object or 'void' literal"); |
| 657 | |
| 658 | Class operandType = val.getType(); |
| 659 | Object operand = promoteToInteger(val.getValue()); |
| 660 | |
| 661 | if ( operand instanceof Boolean ) |
| 662 | return booleanUnaryOperation((Boolean)operand, kind) |
| 663 | ? Primitive.TRUE : Primitive.FALSE; |
| 664 | else if(operand instanceof Integer) |
| 665 | { |
| 666 | int result = intUnaryOperation((Integer)operand, kind); |
| 667 | |
| 668 | // ++ and -- must be cast back the original type |
| 669 | if(kind == INCR || kind == DECR) |
| 670 | { |
| 671 | if(operandType == Byte.TYPE) |
| 672 | return new Primitive((byte)result); |
| 673 | if(operandType == Short.TYPE) |
| 674 | return new Primitive((short)result); |
| 675 | if(operandType == Character.TYPE) |
| 676 | return new Primitive((char)result); |
| 677 | } |
| 678 | |
| 679 | return new Primitive(result); |
| 680 | } |
| 681 | else if(operand instanceof Long) |
| 682 | return new Primitive(longUnaryOperation((Long)operand, kind)); |
| 683 | else if(operand instanceof Float) |
| 684 | return new Primitive(floatUnaryOperation((Float)operand, kind)); |
| 685 | else if(operand instanceof Double) |
| 686 | return new Primitive(doubleUnaryOperation((Double)operand, kind)); |
| 687 | else |
| 688 | throw new InterpreterError( |
| 689 | "An error occurred. Please call technical support."); |
| 690 | } |
| 691 | |
| 692 | static boolean booleanUnaryOperation(Boolean B, int kind) |
| 693 | throws UtilEvalError |
no test coverage detected