KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > javadoc > JavaDocCommentReader


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.corext.javadoc;
12
13 import org.eclipse.jface.internal.text.html.SingleCharReader;
14
15 import org.eclipse.jdt.core.IBuffer;
16 import org.eclipse.jdt.core.formatter.IndentManipulation;
17
18
19 /**
20  * Reads a java doc comment from a java doc comment. Skips star-character
21  * on begin of line
22  */

23 public class JavaDocCommentReader extends SingleCharReader {
24
25     private IBuffer fBuffer;
26     
27     private int fCurrPos;
28     private int fStartPos;
29     private int fEndPos;
30     
31     private boolean fWasNewLine;
32         
33     public JavaDocCommentReader(IBuffer buf, int start, int end) {
34         fBuffer= buf;
35         fStartPos= start + 3;
36         fEndPos= end - 2;
37         
38         reset();
39     }
40         
41     /**
42      * @see java.io.Reader#read()
43      */

44     public int read() {
45         if (fCurrPos < fEndPos) {
46             char ch;
47             if (fWasNewLine) {
48                 do {
49                     ch= fBuffer.getChar(fCurrPos++);
50                 } while (fCurrPos < fEndPos && Character.isWhitespace(ch));
51                 if (ch == '*') {
52                     if (fCurrPos < fEndPos) {
53                         do {
54                             ch= fBuffer.getChar(fCurrPos++);
55                         } while (ch == '*');
56                     } else {
57                         return -1;
58                     }
59                 }
60             } else {
61                 ch= fBuffer.getChar(fCurrPos++);
62             }
63             fWasNewLine= IndentManipulation.isLineDelimiterChar(ch);
64             
65             return ch;
66         }
67         return -1;
68     }
69         
70     /**
71      * @see java.io.Reader#close()
72      */

73     public void close() {
74         fBuffer= null;
75     }
76     
77     /**
78      * @see java.io.Reader#reset()
79      */

80     public void reset() {
81         fCurrPos= fStartPos;
82         fWasNewLine= true;
83     }
84     
85     
86     /**
87      * Returns the offset of the last read character in the passed buffer.
88      */

89     public int getOffset() {
90         return fCurrPos;
91     }
92         
93         
94 }
95
Popular Tags