X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/DocumentCharacterIterator.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/DocumentCharacterIterator.java index ea30c7a..416ddaf 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/DocumentCharacterIterator.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/DocumentCharacterIterator.java @@ -16,7 +16,6 @@ import org.eclipse.jface.text.Assert; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; - /** * An IDocument based implementation of * CharacterIterator and CharSequence. Note that @@ -26,14 +25,18 @@ import org.eclipse.jface.text.IDocument; * accessing the document fails with a {@link BadLocationException}, any of * CharacterIterator methods as well as charAtmay * return {@link CharacterIterator#DONE}. - * + * * @since 3.0 */ -public class DocumentCharacterIterator implements CharacterIterator, CharSequence { +public class DocumentCharacterIterator implements CharacterIterator, + CharSequence { + + private int fIndex = -1; - private int fIndex= -1; private final IDocument fDocument; + private final int fFirst; + private final int fLast; private void invariant() { @@ -43,8 +46,9 @@ public class DocumentCharacterIterator implements CharacterIterator, CharSequenc /** * Creates an iterator for the entire document. - * - * @param document the document backing this iterator + * + * @param document + * the document backing this iterator */ public DocumentCharacterIterator(IDocument document) { this(document, 0); @@ -52,35 +56,44 @@ public class DocumentCharacterIterator implements CharacterIterator, CharSequenc /** * Creates an iterator, starting at offset first. - * - * @param document the document backing this iterator - * @param first the first character to consider - * @throws IllegalArgumentException if the indices are out of bounds - */ - public DocumentCharacterIterator(IDocument document, int first) throws IllegalArgumentException { + * + * @param document + * the document backing this iterator + * @param first + * the first character to consider + * @throws IllegalArgumentException + * if the indices are out of bounds + */ + public DocumentCharacterIterator(IDocument document, int first) + throws IllegalArgumentException { this(document, first, document.getLength()); } /** * Creates an iterator for the document contents from first * (inclusive) to last (exclusive). - * - * @param document the document backing this iterator - * @param first the first character to consider - * @param last the last character index to consider - * @throws IllegalArgumentException if the indices are out of bounds - */ - public DocumentCharacterIterator(IDocument document, int first, int last) throws IllegalArgumentException { + * + * @param document + * the document backing this iterator + * @param first + * the first character to consider + * @param last + * the last character index to consider + * @throws IllegalArgumentException + * if the indices are out of bounds + */ + public DocumentCharacterIterator(IDocument document, int first, int last) + throws IllegalArgumentException { if (document == null) throw new NullPointerException(); if (first < 0 || first > last) throw new IllegalArgumentException(); if (last > document.getLength()) throw new IllegalArgumentException(); - fDocument= document; - fFirst= first; - fLast= last; - fIndex= first; + fDocument = document; + fFirst = first; + fLast = last; + fIndex = first; invariant(); } @@ -137,7 +150,7 @@ public class DocumentCharacterIterator implements CharacterIterator, CharSequenc */ public char setIndex(int position) { if (position >= getBeginIndex() && position <= getEndIndex()) - fIndex= position; + fIndex = position; else throw new IllegalArgumentException(); @@ -191,8 +204,9 @@ public class DocumentCharacterIterator implements CharacterIterator, CharSequenc * return {@link CharacterIterator#DONE} if a {@link BadLocationException} * was thrown when accessing the backing document. *

- * - * @param index {@inheritDoc} + * + * @param index + * {@inheritDoc} * @return {@inheritDoc} */ public char charAt(int index) { @@ -217,6 +231,7 @@ public class DocumentCharacterIterator implements CharacterIterator, CharSequenc throw new IndexOutOfBoundsException(); if (end > length()) throw new IndexOutOfBoundsException(); - return new DocumentCharacterIterator(fDocument, getBeginIndex() + start, getBeginIndex() + end); + return new DocumentCharacterIterator(fDocument, + getBeginIndex() + start, getBeginIndex() + end); } }