KickJava   Java API By Example, From Geeks To Geeks.

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


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.jdt.debug.core.IJavaPrimitiveValue;
15 import org.eclipse.jdt.debug.core.IJavaValue;
16 import org.eclipse.jdt.debug.core.IJavaVariable;
17
18 public class AssignmentOperator extends CompoundInstruction {
19
20     protected int fVariableTypeId;
21     protected int fValueTypeId;
22
23
24     public AssignmentOperator(int variableTypeId, int valueTypeId, int start) {
25         super(start);
26         fVariableTypeId = variableTypeId;
27         fValueTypeId = valueTypeId;
28     }
29
30     /*
31      * @see Instruction#execute()
32      */

33     public void execute() throws CoreException {
34         IJavaValue value = popValue();
35         IJavaVariable variable = (IJavaVariable) pop();
36         
37         if (value instanceof IJavaPrimitiveValue) {
38             IJavaPrimitiveValue primitiveValue = (IJavaPrimitiveValue) value;
39             switch (fVariableTypeId) {
40                 case T_boolean:
41                     variable.setValue(newValue(primitiveValue.getBooleanValue()));
42                     break;
43                 case T_byte:
44                     variable.setValue(newValue(primitiveValue.getByteValue()));
45                     break;
46                 case T_short:
47                     variable.setValue(newValue(primitiveValue.getShortValue()));
48                     break;
49                 case T_char:
50                     variable.setValue(newValue(primitiveValue.getCharValue()));
51                     break;
52                 case T_int:
53                     variable.setValue(newValue(primitiveValue.getIntValue()));
54                     break;
55                 case T_long:
56                     variable.setValue(newValue(primitiveValue.getLongValue()));
57                     break;
58                 case T_float:
59                     variable.setValue(newValue(primitiveValue.getFloatValue()));
60                     break;
61                 case T_double:
62                     variable.setValue(newValue(primitiveValue.getDoubleValue()));
63                     break;
64             }
65         } else {
66             variable.setValue(value);
67         }
68         push(variable.getValue());
69     }
70
71     public String JavaDoc toString() {
72         return InstructionsEvaluationMessages.AssignmentOperator_operator_1;
73     }
74 }
75
Popular Tags