KickJava   Java API By Example, From Geeks To Geeks.

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


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.debug.core.model.IVariable;
18 import org.eclipse.jdi.internal.PrimitiveTypeImpl;
19 import org.eclipse.jdi.internal.VirtualMachineImpl;
20 import org.eclipse.jdt.debug.core.IJavaType;
21 import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
22 import org.eclipse.jdt.internal.debug.core.model.JDIType;
23
24 import com.sun.jdi.VirtualMachine;
25
26 public class LocalVariableCreation extends CompoundInstruction {
27
28     /**
29      * Indicate if the type is a primitive type.
30      */

31     private boolean fIsPrimitiveType;
32
33     /**
34      * The name of the variable to create.
35      */

36     private String JavaDoc fName;
37     
38     /**
39      * The signature of the type, or of the element type in case of an array type.
40      */

41     private String JavaDoc fTypeSignature;
42     
43     /**
44      * The dimension of the array type.
45      */

46     private int fDimension;
47     
48     /**
49      * Indicate if there is an initializer for this variable.
50      */

51     private boolean fHasInitializer;
52
53     /**
54      * Constructor for LocalVariableCreation.
55      *
56      * @param name the name of the variable to create.
57      * @param typeSignature the signature of the type, or of the element type in case of an array type.
58      * @param dimension the dimension of the array type, <code>0</code> if it's not an array type.
59      * @param isPrimitiveType indicate if the type is a primitive type.
60      * @param hasInitializer indicate if there is an initializer for this variable.
61      * @param start
62      */

63     public LocalVariableCreation(String JavaDoc name, String JavaDoc typeSignature, int dimension, boolean isPrimitiveType, boolean hasInitializer, int start) {
64         super(start);
65         fName= name;
66         fTypeSignature= typeSignature.replace('/', '.');
67         fIsPrimitiveType= isPrimitiveType;
68         fHasInitializer= hasInitializer;
69         fDimension= dimension;
70     }
71
72     /**
73      * @see org.eclipse.jdt.internal.debug.eval.ast.instructions.Instruction#execute()
74      */

75     public void execute() throws CoreException {
76         IJavaType type;
77         if (fIsPrimitiveType) {
78             JDIDebugTarget debugTarget= (JDIDebugTarget)getVM();
79             VirtualMachine vm = debugTarget.getVM();
80             if (vm == null) {
81                 debugTarget.requestFailed(InstructionsEvaluationMessages.LocalVariableCreation_Execution_failed___VM_disconnected__1, null);
82             }
83             type= JDIType.createType(debugTarget, PrimitiveTypeImpl.create((VirtualMachineImpl)vm, fTypeSignature));
84         } else if (fDimension == 0) {
85             type= getType(RuntimeSignature.toString(fTypeSignature)); // See Bug 22165
86
} else {
87             type= getArrayType(fTypeSignature, fDimension);
88         }
89         IVariable var= createInternalVariable(fName, type);
90         if (fHasInitializer) {
91             var.setValue(popValue());
92         }
93     }
94
95     public String JavaDoc toString() {
96         return MessageFormat.format(InstructionsEvaluationMessages.LocalVariableCreation_create_local_variable__0___1___1, new String JavaDoc[]{fName, fTypeSignature});
97     }
98 }
99
Popular Tags