KickJava   Java API By Example, From Geeks To Geeks.

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


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.IJavaClassType;
20 import org.eclipse.jdt.debug.core.IJavaInterfaceType;
21 import org.eclipse.jdt.debug.core.IJavaType;
22 import org.eclipse.jdt.debug.core.IJavaVariable;
23 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
24  
25 /**
26  * Pushes the value of the static fields of the given type
27  * onto the stack.
28  */

29 public class PushStaticFieldVariable extends CompoundInstruction {
30     
31     private String JavaDoc fFieldName;
32     
33     private String JavaDoc fQualifiedTypeName;
34     
35     public PushStaticFieldVariable(String JavaDoc fieldName, String JavaDoc qualifiedTypeName, int start) {
36         super(start);
37         fFieldName= fieldName;
38         fQualifiedTypeName= qualifiedTypeName;
39     }
40     
41     public void execute() throws CoreException {
42         IJavaType receiver= getType(fQualifiedTypeName);
43         
44         IJavaVariable field= null;
45
46         if (receiver instanceof IJavaInterfaceType) {
47             field= ((IJavaInterfaceType)receiver).getField(fFieldName);
48         } else if (receiver instanceof IJavaClassType) {
49             field= ((IJavaClassType)receiver).getField(fFieldName);
50         }
51         if (field == null) {
52             String JavaDoc message= MessageFormat.format(InstructionsEvaluationMessages.PushStaticFieldVariable_Cannot_find_the_field__0__in__1__1, new String JavaDoc[]{fFieldName, fQualifiedTypeName});
53             throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, message, null)); // couldn't find the field
54
}
55         push(field);
56     }
57     
58     public String JavaDoc toString() {
59         return MessageFormat.format(InstructionsEvaluationMessages.PushStaticFieldVariable_push_static_field__0__2, new String JavaDoc[]{fFieldName});
60     }
61
62 }
63
64
Popular Tags