KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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
14 import com.ibm.icu.text.MessageFormat;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.Status;
19 import org.eclipse.jdt.debug.core.IJavaObject;
20 import org.eclipse.jdt.debug.core.IJavaVariable;
21 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
22 import org.eclipse.jdt.internal.debug.core.model.JDINullValue;
23 import org.eclipse.jdt.internal.debug.core.model.JDIObjectValue;
24  
25 /**
26  * Pops an object off the stack, and pushes the value
27  * of one of its fields onto the stack.
28  */

29 public class PushFieldVariable extends CompoundInstruction {
30     
31     private String JavaDoc fDeclaringTypeSignature;
32     
33     private String JavaDoc fName;
34     
35     private int fSuperClassLevel;
36     
37     public PushFieldVariable(String JavaDoc name, int superClassLevel, int start) {
38         super(start);
39         fName= name;
40         fSuperClassLevel= superClassLevel;
41     }
42     
43     public PushFieldVariable(String JavaDoc name, String JavaDoc declaringTypeSignature, int start) {
44         super(start);
45         fName= name;
46         fDeclaringTypeSignature= declaringTypeSignature;
47     }
48     
49     public void execute() throws CoreException {
50         Object JavaDoc value= popValue();
51         if (value instanceof JDINullValue) {
52             throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, InstructionsEvaluationMessages.PushFieldVariable_0, null));
53         }
54         IJavaObject receiver=(IJavaObject) value;
55         
56         IJavaVariable field= null;
57         
58         if (fDeclaringTypeSignature == null) {
59             field= ((JDIObjectValue)receiver).getField(fName, fSuperClassLevel);
60         } else {
61             field= receiver.getField(fName, fDeclaringTypeSignature);
62         }
63         
64         if (field == null) {
65             throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.PushFieldVariable_Cannot_find_the_field__0__for_the_object__1__1, new String JavaDoc[] {fName, receiver.toString()}), null)); //
66
}
67         push(field);
68     }
69     
70     public String JavaDoc toString() {
71         return MessageFormat.format(InstructionsEvaluationMessages.PushFieldVariable_push_field__0__2, new String JavaDoc[] {fName});
72     }
73 }
74
75
Popular Tags