MCPcopy Create free account
hub / github.com/beanshell/beanshell / unaryOperation

Method unaryOperation

src/bsh/Primitive.java:648–690  ·  view source on GitHub ↗
(Primitive val, int kind)

Source from the content-addressed store, hash-verified

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

Callers 1

unaryOperationMethod · 0.95

Calls 8

promoteToIntegerMethod · 0.95
booleanUnaryOperationMethod · 0.95
intUnaryOperationMethod · 0.95
longUnaryOperationMethod · 0.95
floatUnaryOperationMethod · 0.95
doubleUnaryOperationMethod · 0.95
getTypeMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected