1 11 package org.eclipse.jdt.internal.debug.ui; 12 13 import org.eclipse.core.resources.IMarker; 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.debug.core.DebugPlugin; 16 import org.eclipse.debug.core.IBreakpointManager; 17 import org.eclipse.debug.core.model.IBreakpoint; 18 import org.eclipse.jdt.core.dom.AST; 19 import org.eclipse.jdt.core.dom.ASTParser; 20 import org.eclipse.jdt.core.dom.CompilationUnit; 21 import org.eclipse.jdt.debug.core.IJavaPatternBreakpoint; 22 import org.eclipse.jdt.debug.core.IJavaStratumLineBreakpoint; 23 import org.eclipse.jdt.internal.debug.ui.actions.ValidBreakpointLocationLocator; 24 import org.eclipse.jface.text.BadLocationException; 25 import org.eclipse.jface.text.IDocument; 26 import org.eclipse.jface.text.Position; 27 import org.eclipse.ui.texteditor.IMarkerUpdater; 28 29 51 public class BreakpointMarkerUpdater implements IMarkerUpdater { 52 53 public BreakpointMarkerUpdater() {} 54 55 58 public String [] getAttribute() { 59 return new String [] {IMarker.LINE_NUMBER}; 60 } 61 62 65 public String getMarkerType() { 66 return "org.eclipse.debug.core.breakpointMarker"; } 68 69 72 public boolean updateMarker(IMarker marker, IDocument document, Position position) { 73 if(position.isDeleted()) { 74 return false; 75 } 76 IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager(); 77 IBreakpoint breakpoint = manager.getBreakpoint(marker); 78 if (breakpoint instanceof IJavaStratumLineBreakpoint || breakpoint instanceof IJavaPatternBreakpoint) { 79 return true; 80 } 81 ASTParser parser = ASTParser.newParser(AST.JLS3); 82 parser.setSource(document.get().toCharArray()); 83 CompilationUnit unit = (CompilationUnit) parser.createAST(null); 84 if(unit != null) { 85 try { 86 ValidBreakpointLocationLocator loc = new ValidBreakpointLocationLocator(unit, document.getLineOfOffset(position.getOffset())+1, true, true); 87 unit.accept(loc); 88 if(loc.getLocationType() == ValidBreakpointLocationLocator.LOCATION_NOT_FOUND) { 89 return false; 90 } 91 if(marker.getAttribute(IMarker.LINE_NUMBER, -1) == loc.getLineLocation()) { 93 return true; 94 } 95 marker.setAttribute(IMarker.LINE_NUMBER, loc.getLineLocation()); 96 return true; 97 } 98 catch (BadLocationException e) {JDIDebugUIPlugin.log(e);} 99 catch (CoreException e) {JDIDebugUIPlugin.log(e);} 100 } 101 return false; 102 } 103 } 104 | Popular Tags |