1 11 package org.eclipse.jdt.internal.debug.eval; 12 13 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 17 import org.eclipse.debug.core.DebugEvent; 18 import org.eclipse.debug.core.DebugPlugin; 19 import org.eclipse.debug.core.IDebugEventSetListener; 20 import org.eclipse.jdt.core.IJavaProject; 21 import org.eclipse.jdt.debug.core.IJavaDebugTarget; 22 import org.eclipse.jdt.debug.eval.EvaluationManager; 23 import org.eclipse.jdt.debug.eval.IAstEvaluationEngine; 24 25 public class JavaEvaluationEngineManager implements IDebugEventSetListener { 26 27 36 HashMap fTargetMap= new HashMap (); 37 38 public JavaEvaluationEngineManager() { 39 DebugPlugin.getDefault().addDebugEventListener(this); 40 } 41 42 48 public void handleDebugEvents(DebugEvent[] events) { 49 DebugEvent event; 50 for (int i= 0, numEvents= events.length; i < numEvents; i++) { 51 event= events[i]; 52 if (event.getKind() == DebugEvent.TERMINATE && event.getSource() instanceof IJavaDebugTarget) { 53 HashMap map = (HashMap )fTargetMap.remove(event.getSource()); 54 if (map != null) { 55 Iterator iter = map.values().iterator(); 56 while (iter.hasNext()) { 57 ((IAstEvaluationEngine)iter.next()).dispose(); 58 } 59 map.clear(); 60 } 61 } 62 } 63 } 64 65 70 public IAstEvaluationEngine getEvaluationEngine(IJavaProject project, IJavaDebugTarget target) { 71 IAstEvaluationEngine engine= null; 72 HashMap map= (HashMap )fTargetMap.get(target); 73 if (map == null) { 74 map= new HashMap (); 75 fTargetMap.put(target, map); 76 } 77 engine= (IAstEvaluationEngine)map.get(project); 78 if (engine == null) { 79 engine= EvaluationManager.newAstEvaluationEngine(project, target); 80 map.put(project, engine); 81 } 82 return engine; 83 } 84 85 93 public void dispose() { 94 HashMap engines; 95 Iterator iter= fTargetMap.values().iterator(); 96 while (iter.hasNext()) { 97 engines= ((HashMap )iter.next()); 98 Iterator engineIter= engines.values().iterator(); 99 while (engineIter.hasNext()) { 100 IAstEvaluationEngine engine = (IAstEvaluationEngine)engineIter.next(); 101 engine.dispose(); 102 } 103 engines.clear(); 104 } 105 DebugPlugin.getDefault().removeDebugEventListener(this); 106 } 107 108 } 109 | Popular Tags |