KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > monitors > DeferredJavaThread


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.monitors;
12
13 import org.eclipse.debug.core.DebugException;
14 import org.eclipse.debug.core.model.IDebugElement;
15 import org.eclipse.debug.core.model.IStackFrame;
16 import org.eclipse.jdt.debug.core.IJavaDebugTarget;
17 import org.eclipse.jdt.debug.core.IJavaThread;
18 import org.eclipse.jdt.debug.ui.JavaDebugUtils;
19
20 /**
21  * Generates monitor information as well as stack frames
22  */

23 public class DeferredJavaThread extends DeferredMonitorElement {
24
25     /* (non-Javadoc)
26      * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object)
27      */

28     public Object JavaDoc[] getChildren(Object JavaDoc parent) {
29         IJavaThread thread = (IJavaThread) parent;
30         if (!thread.isSuspended()) {
31             return EMPTY;
32         }
33         try {
34             IStackFrame[] frames = thread.getStackFrames();
35             if (!isDisplayMonitors()) {
36                 return frames;
37             }
38
39             Object JavaDoc[] children;
40             int length = frames.length;
41             if (((IJavaDebugTarget) thread.getDebugTarget()).supportsMonitorInformation()) {
42                 IDebugElement[] ownedMonitors = JavaDebugUtils.getOwnedMonitors(thread);
43                 IDebugElement contendedMonitor = JavaDebugUtils.getContendedMonitor(thread);
44                 
45                 if (ownedMonitors != null) {
46                     length+=ownedMonitors.length;
47                 }
48                 if (contendedMonitor != null) {
49                     length++;
50                 }
51                 children = new Object JavaDoc[length];
52                 if (ownedMonitors != null && ownedMonitors.length > 0) {
53                     System.arraycopy(ownedMonitors, 0, children, 0, ownedMonitors.length);
54                 }
55                 if (contendedMonitor != null) {
56                     // Insert the contended monitor after the owned monitors
57
children[ownedMonitors.length] = contendedMonitor;
58                 }
59             } else {
60                 children= new Object JavaDoc[length + 1];
61                 children[0]= new NoMonitorInformationElement(thread.getDebugTarget());
62             }
63             int offset= children.length - frames.length;
64             System.arraycopy(frames, 0, children, offset, frames.length);
65             return children;
66         } catch (DebugException e) {
67             return EMPTY;
68         }
69     }
70     
71     /* (non-Javadoc)
72      * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object)
73      */

74     public Object JavaDoc getParent(Object JavaDoc element) {
75         return ((IJavaThread)element).getDebugTarget();
76     }
77     
78     
79 }
80
Popular Tags