KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > eval > ast > engine > RuntimeContext


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.engine;
12
13  
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.jdt.core.IJavaProject;
16 import org.eclipse.jdt.debug.core.IJavaDebugTarget;
17 import org.eclipse.jdt.debug.core.IJavaObject;
18 import org.eclipse.jdt.debug.core.IJavaReferenceType;
19 import org.eclipse.jdt.debug.core.IJavaStackFrame;
20 import org.eclipse.jdt.debug.core.IJavaThread;
21 import org.eclipse.jdt.debug.core.IJavaVariable;
22
23 public class RuntimeContext extends AbstractRuntimeContext {
24
25     /**
26      * Stack frame context
27      */

28     private IJavaStackFrame fFrame;
29
30     /**
31      * Creates a runtime context for the given java project and
32      * stack frame.
33      *
34      * @param project Java project context used to compile expressions in
35      * @param frame stack frame used to define locals and receiving type
36      * context
37      * @return a new runtime context
38      */

39     public RuntimeContext(IJavaProject project, IJavaStackFrame frame) {
40         super(project);
41         setFrame(frame);
42     }
43     
44     /**
45      * @see IRuntimeContext#getVM()
46      */

47     public IJavaDebugTarget getVM() {
48         return (IJavaDebugTarget)getFrame().getDebugTarget();
49     }
50
51     /**
52      * @see IRuntimeContext#getThis()
53      */

54     public IJavaObject getThis() throws CoreException {
55         return getFrame().getThis();
56     }
57
58     /**
59      * @see IRuntimeContext#getReceivingType()
60      */

61     public IJavaReferenceType getReceivingType() throws CoreException {
62         IJavaObject rec = getThis();
63         if (rec != null) {
64             return (IJavaReferenceType)rec.getJavaType();
65         }
66         return getFrame().getReferenceType();
67     }
68
69     /**
70      * @see IRuntimeContext#getLocals()
71      */

72     public IJavaVariable[] getLocals() throws CoreException {
73         return getFrame().getLocalVariables();
74     }
75     
76     /**
77      * Sets the stack frame context used to compile/run expressions
78      *
79      * @param frame the stack frame context used to compile/run expressions
80      */

81     protected IJavaStackFrame getFrame() {
82         return fFrame;
83     }
84         
85     /**
86      * Sets the stack frame context used to compile/run expressions
87      *
88      * @param frame the stack frame context used to compile/run expressions
89      */

90     private void setFrame(IJavaStackFrame frame) {
91         fFrame = frame;
92     }
93
94     /**
95      * @see IRuntimeContext#getThread()
96      */

97     public IJavaThread getThread() {
98         return (IJavaThread)getFrame().getThread();
99     }
100
101     /**
102      * @see IRuntimeContext#isConstructor()
103      */

104     public boolean isConstructor() throws CoreException {
105         return getFrame().isConstructor();
106     }
107
108 }
109
110
Popular Tags