KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > contentassist > display > JavaDocCommentReader


1 /*******************************************************************************
2  * Copyright (c) 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.pde.internal.ui.editor.contentassist.display;
12
13
14 import org.eclipse.jdt.core.IBuffer;
15 import org.eclipse.jdt.core.formatter.IndentManipulation;
16
17 /**
18  * Reads a java doc comment from a java doc comment. Skips star-character
19  * on begin of line
20  */

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

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

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

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

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