X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/BufferedDocumentScanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/BufferedDocumentScanner.java index b4fe57d..cd6833f 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/BufferedDocumentScanner.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/BufferedDocumentScanner.java @@ -10,94 +10,103 @@ *******************************************************************************/ package net.sourceforge.phpdt.internal.ui.text; - import org.eclipse.jface.text.Assert; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.rules.ICharacterScanner; - - /** - * A buffered document scanner. The buffer always contains a section - * of a fixed size of the document to be scanned. + * A buffered document scanner. The buffer always contains a section of a fixed + * size of the document to be scanned. */ public final class BufferedDocumentScanner implements ICharacterScanner { /** The document being scanned. */ private IDocument fDocument; + /** The offset of the document range to scan. */ private int fRangeOffset; + /** The length of the document range to scan. */ private int fRangeLength; + /** The delimiters of the document. */ private char[][] fDelimiters; /** The buffer. */ private final char[] fBuffer; + /** The offset of the buffer within the document. */ private int fBufferOffset; + /** The valid length of the buffer for access. */ private int fBufferLength; + /** The offset of the scanner within the buffer. */ private int fOffset; - /** - * Creates a new buffered document scanner. - * The buffer size is set to the given number of characters. - * - * @param size the buffer size + * Creates a new buffered document scanner. The buffer size is set to the + * given number of characters. + * + * @param size + * the buffer size */ public BufferedDocumentScanner(int size) { Assert.isTrue(size >= 1); - fBuffer= new char[size]; + fBuffer = new char[size]; } /** - * Fills the buffer with the contens of the document starting at the given offset. - * - * @param offset the document offset at which the buffer starts + * Fills the buffer with the contens of the document starting at the given + * offset. + * + * @param offset + * the document offset at which the buffer starts */ private final void updateBuffer(int offset) { - fBufferOffset= offset; + fBufferOffset = offset; if (fBufferOffset + fBuffer.length > fRangeOffset + fRangeLength) - fBufferLength= fRangeLength - (fBufferOffset - fRangeOffset); + fBufferLength = fRangeLength - (fBufferOffset - fRangeOffset); else - fBufferLength= fBuffer.length; + fBufferLength = fBuffer.length; try { - final String content= fDocument.get(fBufferOffset, fBufferLength); - if (content!=null) { - content.getChars(0, fBufferLength, fBuffer, 0); + final String content = fDocument.get(fBufferOffset, fBufferLength); + if (content != null) { + content.getChars(0, fBufferLength, fBuffer, 0); } } catch (BadLocationException e) { } } /** - * Configures the scanner by providing access to the document range over which to scan. - * - * @param document the document to scan - * @param offset the offset of the document range to scan - * @param length the length of the document range to scan + * Configures the scanner by providing access to the document range over + * which to scan. + * + * @param document + * the document to scan + * @param offset + * the offset of the document range to scan + * @param length + * the length of the document range to scan */ public final void setRange(IDocument document, int offset, int length) { - fDocument= document; - fRangeOffset= offset; - fRangeLength= length; + fDocument = document; + fRangeOffset = offset; + fRangeLength = length; - String[] delimiters= document.getLegalLineDelimiters(); - fDelimiters= new char[delimiters.length][]; - for (int i= 0; i < delimiters.length; i++) - fDelimiters[i]= delimiters[i].toCharArray(); + String[] delimiters = document.getLegalLineDelimiters(); + fDelimiters = new char[delimiters.length][]; + for (int i = 0; i < delimiters.length; i++) + fDelimiters[i] = delimiters[i].toCharArray(); updateBuffer(offset); - fOffset= 0; + fOffset = 0; } /* @@ -110,16 +119,16 @@ public final class BufferedDocumentScanner implements ICharacterScanner { return EOF; else { updateBuffer(fBufferOffset + fBufferLength); - fOffset= 0; + fOffset = 0; } } - try { - return fBuffer[fOffset++]; - } catch (ArrayIndexOutOfBoundsException e) { - System.out.println("Offset:"+fOffset); - System.out.println("Buffer:"+fBuffer.toString()); - throw e; - } + try { + return fBuffer[fOffset++]; + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("Offset:" + fOffset); + System.out.println("Buffer:" + fBuffer.toString()); + throw e; + } } /* @@ -132,7 +141,7 @@ public final class BufferedDocumentScanner implements ICharacterScanner { // error: BOF } else { updateBuffer(fBufferOffset - fBuffer.length); - fOffset= fBuffer.length - 1; + fOffset = fBuffer.length - 1; } } else { --fOffset; @@ -145,9 +154,9 @@ public final class BufferedDocumentScanner implements ICharacterScanner { public final int getColumn() { try { - final int offset= fBufferOffset + fOffset; - final int line= fDocument.getLineOfOffset(offset); - final int start= fDocument.getLineOffset(line); + final int offset = fBufferOffset + fOffset; + final int line = fDocument.getLineOfOffset(offset); + final int start = fDocument.getLineOffset(line); return offset - start; } catch (BadLocationException e) { }