KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.core.runtime.CoreException;
14 import org.eclipse.debug.core.DebugException;
15 import org.eclipse.debug.core.model.IDebugElement;
16 import org.eclipse.debug.core.model.IStackFrame;
17 import org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext;
18 import org.eclipse.jdt.debug.core.IJavaDebugTarget;
19 import org.eclipse.jdt.debug.core.IJavaThread;
20 import org.eclipse.jdt.debug.ui.JavaDebugUtils;
21
22 /**
23  * Generates monitor information as well as stack frames
24  */

25 public class AsyncJavaThreadAdapter extends AsyncMonitorAdapter {
26
27     protected Object JavaDoc[] getChildren(Object JavaDoc parent, IPresentationContext context) throws CoreException {
28         IJavaThread thread = (IJavaThread) parent;
29         if (!thread.isSuspended()) {
30             return EMPTY;
31         }
32         try {
33             IStackFrame[] frames = thread.getStackFrames();
34             if (!isDisplayMonitors()) {
35                 return frames;
36             }
37
38             Object JavaDoc[] children;
39             int length = frames.length;
40             if (((IJavaDebugTarget) thread.getDebugTarget()).supportsMonitorInformation()) {
41                 IDebugElement[] ownedMonitors = JavaDebugUtils.getOwnedMonitors(thread);
42                 IDebugElement contendedMonitor = JavaDebugUtils.getContendedMonitor(thread);
43
44                 if (ownedMonitors != null) {
45                     length += ownedMonitors.length;
46                 }
47                 if (contendedMonitor != null) {
48                     length++;
49                 }
50                 children = new Object JavaDoc[length];
51                 if (ownedMonitors != null && ownedMonitors.length > 0) {
52                     System.arraycopy(ownedMonitors, 0, children, 0, ownedMonitors.length);
53                 }
54                 if (contendedMonitor != null) {
55                     // Insert the contended monitor after the owned monitors
56
children[ownedMonitors.length] = contendedMonitor;
57                 }
58             } else {
59                 children = new Object JavaDoc[length + 1];
60                 children[0] = new NoMonitorInformationElement(thread.getDebugTarget());
61             }
62             int offset = children.length - frames.length;
63             System.arraycopy(frames, 0, children, offset, frames.length);
64             return children;
65         } catch (DebugException e) {
66             return EMPTY;
67         }
68     }
69
70     protected boolean hasChildren(Object JavaDoc element, IPresentationContext context) throws CoreException {
71         IJavaThread thread = (IJavaThread) element;
72         return thread.hasStackFrames();
73     }
74
75 }
76
Popular Tags