/*
* @see Instruction#execute()
*/
@Override
public void execute() throws CoreException {
IJavaValue value = popValue();
if (value instanceof IJavaPrimitiveValue) {
IJavaPrimitiveValue primitiveValue = (IJavaPrimitiveValue) value;
switch (fTypeTypeId) {
case T_double:
push(newValue(primitiveValue.getDoubleValue()));
break;
case T_float:
push(newValue(primitiveValue.getFloatValue()));
break;
case T_long:
push(newValue(primitiveValue.getLongValue()));
break;
case T_int:
push(newValue(primitiveValue.getIntValue()));
break;
case T_short:
push(newValue(primitiveValue.getShortValue()));
break;
case T_byte:
push(newValue(primitiveValue.getByteValue()));
break;
case T_char:
push(newValue(primitiveValue.getCharValue()));
break;
}
} else if (value instanceof JDINullValue) {
// null value can be cast to all non-primitive types (bug 31637).
push(value);
} else {
IJavaObject classObject;
if (fDimension == 0) {
classObject = getClassObject(getType(fBaseTypeName));
} else {
classObject = getClassObject(getArrayType(
Signature.createTypeSignature(fBaseTypeName, true),
fDimension));
}
if (classObject == null) {
throw new CoreException(
new Status(
IStatus.ERROR,
JDIDebugPlugin.getUniqueIdentifier(),
IStatus.OK,
NLS.bind(InstructionsEvaluationMessages.Cast_No_class_object,
new String[] { typeName() }),
null));
}
IJavaPrimitiveValue resultValue = (IJavaPrimitiveValue) classObject
.sendMessage(IS_INSTANCE, IS_INSTANCE_SIGNATURE,
new IJavaValue[] { value }, getContext()
.getThread(), false);
if (!resultValue.getBooleanValue()) {
throw new CoreException(
new Status(
IStatus.ERROR,
JDIDebugPlugin.getUniqueIdentifier(),
IStatus.OK,
NLS.bind(InstructionsEvaluationMessages.Cast_ClassCastException__Cannot_cast__0__as__1___1,
new String[] {
value.toString(),
typeName() }), null));
}
push(value);
}