1 11 package org.eclipse.jdt.internal.debug.eval.ast.instructions; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.debug.core.DebugException; 15 import org.eclipse.jdt.debug.core.IJavaObject; 16 import org.eclipse.jdt.debug.core.IJavaPrimitiveValue; 17 import org.eclipse.jdt.debug.core.IJavaValue; 18 import org.eclipse.jdt.internal.debug.core.model.JDINullValue; 19 20 public class PlusOperator extends BinaryOperator { 21 22 public static final String NULL= "null"; public static final String TOSTRING_SELECTOR= "toString"; public static final String TOSTRING_SIGNATURE= "()Ljava/lang/String;"; 26 public PlusOperator(int resultId, int leftTypeId, int rightTypeId, int start) { 27 this(resultId, leftTypeId, rightTypeId, false, start); 28 } 29 30 protected PlusOperator(int resultId, int leftTypeId, int rightTypeId, boolean isAssignmentOperator, int start) { 31 super(resultId, leftTypeId, rightTypeId, isAssignmentOperator, start); 32 } 33 34 private String getString(IJavaValue value, int typeId) throws DebugException { 35 36 if (value instanceof JDINullValue) { 38 return NULL; 39 } 40 41 if (value instanceof IJavaObject) { 42 if (typeId == T_String) { 43 return value.getValueString(); 44 } 45 return ((IJavaObject) value).sendMessage(TOSTRING_SELECTOR, TOSTRING_SIGNATURE, null, getContext().getThread(), null).getValueString(); 46 } 47 48 IJavaPrimitiveValue primitiveValue= (IJavaPrimitiveValue)value; 49 switch (typeId) { 50 case T_boolean: 51 return Boolean.valueOf(primitiveValue.getBooleanValue()).toString(); 52 case T_byte: 53 return new Integer (primitiveValue.getByteValue()).toString(); 54 case T_char: 55 return new Character (primitiveValue.getCharValue()).toString(); 56 case T_double: 57 return new Double (primitiveValue.getDoubleValue()).toString(); 58 case T_float: 59 return new Float (primitiveValue.getFloatValue()).toString(); 60 case T_int: 61 return new Integer (primitiveValue.getIntValue()).toString(); 62 case T_long: 63 return new Long (primitiveValue.getLongValue()).toString(); 64 case T_short: 65 return new Integer (primitiveValue.getShortValue()).toString(); 66 } 67 return NULL; 68 } 69 70 73 protected boolean getBooleanResult(IJavaValue leftOperand, IJavaValue rightOperand) { 74 return false; 75 } 76 77 80 protected double getDoubleResult(IJavaValue leftOperand, IJavaValue rightOperand) { 81 return ((IJavaPrimitiveValue)leftOperand).getDoubleValue() + ((IJavaPrimitiveValue)rightOperand).getDoubleValue(); 82 } 83 84 87 protected float getFloatResult(IJavaValue leftOperand, IJavaValue rightOperand) { 88 return ((IJavaPrimitiveValue)leftOperand).getFloatValue() + ((IJavaPrimitiveValue)rightOperand).getFloatValue(); 89 } 90 91 94 protected int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) { 95 return ((IJavaPrimitiveValue)leftOperand).getIntValue() + ((IJavaPrimitiveValue)rightOperand).getIntValue(); 96 } 97 98 101 protected long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) { 102 return ((IJavaPrimitiveValue)leftOperand).getLongValue() + ((IJavaPrimitiveValue)rightOperand).getLongValue(); 103 } 104 105 108 protected String getStringResult(IJavaValue leftOperand, IJavaValue rightOperand) throws CoreException { 109 return getString(leftOperand, fLeftTypeId) + getString(rightOperand, fRightTypeId); 110 } 111 112 public String toString() { 113 return InstructionsEvaluationMessages.PlusOperator______operator_2; 114 } 115 116 } 117 | Popular Tags |