1 11 package org.eclipse.jdt.internal.debug.core.logicalstructures; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IStatus; 15 import org.eclipse.core.runtime.Status; 16 import org.eclipse.debug.core.DebugEvent; 17 import org.eclipse.debug.core.DebugException; 18 import org.eclipse.debug.core.DebugPlugin; 19 import org.eclipse.debug.core.IStatusHandler; 20 import org.eclipse.debug.core.model.IDebugTarget; 21 import org.eclipse.debug.core.model.ILogicalStructureTypeDelegate; 22 import org.eclipse.debug.core.model.IThread; 23 import org.eclipse.debug.core.model.IValue; 24 import org.eclipse.jdt.debug.core.IEvaluationRunnable; 25 import org.eclipse.jdt.debug.core.IJavaClassType; 26 import org.eclipse.jdt.debug.core.IJavaDebugTarget; 27 import org.eclipse.jdt.debug.core.IJavaInterfaceType; 28 import org.eclipse.jdt.debug.core.IJavaObject; 29 import org.eclipse.jdt.debug.core.IJavaThread; 30 import org.eclipse.jdt.debug.core.IJavaType; 31 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; 32 33 36 public abstract class LogicalObjectStructureInterfaceType implements ILogicalStructureTypeDelegate { 37 38 private IJavaObject fObject; 40 private IValue fResult; 42 private boolean fDone = false; 44 private static IStatus fgNeedThread = new Status(IStatus.INFO, JDIDebugPlugin.getUniqueIdentifier(), LogicalObjectStructureInterfaceType.INFO_EVALUATION_THREAD, "Provides thread context for an evaluation", null); private static IStatusHandler fgThreadProvider; 46 47 54 public static final int INFO_EVALUATION_THREAD = 110; 55 56 59 public boolean providesLogicalStructure(IValue value) { 60 if (value instanceof IJavaObject) { 61 IJavaObject object = (IJavaObject) value; 62 try { 63 IJavaType type = object.getJavaType(); 64 if (type instanceof IJavaClassType) { 65 IJavaClassType classType = (IJavaClassType) type; 66 IJavaInterfaceType[] interfaceTypes = classType.getAllInterfaces(); 67 String targetInterface = getTargetInterfaceName(); 68 for (int i = 0; i < interfaceTypes.length; i++) { 69 IJavaInterfaceType inter = interfaceTypes[i]; 70 if (inter.getName().equals(targetInterface)) { 71 return true; 72 } 73 } 74 } 75 } catch (DebugException e) { 76 } 77 } 78 return false; 79 } 80 81 88 protected abstract String getTargetInterfaceName(); 89 90 97 protected abstract IEvaluationRunnable getEvaluation(); 98 99 102 public synchronized IValue getLogicalStructure(IValue value) throws CoreException { 103 final IJavaThread thread = getThread(value); 104 if (thread == null) { 105 throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), JDIDebugPlugin.INTERNAL_ERROR, LogicalStructuresMessages.LogicalObjectStructureType_1, null)); 107 } 108 setObject((IJavaObject)value); 109 final IEvaluationRunnable evaluation = getEvaluation(); 110 final CoreException[] ex = new CoreException[1]; 111 final Object lock = this; 112 fDone = false; 113 if (thread.isPerformingEvaluation() && thread.isSuspended()) { 114 return value; 115 } 116 thread.queueRunnable(new Runnable () { 117 public void run() { 118 try { 119 thread.runEvaluation(evaluation, null, DebugEvent.EVALUATION_IMPLICIT, false); 120 } catch (DebugException e) { 121 ex[0] = e; 122 } 123 synchronized (lock) { 124 fDone = true; 125 lock.notifyAll(); 126 } 127 } 128 }); 129 try { 130 synchronized (lock) { 131 if (!fDone) { 132 lock.wait(); 133 } 134 } 135 } catch (InterruptedException e) { 136 } 137 if (ex[0] != null) { 138 throw ex[0]; 139 } 140 return fResult; 141 } 142 143 private IJavaThread getThread(IValue value) throws CoreException { 144 IStatusHandler handler = getThreadProvider(); 145 if (handler != null) { 146 IJavaThread thread = (IJavaThread)handler.handleStatus(fgNeedThread, value); 147 if (thread != null) { 148 return thread; 149 } 150 } 151 IDebugTarget target = value.getDebugTarget(); 152 IJavaDebugTarget javaTarget = (IJavaDebugTarget) target.getAdapter(IJavaDebugTarget.class); 153 if (javaTarget != null) { 154 IThread[] threads = javaTarget.getThreads(); 155 for (int i = 0; i < threads.length; i++) { 156 IThread thread = threads[i]; 157 if (thread.isSuspended()) { 158 return (IJavaThread)thread; 159 } 160 } 161 } 162 return null; 163 } 164 165 private static IStatusHandler getThreadProvider() { 166 if (fgThreadProvider == null) { 167 fgThreadProvider = DebugPlugin.getDefault().getStatusHandler(fgNeedThread); 168 } 169 return fgThreadProvider; 170 } 171 172 177 private void setObject(IJavaObject object) { 178 fObject = object; 179 } 180 181 186 protected IJavaObject getObject() { 187 return fObject; 188 } 189 190 195 protected void setLogicalStructure(IValue result) { 196 fResult = result; 197 } 198 199 } 200 | Popular Tags |