KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > JDIModelPresentation


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.List JavaDoc;
17 import java.util.StringTokenizer JavaDoc;
18
19 import org.eclipse.core.resources.IMarker;
20 import org.eclipse.core.resources.IResource;
21 import org.eclipse.core.runtime.CoreException;
22 import org.eclipse.core.runtime.IAdaptable;
23 import org.eclipse.debug.core.DebugException;
24 import org.eclipse.debug.core.DebugPlugin;
25 import org.eclipse.debug.core.model.IBreakpoint;
26 import org.eclipse.debug.core.model.IDisconnect;
27 import org.eclipse.debug.core.model.IExpression;
28 import org.eclipse.debug.core.model.IStackFrame;
29 import org.eclipse.debug.core.model.ITerminate;
30 import org.eclipse.debug.core.model.IThread;
31 import org.eclipse.debug.core.model.IValue;
32 import org.eclipse.debug.core.model.IWatchExpression;
33 import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
34 import org.eclipse.debug.core.sourcelookup.containers.ZipEntryStorage;
35 import org.eclipse.debug.ui.DebugUITools;
36 import org.eclipse.debug.ui.IDebugModelPresentation;
37 import org.eclipse.debug.ui.IDebugUIConstants;
38 import org.eclipse.debug.ui.IValueDetailListener;
39 import org.eclipse.jdt.core.IMember;
40 import org.eclipse.jdt.core.IType;
41 import org.eclipse.jdt.core.Signature;
42 import org.eclipse.jdt.debug.core.IJavaArray;
43 import org.eclipse.jdt.debug.core.IJavaBreakpoint;
44 import org.eclipse.jdt.debug.core.IJavaClassPrepareBreakpoint;
45 import org.eclipse.jdt.debug.core.IJavaDebugTarget;
46 import org.eclipse.jdt.debug.core.IJavaExceptionBreakpoint;
47 import org.eclipse.jdt.debug.core.IJavaFieldVariable;
48 import org.eclipse.jdt.debug.core.IJavaLineBreakpoint;
49 import org.eclipse.jdt.debug.core.IJavaMethodBreakpoint;
50 import org.eclipse.jdt.debug.core.IJavaMethodEntryBreakpoint;
51 import org.eclipse.jdt.debug.core.IJavaModifiers;
52 import org.eclipse.jdt.debug.core.IJavaObject;
53 import org.eclipse.jdt.debug.core.IJavaPatternBreakpoint;
54 import org.eclipse.jdt.debug.core.IJavaReferenceType;
55 import org.eclipse.jdt.debug.core.IJavaStackFrame;
56 import org.eclipse.jdt.debug.core.IJavaStratumLineBreakpoint;
57 import org.eclipse.jdt.debug.core.IJavaTargetPatternBreakpoint;
58 import org.eclipse.jdt.debug.core.IJavaThread;
59 import org.eclipse.jdt.debug.core.IJavaType;
60 import org.eclipse.jdt.debug.core.IJavaValue;
61 import org.eclipse.jdt.debug.core.IJavaVariable;
62 import org.eclipse.jdt.debug.core.IJavaWatchpoint;
63 import org.eclipse.jdt.internal.debug.core.breakpoints.JavaExceptionBreakpoint;
64 import org.eclipse.jdt.internal.debug.core.logicalstructures.JDIAllInstancesValue;
65 import org.eclipse.jdt.internal.debug.core.model.JDIReferenceListEntryVariable;
66 import org.eclipse.jdt.internal.debug.core.model.JDIReferenceListValue;
67 import org.eclipse.jdt.internal.debug.core.model.JDIReferenceListVariable;
68 import org.eclipse.jdt.internal.debug.core.model.JDIThread;
69 import org.eclipse.jdt.internal.debug.ui.display.JavaInspectExpression;
70 import org.eclipse.jdt.internal.debug.ui.monitors.JavaContendedMonitor;
71 import org.eclipse.jdt.internal.debug.ui.monitors.JavaOwnedMonitor;
72 import org.eclipse.jdt.internal.debug.ui.monitors.JavaOwningThread;
73 import org.eclipse.jdt.internal.debug.ui.monitors.JavaWaitingThread;
74 import org.eclipse.jdt.internal.debug.ui.monitors.NoMonitorInformationElement;
75 import org.eclipse.jdt.internal.debug.ui.monitors.ThreadMonitorManager;
76 import org.eclipse.jdt.internal.ui.JavaPlugin;
77 import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
78 import org.eclipse.jdt.internal.ui.viewsupport.ImageDescriptorRegistry;
79 import org.eclipse.jdt.ui.ISharedImages;
80 import org.eclipse.jdt.ui.JavaElementImageDescriptor;
81 import org.eclipse.jdt.ui.JavaElementLabelProvider;
82 import org.eclipse.jdt.ui.JavaUI;
83 import org.eclipse.jface.resource.ImageDescriptor;
84 import org.eclipse.jface.viewers.IColorProvider;
85 import org.eclipse.jface.viewers.LabelProvider;
86 import org.eclipse.swt.graphics.Color;
87 import org.eclipse.swt.graphics.Image;
88 import org.eclipse.swt.graphics.Point;
89 import org.eclipse.ui.IEditorDescriptor;
90 import org.eclipse.ui.IEditorInput;
91 import org.eclipse.ui.IWorkbenchWindow;
92 import org.eclipse.ui.PartInitException;
93 import org.eclipse.ui.PlatformUI;
94 import org.eclipse.ui.ide.IDE;
95
96 import com.ibm.icu.text.MessageFormat;
97 import com.sun.jdi.ObjectCollectedException;
98
99 /**
100  * Determines how to display java elements, including labels, images and editors.
101  * @see IDebugModelPresentation
102  */

103 public class JDIModelPresentation extends LabelProvider implements IDebugModelPresentation, IColorProvider {
104
105     /**
106      * Qualified names presentation property (value <code>"DISPLAY_QUALIFIED_NAMES"</code>).
107      * When <code>DISPLAY_QUALIFIED_NAMES</code> is set to <code>True</code>,
108      * this label provider should use fully qualified type names when rendering elements.
109      * When set to <code>False</code>, this label provider should use simple
110      * names when rendering elements.
111      * @see #setAttribute(String, Object)
112      */

113     public final static String JavaDoc DISPLAY_QUALIFIED_NAMES= "DISPLAY_QUALIFIED_NAMES"; //$NON-NLS-1$
114

115     protected HashMap JavaDoc fAttributes= new HashMap JavaDoc(3);
116     
117     static final Point BIG_SIZE= new Point(16, 16);
118     
119     private static ImageDescriptorRegistry fgJavaElementImageRegistry;
120     private static org.eclipse.jdt.internal.debug.ui.ImageDescriptorRegistry fgDebugImageRegistry;
121     
122     /**
123      * Flag to indicate if image registry's referenced by this model presentation is initialized
124      */

125     private static boolean fInitialized = false;
126
127     protected static final String JavaDoc fgStringName= "java.lang.String"; //$NON-NLS-1$
128

129     private JavaElementLabelProvider fJavaLabelProvider;
130     
131     public JDIModelPresentation() {
132         super();
133     }
134     
135     /* (non-Javadoc)
136      * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
137      */

138     public void dispose() {
139         super.dispose();
140         if (fJavaLabelProvider != null) {
141             fJavaLabelProvider.dispose();
142         }
143         fAttributes.clear();
144     }
145
146     /**
147      * @see IDebugModelPresentation#computeDetail(IValue, IValueDetailListener)
148      */

149     public void computeDetail(IValue value, IValueDetailListener listener) {
150         IJavaThread thread = getEvaluationThread((IJavaDebugTarget)value.getDebugTarget());
151         if (thread == null) {
152             listener.detailComputed(value, DebugUIMessages.JDIModelPresentation_no_suspended_threads);
153         } else {
154             JavaDetailFormattersManager.getDefault().computeValueDetail((IJavaValue)value, thread, listener);
155         }
156     }
157     
158     /**
159      * Returns a thread from the specified VM that can be
160      * used for an evaluation or <code>null</code> if
161      * none.
162      *
163      * @param debug target the target in which a thread is
164      * required
165      * @return thread or <code>null</code>
166      */

167     public static IJavaThread getEvaluationThread(IJavaDebugTarget target) {
168         IJavaStackFrame frame = EvaluationContextManager.getEvaluationContext((IWorkbenchWindow)null);
169         IJavaThread thread = null;
170         if (frame != null) {
171             thread = (IJavaThread) frame.getThread();
172         }
173         if (thread != null && (!thread.getDebugTarget().equals(target) || (!thread.isSuspended() && !thread.isPerformingEvaluation()))) {
174             // can only use suspended threads in the same target
175
thread = null;
176         }
177         if (thread == null) {
178             try {
179                 IThread[] threads = target.getThreads();
180                 for (int i = 0; i < threads.length; i++) {
181                     if (threads[i].isSuspended()) {
182                         thread = (IJavaThread)threads[i];
183                         break;
184                     }
185                 }
186             } catch (DebugException e) {
187                 JDIDebugUIPlugin.log(e);
188             }
189         }
190         return thread;
191     }
192             
193     /**
194      * @see IDebugModelPresentation#getText(Object)
195      */

196     public String JavaDoc getText(Object JavaDoc item) {
197         try {
198             boolean showQualified= isShowQualifiedNames();
199             if (item instanceof IJavaVariable) {
200                 return getVariableText((IJavaVariable) item);
201             } else if (item instanceof IStackFrame) {
202                 StringBuffer JavaDoc label= new StringBuffer JavaDoc(getStackFrameText((IStackFrame) item));
203                 if (item instanceof IJavaStackFrame) {
204                     if (((IJavaStackFrame)item).isOutOfSynch()) {
205                         label.append(DebugUIMessages.JDIModelPresentation___out_of_synch__1);
206                     }
207                 }
208                 return label.toString();
209             } else if (item instanceof IMarker) {
210                 IBreakpoint breakpoint = getBreakpoint((IMarker)item);
211                 if (breakpoint != null) {
212                     return getBreakpointText(breakpoint);
213                 }
214                 return null;
215             } else if (item instanceof IBreakpoint) {
216                 return getBreakpointText((IBreakpoint)item);
217             } else if (item instanceof IWatchExpression) {
218                 return getWatchExpressionText((IWatchExpression)item);
219             } else if (item instanceof IExpression) {
220                 return getExpressionText((IExpression)item);
221             } else if (item instanceof JavaOwnedMonitor) {
222                 return getJavaOwnedMonitorText((JavaOwnedMonitor)item);
223             } else if (item instanceof JavaContendedMonitor) {
224                 return getJavaContendedMonitorText((JavaContendedMonitor)item);
225             } else if (item instanceof JavaOwningThread) {
226                 return getJavaOwningTreadText((JavaOwningThread)item);
227             } else if (item instanceof JavaWaitingThread) {
228                 return getJavaWaitingTreadText((JavaWaitingThread)item);
229             } else if (item instanceof NoMonitorInformationElement) {
230                 return DebugUIMessages.JDIModelPresentation_5;
231             } else {
232                 StringBuffer JavaDoc label= new StringBuffer JavaDoc();
233                 if (item instanceof IJavaThread) {
234                     label.append(getThreadText((IJavaThread) item, showQualified));
235                     if (((IJavaThread)item).isOutOfSynch()) {
236                         label.append(DebugUIMessages.JDIModelPresentation___out_of_synch__1);
237                     } else if (((IJavaThread)item).mayBeOutOfSynch()) {
238                         label.append(DebugUIMessages.JDIModelPresentation___may_be_out_of_synch__2);
239                     }
240                 } else if (item instanceof IJavaDebugTarget) {
241                     label.append(getDebugTargetText((IJavaDebugTarget) item));
242                     if (((IJavaDebugTarget)item).isOutOfSynch()) {
243                         label.append(DebugUIMessages.JDIModelPresentation___out_of_synch__1);
244                     } else if (((IJavaDebugTarget)item).mayBeOutOfSynch()) {
245                         label.append(DebugUIMessages.JDIModelPresentation___may_be_out_of_synch__2);
246                     }
247                 } else if (item instanceof IJavaValue) {
248                     label.append(getValueText((IJavaValue) item));
249                 }
250                 if (item instanceof ITerminate) {
251                     if (((ITerminate) item).isTerminated()) {
252                         label.insert(0, DebugUIMessages.JDIModelPresentation__terminated__2);
253                         return label.toString();
254                     }
255                 }
256                 if (item instanceof IDisconnect) {
257                     if (((IDisconnect) item).isDisconnected()) {
258                         label.insert(0, DebugUIMessages.JDIModelPresentation__disconnected__4);
259                         return label.toString();
260                     }
261                 }
262                 if (label.length() > 0) {
263                     return label.toString();
264                 }
265             }
266         } catch (CoreException e) {
267             return DebugUIMessages.JDIModelPresentation__not_responding__6;
268         }
269         return null;
270     }
271
272     private String JavaDoc getJavaOwningTreadText(JavaOwningThread thread) throws CoreException {
273         return getFormattedString(DebugUIMessages.JDIModelPresentation_0, getThreadText(thread.getThread().getThread(), isShowQualifiedNames()));
274     }
275
276     private String JavaDoc getJavaWaitingTreadText(JavaWaitingThread thread) throws CoreException {
277         return getFormattedString(DebugUIMessages.JDIModelPresentation_1, getThreadText(thread.getThread().getThread(), isShowQualifiedNames()));
278     }
279
280     private String JavaDoc getJavaContendedMonitorText(JavaContendedMonitor monitor) throws DebugException {
281         return getFormattedString(DebugUIMessages.JDIModelPresentation_2, getValueText(monitor.getMonitor().getMonitor()));
282     }
283
284     private String JavaDoc getJavaOwnedMonitorText(JavaOwnedMonitor monitor) throws DebugException {
285         return getFormattedString(DebugUIMessages.JDIModelPresentation_3, getValueText(monitor.getMonitor().getMonitor()));
286     }
287
288     protected IBreakpoint getBreakpoint(IMarker marker) {
289         return DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(marker);
290         }
291     
292     /**
293      * Build the text for an IJavaThread.
294      */

295     protected String JavaDoc getThreadText(IJavaThread thread, boolean qualified) throws CoreException {
296         StringBuffer JavaDoc key = new StringBuffer JavaDoc("thread_"); //$NON-NLS-1$
297
String JavaDoc[] args = null;
298         IBreakpoint[] breakpoints= thread.getBreakpoints();
299         if (thread.isDaemon()) {
300             key.append("daemon_"); //$NON-NLS-1$
301
}
302         if (thread.isSystemThread()) {
303             key.append("system_"); //$NON-NLS-1$
304
}
305         if (thread.isTerminated()) {
306             key.append("terminated"); //$NON-NLS-1$
307
args = new String JavaDoc[] {thread.getName()};
308         } else if (thread.isStepping()) {
309             key.append("stepping"); //$NON-NLS-1$
310
args = new String JavaDoc[] {thread.getName()};
311         } else if (thread.isPerformingEvaluation() && breakpoints.length == 0) {
312             key.append("evaluating"); //$NON-NLS-1$
313
args = new String JavaDoc[] {thread.getName()};
314         } else if (!thread.isSuspended() || (thread instanceof JDIThread && ((JDIThread)thread).isSuspendedQuiet())) {
315             key.append("running"); //$NON-NLS-1$
316
args = new String JavaDoc[] {thread.getName()};
317         } else {
318             key.append("suspended"); //$NON-NLS-1$
319
if (breakpoints.length > 0) {
320                 IJavaBreakpoint breakpoint= (IJavaBreakpoint)breakpoints[0];
321                 for (int i= 0, numBreakpoints= breakpoints.length; i < numBreakpoints; i++) {
322                     if (BreakpointUtils.isProblemBreakpoint(breakpoints[i])) {
323                         // If a compilation error breakpoint exists, display it instead of the first breakpoint
324
breakpoint= (IJavaBreakpoint)breakpoints[i];
325                         break;
326                     }
327                 }
328                 String JavaDoc typeName= getMarkerTypeName(breakpoint, qualified);
329                 if (BreakpointUtils.isProblemBreakpoint(breakpoint)) {
330                     IJavaStackFrame frame = (IJavaStackFrame)thread.getTopStackFrame();
331                     IMarker problem = null;
332                     if (frame != null) {
333                         problem = JavaDebugOptionsManager.getDefault().getProblem(frame);
334                     }
335                     if (problem != null) {
336                         key.append("_problem"); //$NON-NLS-1$
337
String JavaDoc message = problem.getAttribute(IMarker.MESSAGE, DebugUIMessages.JDIModelPresentation_Compilation_error_1);
338                         args = new String JavaDoc[] {thread.getName(), message};
339                     }
340                 }
341                 // check args == null in case the exception is a compilation error
342
if (breakpoint instanceof IJavaExceptionBreakpoint && args == null) {
343                     key.append("_exception"); //$NON-NLS-1$
344
String JavaDoc exName = ((IJavaExceptionBreakpoint)breakpoint).getExceptionTypeName();
345                     if (exName == null) {
346                         exName = typeName;
347                     } else if (!qualified) {
348                         int index = exName.lastIndexOf('.');
349                         exName = exName.substring(index + 1);
350                     }
351                     args = new String JavaDoc[] {thread.getName(), exName};
352                 } else if (breakpoint instanceof IJavaWatchpoint) {
353                     IJavaWatchpoint wp = (IJavaWatchpoint)breakpoint;
354                     String JavaDoc fieldName = wp.getFieldName();
355                     args = new String JavaDoc[] {thread.getName(), fieldName, typeName};
356                     if (wp.isAccessSuspend(thread.getDebugTarget())) {
357                         key.append("_fieldaccess"); //$NON-NLS-1$
358
} else {
359                         key.append("_fieldmodification"); //$NON-NLS-1$
360
}
361                 } else if (breakpoint instanceof IJavaMethodBreakpoint) {
362                     IJavaMethodBreakpoint me= (IJavaMethodBreakpoint)breakpoint;
363                     String JavaDoc methodName= me.getMethodName();
364                     args = new String JavaDoc[] {thread.getName(), methodName, typeName};
365                     if (me.isEntrySuspend(thread.getDebugTarget())) {
366                         key.append("_methodentry"); //$NON-NLS-1$
367
} else {
368                         key.append("_methodexit"); //$NON-NLS-1$
369
}
370                 } else if (breakpoint instanceof IJavaLineBreakpoint) {
371                     IJavaLineBreakpoint jlbp = (IJavaLineBreakpoint)breakpoint;
372                     int lineNumber= jlbp.getLineNumber();
373                     if (lineNumber > -1) {
374                         args = new String JavaDoc[] {thread.getName(), String.valueOf(lineNumber), typeName};
375                         if (BreakpointUtils.isRunToLineBreakpoint(jlbp)) {
376                             key.append("_runtoline"); //$NON-NLS-1$
377
} else {
378                             key.append("_linebreakpoint"); //$NON-NLS-1$
379
}
380                     }
381                 } else if (breakpoint instanceof IJavaClassPrepareBreakpoint) {
382                     key.append("_classprepare"); //$NON-NLS-1$
383
args = new String JavaDoc[]{thread.getName(), getQualifiedName(breakpoint.getTypeName())};
384                 }
385             }
386     
387             if (args == null) {
388                 // Otherwise, it's just suspended
389
args = new String JavaDoc[] {thread.getName()};
390             }
391         }
392         try {
393             return getFormattedString((String JavaDoc)DebugUIMessages.class.getDeclaredField(key.toString()).get(null), args);
394         } catch (IllegalArgumentException JavaDoc e) {
395             JDIDebugUIPlugin.log(e);
396         } catch (SecurityException JavaDoc e) {
397             JDIDebugUIPlugin.log(e);
398         } catch (IllegalAccessException JavaDoc e) {
399             JDIDebugUIPlugin.log(e);
400         } catch (NoSuchFieldException JavaDoc e) {
401             JDIDebugUIPlugin.log(e);
402         }
403         return DebugUIMessages.JDIModelPresentation_unknown_name__1;
404     }
405
406     /**
407      * Build the text for an IJavaDebugTarget.
408      */

409     protected String JavaDoc getDebugTargetText(IJavaDebugTarget debugTarget) throws DebugException {
410         String JavaDoc labelString= debugTarget.getName();
411         if (debugTarget.isSuspended()) {
412             labelString += DebugUIMessages.JDIModelPresentation_target_suspended;
413         }
414         return labelString;
415     }
416
417     /**
418      * Build the text for an IJavaValue.
419      */

420     public String JavaDoc getValueText(IJavaValue value) throws DebugException {
421         
422         String JavaDoc refTypeName= value.getReferenceTypeName();
423         String JavaDoc valueString= value.getValueString();
424         boolean isString= refTypeName.equals(fgStringName);
425         IJavaType type= value.getJavaType();
426         String JavaDoc signature= null;
427         if (type != null) {
428             signature= type.getSignature();
429         }
430         if ("V".equals(signature)) { //$NON-NLS-1$
431
valueString= DebugUIMessages.JDIModelPresentation__No_explicit_return_value__30;
432         }
433         boolean isObject= isObjectValue(signature);
434         boolean isArray= value instanceof IJavaArray;
435         StringBuffer JavaDoc buffer= new StringBuffer JavaDoc();
436         // Always show type name for objects & arrays (but not Strings)
437
if (isObject && !isString && (refTypeName.length() > 0)) {
438             // Don't show type name for instances and references
439
if (!(value instanceof JDIReferenceListValue || value instanceof JDIAllInstancesValue)){
440                 String JavaDoc qualTypeName= getQualifiedName(refTypeName);
441                 if (isArray) {
442                     qualTypeName= adjustTypeNameForArrayIndex(qualTypeName, ((IJavaArray)value).getLength());
443                 }
444                 buffer.append(qualTypeName);
445                 buffer.append(' ');
446             }
447         }
448         
449         // Put double quotes around Strings
450
if (valueString != null && (isString || valueString.length() > 0)) {
451             if (isString) {
452                 buffer.append('"');
453             }
454             buffer.append(valueString);
455             if (isString) {
456                 buffer.append('"');
457             }
458         }
459         
460         // show unsigned value second, if applicable
461
if (isShowUnsignedValues()) {
462             buffer= appendUnsignedText(value, buffer);
463         }
464         // show hex value third, if applicable
465
if (isShowHexValues()) {
466             buffer= appendHexText(value, buffer);
467         }
468         // show byte character value last, if applicable
469
if (isShowCharValues()) {
470             buffer= appendCharText(value, buffer);
471         }
472         
473         return buffer.toString();
474     }
475     
476
477     private StringBuffer JavaDoc appendUnsignedText(IJavaValue value, StringBuffer JavaDoc buffer) throws DebugException {
478         String JavaDoc unsignedText= getValueUnsignedText(value);
479         if (unsignedText != null) {
480             buffer.append(" ["); //$NON-NLS-1$
481
buffer.append(unsignedText);
482             buffer.append("]"); //$NON-NLS-1$
483
}
484         return buffer;
485     }
486         
487     protected StringBuffer JavaDoc appendHexText(IJavaValue value, StringBuffer JavaDoc buffer) throws DebugException {
488         String JavaDoc hexText = getValueHexText(value);
489         if (hexText != null) {
490             buffer.append(" ["); //$NON-NLS-1$
491
buffer.append(hexText);
492             buffer.append("]"); //$NON-NLS-1$
493
}
494         return buffer;
495     }
496     
497     protected StringBuffer JavaDoc appendCharText(IJavaValue value, StringBuffer JavaDoc buffer) throws DebugException {
498         String JavaDoc charText= getValueCharText(value);
499         if (charText != null) {
500             buffer.append(" ["); //$NON-NLS-1$
501
buffer.append(charText);
502             buffer.append("]"); //$NON-NLS-1$
503
}
504         return buffer;
505     }
506     
507     /**
508      * Given a JNI-style signature String for a IJavaValue, return true
509      * if the signature represents an Object or an array of Objects.
510      */

511     public static boolean isObjectValue(String JavaDoc signature) {
512         if (signature == null) {
513             return false;
514         }
515         char sigChar= ' ';
516         for (int i= 0; i < signature.length(); i++) {
517             sigChar= signature.charAt(i);
518             if (sigChar == '[') {
519                 return true;
520             }
521             break;
522         }
523         if ((sigChar == 'L') || (sigChar == 'Q')) {
524             return true;
525         }
526         return false;
527     }
528     
529     /**
530      * Returns whether the image registry's have been retrieved.
531      *
532      * @return whether image registry's have been retrieved.
533      */

534     public static boolean isInitialized() {
535         return fgJavaElementImageRegistry != null && fgDebugImageRegistry != null;
536     }
537     
538     /**
539      * Returns the type signature for this value if its type is primitive.
540      * For non-primitive types, null is returned.
541      */

542     protected String JavaDoc getPrimitiveValueTypeSignature(IJavaValue value) throws DebugException {
543         IJavaType type= value.getJavaType();
544         if (type != null) {
545             String JavaDoc sig= type.getSignature();
546             if (sig != null && sig.length() == 1) {
547                 return sig;
548             }
549         }
550         return null;
551     }
552     /**
553      * Returns the character string of a byte or <code>null</code> if
554      * the value can not be interpreted as a valid character.
555      */

556     protected String JavaDoc getValueCharText(IJavaValue value) throws DebugException {
557         String JavaDoc sig= getPrimitiveValueTypeSignature(value);
558         if (sig == null) {
559             return null;
560         }
561         String JavaDoc valueString= value.getValueString();
562         long longValue;
563         try {
564             longValue= Long.parseLong(valueString);
565         } catch (NumberFormatException JavaDoc e) {
566             return null;
567         }
568         switch (sig.charAt(0)) {
569             case 'B' : // byte
570
longValue= longValue & 0xFF; // Only lower 8 bits
571
break;
572             case 'I' : // integer
573
longValue= longValue & 0xFFFFFFFF; // Only lower 32 bits
574
if (longValue > 0xFFFF || longValue < 0) {
575                     return null;
576                 }
577                 break;
578             case 'S' : // short
579
longValue= longValue & 0xFFFF; // Only lower 16 bits
580
break;
581             case 'J' :
582                 if (longValue > 0xFFFF || longValue < 0) {
583                     // Out of character range
584
return null;
585                 }
586                 break;
587             default :
588                 return null;
589         }
590         char charValue= (char)longValue;
591         StringBuffer JavaDoc charText = new StringBuffer JavaDoc();
592         if (Character.getType(charValue) == Character.CONTROL) {
593             Character JavaDoc ctrl = new Character JavaDoc((char) (charValue + 64));
594             charText.append('^');
595             charText.append(ctrl);
596             switch (charValue) { // common use
597
case 0: charText.append(" (NUL)"); break; //$NON-NLS-1$
598
case 8: charText.append(" (BS)"); break; //$NON-NLS-1$
599
case 9: charText.append(" (TAB)"); break; //$NON-NLS-1$
600
case 10: charText.append(" (LF)"); break; //$NON-NLS-1$
601
case 13: charText.append(" (CR)"); break; //$NON-NLS-1$
602
case 21: charText.append(" (NL)"); break; //$NON-NLS-1$
603
case 27: charText.append(" (ESC)"); break; //$NON-NLS-1$
604
case 127: charText.append(" (DEL)"); break; //$NON-NLS-1$
605
}
606         } else {
607             charText.append(new Character JavaDoc(charValue));
608         }
609         return charText.toString();
610     }
611
612     protected String JavaDoc getMarkerTypeName(IJavaBreakpoint breakpoint, boolean qualified) throws CoreException {
613         String JavaDoc typeName= null;
614         if (breakpoint instanceof IJavaPatternBreakpoint) {
615             typeName = breakpoint.getMarker().getResource().getName();
616         } else {
617             typeName = breakpoint.getTypeName();
618         }
619         if (!qualified) {
620             int index= typeName.lastIndexOf('.');
621             if (index != -1) {
622                 typeName= typeName.substring(index + 1);
623             }
624         }
625         return typeName;
626     }
627
628     /**
629      * Maps a Java element to an appropriate image.
630      *
631      * @see IDebugModelPresentation#getImage(Object)
632      */

633     public Image getImage(Object JavaDoc item) {
634         
635         initImageRegistries();
636         
637         try {
638             if (item instanceof JDIReferenceListVariable) {
639                 return getReferencesImage(item);
640             }
641             if (item instanceof JDIReferenceListEntryVariable){
642                 return getReferenceImage(item);
643             }
644             if (item instanceof IJavaVariable) {
645                 return getVariableImage((IAdaptable) item);
646             }
647             if (item instanceof IMarker) {
648                 IBreakpoint bp = getBreakpoint((IMarker)item);
649                 if (bp != null && bp instanceof IJavaBreakpoint) {
650                     return getBreakpointImage((IJavaBreakpoint)bp);
651                 }
652             }
653             if (item instanceof IJavaBreakpoint) {
654                 return getBreakpointImage((IJavaBreakpoint)item);
655             }
656             if (item instanceof IJavaStackFrame || item instanceof IJavaThread || item instanceof IJavaDebugTarget) {
657                 return getDebugElementImage(item);
658             }
659             if (item instanceof IJavaValue) {
660                 return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_PUBLIC);
661             }
662             if (item instanceof IExpression) {
663                 return getExpressionImage(item);
664             }
665             if (item instanceof JavaOwnedMonitor) {
666                 return getJavaOwnedMonitorImage((JavaOwnedMonitor)item);
667             }
668             if (item instanceof JavaContendedMonitor) {
669                 return getJavaContendedMonitorImage((JavaContendedMonitor)item);
670             }
671             if (item instanceof JavaOwningThread) {
672                 return getJavaOwningThreadImage((JavaOwningThread)item);
673             }
674             if (item instanceof JavaWaitingThread) {
675                 return getJavaWaitingThreadImage((JavaWaitingThread)item);
676             }
677             if (item instanceof NoMonitorInformationElement) {
678                 return getDebugImageRegistry().get(new JDIImageDescriptor(
679                         getImageDescriptor(JavaDebugImages.IMG_OBJS_MONITOR), 0));
680             }
681         } catch (CoreException e) {
682             // no need to log errors - elements may no longer exist by the time we render them
683
}
684         return null;
685     }
686
687     /**
688      * Initialize image registry's that this model presentation references to
689      */

690     private synchronized void initImageRegistries() {
691         
692         // if not initialized and this is called on the UI thread
693
if (!fInitialized && Thread.currentThread().equals(JDIDebugUIPlugin.getStandardDisplay().getThread())) {
694             // call get image registry's to force them to be created on the UI thread
695
getDebugImageRegistry();
696             getJavaElementImageRegistry();
697             JavaUI.getSharedImages();
698             fInitialized = true;
699         }
700     }
701
702     /**
703      * @param thread
704      * @return
705      */

706     private Image getJavaWaitingThreadImage(JavaWaitingThread thread) {
707         JDIImageDescriptor descriptor;
708         int flag= JDIImageDescriptor.IN_CONTENTION_FOR_MONITOR | (thread.getThread().isInDeadlock() ? JDIImageDescriptor.IN_DEADLOCK : 0);
709         if (thread.isSuspended()) {
710             descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_THREAD_SUSPENDED), flag);
711         } else {
712             descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_THREAD_RUNNING), flag);
713         }
714         return getDebugImageRegistry().get(descriptor);
715     }
716
717     /**
718      * @param thread
719      * @return
720      */

721     private Image getJavaOwningThreadImage(JavaOwningThread thread) {
722         JDIImageDescriptor descriptor;
723         int flag= JDIImageDescriptor.OWNS_MONITOR | (thread.getThread().isInDeadlock() ? JDIImageDescriptor.IN_DEADLOCK : 0);
724         if (thread.isSuspended()) {
725             descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_THREAD_SUSPENDED), flag);
726         } else {
727             descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_THREAD_RUNNING), flag);
728         }
729         return getDebugImageRegistry().get(descriptor);
730     }
731
732     /**
733      * @param monitor
734      * @return
735      */

736     private Image getJavaContendedMonitorImage(JavaContendedMonitor monitor) {
737         int flag= monitor.getMonitor().isInDeadlock() ? JDIImageDescriptor.IN_DEADLOCK : 0;
738         JDIImageDescriptor descriptor= new JDIImageDescriptor(
739                 getImageDescriptor(JavaDebugImages.IMG_OBJS_CONTENDED_MONITOR), flag);
740         return getDebugImageRegistry().get(descriptor);
741     }
742
743     /**
744      * @param monitor
745      * @return
746      */

747     private Image getJavaOwnedMonitorImage(JavaOwnedMonitor monitor) {
748         int flag= monitor.getMonitor().isInDeadlock() ? JDIImageDescriptor.IN_DEADLOCK : 0;
749         JDIImageDescriptor descriptor= new JDIImageDescriptor(getImageDescriptor(JavaDebugImages.IMG_OBJS_OWNED_MONITOR), flag);
750         return getDebugImageRegistry().get(descriptor);
751     }
752
753     protected Image getBreakpointImage(IJavaBreakpoint breakpoint) throws CoreException {
754         if (breakpoint instanceof IJavaExceptionBreakpoint) {
755             return getExceptionBreakpointImage((IJavaExceptionBreakpoint)breakpoint);
756         } else if (breakpoint instanceof IJavaClassPrepareBreakpoint) {
757             return getClassPrepareBreakpointImage((IJavaClassPrepareBreakpoint)breakpoint);
758         }
759         
760         if (breakpoint instanceof IJavaLineBreakpoint && BreakpointUtils.isRunToLineBreakpoint((IJavaLineBreakpoint)breakpoint)) {
761             return null;
762         }
763         return getJavaBreakpointImage(breakpoint);
764     }
765
766     protected Image getExceptionBreakpointImage(IJavaExceptionBreakpoint exception) throws CoreException {
767         int flags= computeBreakpointAdornmentFlags(exception);
768         JDIImageDescriptor descriptor= null;
769         if ((flags & JDIImageDescriptor.ENABLED) == 0) {
770             descriptor= new JDIImageDescriptor(getImageDescriptor(JavaDebugImages.IMG_OBJS_EXCEPTION_DISABLED), flags);
771         } else if (exception.isChecked()) {
772             descriptor= new JDIImageDescriptor(getImageDescriptor(JavaDebugImages.IMG_OBJS_EXCEPTION), flags);
773         } else {
774             descriptor= new JDIImageDescriptor(getImageDescriptor(JavaDebugImages.IMG_OBJS_ERROR), flags);
775         }
776         return getDebugImageRegistry().get(descriptor);
777     }
778
779     protected Image getJavaBreakpointImage(IJavaBreakpoint breakpoint) throws CoreException {
780         if (breakpoint instanceof IJavaMethodBreakpoint) {
781             IJavaMethodBreakpoint mBreakpoint= (IJavaMethodBreakpoint)breakpoint;
782             return getJavaMethodBreakpointImage(mBreakpoint);
783         } else if (breakpoint instanceof IJavaWatchpoint) {
784             IJavaWatchpoint watchpoint= (IJavaWatchpoint)breakpoint;
785             return getJavaWatchpointImage(watchpoint);
786         } else if (breakpoint instanceof IJavaMethodEntryBreakpoint) {
787             IJavaMethodEntryBreakpoint meBreakpoint = (IJavaMethodEntryBreakpoint)breakpoint;
788             return getJavaMethodEntryBreakpointImage(meBreakpoint);
789         } else {
790             int flags= computeBreakpointAdornmentFlags(breakpoint);
791             JDIImageDescriptor descriptor= null;
792             if (breakpoint.isEnabled()) {
793                 descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_BREAKPOINT), flags);
794             } else {
795                 descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_BREAKPOINT_DISABLED), flags);
796             }
797             return getDebugImageRegistry().get(descriptor);
798         }
799     }
800
801     protected Image getJavaMethodBreakpointImage(IJavaMethodBreakpoint mBreakpoint) throws CoreException {
802         int flags= computeBreakpointAdornmentFlags(mBreakpoint);
803         JDIImageDescriptor descriptor= null;
804         if (mBreakpoint.isEnabled()) {
805             descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_BREAKPOINT), flags);
806         } else {
807             descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_BREAKPOINT_DISABLED), flags);
808         }
809             
810         return getDebugImageRegistry().get(descriptor);
811     }
812     
813     protected Image getJavaMethodEntryBreakpointImage(IJavaMethodEntryBreakpoint mBreakpoint) throws CoreException {
814         int flags= computeBreakpointAdornmentFlags(mBreakpoint);
815         JDIImageDescriptor descriptor= null;
816         if (mBreakpoint.isEnabled()) {
817             descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_BREAKPOINT), flags);
818         } else {
819             descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_BREAKPOINT_DISABLED), flags);
820         }
821             
822         return getDebugImageRegistry().get(descriptor);
823     }
824     
825     protected Image getClassPrepareBreakpointImage(IJavaClassPrepareBreakpoint breakpoint) throws CoreException {
826         int flags= computeBreakpointAdornmentFlags(breakpoint);
827         JDIImageDescriptor descriptor= null;
828         if (breakpoint.getMemberType() == IJavaClassPrepareBreakpoint.TYPE_CLASS) {
829             descriptor= new JDIImageDescriptor(JavaUI.getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_CLASS), flags);
830         } else {
831             descriptor= new JDIImageDescriptor(JavaUI.getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_INTERFACE), flags);
832         }
833         return getDebugImageRegistry().get(descriptor);
834     }
835     
836     protected Image getJavaWatchpointImage(IJavaWatchpoint watchpoint) throws CoreException {
837         int flags= computeBreakpointAdornmentFlags(watchpoint);
838         JDIImageDescriptor descriptor= null;
839         boolean enabled= (flags & JDIImageDescriptor.ENABLED) != 0;
840         if (watchpoint.isAccess()) {
841             if (watchpoint.isModification()) {
842                 //access and modification
843
if (enabled) {
844                     descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_WATCHPOINT), flags);
845                 } else {
846                     descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_WATCHPOINT_DISABLED), flags);
847                 }
848             } else {
849                 if (enabled) {
850                     descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_ACCESS_WATCHPOINT), flags);
851                 } else {
852                     descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_ACCESS_WATCHPOINT_DISABLED), flags);
853                 }
854             }
855         } else if (watchpoint.isModification()) {
856             if (enabled) {
857                 descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_MODIFICATION_WATCHPOINT), flags);
858             } else {
859                 descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_MODIFICATION_WATCHPOINT_DISABLED), flags);
860             }
861         } else {
862             //neither access nor modification
863
descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_WATCHPOINT_DISABLED), flags);
864         }
865         return getDebugImageRegistry().get(descriptor);
866     }
867     
868     protected Image getVariableImage(IAdaptable element) {
869         JavaElementImageDescriptor descriptor= new JavaElementImageDescriptor(
870             computeBaseImageDescriptor(element), computeAdornmentFlags(element), BIG_SIZE);
871
872         return getJavaElementImageRegistry().get(descriptor);
873     }
874     
875     /**
876      * Returns the image associated with reference variables being used to display
877      * references to a root object.
878      *
879      * @param element
880      * @return image associated with reference variables
881      */

882     protected Image getReferencesImage(Object JavaDoc element){
883         return JavaDebugImages.get(JavaDebugImages.IMG_ELCL_ALL_REFERENCES);
884     }
885     
886     /**
887      * Returns the image associated with reference variables being used to display
888      * references to a root object.
889      *
890      * @param element
891      * @return image associated with reference variables
892      */

893     protected Image getReferenceImage(Object JavaDoc element){
894         return JavaDebugImages.get(JavaDebugImages.IMG_OBJS_REFERENCE);
895     }
896     
897     /**
898      * Returns the image associated with the given element or <code>null</code>
899      * if none is defined.
900      */

901     protected Image getDebugElementImage(Object JavaDoc element) {
902         ImageDescriptor image= null;
903         if (element instanceof IJavaThread) {
904             IJavaThread thread = (IJavaThread)element;
905             if (thread.isSuspended() && !thread.isPerformingEvaluation()) {
906                 image= DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_THREAD_SUSPENDED);
907             } else if (thread.isTerminated()) {
908                 image= DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_THREAD_TERMINATED);
909             } else {
910                 image= DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_THREAD_RUNNING);
911             }
912         } else {
913             image= DebugUITools.getDefaultImageDescriptor(element);
914         }
915         if (image == null) {
916             return null;
917         }
918         int flags= computeJDIAdornmentFlags(element);
919         JDIImageDescriptor descriptor= new JDIImageDescriptor(image, flags);
920         return getDebugImageRegistry().get(descriptor);
921     }
922     
923     /**
924      * Returns the image associated with the given element or <code>null</code>
925      * if none is defined.
926      */

927     protected Image getExpressionImage(Object JavaDoc expression) {
928         ImageDescriptor image= null;
929         boolean bigSize = false;
930         if (expression instanceof JavaInspectExpression) {
931             image= JavaDebugImages.getImageDescriptor(JavaDebugImages.IMG_OBJ_JAVA_INSPECT_EXPRESSION);
932             bigSize = true;
933         }
934         if (image == null) {
935             return null;
936         }
937         JDIImageDescriptor descriptor= new JDIImageDescriptor(image, 0);
938         if (bigSize) {
939             descriptor.setSize(BIG_SIZE);
940         }
941         return getDebugImageRegistry().get(descriptor);
942     }
943
944     /**
945      * Returns the adornment flags for the given element.
946      * These flags are used to render appropriate overlay
947      * icons for the element.
948      */

949     private int computeJDIAdornmentFlags(Object JavaDoc element) {
950         try {
951             if (element instanceof IJavaStackFrame) {
952                 IJavaStackFrame javaStackFrame = ((IJavaStackFrame)element);
953                 if (javaStackFrame.isOutOfSynch()) {
954                     return JDIImageDescriptor.IS_OUT_OF_SYNCH;
955                 }
956                 if (!javaStackFrame.isObsolete() && javaStackFrame.isSynchronized()) {
957                     return JDIImageDescriptor.SYNCHRONIZED;
958                 }
959             }
960             if (element instanceof IJavaThread) {
961                 int flag= 0;
962                 IJavaThread javaThread = ((IJavaThread)element);
963                 if (ThreadMonitorManager.getDefault().isInDeadlock(javaThread)) {
964                     flag= JDIImageDescriptor.IN_DEADLOCK;
965                 }
966                 if (javaThread.isOutOfSynch()) {
967                     return flag | JDIImageDescriptor.IS_OUT_OF_SYNCH;
968                 }
969                 if (javaThread.mayBeOutOfSynch()) {
970                     return flag | JDIImageDescriptor.MAY_BE_OUT_OF_SYNCH;
971                 }
972                 return flag;
973             }
974             if (element instanceof IJavaDebugTarget) {
975                 if (((IJavaDebugTarget)element).isOutOfSynch()) {
976                     return JDIImageDescriptor.IS_OUT_OF_SYNCH;
977                 }
978                 if (((IJavaDebugTarget)element).mayBeOutOfSynch()) {
979                     return JDIImageDescriptor.MAY_BE_OUT_OF_SYNCH;
980                 }
981             }
982         } catch (DebugException e) {
983             // no need to log errors - elements may no longer exist by the time we render them
984
}
985         return 0;
986     }
987     
988     /**
989      * Returns the adornment flags for the given breakpoint.
990      * These flags are used to render appropriate overlay
991      * icons for the breakpoint.
992      */

993     private int computeBreakpointAdornmentFlags(IJavaBreakpoint breakpoint) {
994         int flags= 0;
995         try {
996             if (breakpoint.isEnabled()) {
997                 flags |= JDIImageDescriptor.ENABLED;
998             }
999             if (breakpoint.isInstalled()) {
1000                flags |= JDIImageDescriptor.INSTALLED;
1001            }
1002            if (breakpoint instanceof IJavaLineBreakpoint) {
1003                if (((IJavaLineBreakpoint)breakpoint).isConditionEnabled()) {
1004                    flags |= JDIImageDescriptor.CONDITIONAL;
1005                }
1006                if (breakpoint instanceof IJavaMethodBreakpoint) {
1007                    IJavaMethodBreakpoint mBreakpoint= (IJavaMethodBreakpoint)breakpoint;
1008                    if (mBreakpoint.isEntry()) {
1009                        flags |= JDIImageDescriptor.ENTRY;
1010                    }
1011                    if (mBreakpoint.isExit()) {
1012                        flags |= JDIImageDescriptor.EXIT;
1013                    }
1014                }
1015                if (breakpoint instanceof IJavaMethodEntryBreakpoint) {
1016                    flags |= JDIImageDescriptor.ENTRY;
1017                }
1018            } else if (breakpoint instanceof IJavaExceptionBreakpoint) {
1019                IJavaExceptionBreakpoint eBreakpoint= (IJavaExceptionBreakpoint)breakpoint;
1020                if (eBreakpoint.isCaught()) {
1021                    flags |= JDIImageDescriptor.CAUGHT;
1022                }
1023                if (eBreakpoint.isUncaught()) {
1024                    flags |= JDIImageDescriptor.UNCAUGHT;
1025                }
1026                if (eBreakpoint.getExclusionFilters().length > 0 || eBreakpoint.getInclusionFilters().length > 0) {
1027                    flags |= JDIImageDescriptor.SCOPED;
1028                }
1029            }
1030        } catch (CoreException e) {
1031        }
1032        return flags;
1033    }
1034    
1035    private ImageDescriptor computeBaseImageDescriptor(IAdaptable element) {
1036        IJavaVariable javaVariable= (IJavaVariable) element.getAdapter(IJavaVariable.class);
1037        if (javaVariable != null) {
1038            try {
1039                if (javaVariable.isLocal())
1040                    return JavaDebugImages.getImageDescriptor(JavaDebugImages.IMG_OBJS_LOCAL_VARIABLE);
1041                if (javaVariable.isPublic())
1042                    return JavaUI.getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_PUBLIC);
1043                if (javaVariable.isProtected())
1044                    return JavaUI.getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_PROTECTED);
1045                if (javaVariable.isPrivate())
1046                    return JavaUI.getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_PRIVATE);
1047            } catch (DebugException e) {
1048                // no need to log errors - elements may no longer exist by the time we render them
1049
}
1050        }
1051        return JavaUI.getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_DEFAULT);
1052    }
1053    
1054    private int computeAdornmentFlags(IAdaptable element) {
1055        int flags= 0;
1056        IJavaModifiers javaProperties= (IJavaModifiers)element.getAdapter(IJavaModifiers.class);
1057        try {
1058            if (javaProperties != null) {
1059                if (javaProperties.isFinal()) {
1060                    flags |= JavaElementImageDescriptor.FINAL;
1061                }
1062                if (javaProperties.isStatic()) {
1063                    flags |= JavaElementImageDescriptor.STATIC;
1064                }
1065            }
1066        } catch(DebugException e) {
1067            // no need to log errors - elements may no longer exist by the time we render them
1068
}
1069        return flags;
1070    }
1071
1072    /**
1073     * @see IDebugModelPresentation#getEditorInput(Object)
1074     */

1075    public IEditorInput getEditorInput(Object JavaDoc item) {
1076        try {
1077            if (item instanceof IMarker) {
1078                item = getBreakpoint((IMarker)item);
1079            }
1080            if (item instanceof IJavaBreakpoint) {
1081                IType type = BreakpointUtils.getType((IJavaBreakpoint)item);
1082                if (type == null) {
1083                    // if the breakpoint is not associated with a type, use its resource
1084
item = ((IJavaBreakpoint)item).getMarker().getResource();
1085                } else {
1086                    item = type;
1087                }
1088            }
1089            if (item instanceof LocalFileStorage) {
1090                return new LocalFileStorageEditorInput((LocalFileStorage)item);
1091            }
1092            if (item instanceof ZipEntryStorage) {
1093                return new ZipEntryStorageEditorInput((ZipEntryStorage)item);
1094            }
1095            // for types that correspond to external files, return null so we do not
1096
// attempt to open a non-existing workspace file on the breakpoint (bug 184934)
1097
if (item instanceof IType) {
1098                IType type = (IType) item;
1099                if (!type.exists()) {
1100                    return null;
1101                }
1102            }
1103            return EditorUtility.getEditorInput(item);
1104        } catch (CoreException e) {
1105            JDIDebugUIPlugin.log(e);
1106            return null;
1107        }
1108    }
1109
1110    /**
1111     * @see IDebugModelPresentation#getEditorId(IEditorInput, Object)
1112     */

1113    public String JavaDoc getEditorId(IEditorInput input, Object JavaDoc inputObject) {
1114        try {
1115            IEditorDescriptor descriptor= IDE.getEditorDescriptor(input.getName());
1116            return descriptor.getId();
1117        } catch (PartInitException e) {
1118            return null;
1119        }
1120    }
1121
1122    /**
1123     * @see IDebugModelPresentation#setAttribute(String, Object)
1124     */

1125    public void setAttribute(String JavaDoc id, Object JavaDoc value) {
1126        if (value == null) {
1127            return;
1128        }
1129        synchronized (fAttributes) {
1130            fAttributes.put(id, value);
1131        }
1132    }
1133
1134    protected boolean isShowQualifiedNames() {
1135        synchronized (fAttributes) {
1136            Boolean JavaDoc showQualified= (Boolean JavaDoc) fAttributes.get(DISPLAY_QUALIFIED_NAMES);
1137            showQualified= showQualified == null ? Boolean.FALSE : showQualified;
1138            return showQualified.booleanValue();
1139        }
1140    }
1141
1142    protected boolean isShowVariableTypeNames() {
1143        synchronized (fAttributes) {
1144            Boolean JavaDoc show= (Boolean JavaDoc) fAttributes.get(DISPLAY_VARIABLE_TYPE_NAMES);
1145            show= show == null ? Boolean.FALSE : show;
1146            return show.booleanValue();
1147        }
1148    }
1149
1150    protected boolean isShowHexValues() {
1151        return JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_SHOW_HEX);
1152    }
1153
1154    protected boolean isShowCharValues() {
1155        return JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_SHOW_CHAR);
1156    }
1157
1158    protected boolean isShowUnsignedValues() {
1159        return JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_SHOW_UNSIGNED);
1160    }
1161
1162    protected String JavaDoc getVariableText(IJavaVariable var) {
1163        String JavaDoc varLabel= DebugUIMessages.JDIModelPresentation_unknown_name__1;
1164        try {
1165            varLabel= var.getName();
1166        } catch (DebugException exception) {
1167        }
1168
1169        IJavaValue javaValue= null;
1170        try {
1171            javaValue = (IJavaValue) var.getValue();
1172        } catch (DebugException e1) {
1173        }
1174        boolean showTypes= isShowVariableTypeNames();
1175        StringBuffer JavaDoc buff= new StringBuffer JavaDoc();
1176        String JavaDoc typeName= DebugUIMessages.JDIModelPresentation_unknown_type__2;
1177        try {
1178            typeName= var.getReferenceTypeName();
1179            if (showTypes) {
1180                typeName= getQualifiedName(typeName);
1181            }
1182        } catch (DebugException exception) {
1183        }
1184        if (showTypes) {
1185            buff.append(typeName);
1186            buff.append(' ');
1187        }
1188        buff.append(varLabel);
1189
1190        // add declaring type name if required
1191
if (var instanceof IJavaFieldVariable) {
1192            IJavaFieldVariable field = (IJavaFieldVariable)var;
1193            if (isDuplicateName(field)) {
1194                try {
1195                    String JavaDoc decl = field.getDeclaringType().getName();
1196                    buff.append(MessageFormat.format(" ({0})", new String JavaDoc[]{getQualifiedName(decl)})); //$NON-NLS-1$
1197
} catch (DebugException e) {
1198                }
1199            }
1200        }
1201        
1202        String JavaDoc valueString= getFormattedValueText(javaValue);
1203        
1204        //do not put the equal sign for array partitions
1205
if (valueString.length() != 0) {
1206            buff.append("= "); //$NON-NLS-1$
1207
buff.append(valueString);
1208        }
1209        return buff.toString();
1210    }
1211    
1212    /**
1213     * Returns text for the given value based on user preferences to display
1214     * toString() details.
1215     *
1216     * @param javaValue
1217     * @return text
1218     */

1219    public String JavaDoc getFormattedValueText(IJavaValue javaValue) {
1220        String JavaDoc valueString= DebugUIMessages.JDIModelPresentation_unknown_value__3;
1221        if (javaValue != null) {
1222            if (isShowLabelDetails(javaValue)) {
1223                valueString = getVariableDetail(javaValue);
1224                if (valueString == null) {
1225                    valueString = DebugUIMessages.JDIModelPresentation_unknown_value__3;
1226                }
1227            } else {
1228                try {
1229                    valueString= getValueText(javaValue);
1230                } catch (DebugException exception) {
1231                }
1232            }
1233        }
1234        return valueString;
1235    }
1236    
1237    /**
1238     * Returns whether or not details should be shown in the
1239     * label of the given variable.
1240     * @param variable the variable
1241     * @return whether or not details should be shown in the label
1242     * of the given variable
1243     */

1244    public boolean isShowLabelDetails(IJavaValue value) {
1245        boolean showDetails= false;
1246        String JavaDoc details= JDIDebugUIPlugin.getDefault().getPreferenceStore().getString(IJDIPreferencesConstants.PREF_SHOW_DETAILS);
1247        if (details != null) {
1248            if (details.equals(IJDIPreferencesConstants.INLINE_ALL)) {
1249                showDetails= true;
1250            } else if (details.equals(IJDIPreferencesConstants.INLINE_FORMATTERS)){
1251                try {
1252                    IJavaType javaType = value.getJavaType();
1253                    JavaDetailFormattersManager manager= JavaDetailFormattersManager.getDefault();
1254                    DetailFormatter formatter = manager.getAssociatedDetailFormatter(javaType);
1255                    showDetails= formatter != null && formatter.isEnabled();
1256                } catch (DebugException e) {
1257                }
1258            }
1259        }
1260        return showDetails;
1261    }
1262    
1263    /**
1264     * Returns the detail value for the given variable or <code>null</code>
1265     * if none can be computed.
1266     * @param variable the variable to compute the detail for
1267     * @return the detail value for the variable
1268     */

1269    private String JavaDoc getVariableDetail(IJavaValue value) {
1270        final String JavaDoc[] detail= new String JavaDoc[1];
1271        final Object JavaDoc lock= new Object JavaDoc();
1272        computeDetail(value, new IValueDetailListener() {
1273            /* (non-Javadoc)
1274             * @see org.eclipse.debug.ui.IValueDetailListener#detailComputed(org.eclipse.debug.core.model.IValue, java.lang.String)
1275             */

1276            public void detailComputed(IValue computedValue, String JavaDoc result) {
1277                synchronized (lock) {
1278                    detail[0]= result;
1279                    lock.notifyAll();
1280                }
1281            }
1282        });
1283        synchronized (lock) {
1284            if (detail[0] == null) {
1285                try {
1286                    lock.wait(5000);
1287                } catch (InterruptedException JavaDoc e1) {
1288                    // Fall through
1289
}
1290            }
1291        }
1292        return detail[0];
1293    }
1294
1295    protected String JavaDoc getExpressionText(IExpression expression) throws DebugException {
1296        boolean showTypes= isShowVariableTypeNames();
1297        StringBuffer JavaDoc buff= new StringBuffer JavaDoc();
1298        IJavaValue javaValue= (IJavaValue) expression.getValue();
1299        if (javaValue != null) {
1300            String JavaDoc typeName=null;
1301            try {
1302                typeName= javaValue.getReferenceTypeName();
1303            } catch (DebugException exception) {
1304                // ObjectCollectedException is an expected exception which will
1305
// occur if the inspected object has been garbage collected.
1306
if (exception.getStatus().getException() instanceof ObjectCollectedException) {
1307                    return DebugUIMessages.JDIModelPresentation__garbage_collected_object__6;
1308                }
1309                throw exception;
1310            }
1311            if (showTypes ) {
1312                typeName= getQualifiedName(typeName);
1313                if (typeName.length() > 0) {
1314                    buff.append(typeName);
1315                    buff.append(' ');
1316                }
1317            }
1318        }
1319        buff.append('"' + expression.getExpressionText() + '"');
1320
1321        if (javaValue != null) {
1322            String JavaDoc valueString= getValueText(javaValue);
1323            if (valueString.length() > 0) {
1324                buff.append("= "); //$NON-NLS-1$
1325
buff.append(valueString);
1326            }
1327        }
1328        return buff.toString();
1329    }
1330    
1331    protected String JavaDoc getWatchExpressionText(IWatchExpression expression) throws DebugException {
1332        return getExpressionText(expression) + (expression.isEnabled() ? "" : DebugUIMessages.JDIModelPresentation_116); //$NON-NLS-1$
1333
}
1334
1335    /**
1336     * Given the reference type name of an array type, insert the array length
1337     * in between the '[]' for the first dimension and return the result.
1338     */

1339    protected String JavaDoc adjustTypeNameForArrayIndex(String JavaDoc typeName, int arrayIndex) {
1340        int firstBracket= typeName.indexOf("[]"); //$NON-NLS-1$
1341
if (firstBracket < 0) {
1342            return typeName;
1343        }
1344        StringBuffer JavaDoc buffer= new StringBuffer JavaDoc(typeName);
1345        buffer.insert(firstBracket + 1, Integer.toString(arrayIndex));
1346        return buffer.toString();
1347    }
1348    
1349    protected String JavaDoc getValueUnsignedText(IJavaValue value) throws DebugException {
1350        String JavaDoc sig= getPrimitiveValueTypeSignature(value);
1351        if (sig == null) {
1352            return null;
1353        }
1354
1355        switch (sig.charAt(0)) {
1356            case 'B' : // byte
1357
int byteVal;
1358                try {
1359                    byteVal= Integer.parseInt(value.getValueString());
1360                } catch (NumberFormatException JavaDoc e) {
1361                    return null;
1362                }
1363                if (byteVal < 0) {
1364                    byteVal = byteVal & 0xFF;
1365                    return Integer.toString(byteVal);
1366                }
1367            default :
1368                return null;
1369        }
1370    }
1371
1372    protected String JavaDoc getValueHexText(IJavaValue value) throws DebugException {
1373        String JavaDoc sig= getPrimitiveValueTypeSignature(value);
1374        if (sig == null) {
1375            return null;
1376        }
1377
1378        StringBuffer JavaDoc buff= new StringBuffer JavaDoc();
1379        long longValue;
1380        char sigValue = sig.charAt(0);
1381        try {
1382            if (sigValue == 'C') {
1383                longValue = value.getValueString().charAt(0);
1384            } else {
1385                longValue= Long.parseLong(value.getValueString());
1386            }
1387        } catch (NumberFormatException JavaDoc e) {
1388            return null;
1389        }
1390        switch (sigValue) {
1391            case 'B' :
1392                buff.append("0x"); //$NON-NLS-1$
1393
// keep only the relevant bits for byte
1394
longValue &= 0xFF;
1395                buff.append(Long.toHexString(longValue));
1396                break;
1397            case 'I' :
1398                buff.append("0x"); //$NON-NLS-1$
1399
// keep only the relevant bits for integer
1400
longValue &= 0xFFFFFFFFl;
1401                buff.append(Long.toHexString(longValue));
1402                break;
1403            case 'S' :
1404                buff.append("0x"); //$NON-NLS-1$
1405
// keep only the relevant bits for short
1406
longValue = longValue & 0xFFFF;
1407                buff.append(Long.toHexString(longValue));
1408                break;
1409            case 'J' :
1410                buff.append("0x"); //$NON-NLS-1$
1411
buff.append(Long.toHexString(longValue));
1412                break;
1413            case 'C' :
1414                buff.append("\\u"); //$NON-NLS-1$
1415
String JavaDoc hexString= Long.toHexString(longValue);
1416                int length= hexString.length();
1417                while (length < 4) {
1418                    buff.append('0');
1419                    length++;
1420                }
1421                buff.append(hexString);
1422                break;
1423            default:
1424                return null;
1425        }
1426        return buff.toString();
1427    }
1428
1429    protected String JavaDoc getBreakpointText(IBreakpoint breakpoint) {
1430        try {
1431            if (breakpoint instanceof IJavaExceptionBreakpoint) {
1432                return getExceptionBreakpointText((IJavaExceptionBreakpoint)breakpoint);
1433            } else if (breakpoint instanceof IJavaWatchpoint) {
1434                return getWatchpointText((IJavaWatchpoint)breakpoint);
1435            } else if (breakpoint instanceof IJavaMethodBreakpoint) {
1436                return getMethodBreakpointText((IJavaMethodBreakpoint)breakpoint);
1437            } else if (breakpoint instanceof IJavaPatternBreakpoint) {
1438                return getJavaPatternBreakpointText((IJavaPatternBreakpoint)breakpoint);
1439            } else if (breakpoint instanceof IJavaTargetPatternBreakpoint) {
1440                return getJavaTargetPatternBreakpointText((IJavaTargetPatternBreakpoint)breakpoint);
1441            } else if (breakpoint instanceof IJavaStratumLineBreakpoint) {
1442                return getJavaStratumLineBreakpointText((IJavaStratumLineBreakpoint)breakpoint);
1443            } else if (breakpoint instanceof IJavaLineBreakpoint) {
1444                return getLineBreakpointText((IJavaLineBreakpoint)breakpoint);
1445            } else if (breakpoint instanceof IJavaClassPrepareBreakpoint) {
1446                return getClassPrepareBreakpointText((IJavaClassPrepareBreakpoint)breakpoint);
1447            }
1448            // Should never get here
1449
return ""; //$NON-NLS-1$
1450
} catch (CoreException e) {
1451            // if the breakpoint has been deleted, don't log exception
1452
IMarker marker = breakpoint.getMarker();
1453            if (marker == null || !marker.exists()) {
1454                return DebugUIMessages.JDIModelPresentation_6;
1455            }
1456            JDIDebugUIPlugin.log(e);
1457            return DebugUIMessages.JDIModelPresentation_4;
1458        }
1459    }
1460
1461    /**
1462     * @param breakpoint
1463     * @return
1464     */

1465    private String JavaDoc getJavaStratumLineBreakpointText(IJavaStratumLineBreakpoint breakpoint) throws CoreException {
1466        IMember member= BreakpointUtils.getMember(breakpoint);
1467        String JavaDoc sourceName = breakpoint.getSourceName();
1468        if (sourceName == null) {
1469            sourceName = ""; //$NON-NLS-1$
1470
IMarker marker = breakpoint.getMarker();
1471            if (marker != null) {
1472                IResource resource = marker.getResource();
1473                if (resource.getType() == IResource.FILE) {
1474                    sourceName = resource.getName();
1475                }
1476            }
1477        }
1478        StringBuffer JavaDoc label= new StringBuffer JavaDoc(sourceName);
1479        appendLineNumber(breakpoint, label);
1480        appendHitCount(breakpoint, label);
1481        appendSuspendPolicy(breakpoint,label);
1482        appendThreadFilter(breakpoint, label);
1483                    
1484        if (member != null) {
1485            label.append(" - "); //$NON-NLS-1$
1486
label.append(getJavaLabelProvider().getText(member));
1487        }
1488        
1489        return label.toString();
1490    }
1491
1492    protected String JavaDoc getExceptionBreakpointText(IJavaExceptionBreakpoint breakpoint) throws CoreException {
1493        StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
1494        String JavaDoc typeName = breakpoint.getTypeName();
1495        buffer.append(getQualifiedName(typeName));
1496        appendHitCount(breakpoint, buffer);
1497        appendSuspendPolicy(breakpoint, buffer);
1498        //TODO remove the cast once the API freeze has thawed
1499
if(((JavaExceptionBreakpoint)breakpoint).isSuspendOnSubclasses()) {
1500            buffer.append(DebugUIMessages.JDIModelPresentation_117);
1501        }
1502        appendThreadFilter(breakpoint, buffer);
1503        if (breakpoint.getExclusionFilters().length > 0 || breakpoint.getInclusionFilters().length > 0) {
1504            buffer.append(DebugUIMessages.JDIModelPresentation___scoped__1);
1505        }
1506        appendInstanceFilter(breakpoint, buffer);
1507        String JavaDoc state= null;
1508        boolean c= breakpoint.isCaught();
1509        boolean u= breakpoint.isUncaught();
1510        if (c && u) {
1511            state= DebugUIMessages.JDIModelPresentation_caught_and_uncaught_60;
1512        } else if (c) {
1513            state= DebugUIMessages.JDIModelPresentation_caught_61;
1514        } else if (u) {
1515            state= DebugUIMessages.JDIModelPresentation_uncaught_62;
1516        }
1517        String JavaDoc label= null;
1518        if (state == null) {
1519            label= buffer.toString();
1520        } else {
1521            String JavaDoc format= DebugUIMessages.JDIModelPresentation__1____0__63;
1522            label= MessageFormat.format(format, new Object JavaDoc[] {state, buffer});
1523        }
1524        return label;
1525    }
1526
1527    protected String JavaDoc getLineBreakpointText(IJavaLineBreakpoint breakpoint) throws CoreException {
1528
1529        String JavaDoc typeName= breakpoint.getTypeName();
1530        IMember member= BreakpointUtils.getMember(breakpoint);
1531        StringBuffer JavaDoc label= new StringBuffer JavaDoc();
1532        label.append(getQualifiedName(typeName));
1533        appendLineNumber(breakpoint, label);
1534        appendHitCount(breakpoint, label);
1535        appendSuspendPolicy(breakpoint,label);
1536        appendThreadFilter(breakpoint, label);
1537        appendConditional(breakpoint, label);
1538        appendInstanceFilter(breakpoint, label);
1539        
1540        if (member != null) {
1541            label.append(" - "); //$NON-NLS-1$
1542
label.append(getJavaLabelProvider().getText(member));
1543        }
1544        
1545        return label.toString();
1546    }
1547    
1548    protected String JavaDoc getClassPrepareBreakpointText(IJavaClassPrepareBreakpoint breakpoint) throws CoreException {
1549        String JavaDoc typeName= breakpoint.getTypeName();
1550        StringBuffer JavaDoc label = new StringBuffer JavaDoc();
1551        label.append(getQualifiedName(typeName));
1552        appendHitCount(breakpoint, label);
1553        appendSuspendPolicy(breakpoint, label);
1554        return label.toString();
1555    }
1556    
1557    protected StringBuffer JavaDoc appendLineNumber(IJavaLineBreakpoint breakpoint, StringBuffer JavaDoc label) throws CoreException {
1558        int lineNumber= breakpoint.getLineNumber();
1559        if (lineNumber > 0) {
1560            label.append(" ["); //$NON-NLS-1$
1561
label.append(DebugUIMessages.JDIModelPresentation_line__65);
1562            label.append(' ');
1563            label.append(lineNumber);
1564            label.append(']');
1565
1566        }
1567        return label;
1568    }
1569    
1570    protected StringBuffer JavaDoc appendHitCount(IJavaBreakpoint breakpoint, StringBuffer JavaDoc label) throws CoreException {
1571        int hitCount= breakpoint.getHitCount();
1572        if (hitCount > 0) {
1573            label.append(" ["); //$NON-NLS-1$
1574
label.append(DebugUIMessages.JDIModelPresentation_hit_count__67);
1575            label.append(' ');
1576            label.append(hitCount);
1577            label.append(']');
1578        }
1579        return label;
1580    }
1581    
1582    protected String JavaDoc getJavaPatternBreakpointText(IJavaPatternBreakpoint breakpoint) throws CoreException {
1583    
1584        IResource resource= breakpoint.getMarker().getResource();
1585        IMember member= BreakpointUtils.getMember(breakpoint);
1586        StringBuffer JavaDoc label= new StringBuffer JavaDoc(resource.getName());
1587        appendLineNumber(breakpoint, label);
1588        appendHitCount(breakpoint, label);
1589        appendSuspendPolicy(breakpoint,label);
1590        appendThreadFilter(breakpoint, label);
1591                    
1592        if (member != null) {
1593            label.append(" - "); //$NON-NLS-1$
1594
label.append(getJavaLabelProvider().getText(member));
1595        }
1596        
1597        return label.toString();
1598    }
1599
1600    protected String JavaDoc getJavaTargetPatternBreakpointText(IJavaTargetPatternBreakpoint breakpoint) throws CoreException {
1601        IMember member= BreakpointUtils.getMember(breakpoint);
1602        StringBuffer JavaDoc label= new StringBuffer JavaDoc(breakpoint.getSourceName());
1603        appendLineNumber(breakpoint, label);
1604        appendHitCount(breakpoint, label);
1605        appendSuspendPolicy(breakpoint,label);
1606        appendThreadFilter(breakpoint, label);
1607                    
1608        if (member != null) {
1609            label.append(" - "); //$NON-NLS-1$
1610
label.append(getJavaLabelProvider().getText(member));
1611        }
1612        
1613        return label.toString();
1614    }
1615        
1616    protected String JavaDoc getWatchpointText(IJavaWatchpoint watchpoint) throws CoreException {
1617        
1618        String JavaDoc typeName= watchpoint.getTypeName();
1619        IMember member= BreakpointUtils.getMember(watchpoint);
1620        StringBuffer JavaDoc label= new StringBuffer JavaDoc();
1621        label.append(getQualifiedName(typeName));
1622        appendHitCount(watchpoint, label);
1623        appendSuspendPolicy(watchpoint,label);
1624        appendThreadFilter(watchpoint, label);
1625        
1626
1627        boolean access= watchpoint.isAccess();
1628        boolean modification= watchpoint.isModification();
1629        if (access && modification) {
1630            label.append(DebugUIMessages.JDIModelPresentation_access_and_modification_70);
1631        } else if (access) {
1632            label.append(DebugUIMessages.JDIModelPresentation_access_71);
1633        } else if (modification) {
1634            label.append(DebugUIMessages.JDIModelPresentation_modification_72);
1635        }
1636        
1637        label.append(" - "); //$NON-NLS-1$
1638
if (member != null) {
1639            label.append(getJavaLabelProvider().getText(member));
1640        } else {
1641            label.append(watchpoint.getFieldName());
1642        }
1643
1644        return label.toString();
1645    }
1646
1647    protected String JavaDoc getMethodBreakpointText(IJavaMethodBreakpoint methodBreakpoint) throws CoreException {
1648        
1649        String JavaDoc typeName= methodBreakpoint.getTypeName();
1650        IMember member= BreakpointUtils.getMember(methodBreakpoint);
1651        StringBuffer JavaDoc label= new StringBuffer JavaDoc();
1652        label.append(getQualifiedName(typeName));
1653        appendHitCount(methodBreakpoint, label);
1654        appendSuspendPolicy(methodBreakpoint,label);
1655        appendThreadFilter(methodBreakpoint, label);
1656        
1657
1658        boolean entry = methodBreakpoint.isEntry();
1659        boolean exit = methodBreakpoint.isExit();
1660        if (entry && exit) {
1661            label.append(DebugUIMessages.JDIModelPresentation_entry_and_exit);
1662        } else if (entry) {
1663            label.append(DebugUIMessages.JDIModelPresentation_entry);
1664        } else if (exit) {
1665            label.append(DebugUIMessages.JDIModelPresentation_exit);
1666        }
1667        appendConditional(methodBreakpoint, label);
1668        
1669        if (member != null) {
1670            label.append(" - "); //$NON-NLS-1$
1671
label.append(getJavaLabelProvider().getText(member));
1672        } else {
1673            String JavaDoc methodSig= methodBreakpoint.getMethodSignature();
1674            String JavaDoc methodName= methodBreakpoint.getMethodName();
1675            if (methodSig != null) {
1676                label.append(" - "); //$NON-NLS-1$
1677
label.append(Signature.toString(methodSig, methodName, null, false, false));
1678            } else if (methodName != null) {
1679                label.append(" - "); //$NON-NLS-1$
1680
label.append(methodName);
1681            }
1682        }
1683
1684        return label.toString();
1685    }
1686
1687    protected String JavaDoc getStackFrameText(IStackFrame stackFrame) throws DebugException {
1688        IJavaStackFrame frame= (IJavaStackFrame) stackFrame.getAdapter(IJavaStackFrame.class);
1689        if (frame != null) {
1690            StringBuffer JavaDoc label= new StringBuffer JavaDoc();
1691            
1692            String JavaDoc dec= DebugUIMessages.JDIModelPresentation_unknown_declaring_type__4;
1693            try {
1694                dec= frame.getDeclaringTypeName();
1695            } catch (DebugException exception) {
1696            }
1697            if (frame.isObsolete()) {
1698                label.append(DebugUIMessages.JDIModelPresentation__obsolete_method_in__1);
1699                label.append(dec);
1700                label.append('>');
1701                return label.toString();
1702            }
1703            
1704            boolean javaStratum= true;
1705            try {
1706                javaStratum = frame.getReferenceType().getDefaultStratum().equals("Java"); //$NON-NLS-1$
1707
} catch (DebugException e) {
1708            }
1709            
1710            if (javaStratum) {
1711                // receiver name
1712
String JavaDoc rec= DebugUIMessages.JDIModelPresentation_unknown_receiving_type__5;
1713                try {
1714                    rec= frame.getReceivingTypeName();
1715                } catch (DebugException exception) {
1716                }
1717                label.append(getQualifiedName(rec));
1718
1719                // append declaring type name if different
1720
if (!dec.equals(rec)) {
1721                    label.append('(');
1722                    label.append(getQualifiedName(dec));
1723                    label.append(')');
1724                }
1725                // append a dot separator and method name
1726
label.append('.');
1727                try {
1728                    label.append(frame.getMethodName());
1729                } catch (DebugException exception) {
1730                    label.append(DebugUIMessages.JDIModelPresentation_unknown_method_name__6);
1731                }
1732                try {
1733                    List JavaDoc args= frame.getArgumentTypeNames();
1734                    if (args.isEmpty()) {
1735                        label.append("()"); //$NON-NLS-1$
1736
} else {
1737                        label.append('(');
1738                        Iterator JavaDoc iter= args.iterator();
1739                        while (iter.hasNext()) {
1740                            label.append(getQualifiedName((String JavaDoc) iter.next()));
1741                            if (iter.hasNext()) {
1742                                label.append(", "); //$NON-NLS-1$
1743
} else if (frame.isVarArgs()) {
1744                                label.replace(label.length() - 2, label.length(), "..."); //$NON-NLS-1$
1745
}
1746                        }
1747                        label.append(')');
1748                    }
1749                } catch (DebugException exception) {
1750                    label.append(DebugUIMessages.JDIModelPresentation__unknown_arguements___7);
1751                }
1752            } else {
1753                if (isShowQualifiedNames()) {
1754                    label.append(frame.getSourcePath());
1755                } else {
1756                    label.append(frame.getSourceName());
1757                }
1758            }
1759
1760            try {
1761                int lineNumber= frame.getLineNumber();
1762                label.append(' ');
1763                label.append(DebugUIMessages.JDIModelPresentation_line__76);
1764                label.append(' ');
1765                if (lineNumber >= 0) {
1766                    label.append(lineNumber);
1767                } else {
1768                    label.append(DebugUIMessages.JDIModelPresentation_not_available);
1769                    if (frame.isNative()) {
1770                        label.append(' ');
1771                        label.append(DebugUIMessages.JDIModelPresentation_native_method);
1772                    }
1773                }
1774            } catch (DebugException exception) {
1775                label.append(DebugUIMessages.JDIModelPresentation__unknown_line_number__8);
1776            }
1777            
1778            if (!frame.wereLocalsAvailable()) {
1779                label.append(' ');
1780                label.append(DebugUIMessages.JDIModelPresentation_local_variables_unavailable);
1781            }
1782            
1783            return label.toString();
1784
1785        }
1786        return null;
1787    }
1788    
1789    protected String JavaDoc getQualifiedName(String JavaDoc qualifiedName) {
1790        if (!isShowQualifiedNames()) {
1791            return removeQualifierFromGenericName(qualifiedName);
1792        }
1793        return qualifiedName;
1794    }
1795    
1796    /**
1797     * Return the simple generic name from a qualified generic name
1798     */

1799    public String JavaDoc removeQualifierFromGenericName(String JavaDoc qualifiedName) {
1800        if (qualifiedName.endsWith("...")) { //$NON-NLS-1$
1801
// handle variable argument name
1802
return removeQualifierFromGenericName(qualifiedName.substring(0, qualifiedName.length() - 3)) + "..."; //$NON-NLS-1$
1803
}
1804        if (qualifiedName.endsWith("[]")) { //$NON-NLS-1$
1805
// handle array type
1806
return removeQualifierFromGenericName(qualifiedName.substring(0, qualifiedName.length() - 2)) + "[]"; //$NON-NLS-1$
1807
}
1808        // check if the type has parameters
1809
int parameterStart= qualifiedName.indexOf('<');
1810        if (parameterStart == -1) {
1811            return getSimpleName(qualifiedName);
1812        }
1813        // get the list of the parameters and generates their simple name
1814
List JavaDoc parameters= getNameList(qualifiedName.substring(parameterStart + 1, qualifiedName.length() - 1));
1815        StringBuffer JavaDoc name= new StringBuffer JavaDoc(getSimpleName(qualifiedName.substring(0, parameterStart)));
1816        name.append('<');
1817        Iterator JavaDoc iterator= parameters.iterator();
1818        if (iterator.hasNext()) {
1819            name.append(removeQualifierFromGenericName((String JavaDoc)iterator.next()));
1820            while (iterator.hasNext()) {
1821                name.append(',').append(removeQualifierFromGenericName((String JavaDoc)iterator.next()));
1822            }
1823        }
1824        name.append('>');
1825        return name.toString();
1826    }
1827    
1828    /**
1829     * Return the simple name from a qualified name (non-generic)
1830     */

1831    private String JavaDoc getSimpleName(String JavaDoc qualifiedName) {
1832        int index = qualifiedName.lastIndexOf('.');
1833        if (index >= 0) {
1834            return qualifiedName.substring(index + 1);
1835        }
1836        return qualifiedName;
1837    }
1838
1839    /**
1840     * Decompose a comma separated list of generic names (String) to a list of generic names (List)
1841     */

1842    private List JavaDoc getNameList(String JavaDoc listName) {
1843        List JavaDoc names= new ArrayList JavaDoc();
1844        StringTokenizer JavaDoc tokenizer= new StringTokenizer JavaDoc(listName, ",<>", true); //$NON-NLS-1$
1845
int enclosingLevel= 0;
1846        int startPos= 0;
1847        int currentPos= 0;
1848        while (tokenizer.hasMoreTokens()) {
1849            String JavaDoc token= tokenizer.nextToken();
1850            switch (token.charAt(0)) {
1851                case ',':
1852                    if (enclosingLevel == 0) {
1853                        names.add(listName.substring(startPos, currentPos));
1854                        startPos= currentPos + 1;
1855                    }
1856                    break;
1857                case '<':
1858                    enclosingLevel++;
1859                    break;
1860                case '>':
1861                    enclosingLevel--;
1862                    break;
1863            }
1864            currentPos += token.length();
1865        }
1866        names.add(listName.substring(startPos));
1867        return names;
1868    }
1869
1870    /**
1871     * Plug in the single argument to the resource String for the key to get a formatted resource String
1872     */

1873    public static String JavaDoc getFormattedString(String JavaDoc key, String JavaDoc arg) {
1874        return getFormattedString(key, new String JavaDoc[] {arg});
1875    }
1876
1877    /**
1878     * Plug in the arguments to the resource String for the key to get a formatted resource String
1879     */

1880    public static String JavaDoc getFormattedString(String JavaDoc string, String JavaDoc[] args) {
1881        return MessageFormat.format(string, args);
1882    }
1883    
1884    interface IValueDetailProvider {
1885        public void computeDetail(IValue value, IJavaThread thread, IValueDetailListener listener) throws DebugException;
1886    }
1887    
1888    protected void appendSuspendPolicy(IJavaBreakpoint breakpoint, StringBuffer JavaDoc buffer) throws CoreException {
1889        if (breakpoint.getSuspendPolicy() == IJavaBreakpoint.SUSPEND_VM) {
1890            buffer.append(' ');
1891            buffer.append(DebugUIMessages.JDIModelPresentation_Suspend_VM);
1892        }
1893    }
1894    
1895    protected void appendThreadFilter(IJavaBreakpoint breakpoint, StringBuffer JavaDoc buffer) throws CoreException {
1896        if (breakpoint.getThreadFilters().length != 0) {
1897            buffer.append(' ');
1898            buffer.append(DebugUIMessages.JDIModelPresentation_thread_filtered);
1899        }
1900    }
1901    
1902    protected void appendConditional(IJavaLineBreakpoint breakpoint, StringBuffer JavaDoc buffer) throws CoreException {
1903        if (breakpoint.isConditionEnabled() && breakpoint.getCondition() != null) {
1904            buffer.append(' ');
1905            buffer.append(DebugUIMessages.JDIModelPresentation__conditional__2);
1906        }
1907    }
1908    
1909    protected void appendInstanceFilter(IJavaBreakpoint breakpoint, StringBuffer JavaDoc buffer) throws CoreException {
1910        IJavaObject[] instances = breakpoint.getInstanceFilters();
1911        for (int i = 0; i < instances.length; i++) {
1912            String JavaDoc instanceText= instances[i].getValueString();
1913            if (instanceText != null) {
1914                buffer.append(' ');
1915                buffer.append(MessageFormat.format(DebugUIMessages.JDIModelPresentation_instance_1, new String JavaDoc[] {instanceText}));
1916            }
1917        }
1918    }
1919    
1920    protected static ImageDescriptorRegistry getJavaElementImageRegistry() {
1921        if (fgJavaElementImageRegistry == null) {
1922            fgJavaElementImageRegistry = JavaPlugin.getImageDescriptorRegistry();
1923        }
1924        return fgJavaElementImageRegistry;
1925    }
1926
1927    protected static org.eclipse.jdt.internal.debug.ui.ImageDescriptorRegistry getDebugImageRegistry() {
1928        if (fgDebugImageRegistry == null) {
1929            fgDebugImageRegistry = JDIDebugUIPlugin.getImageDescriptorRegistry();
1930        }
1931        return fgDebugImageRegistry;
1932    }
1933
1934    protected JavaElementLabelProvider getJavaLabelProvider() {
1935        if (fJavaLabelProvider == null) {
1936            fJavaLabelProvider = new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT);
1937        }
1938        return fJavaLabelProvider;
1939    }
1940    
1941    /**
1942     * Returns whether the given field variable has the same name as any variables
1943     */

1944    protected boolean isDuplicateName(IJavaFieldVariable variable) {
1945        IJavaReferenceType javaType= variable.getReceivingType();
1946        try {
1947            String JavaDoc[] names = javaType.getAllFieldNames();
1948            boolean found= false;
1949            for (int i = 0; i < names.length; i++) {
1950                if (variable.getName().equals(names[i])) {
1951                    if (found) {
1952                        return true;
1953                    }
1954                    found= true;
1955                }
1956            }
1957            return false;
1958        } catch (DebugException e) {
1959        }
1960        return false;
1961    }
1962
1963    /* (non-Javadoc)
1964     * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
1965     */

1966    public Color getForeground(Object JavaDoc element) {
1967        if (element instanceof JavaContendedMonitor && ((JavaContendedMonitor)element).getMonitor().isInDeadlock()) {
1968            return PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry().get(IJDIPreferencesConstants.PREF_THREAD_MONITOR_IN_DEADLOCK_COLOR);
1969        }
1970        if (element instanceof JavaOwnedMonitor && ((JavaOwnedMonitor)element).getMonitor().isInDeadlock()) {
1971            return PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry().get(IJDIPreferencesConstants.PREF_THREAD_MONITOR_IN_DEADLOCK_COLOR);
1972        }
1973        if (element instanceof JavaWaitingThread && ((JavaWaitingThread)element).getThread().isInDeadlock()) {
1974            return PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry().get(IJDIPreferencesConstants.PREF_THREAD_MONITOR_IN_DEADLOCK_COLOR);
1975        }
1976        if (element instanceof JavaOwningThread && ((JavaOwningThread)element).getThread().isInDeadlock()) {
1977            return PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry().get(IJDIPreferencesConstants.PREF_THREAD_MONITOR_IN_DEADLOCK_COLOR);
1978        }
1979        if (element instanceof IJavaThread && ThreadMonitorManager.getDefault().isInDeadlock((IJavaThread)element)) {
1980            return PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry().get(IJDIPreferencesConstants.PREF_THREAD_MONITOR_IN_DEADLOCK_COLOR);
1981        }
1982        return null;
1983    }
1984
1985    /* (non-Javadoc)
1986     * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
1987     */

1988    public Color getBackground(Object JavaDoc element) {
1989        return null;
1990    }
1991    
1992    private ImageDescriptor getImageDescriptor(String JavaDoc key) {
1993        return JavaDebugImages.getImageDescriptor(key);
1994    }
1995}
1996
Popular Tags