1 11 package org.eclipse.jdt.internal.corext.template.java; 12 13 import org.eclipse.jface.text.BadPositionCategoryException; 14 import org.eclipse.jface.text.DocumentEvent; 15 import org.eclipse.jface.text.IPositionUpdater; 16 import org.eclipse.jface.text.Position; 17 18 23 final class ExclusivePositionUpdater implements IPositionUpdater { 24 25 26 private final String fCategory; 27 28 33 public ExclusivePositionUpdater(String category) { 34 fCategory= category; 35 } 36 37 40 public void update(DocumentEvent event) { 41 42 int eventOffset= event.getOffset(); 43 int eventOldLength= event.getLength(); 44 int eventNewLength= event.getText() == null ? 0 : event.getText().length(); 45 int deltaLength= eventNewLength - eventOldLength; 46 47 try { 48 Position[] positions= event.getDocument().getPositions(fCategory); 49 50 for (int i= 0; i != positions.length; i++) { 51 52 Position position= positions[i]; 53 54 if (position.isDeleted()) 55 continue; 56 57 int offset= position.getOffset(); 58 int length= position.getLength(); 59 int end= offset + length; 60 61 if (offset >= eventOffset + eventOldLength) 62 position.setOffset(offset + deltaLength); 65 else if (end <= eventOffset) { 66 } else if (offset <= eventOffset && end >= eventOffset + eventOldLength) { 69 position.setLength(length + deltaLength); 71 } else if (offset < eventOffset) { 72 int newEnd= eventOffset; 74 position.setLength(newEnd - offset); 75 } else if (end > eventOffset + eventOldLength) { 76 int newOffset= eventOffset + eventNewLength; 80 position.setOffset(newOffset); 81 position.setLength(end - newOffset); 82 } else { 83 position.delete(); 85 } 86 } 87 } catch (BadPositionCategoryException e) { 88 } 90 } 91 92 97 public String getCategory() { 98 return fCategory; 99 } 100 101 } 102 | Popular Tags |