1 11 package org.eclipse.jface.text.link; 12 13 import org.eclipse.core.runtime.Assert; 14 15 import org.eclipse.jface.text.BadLocationException; 16 import org.eclipse.jface.text.DocumentEvent; 17 import org.eclipse.jface.text.IDocument; 18 import org.eclipse.jface.text.Position; 19 20 28 public class LinkedPosition extends Position { 29 30 31 private IDocument fDocument; 32 private int fSequenceNumber; 33 34 42 public LinkedPosition(IDocument document, int offset, int length, int sequence) { 43 super(offset, length); 44 Assert.isNotNull(document); 45 fDocument= document; 46 fSequenceNumber= sequence; 47 } 48 49 57 public LinkedPosition(IDocument document, int offset, int length) { 58 this(document, offset, length, LinkedPositionGroup.NO_STOP); 59 } 60 61 64 public IDocument getDocument() { 65 return fDocument; 66 } 67 68 71 public boolean equals(Object other) { 72 if (other instanceof LinkedPosition) { 73 LinkedPosition p= (LinkedPosition) other; 74 return p.offset == offset && p.length == length && p.fDocument == fDocument; 75 } 76 return false; 77 } 78 79 86 public boolean overlapsWith(LinkedPosition position) { 87 return position.getDocument() == fDocument && overlapsWith(position.getOffset(), position.getLength()); 88 } 89 90 97 public boolean includes(DocumentEvent event) { 98 return includes(event.getDocument(), event.getOffset(), event.getLength()); 99 } 100 101 108 public boolean includes(LinkedPosition position) { 109 return includes(position.getDocument(), position.getOffset(), position.getLength()); 110 } 111 112 121 public boolean includes(int pOffset) { 122 return this.offset <= pOffset && pOffset <= this.offset + this.length; 123 } 124 125 139 protected boolean includes(IDocument doc, int off, int len) { 140 return doc == fDocument && off >= offset && len + off <= offset + length; 141 142 } 143 144 150 public String getContent() throws BadLocationException { 151 return fDocument.get(offset, length); 152 } 153 154 159 public int getSequenceNumber() { 160 return fSequenceNumber; 161 } 162 163 168 public void setSequenceNumber(int sequence) { 169 fSequenceNumber= sequence; 170 } 171 172 175 public int hashCode() { 176 return fDocument.hashCode() | super.hashCode() | fSequenceNumber; 177 } 178 } 179 | Popular Tags |