KickJava   Java API By Example, From Geeks To Geeks.

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


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.debug.core.model.IVariable;
20 import org.eclipse.jdt.debug.core.IJavaVariable;
21 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
22 import org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext;
23  
24 /**
25  * Pushes the value of a local, instance, or static
26  * variable onto the stack.
27  */

28 public class PushLocalVariable extends SimpleInstruction {
29     
30     /**
31      * Name of variable to push.
32      */

33     private String JavaDoc fName;
34     
35     public PushLocalVariable(String JavaDoc name) {
36         fName = name;
37     }
38     
39     public void execute() throws CoreException {
40         IVariable internalVariable= getInternalVariable(fName);
41         if (internalVariable != null) {
42             push(internalVariable);
43             return;
44         }
45         IRuntimeContext context= getContext();
46         IJavaVariable[] locals = context.getLocals();
47         for (int i = 0; i < locals.length; i++) {
48             if (locals[i].getName().equals(getName())) {
49                 push(locals[i]);
50                 return;
51             }
52         }
53
54         throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.PushLocalVariable_Cannot_find_the_variable____1, new String JavaDoc[]{fName}), null));
55     }
56     
57     /**
58      * Returns the name of the variable to push
59      * onto the stack.
60      *
61      * @return the name of the variable to push
62      * onto the stack
63      */

64     protected String JavaDoc getName() {
65         return fName;
66     }
67
68     public String JavaDoc toString() {
69         return MessageFormat.format(InstructionsEvaluationMessages.PushLocalVariable_push____0___2, new String JavaDoc[]{getName()});
70     }
71 }
72
73
Popular Tags