blob: d25988d3228c170e9c91122bb35df7d9ae112d71 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.debug.eval.ast.instructions;
import com.ibm.icu.text.MessageFormat;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.debug.core.IJavaArray;
import org.eclipse.jdt.debug.core.IJavaPrimitiveValue;
import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
/**
* Resolves an array access - the top of the stack is
* the position, and the second from top is the array
* object.
*/
public class ArrayAccess extends ArrayInstruction {
public ArrayAccess(int start) {
super(start);
}
public void execute() throws CoreException {
int index = ((IJavaPrimitiveValue)popValue()).getIntValue();
IJavaArray array = (IJavaArray)popValue();
if (index >= array.getLength() || index < 0) {
throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.ArrayAccess_illegal_index, new Object[] {new Integer(index)}), null));
}
push(array.getVariable(index));
}
public String toString() {
return InstructionsEvaluationMessages.ArrayAccess_array_access_1;
}
}