01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.corext.javadoc;
11:
12: import org.eclipse.jface.internal.text.html.SingleCharReader;
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
49: && 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 = IndentManipulation.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: /**
85: * Returns the offset of the last read character in the passed buffer.
86: */
87: public int getOffset() {
88: return fCurrPos;
89: }
90:
91: }
|