1 11 package org.eclipse.ui.texteditor; 12 13 import org.eclipse.jface.text.BadLocationException; 14 import org.eclipse.jface.text.IDocument; 15 import org.eclipse.jface.text.Position; 16 17 import org.eclipse.core.resources.IMarker; 18 19 20 24 public final class BasicMarkerUpdater implements IMarkerUpdater { 25 26 private final static String [] ATTRIBUTES= { 27 IMarker.CHAR_START, 28 IMarker.CHAR_END, 29 IMarker.LINE_NUMBER 30 }; 31 32 35 public BasicMarkerUpdater() { 36 super(); 37 } 38 39 42 public String [] getAttribute() { 43 return ATTRIBUTES; 44 } 45 46 49 public String getMarkerType() { 50 return null; 51 } 52 53 56 public boolean updateMarker(IMarker marker, IDocument document, Position position) { 57 58 if (position == null) 59 return true; 60 61 if (position.isDeleted()) 62 return false; 63 64 boolean offsetsInitialized= false; 65 boolean offsetsChanged= false; 66 int markerStart= MarkerUtilities.getCharStart(marker); 67 int markerEnd= MarkerUtilities.getCharEnd(marker); 68 69 if (markerStart != -1 && markerEnd != -1) { 70 71 offsetsInitialized= true; 72 73 int offset= position.getOffset(); 74 if (markerStart != offset) { 75 MarkerUtilities.setCharStart(marker, offset); 76 offsetsChanged= true; 77 } 78 79 offset += position.getLength(); 80 if (markerEnd != offset) { 81 MarkerUtilities.setCharEnd(marker, offset); 82 offsetsChanged= true; 83 } 84 } 85 86 if (!offsetsInitialized || (offsetsChanged && MarkerUtilities.getLineNumber(marker) != -1)) { 87 try { 88 MarkerUtilities.setLineNumber(marker, document.getLineOfOffset(position.getOffset()) + 1); 90 } catch (BadLocationException x) { 91 } 92 } 93 94 return true; 95 } 96 } 97 | Popular Tags |