KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.jdt.debug.core.IJavaArray;
15 import org.eclipse.jdt.debug.core.IJavaArrayType;
16
17 public class ArrayInitializerInstruction extends ArrayInstruction {
18
19     private String JavaDoc fTypeSignature;
20     
21     private int fDimensions;
22     
23     private int fLength;
24
25     /**
26      * Constructor for ArrayInitializerInstruction.
27      * @param start
28      */

29     public ArrayInitializerInstruction(String JavaDoc typeSignature, int length, int dimensions, int start) {
30         super(start);
31         fTypeSignature = typeSignature;
32         fDimensions = dimensions;
33         fLength = length;
34     }
35
36     /*
37      * @see Instruction#execute()
38      */

39     public void execute() throws CoreException {
40         
41         IJavaArrayType arrayType = getArrayType(fTypeSignature.replace('/','.'), fDimensions);
42         IJavaArray array = arrayType.newInstance(fLength);
43         
44         for (int i = fLength - 1; i >= 0; i--) {
45             array.setValue(i, popValue());
46         }
47         
48         push(array);
49         
50     }
51
52     public String JavaDoc toString() {
53         return InstructionsEvaluationMessages.ArrayInitializerInstruction_array_initializer_1;
54     }
55
56 }
57
Popular Tags