1 11 package org.eclipse.jdt.internal.debug.ui.display; 12 13 14 import com.ibm.icu.text.MessageFormat; 15 16 import org.eclipse.core.runtime.PlatformObject; 17 import org.eclipse.debug.core.DebugEvent; 18 import org.eclipse.debug.core.DebugException; 19 import org.eclipse.debug.core.DebugPlugin; 20 import org.eclipse.debug.core.IDebugEventSetListener; 21 import org.eclipse.debug.core.ILaunch; 22 import org.eclipse.debug.core.model.IDebugElement; 23 import org.eclipse.debug.core.model.IDebugTarget; 24 import org.eclipse.debug.core.model.IErrorReportingExpression; 25 import org.eclipse.debug.core.model.IValue; 26 import org.eclipse.jdt.debug.core.IJavaValue; 27 import org.eclipse.jdt.debug.eval.IEvaluationResult; 28 29 import com.sun.jdi.InvocationException; 30 31 37 public class JavaInspectExpression extends PlatformObject implements IErrorReportingExpression, IDebugEventSetListener { 38 39 42 private IJavaValue fValue; 43 44 47 private String fExpression; 48 49 private IEvaluationResult fResult; 50 51 61 public JavaInspectExpression(String expression, IJavaValue value) { 62 fValue = value; 63 fExpression = expression; 64 DebugPlugin.getDefault().addDebugEventListener(this); 65 } 66 67 74 public JavaInspectExpression(IEvaluationResult result) { 75 this(result.getSnippet(), result.getValue()); 76 fResult= result; 77 } 78 79 82 public String getExpressionText() { 83 return fExpression; 84 } 85 86 89 public IValue getValue() { 90 return fValue; 91 } 92 93 96 public IDebugTarget getDebugTarget() { 97 IValue value= getValue(); 98 if (value != null) { 99 return getValue().getDebugTarget(); 100 } 101 if (fResult != null) { 102 return fResult.getThread().getDebugTarget(); 103 } 104 return null; 107 } 108 109 112 public String getModelIdentifier() { 113 return getDebugTarget().getModelIdentifier(); 114 } 115 116 119 public ILaunch getLaunch() { 120 return getDebugTarget().getLaunch(); 121 } 122 123 126 public void handleDebugEvents(DebugEvent[] events) { 127 for (int i = 0; i < events.length; i++) { 128 DebugEvent event = events[i]; 129 switch (event.getKind()) { 130 case DebugEvent.TERMINATE: 131 if (event.getSource().equals(getDebugTarget())) { 132 DebugPlugin.getDefault().getExpressionManager().removeExpression(this); 133 } 134 break; 135 case DebugEvent.SUSPEND: 136 if (event.getDetail() != DebugEvent.EVALUATION_IMPLICIT) { 137 if (event.getSource() instanceof IDebugElement) { 138 IDebugElement source = (IDebugElement) event.getSource(); 139 if (source.getDebugTarget().equals(getDebugTarget())) { 140 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[]{new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT)}); 141 } 142 } 143 } 144 break; 145 } 146 } 147 } 148 149 152 public void dispose() { 153 DebugPlugin.getDefault().removeDebugEventListener(this); 154 } 155 156 159 public boolean hasErrors() { 160 return fResult != null && fResult.hasErrors(); 161 } 162 163 166 public String [] getErrorMessages() { 167 return getErrorMessages(fResult); 168 } 169 170 public static String [] getErrorMessages(IEvaluationResult result) { 171 if (result == null) { 172 return new String [0]; 173 } 174 String messages[]= result.getErrorMessages(); 175 if (messages.length > 0) { 176 return messages; 177 } 178 DebugException exception= result.getException(); 179 if (exception != null ) { 180 Throwable cause= exception.getStatus().getException(); 181 if (cause instanceof InvocationException) { 182 String nestedMessage= ((InvocationException) cause).exception().referenceType().name(); 183 return new String [] { MessageFormat.format(DisplayMessages.JavaInspectExpression_0, new String [] {nestedMessage}) }; 184 } 185 return new String [] { exception.getMessage() }; 186 } 187 return new String [0]; 188 } 189 } 190 | Popular Tags |