KickJava   Java API By Example, From Geeks To Geeks.

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


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
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17 import org.eclipse.jdt.debug.core.IJavaObject;
18 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
19 import org.eclipse.jdt.internal.debug.core.model.JDIObjectValue;
20 import org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext;
21  
22 /**
23  * Pushes the 'this' object onto the stack.
24  */

25 public class PushThis extends SimpleInstruction {
26     
27     private int fEnclosingLevel;
28     
29     public PushThis(int enclosingLevel) {
30         fEnclosingLevel= enclosingLevel;
31     }
32     
33     public void execute() throws CoreException {
34         IRuntimeContext context= getContext();
35         IJavaObject thisInstance = context.getThis();
36         if (thisInstance == null) {
37             // static context
38
push(context.getReceivingType());
39         } else {
40             if (fEnclosingLevel != 0) {
41                 thisInstance= ((JDIObjectValue)thisInstance).getEnclosingObject(fEnclosingLevel);
42                 if (thisInstance == null) {
43                     throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, InstructionsEvaluationMessages.PushThis_Unable_to_retrieve_the_correct_enclosing_instance_of__this__2, null));
44                 }
45             }
46             push(thisInstance);
47         }
48     }
49
50     public String JavaDoc toString() {
51         return InstructionsEvaluationMessages.PushThis_push___this__1;
52     }
53 }
54
55
Popular Tags