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.AbsentInformationException;
045: import com.sun.jdi.ClassNotLoadedException;
046: import com.sun.jdi.InvalidTypeException;
047: import com.sun.jdi.LocalVariable;
048: import com.sun.jdi.ObjectReference;
049: import com.sun.jdi.StackFrame;
050: import com.sun.jdi.Value;
051: import org.netbeans.api.debugger.jpda.InvalidExpressionException;
052: import org.netbeans.api.debugger.jpda.JPDAThread;
053: import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl;
054:
055: /**
056: * @author Jan Jancura
057: */
058: class ObjectLocalVariable extends AbstractObjectVariable implements
059: org.netbeans.api.debugger.jpda.LocalVariable {
060:
061: LocalVariable local;
062: JPDAThread thread;
063: int depth;
064: String className;
065: String genericSignature;
066:
067: ObjectLocalVariable(JPDADebuggerImpl debugger,
068: ObjectReference value, String className,
069: LocalVariable local, String genericSignature,
070: CallStackFrameImpl frame) {
071: super (debugger, value, genericSignature, local.name()
072: + local.hashCode()
073: + (value instanceof ObjectReference ? "^" : ""));
074: this .local = local;
075: if (frame != null) {
076: this .thread = frame.getThread();
077: this .depth = frame.getFrameDepth();
078: }
079: this .className = className;
080: }
081:
082: // LocalVariable impl.......................................................
083:
084: /**
085: * Returns string representation of type of this variable.
086: *
087: * @return string representation of type of this variable.
088: */
089: public String getName() {
090: return local.name();
091: }
092:
093: /**
094: * Returns name of enclosing class.
095: *
096: * @return name of enclosing class
097: */
098: public String getClassName() {
099: return className;
100: }
101:
102: protected final void setClassName(String className) {
103: this .className = className;
104: }
105:
106: /**
107: * Returns string representation of type of this variable.
108: *
109: * @return string representation of type of this variable.
110: */
111: public String getDeclaredType() {
112: return local.typeName();
113: }
114:
115: protected final void setValue(Value value)
116: throws InvalidExpressionException {
117: try {
118: StackFrame sf = ((CallStackFrameImpl) thread.getCallStack(
119: depth, depth + 1)[0]).getStackFrame();
120: sf.setValue(local, value);
121: setInnerValue(value);
122: } catch (AbsentInformationException aiex) {
123: throw new InvalidExpressionException(aiex);
124: } catch (InvalidTypeException ex) {
125: throw new InvalidExpressionException(ex);
126: } catch (ClassNotLoadedException ex) {
127: throw new InvalidExpressionException(ex);
128: }
129: }
130:
131: public ObjectLocalVariable clone() {
132: ObjectLocalVariable clon = new ObjectLocalVariable(
133: getDebugger(), (ObjectReference) getJDIValue(),
134: className, local, genericSignature, null);
135: clon.depth = this .depth;
136: clon.thread = this .thread;
137: return clon;
138: }
139:
140: // other methods ...........................................................
141:
142: final void setFrame(CallStackFrameImpl frame) {
143: this .thread = frame.getThread();
144: this .depth = frame.getFrameDepth();
145: }
146:
147: public String toString() {
148: return "ObjectLocalVariable " + local.name();
149: }
150: }
|