KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > eval > ast > instructions > RemainderOperator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 RemainderOperator extends BinaryOperator {
21     public RemainderOperator(int resultId, int leftTypeId, int rightTypeId, int start) {
22         this(resultId, leftTypeId, rightTypeId, false, start);
23     }
24
25     protected RemainderOperator(int resultId, int leftTypeId, int rightTypeId, boolean isAssignmentOperator, int start) {
26         super(resultId, leftTypeId, rightTypeId, isAssignmentOperator, start);
27     }
28
29     /*
30      * @see BinaryOperator#getBooleanResult(IJavaValue, IJavaValue)
31      */

32     protected boolean getBooleanResult(IJavaValue leftOperand, IJavaValue rightOperand) {
33         return false;
34     }
35
36     /*
37      * @see BinaryOperator#getDoubleResult(IJavaValue, IJavaValue)
38      */

39     protected double getDoubleResult(IJavaValue leftOperand, IJavaValue rightOperand) {
40         return ((IJavaPrimitiveValue) leftOperand).getDoubleValue() % ((IJavaPrimitiveValue) rightOperand).getDoubleValue();
41     }
42
43     /*
44      * @see BinaryOperator#getFloatResult(IJavaValue, IJavaValue)
45      */

46     protected float getFloatResult(IJavaValue leftOperand, IJavaValue rightOperand) {
47         return ((IJavaPrimitiveValue) leftOperand).getFloatValue() % ((IJavaPrimitiveValue) rightOperand).getFloatValue();
48     }
49
50     /*
51      * @see BinaryOperator#getIntResult(IJavaValue, IJavaValue)
52      */

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.RemainderOperator_Divide_by_zero_1, null));
57         }
58         return ((IJavaPrimitiveValue) leftOperand).getIntValue() % divisor;
59     }
60
61     /*
62      * @see BinaryOperator#getLongResult(IJavaValue, IJavaValue)
63      */

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.RemainderOperator_Divide_by_zero_2, null));
68         }
69         return ((IJavaPrimitiveValue) leftOperand).getLongValue() % divisor;
70     }
71
72     /*
73      * @see BinaryOperator#getStringResult(IJavaValue, IJavaValue)
74      */

75     protected String JavaDoc getStringResult(IJavaValue leftOperand, IJavaValue rightOperand) {
76         return null;
77     }
78
79     public String JavaDoc toString() {
80         return InstructionsEvaluationMessages.RemainderOperator______operator_3;
81     }
82
83 }
84
Popular Tags