}
return newEdit;
}
private static Document createDocument(String string, Position[] positions) throws IllegalArgumentException {
Document doc= new Document(string);
try {
if (positions != null) {
final String POS_CATEGORY= "myCategory"; //$NON-NLS-1$
doc.addPositionCategory(POS_CATEGORY);
doc.addPositionUpdater(new DefaultPositionUpdater(POS_CATEGORY) {
protected boolean notDeleted() {
int start= this.fOffset;
int end= start + this.fLength;
if (start < this.fPosition.offset && (this.fPosition.offset + this.fPosition.length < end)) {
this.fPosition.offset= end; // deleted positions: set to end of remove
return false;
}
return true;
}
});
for (int i= 0; i < positions.length; i++) {
try {
doc.addPosition(POS_CATEGORY, positions[i]);
} catch (BadLocationException e) {
throw new IllegalArgumentException("Position outside of string. offset: " + positions[i].offset + ", length: " + positions[i].length + ", string size: " + string.length()); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
}
}
}