|
Java example source code file (ArrayReferenceImpl.java)
The ArrayReferenceImpl.java Java example source code/* * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.tools.jdi; import com.sun.jdi.*; import java.util.List; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; public class ArrayReferenceImpl extends ObjectReferenceImpl implements ArrayReference { int length = -1; ArrayReferenceImpl(VirtualMachine aVm,long aRef) { super(aVm,aRef); } protected ClassTypeImpl invokableReferenceType(Method method) { // The method has to be a method on Object since // arrays don't have methods nor any other 'superclasses' // So, use the ClassTypeImpl for Object instead of // the ArrayTypeImpl for the array itself. return (ClassTypeImpl)method.declaringType(); } ArrayTypeImpl arrayType() { return (ArrayTypeImpl)type(); } /** * Return array length. * Need not be synchronized since it cannot be provably stale. */ public int length() { if(length == -1) { try { length = JDWP.ArrayReference.Length. process(vm, this).arrayLength; } catch (JDWPException exc) { throw exc.toJDIException(); } } return length; } public Value getValue(int index) { List<Value> list = getValues(index, 1); return list.get(0); } public List<Value> getValues() { return getValues(0, -1); } /** * Validate that the range to set/get is valid. * length of -1 (meaning rest of array) has been converted * before entry. */ private void validateArrayAccess(int index, int length) { // because length can be computed from index, // index must be tested first for correct error message if ((index < 0) || (index > length())) { throw new IndexOutOfBoundsException( "Invalid array index: " + index); } if (length < 0) { throw new IndexOutOfBoundsException( "Invalid array range length: " + length); } if (index + length > length()) { throw new IndexOutOfBoundsException( "Invalid array range: " + index + " to " + (index + length - 1)); } } @SuppressWarnings("unchecked") private static <T> T cast(Object x) { return (T)x; } public List<Value> getValues(int index, int length) { if (length == -1) { // -1 means the rest of the array length = length() - index; } validateArrayAccess(index, length); if (length == 0) { return new ArrayList<Value>(); } List<Value> vals; try { vals = cast(JDWP.ArrayReference.GetValues.process(vm, this, index, length).values); } catch (JDWPException exc) { throw exc.toJDIException(); } return vals; } public void setValue(int index, Value value) throws InvalidTypeException, ClassNotLoadedException { List<Value> list = new ArrayList Other Java examples (source code examples)Here is a short list of links related to this Java ArrayReferenceImpl.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.