KickJava   Java API By Example, From Geeks To Geeks.

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


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 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.core.IJavaProject;
17 import org.eclipse.jdt.debug.core.IJavaArray;
18 import org.eclipse.jdt.debug.core.IJavaDebugTarget;
19 import org.eclipse.jdt.debug.core.IJavaObject;
20 import org.eclipse.jdt.debug.core.IJavaReferenceType;
21 import org.eclipse.jdt.debug.core.IJavaThread;
22 import org.eclipse.jdt.debug.core.IJavaType;
23 import org.eclipse.jdt.debug.core.IJavaVariable;
24 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
25 import org.eclipse.jdt.internal.debug.core.logicalstructures.JDIPlaceholderVariable;
26
27 /**
28  * Context for evaluation of an expression in the receiver context of an array.
29  */

30 public class ArrayRuntimeContext extends AbstractRuntimeContext {
31     
32     /**
33      * Name used for temp variable referring to array (replaces 'this').
34      * The same length as "this" so it does not effect code assist.
35      */

36     public static String JavaDoc ARRAY_THIS_VARIABLE = "_a_t"; //$NON-NLS-1$
37

38     private IJavaArray fArray = null;
39     private IJavaReferenceType fReceivingType = null;
40     private IJavaThread fThread = null;
41     private IJavaVariable fLocalArray = null;
42     
43     public ArrayRuntimeContext(IJavaArray arrayObject, IJavaThread thread, IJavaProject project) {
44         super(project);
45         fArray = arrayObject;
46         fThread = thread;
47         fLocalArray = new JDIPlaceholderVariable(ARRAY_THIS_VARIABLE, arrayObject);
48     }
49
50     /* (non-Javadoc)
51      * @see org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#getVM()
52      */

53     public IJavaDebugTarget getVM() {
54         return (IJavaDebugTarget) fArray.getDebugTarget();
55     }
56
57     /* (non-Javadoc)
58      * @see org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#getThis()
59      */

60     public IJavaObject getThis() throws CoreException {
61         return null;
62     }
63
64     /* (non-Javadoc)
65      * @see org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#getReceivingType()
66      */

67     public IJavaReferenceType getReceivingType() throws CoreException {
68         if (fReceivingType == null) {
69             IJavaType[] javaTypes = getVM().getJavaTypes("java.lang.Object"); //$NON-NLS-1$
70
if (javaTypes.length > 0) {
71                 fReceivingType = (IJavaReferenceType) javaTypes[0];
72             } else {
73                 IStatus status = new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), JDIDebugPlugin.INTERNAL_ERROR,
74                         EvaluationEngineMessages.ArrayRuntimeContext_0, null);
75                 throw new CoreException(status);
76             }
77         }
78         return fReceivingType;
79     }
80
81     /* (non-Javadoc)
82      * @see org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#getLocals()
83      */

84     public IJavaVariable[] getLocals() throws CoreException {
85         return new IJavaVariable[]{fLocalArray};
86     }
87
88     /* (non-Javadoc)
89      * @see org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#getThread()
90      */

91     public IJavaThread getThread() {
92         return fThread;
93     }
94
95     /* (non-Javadoc)
96      * @see org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext#isConstructor()
97      */

98     public boolean isConstructor() throws CoreException {
99         return false;
100     }
101
102 }
103
Popular Tags