KickJava   Java API By Example, From Geeks To Geeks.

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


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.IJavaArray;
20 import org.eclipse.jdt.debug.core.IJavaPrimitiveValue;
21 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
22  
23 /**
24  * Resolves an array access - the top of the stack is
25  * the position, and the second from top is the array
26  * object.
27  */

28 public class ArrayAccess extends ArrayInstruction {
29     
30     public ArrayAccess(int start) {
31         super(start);
32     }
33     
34     public void execute() throws CoreException {
35         int index = ((IJavaPrimitiveValue)popValue()).getIntValue();
36         IJavaArray array = (IJavaArray)popValue();
37         if (index >= array.getLength() || index < 0) {
38             throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.ArrayAccess_illegal_index, new Object JavaDoc[] {new Integer JavaDoc(index)}), null));
39         }
40         push(array.getVariable(index));
41     }
42
43     public String JavaDoc toString() {
44         return InstructionsEvaluationMessages.ArrayAccess_array_access_1;
45     }
46 }
47
48
Popular Tags