1 11 package org.eclipse.jdt.internal.debug.eval; 12 13 14 import java.io.File ; 15 import java.io.FileOutputStream ; 16 import java.io.IOException ; 17 import com.ibm.icu.text.MessageFormat; 18 import java.util.ArrayList ; 19 import java.util.Arrays ; 20 import java.util.Collections ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 import org.eclipse.core.resources.IMarker; 25 import org.eclipse.core.runtime.CoreException; 26 import org.eclipse.core.runtime.IProgressMonitor; 27 import org.eclipse.core.runtime.IStatus; 28 import org.eclipse.core.runtime.Status; 29 import org.eclipse.debug.core.DebugEvent; 30 import org.eclipse.debug.core.DebugException; 31 import org.eclipse.debug.core.model.IVariable; 32 import org.eclipse.jdt.core.IJavaProject; 33 import org.eclipse.jdt.core.IType; 34 import org.eclipse.jdt.core.JavaModelException; 35 import org.eclipse.jdt.core.eval.ICodeSnippetRequestor; 36 import org.eclipse.jdt.core.eval.IEvaluationContext; 37 import org.eclipse.jdt.debug.core.IEvaluationRunnable; 38 import org.eclipse.jdt.debug.core.IJavaClassObject; 39 import org.eclipse.jdt.debug.core.IJavaClassType; 40 import org.eclipse.jdt.debug.core.IJavaDebugTarget; 41 import org.eclipse.jdt.debug.core.IJavaObject; 42 import org.eclipse.jdt.debug.core.IJavaStackFrame; 43 import org.eclipse.jdt.debug.core.IJavaThread; 44 import org.eclipse.jdt.debug.core.IJavaType; 45 import org.eclipse.jdt.debug.core.IJavaValue; 46 import org.eclipse.jdt.debug.core.IJavaVariable; 47 import org.eclipse.jdt.debug.core.JDIDebugModel; 48 import org.eclipse.jdt.debug.eval.IClassFileEvaluationEngine; 49 import org.eclipse.jdt.debug.eval.IEvaluationListener; 50 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; 51 import org.eclipse.jdt.internal.debug.core.JavaDebugUtils; 52 import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget; 53 import org.eclipse.jdt.internal.debug.core.model.JDIValue; 54 55 import com.sun.jdi.InvocationException; 56 import com.sun.jdi.ObjectReference; 57 58 61 62 public class LocalEvaluationEngine implements IClassFileEvaluationEngine, ICodeSnippetRequestor , IEvaluationRunnable { 63 64 private static final String CODE_SNIPPET_NAME= "CodeSnippet.class"; 66 72 private static int ENGINE_COUNT= 0; 73 74 77 private IJavaProject fJavaProject; 78 79 82 private IJavaDebugTarget fDebugTarget; 83 84 87 private File fOutputDirectory; 88 89 93 private IEvaluationListener fListener; 94 95 100 private IJavaStackFrame fStackFrame; 101 102 105 private EvaluationResult fResult; 106 107 110 private List fSnippetFiles; 111 112 116 private List fDirectories; 117 118 122 private IEvaluationContext fEvaluationContext; 123 124 131 private int[] fLocalVariableModifiers; 132 133 137 private String [] fLocalVariableNames; 138 139 143 private String [] fLocalVariableTypeNames; 144 145 150 private IJavaObject fThis; 151 152 155 private boolean fDisposed = false; 156 157 161 private int fEvaluationCount = 0; 162 163 166 private String fCodeSnippetClassName = null; 167 168 171 private boolean fHitBreakpoints = false; 172 173 176 private static final String [] EMPTY_STRING_ARRAY = new String [0]; 177 178 181 private static final int[] EMPTY_INT_ARRAY = new int[0]; 182 183 194 public LocalEvaluationEngine(IJavaProject project, IJavaDebugTarget vm, File directory) { 195 setJavaProject(project); 196 setDebugTarget(vm); 197 setOutputDirectory(directory); 198 ENGINE_COUNT++; 199 } 200 201 204 public boolean acceptClassFiles( 205 byte[][] classFileBytes, 206 String [][] classFileCompoundNames, 207 String codeSnippetClassName) { 208 try { 209 deploy(classFileBytes, classFileCompoundNames); 210 } catch (DebugException e) { 211 getResult().setException(e); 212 return false; 213 } 214 if (codeSnippetClassName != null) { 215 setCodeSnippetClassName(codeSnippetClassName); 216 try { 217 getThread().runEvaluation(this, null, DebugEvent.EVALUATION, getHitBreakpoints()); 218 } catch (DebugException e) { 219 } 221 } 222 return true; 223 } 224 225 public void run(IJavaThread thread, IProgressMonitor monitor) { 226 IJavaObject codeSnippetInstance = null; 227 try { 228 codeSnippetInstance = newInstance(getCodeSnippetClassName()); 229 initializeLocals(codeSnippetInstance); 230 codeSnippetInstance.sendMessage(RUN_METHOD, "()V", null, getThread(), false); restoreLocals(codeSnippetInstance); 232 233 IVariable[] fields = codeSnippetInstance.getVariables(); 235 IJavaVariable resultValue = null; 236 IJavaVariable resultType = null; 237 for (int i = 0; i < fields.length; i++) { 238 if (fields[i].getName().equals(RESULT_TYPE_FIELD)) { 239 resultType = (IJavaVariable)fields[i]; 240 } 241 if (fields[i].getName().equals(RESULT_VALUE_FIELD)) { 242 resultValue = (IJavaVariable)fields[i]; 243 } 244 } 245 IJavaValue result = convertResult((IJavaClassObject)resultType.getValue(), (IJavaValue)resultValue.getValue()); 246 getResult().setValue(result); 247 } catch (DebugException e) { 248 getResult().setException(e); 249 250 Throwable underlyingException = e.getStatus().getException(); 251 if (underlyingException instanceof InvocationException) { 252 ObjectReference theException = ((InvocationException)underlyingException).exception(); 253 if (theException != null) { 254 try { 255 try { 256 IJavaObject v = (IJavaObject)JDIValue.createValue((JDIDebugTarget)getDebugTarget(), theException); 257 v.sendMessage("printStackTrace", "()V", null, getThread(), false); } catch (DebugException de) { 259 JDIDebugPlugin.log(de); 260 } 261 } catch (RuntimeException re) { 262 JDIDebugPlugin.log(re); 263 } 264 } 265 } 266 } 267 268 } 269 270 280 protected void initializeLocals(IJavaObject object) throws DebugException { 281 IJavaVariable[] locals = null; 282 IJavaObject thisObject = getThis(); 283 if (getStackFrame() != null) { 284 locals = getStackFrame().getLocalVariables(); 285 } 286 if (locals != null) { 287 for (int i = 0; i < locals.length; i++) { 288 IJavaVariable local = locals[i]; 289 IJavaVariable field = object.getField(LOCAL_VAR_PREFIX + local.getName(), false); 290 if (field == null) { 292 throw new DebugException( 293 new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), 294 DebugException.REQUEST_FAILED, EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___unable_to_initialize_local_variables__4, null) 295 ); 296 } 297 field.setValue(local.getValue()); 298 } 299 } 300 if (thisObject != null) { 301 IJavaVariable field = object.getField(DELEGATE_THIS, false); 302 if (field == null) { 304 throw new DebugException( 305 new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), 306 DebugException.REQUEST_FAILED, EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___unable_to_initialize___this___context__5, null) 307 ); 308 } 309 field.setValue(thisObject); 310 } 311 } 312 313 323 protected void restoreLocals(IJavaObject object) throws DebugException { 324 IJavaVariable[] locals = null; 325 if (getStackFrame() != null) { 326 locals = getStackFrame().getLocalVariables(); 327 } 328 if (locals != null) { 329 for (int i = 0; i < locals.length; i++) { 330 IJavaVariable local = locals[i]; 331 IJavaVariable field = object.getField(LOCAL_VAR_PREFIX + local.getName(), false); 332 if (field == null) { 334 throw new DebugException( 335 new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), 336 DebugException.REQUEST_FAILED, EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___unable_to_initialize_local_variables__6, null) 337 ); 338 } 339 local.setValue(field.getValue()); 340 } 341 } 342 } 343 344 347 public void acceptProblem(IMarker problemMarker, String fragmentSource, int fragmentKind) { 348 if (problemMarker.getAttribute(IMarker.SEVERITY, -1) != IMarker.SEVERITY_ERROR) { 349 return; 350 } 351 getResult().addError(problemMarker.getAttribute(IMarker.MESSAGE, "")); } 353 354 357 public IJavaDebugTarget getDebugTarget() { 358 return fDebugTarget; 359 } 360 361 366 private void setDebugTarget(IJavaDebugTarget debugTarget) { 367 fDebugTarget = debugTarget; 368 } 369 370 373 public IJavaProject getJavaProject() { 374 return fJavaProject; 375 } 376 377 382 private void setJavaProject(IJavaProject javaProject) { 383 fJavaProject = javaProject; 384 } 385 386 391 public File getOutputDirectory() { 392 return fOutputDirectory; 393 } 394 395 401 private void setOutputDirectory(File outputDirectory) { 402 fOutputDirectory = outputDirectory; 403 } 404 405 408 public void evaluate(String snippet, IJavaThread thread, IEvaluationListener listener, boolean hitBreakpoints) throws DebugException { 409 checkDisposed(); 410 checkEvaluating(); 411 try { 412 evaluationStarted(); 413 setListener(listener); 414 setHitBreakpoints(hitBreakpoints); 415 setResult(new EvaluationResult(this, snippet, thread)); 416 checkThread(); 417 setThis(null); 419 setLocalVariableNames(EMPTY_STRING_ARRAY); 420 setLocalVariableTypeNames(EMPTY_STRING_ARRAY); 421 setLocalVariableModifiers(EMPTY_INT_ARRAY); 422 423 Runnable r = new Runnable () { 425 public void run() { 426 try { 427 LocalEvaluationEngine.this.getEvaluationContext(). 428 evaluateCodeSnippet(LocalEvaluationEngine.this.getSnippet(), 429 LocalEvaluationEngine.this, null); 430 } catch (JavaModelException e) { 431 LocalEvaluationEngine.this.getResult().setException(new DebugException(e.getStatus())); 432 } finally { 433 LocalEvaluationEngine.this.evaluationComplete(); 434 } 435 } 436 }; 437 438 Thread t = new Thread (r); 439 t.setDaemon(true); 440 t.start(); 441 } catch (DebugException d) { 442 evaluationAborted(); 443 throw d; 444 } 445 446 } 447 448 451 public void evaluate(String snippet, IJavaStackFrame frame, IEvaluationListener listener, int evaluationDetail, boolean hitBreakpoints) throws DebugException { 452 checkDisposed(); 453 checkEvaluating(); 454 try { 455 evaluationStarted(); 456 setListener(listener); 457 setStackFrame(frame); 458 setHitBreakpoints(hitBreakpoints); 459 setResult(new EvaluationResult(this, snippet, (IJavaThread)frame.getThread())); 460 checkThread(); 461 462 IJavaVariable[] locals = frame.getLocalVariables(); 464 465 List typeNames = new ArrayList (locals.length); 466 List varNames = new ArrayList (locals.length); 467 468 for (int i = 0; i < locals.length; i++) { 469 IJavaVariable var = locals[i]; 470 String typeName = getTranslatedTypeName(var.getReferenceTypeName()); 471 if (typeName != null) { 472 typeNames.add(typeName); 473 varNames.add(var.getName()); 474 } 475 } 476 477 setLocalVariableTypeNames((String [])typeNames.toArray(new String [typeNames.size()])); 478 setLocalVariableNames((String [])varNames.toArray(new String [varNames.size()])); 479 int[] modifiers = new int[typeNames.size()]; 480 Arrays.fill(modifiers, 0); 482 setLocalVariableModifiers(modifiers); 483 setThis(frame.getThis()); 484 485 final boolean isStatic = frame.isStatic(); 486 final boolean isConstructor = frame.isConstructor(); 487 final IType receivingType = JavaDebugUtils.resolveDeclaringType(frame); 488 validateReceivingType(receivingType); 489 490 Runnable r = new Runnable () { 492 public void run() { 493 try { 494 LocalEvaluationEngine.this.getEvaluationContext(). 495 evaluateCodeSnippet( 496 LocalEvaluationEngine.this.getSnippet(), 497 LocalEvaluationEngine.this.getLocalVariableTypeNames(), 498 LocalEvaluationEngine.this.getLocalVariableNames(), 499 LocalEvaluationEngine.this.getLocalVariableModifiers(), 500 receivingType, 501 isStatic, 502 isConstructor, 503 LocalEvaluationEngine.this, 504 null); 505 } catch (JavaModelException e) { 506 LocalEvaluationEngine.this.getResult().setException(new DebugException(e.getStatus())); 507 } finally { 508 LocalEvaluationEngine.this.evaluationComplete(); 509 } 510 } 511 }; 512 513 Thread t = new Thread (r); 514 t.setDaemon(true); 515 t.start(); 516 } catch (DebugException d) { 517 evaluationAborted(); 518 throw d; 519 } catch (CoreException e) { 520 evaluationAborted(); 521 throw new DebugException(e.getStatus()); 522 } 523 } 524 525 531 private void validateReceivingType(final IType receivingType) throws DebugException { 532 if (receivingType == null) { 533 throw new DebugException( 534 new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), 535 DebugException.REQUEST_FAILED, EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___unable_to_determine_receiving_type_context__18, null) 536 ); 537 } 538 539 if (receivingType.getDeclaringType() != null) { 540 throw new DebugException( 541 new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), 542 DebugException.REQUEST_FAILED, EvaluationMessages.LocalEvaluationEngine_Evaluation_in_context_of_inner_type_not_supported__19, null) 543 ); 544 } 545 } 546 547 550 public void evaluate(String snippet, IJavaObject thisContext, IJavaThread thread, IEvaluationListener listener, int evaluationDetail, boolean hitBreakpoints) throws DebugException { 551 checkDisposed(); 552 checkEvaluating(); 553 try { 554 evaluationStarted(); 555 setListener(listener); 556 setHitBreakpoints(hitBreakpoints); 557 setResult(new EvaluationResult(this, snippet, thread)); 558 checkThread(); 559 560 setLocalVariableTypeNames(new String [0]); 562 setLocalVariableNames(new String [0]); 563 setLocalVariableModifiers(new int[0]); 564 565 setThis(thisContext); 566 567 final boolean isStatic = false; 568 final boolean isConstructor = false; 569 final IType receivingType = JavaDebugUtils.resolveType(thisContext.getJavaType()); 570 validateReceivingType(receivingType); 571 572 Runnable r = new Runnable () { 574 public void run() { 575 try { 576 LocalEvaluationEngine.this.getEvaluationContext(). 577 evaluateCodeSnippet( 578 LocalEvaluationEngine.this.getSnippet(), 579 LocalEvaluationEngine.this.getLocalVariableTypeNames(), 580 LocalEvaluationEngine.this.getLocalVariableNames(), 581 LocalEvaluationEngine.this.getLocalVariableModifiers(), 582 receivingType, 583 isStatic, 584 isConstructor, 585 LocalEvaluationEngine.this, 586 null); 587 } catch (JavaModelException e) { 588 LocalEvaluationEngine.this.getResult().setException(new DebugException(e.getStatus())); 589 } finally { 590 LocalEvaluationEngine.this.evaluationComplete(); 591 } 592 } 593 }; 594 595 Thread t = new Thread (r); 596 t.setDaemon(true); 597 t.start(); 598 } catch (DebugException d) { 599 evaluationAborted(); 600 throw d; 601 } catch (CoreException e) { 602 evaluationAborted(); 603 throw new DebugException(e.getStatus()); 604 } 605 } 606 607 613 protected void checkDisposed() throws DebugException { 614 if (isDisposed()) { 615 throw new DebugException( 616 new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), 617 DebugException.REQUEST_FAILED, EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___evaluation_context_has_been_disposed__7, null) 618 ); 619 } 620 } 621 622 629 protected void checkEvaluating() throws DebugException { 630 if (isEvaluating()) { 631 throw new DebugException( 632 new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), 633 DebugException.REQUEST_FAILED, "Cannot perform nested evaluations.", null) ); 635 } 636 } 637 638 645 protected void checkThread() throws DebugException { 646 if (!getThread().isSuspended()) { 647 throw new DebugException( 648 new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), 649 DebugException.REQUEST_FAILED, EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___evaluation_thread_must_be_suspended__8, null) 650 ); 651 } 652 } 653 654 659 public void dispose() { 660 fDisposed = true; 661 ENGINE_COUNT--; 662 if (isEvaluating()) { 663 return; 666 } 667 List snippetFiles = getSnippetFiles(); 668 Iterator iter = snippetFiles.iterator(); 669 while (iter.hasNext()) { 670 File file = (File )iter.next(); 671 if (file.exists()) { 672 if (CODE_SNIPPET_NAME.equals(file.getName()) && ENGINE_COUNT > 0) { 673 continue; } 675 if (!file.delete()) { 676 JDIDebugPlugin.log( 677 new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), DebugException.REQUEST_FAILED, 678 MessageFormat.format("Unable to delete temporary evaluation class file {0}.", new String [] {file.getAbsolutePath()}), null) ); 680 } 681 } 682 } 683 List directories = getDirectories(); 684 int i = directories.size() - 1; 686 while (i >= 0) { 687 File dir = (File )directories.get(i); 688 String [] listing= dir.list(); 689 if (dir.exists() && listing != null && listing.length == 0 && !dir.delete()) { 690 JDIDebugPlugin.log( 691 new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), DebugException.REQUEST_FAILED, 692 MessageFormat.format("Unable to delete temporary evaluation directory {0}.", new String [] {dir.getAbsolutePath()}), null) ); 694 } 695 i--; 696 } 697 reset(); 698 setJavaProject(null); 699 setDebugTarget(null); 700 setOutputDirectory(null); 701 setResult(null); 702 setEvaluationContext(null); 703 } 704 705 706 709 private void reset() { 710 setThis(null); 711 setStackFrame(null); 712 setListener(null); 713 } 714 715 722 protected IEvaluationListener getListener() { 723 return fListener; 724 } 725 726 733 private void setListener(IEvaluationListener listener) { 734 fListener = listener; 735 } 736 737 744 protected IJavaStackFrame getStackFrame() { 745 return fStackFrame; 746 } 747 748 754 private void setStackFrame(IJavaStackFrame stackFrame) { 755 fStackFrame = stackFrame; 756 } 757 758 765 protected IJavaThread getThread() { 766 return getResult().getThread(); 767 } 768 769 774 protected String getSnippet() { 775 return getResult().getSnippet(); 776 } 777 778 783 protected EvaluationResult getResult() { 784 return fResult; 785 } 786 787 792 private void setResult(EvaluationResult result) { 793 fResult = result; 794 } 795 796 805 protected void deploy(byte[][] classFiles, String [][] classFileNames) throws DebugException { 806 for (int i = 0; i < classFiles.length; i++) { 807 String [] compoundName = classFileNames[i]; 808 File dir = LocalEvaluationEngine.this.getOutputDirectory(); 810 try { 811 String pkgDirName = dir.getCanonicalPath(); 812 for (int j = 0; j < (compoundName.length - 1); j++) { 813 pkgDirName += File.separator + compoundName[j]; 814 File pkgDir = new File (pkgDirName); 815 if (!pkgDir.exists()) { 816 pkgDir.mkdir(); 817 addDirectory(pkgDir); 818 } 819 } 820 String name = compoundName[compoundName.length - 1] + ".class"; File classFile = new File (pkgDirName + File.separator + name); 822 if (!classFile.exists()) { 823 classFile.createNewFile(); 824 } 825 FileOutputStream stream = new FileOutputStream (classFile); 826 stream.write(classFiles[i]); 827 stream.close(); 828 LocalEvaluationEngine.this.addSnippetFile(classFile); 829 } catch (IOException e) { 830 throw new DebugException( 831 new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), DebugException.REQUEST_FAILED, 832 MessageFormat.format(EvaluationMessages.LocalEvaluationEngine__0__occurred_deploying_class_file_for_evaluation_9, new String [] {e.toString()}), e) 833 ); 834 } 835 } 836 } 837 838 845 private void addSnippetFile(File file) { 846 if (fSnippetFiles == null) { 847 fSnippetFiles = new ArrayList (); 848 } 849 fSnippetFiles.add(file); 850 } 851 852 859 private void addDirectory(File file) { 860 if (fDirectories == null) { 861 fDirectories = new ArrayList (); 862 } 863 fDirectories.add(file); 864 } 865 866 874 protected IEvaluationContext getEvaluationContext() { 875 if (fEvaluationContext == null) { 876 fEvaluationContext = getJavaProject().newEvaluationContext(); 877 } 878 return fEvaluationContext; 879 } 880 881 887 private void setEvaluationContext(IEvaluationContext context) { 888 fEvaluationContext = context; 889 } 890 891 892 898 protected List getSnippetFiles() { 899 if (fSnippetFiles == null) { 900 return Collections.EMPTY_LIST; 901 } 902 return fSnippetFiles; 903 } 904 905 911 protected List getDirectories() { 912 if (fDirectories == null) { 913 return Collections.EMPTY_LIST; 914 } 915 return fDirectories; 916 } 917 918 925 protected boolean isDisposed() { 926 return fDisposed; 927 } 928 929 933 protected void evaluationComplete() { 934 if (JDIDebugPlugin.getDefault() != null) { 936 getListener().evaluationComplete(getResult()); 937 } 938 evaluationEnded(); 939 reset(); 940 if (isDisposed()) { 941 dispose(); 944 } 945 } 946 947 950 private void evaluationStarted() { 951 fEvaluationCount++; 952 } 953 954 957 private void evaluationEnded() { 958 if (fEvaluationCount > 0) { 959 fEvaluationCount--; 960 } 961 } 962 963 967 protected boolean isEvaluating() { 968 return fEvaluationCount > 0; 969 } 970 971 977 private void evaluationAborted() { 978 evaluationEnded(); 979 if (isDisposed()) { 980 dispose(); 983 } 984 } 985 986 994 protected IJavaObject newInstance(String className) throws DebugException { 995 IJavaObject object = null; 996 IJavaClassType clazz = null; 997 IJavaType[] types = getDebugTarget().getJavaTypes(className); 998 if (types != null && types.length > 0) { 999 clazz = (IJavaClassType)types[0]; 1000 } 1001 if (clazz == null) { 1002 types = getDebugTarget().getJavaTypes("java.lang.Class"); IJavaClassType classClass = null; 1006 if (types != null && types.length > 0) { 1007 classClass = (IJavaClassType)types[0]; 1008 } 1009 if (classClass == null) { 1010 throw new DebugException( 1012 new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), 1013 DebugException.REQUEST_FAILED, EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___unable_to_instantiate_code_snippet_class__11, null) 1014 ); 1015 } 1016 IJavaValue[] args = new IJavaValue[] {getDebugTarget().newValue(className)}; 1017 IJavaObject classObject = (IJavaObject)classClass.sendMessage("forName", "(Ljava/lang/String;)Ljava/lang/Class;", args, getThread()); object = (IJavaObject)classObject.sendMessage("newInstance", "()Ljava/lang/Object;", null, getThread(), false); } else { 1020 object = clazz.newInstance("<init>", null, getThread()); } 1022 return object; 1023 } 1024 1025 1048 protected IJavaValue convertResult(IJavaClassObject resultType, IJavaValue result) throws DebugException { 1049 if (resultType == null) { 1050 return null; 1052 } 1053 1054 String sig = resultType.getInstanceType().getSignature(); 1056 if (sig.equals("V") || sig.equals("Lvoid;")) { return getDebugTarget().voidValue(); 1059 } 1060 1061 if (result.getJavaType() == null) { 1062 return result; 1064 } 1065 1066 if (sig.length() == 1) { 1067 IVariable[] vars = result.getVariables(); 1070 IJavaVariable var = null; 1071 for (int i = 0; i < vars.length; i++) { 1072 IJavaVariable jv = (IJavaVariable)vars[i]; 1073 if (!jv.isStatic() && jv.getSignature().equals(sig)) { 1074 var = jv; 1075 break; 1076 } 1077 } 1078 if (var != null) { 1079 return (IJavaValue)var.getValue(); 1080 } 1081 } else { 1082 return result; 1084 } 1085 throw new DebugException( 1086 new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), 1087 DebugException.REQUEST_FAILED, EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___internal_error_retreiving_result__17, null) 1088 ); 1089 } 1090 1091 1097 private int[] getLocalVariableModifiers() { 1098 return fLocalVariableModifiers; 1099 } 1100 1101 1107 private void setLocalVariableModifiers(int[] localVariableModifiers) { 1108 fLocalVariableModifiers = localVariableModifiers; 1109 } 1110 1111 1117 private String [] getLocalVariableNames() { 1118 return fLocalVariableNames; 1119 } 1120 1121 1127 private void setLocalVariableNames(String [] localVariableNames) { 1128 fLocalVariableNames = localVariableNames; 1129 } 1130 1131 1137 private String [] getLocalVariableTypeNames() { 1138 return fLocalVariableTypeNames; 1139 } 1140 1141 1147 private void setLocalVariableTypeNames(String [] localVariableTypeNames) { 1148 fLocalVariableTypeNames = localVariableTypeNames; 1149 } 1150 1151 1160 private void setThis(IJavaObject thisObject) { 1161 fThis = thisObject; 1162 } 1163 1164 1173 private IJavaObject getThis() { 1174 return fThis; 1175 } 1176 1177 1187 protected String getTranslatedTypeName(String typeName) { 1188 int index = typeName.lastIndexOf('$'); 1189 if (index == -1) { 1190 return typeName; 1191 } 1192 if (index + 1 > typeName.length()) { 1193 return typeName; 1195 } 1196 String last = typeName.substring(index + 1); 1197 try { 1198 Integer.parseInt(last); 1199 return null; 1200 } catch (NumberFormatException e) { 1201 return typeName.replace('$', '.'); 1202 } 1203 } 1204 1205 1214 protected String [] getNestedTypeNames(String typeName) { 1215 int index = typeName.lastIndexOf('.'); 1216 if (index >= 0) { 1217 typeName= typeName.substring(index + 1); 1218 } 1219 index = typeName.indexOf('$'); 1220 ArrayList list = new ArrayList (1); 1221 while (index >= 0) { 1222 list.add(typeName.substring(0, index)); 1223 typeName = typeName.substring(index + 1); 1224 index = typeName.indexOf('$'); 1225 } 1226 list.add(typeName); 1227 return (String [])list.toArray(new String [list.size()]); 1228 } 1229 1230 1233 public String [] getImports() { 1234 return getEvaluationContext().getImports(); 1235 } 1236 1237 1240 public void setImports(String [] imports) { 1241 getEvaluationContext().setImports(imports); 1242 } 1243 1244 1251 private void setCodeSnippetClassName(String name) { 1252 fCodeSnippetClassName = name; 1253 } 1254 1255 1262 protected String getCodeSnippetClassName() { 1263 return fCodeSnippetClassName; 1264 } 1265 1266 1269 public boolean isRequestingClassFiles() { 1270 return true; 1271 } 1272 1273 1278 protected boolean getHitBreakpoints() { 1279 return fHitBreakpoints; 1280 } 1281 1282 1286 private void setHitBreakpoints(boolean hit) { 1287 fHitBreakpoints = hit; 1288 } 1289 1290} 1291 | Popular Tags |