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