001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.debugger.jpda.models;
043:
044: import com.sun.jdi.ArrayReference;
045: import com.sun.jdi.ClassNotLoadedException;
046: import com.sun.jdi.InvalidTypeException;
047: import com.sun.jdi.ObjectReference;
048: import com.sun.jdi.ReferenceType;
049: import com.sun.jdi.Value;
050:
051: import org.netbeans.api.debugger.jpda.InvalidExpressionException;
052: import org.netbeans.api.debugger.jpda.JPDAClassType;
053: import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl;
054:
055: /**
056: * @author Jan Jancura
057: */
058: class ObjectArrayFieldVariable extends AbstractObjectVariable implements
059: org.netbeans.api.debugger.jpda.Field {
060:
061: private final ArrayReference array;
062: private int index;
063: private int maxIndexLog;
064: private String declaredType;
065:
066: ObjectArrayFieldVariable(JPDADebuggerImpl debugger,
067: ObjectReference value, String declaredType,
068: ArrayReference array, int index, int maxIndex,
069: String parentID) {
070: super (debugger, value, parentID + '.' + index
071: + (value instanceof ObjectReference ? "^" : ""));
072: this .index = index;
073: this .maxIndexLog = ArrayFieldVariable.log10(maxIndex);
074: this .declaredType = declaredType;
075: this .array = array;
076: }
077:
078: public String getName() {
079: return ArrayFieldVariable.getName(maxIndexLog, index);
080: }
081:
082: public String getClassName() {
083: return getType();
084: }
085:
086: public JPDAClassType getDeclaringClass() {
087: return new JPDAClassTypeImpl(getDebugger(),
088: (ReferenceType) array.type());
089: }
090:
091: public boolean isStatic() {
092: return false;
093: }
094:
095: public String getDeclaredType() {
096: return declaredType;
097: }
098:
099: protected void setValue(Value value)
100: throws InvalidExpressionException {
101: try {
102: array.setValue(index, value);
103: } catch (InvalidTypeException ex) {
104: throw new InvalidExpressionException(ex);
105: } catch (ClassNotLoadedException ex) {
106: throw new InvalidExpressionException(ex);
107: }
108: }
109:
110: public ObjectArrayFieldVariable clone() {
111: ObjectArrayFieldVariable clon = new ObjectArrayFieldVariable(
112: getDebugger(), (ObjectReference) getJDIValue(),
113: getDeclaredType(), array, index, 0, getID());
114: clon.maxIndexLog = this .maxIndexLog;
115: return clon;
116: }
117:
118: // other methods ...........................................................
119:
120: public String toString() {
121: return "ObjectArrayFieldVariable " + getName();
122: }
123: }
|