1 11 package org.eclipse.jdt.internal.debug.eval.ast.instructions; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IStatus; 15 import org.eclipse.core.runtime.Status; 16 import org.eclipse.jdt.debug.core.IJavaPrimitiveValue; 17 import org.eclipse.jdt.debug.core.IJavaValue; 18 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; 19 20 public class DivideOperator extends BinaryOperator { 21 public DivideOperator(int resultId, int leftTypeId, int rightTypeId, int start) { 22 this(resultId, leftTypeId, rightTypeId, false, start); 23 } 24 25 protected DivideOperator(int resultId, int leftTypeId, int rightTypeId, boolean isAssignmentOperator, int start) { 26 super(resultId, leftTypeId, rightTypeId, isAssignmentOperator, start); 27 } 28 29 32 protected boolean getBooleanResult(IJavaValue leftOperand, IJavaValue rightOperand) { 33 return false; 34 } 35 36 39 protected double getDoubleResult(IJavaValue leftOperand, IJavaValue rightOperand) { 40 return ((IJavaPrimitiveValue) leftOperand).getDoubleValue() / ((IJavaPrimitiveValue) rightOperand).getDoubleValue(); 41 } 42 43 46 protected float getFloatResult(IJavaValue leftOperand, IJavaValue rightOperand) { 47 return ((IJavaPrimitiveValue) leftOperand).getFloatValue() / ((IJavaPrimitiveValue) rightOperand).getFloatValue(); 48 } 49 50 53 protected int getIntResult(IJavaValue leftOperand, IJavaValue rightOperand) throws CoreException { 54 int divisor= ((IJavaPrimitiveValue) rightOperand).getIntValue(); 55 if (divisor == 0) { 56 throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, InstructionsEvaluationMessages.DivideOperator_Divide_by_zero_1, null)); 57 } 58 return ((IJavaPrimitiveValue) leftOperand).getIntValue() / divisor; 59 } 60 61 64 protected long getLongResult(IJavaValue leftOperand, IJavaValue rightOperand) throws CoreException { 65 long divisor= ((IJavaPrimitiveValue) rightOperand).getLongValue(); 66 if (divisor == 0) { 67 throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, InstructionsEvaluationMessages.DivideOperator_Divide_by_zero_2, null)); 68 } 69 return ((IJavaPrimitiveValue) leftOperand).getLongValue() / divisor; 70 } 71 72 75 protected String getStringResult(IJavaValue leftOperand, IJavaValue rightOperand) { 76 return null; 77 } 78 79 public String toString() { 80 return InstructionsEvaluationMessages.DivideOperator______operator_3; 81 } 82 83 } 84 | Popular Tags |