A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / corext / phpdoc / PHPDocBufferCommentReader.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.corext.phpdoc;
12
13 import net.sourceforge.phpdt.core.IBuffer;
14 import net.sourceforge.phpdt.internal.corext.util.Strings;
15
16 /**
17  * Reads a phpdoc comment from a phpdoc comment. Skips star-character on begin
18  * of line
19  */
20 public class PHPDocBufferCommentReader extends SingleCharReader {
21
22         private IBuffer fBuffer;
23
24         private int fCurrPos;
25
26         private int fStartPos;
27
28         private int fEndPos;
29
30         private boolean fWasNewLine;
31
32         public PHPDocBufferCommentReader(IBuffer buf, int start, int end) {
33                 fBuffer = buf;
34                 fStartPos = start + 3;
35                 fEndPos = end - 2;
36
37                 reset();
38         }
39
40         /**
41          * @see java.io.Reader#read()
42          */
43         public int read() {
44                 if (fCurrPos < fEndPos) {
45                         char ch;
46                         if (fWasNewLine) {
47                                 do {
48                                         ch = fBuffer.getChar(fCurrPos++);
49                                 } while (fCurrPos < fEndPos && Character.isWhitespace(ch));
50                                 if (ch == '*') {
51                                         if (fCurrPos < fEndPos) {
52                                                 do {
53                                                         ch = fBuffer.getChar(fCurrPos++);
54                                                 } while (ch == '*');
55                                         } else {
56                                                 return -1;
57                                         }
58                                 }
59                         } else {
60                                 ch = fBuffer.getChar(fCurrPos++);
61                         }
62                         fWasNewLine = Strings.isLineDelimiterChar(ch);
63
64                         return ch;
65                 }
66                 return -1;
67         }
68
69         /**
70          * @see java.io.Reader#close()
71          */
72         public void close() {
73                 fBuffer = null;
74         }
75
76         /**
77          * @see java.io.Reader#reset()
78          */
79         public void reset() {
80                 fCurrPos = fStartPos;
81                 fWasNewLine = true;
82         }
83
84 }