|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
JavaDocReader.java | 78.6% | 80.4% | 66.7% | 78.8% |
|
1 |
/*
|
|
2 |
* Copyright (c) 2001-2003 The XDoclet team
|
|
3 |
* All rights reserved.
|
|
4 |
*/
|
|
5 |
package xjavadoc;
|
|
6 |
|
|
7 |
import java.io.*;
|
|
8 |
|
|
9 |
/**
|
|
10 |
* A reader which strips away any spaces and stars at the beginning of javadoc.
|
|
11 |
* It also keeps track of line numbers, which is needed for error reporting.
|
|
12 |
*
|
|
13 |
* @author Aslak Hellesøy
|
|
14 |
* @created 3. januar 2002
|
|
15 |
*/
|
|
16 |
final class JavaDocReader extends FilterReader |
|
17 |
{ |
|
18 |
private boolean badChar = true; |
|
19 |
private boolean endOfLine = true; |
|
20 |
// private boolean lastStar = true;
|
|
21 |
private int c = -1; |
|
22 |
private int lastC = -1; |
|
23 |
private boolean atEnd = false; |
|
24 |
|
|
25 |
private int _lineOffset = 0; |
|
26 |
|
|
27 |
private int nextChar = -1; |
|
28 |
|
|
29 |
/**
|
|
30 |
* @param in the underlying reader, containing javadoc
|
|
31 |
*/
|
|
32 | 704 |
public JavaDocReader( Reader in )
|
33 |
{ |
|
34 | 704 |
super( in );
|
35 |
// we can skip the slash-star-star
|
|
36 | 704 |
try
|
37 |
{ |
|
38 | 704 |
in.read(); |
39 | 704 |
in.read(); |
40 | 704 |
in.read(); |
41 |
} |
|
42 |
catch( IOException e )
|
|
43 |
{ |
|
44 | 0 |
throw new RuntimeException( "We weren't given javadoc!!" ); |
45 |
} |
|
46 |
} |
|
47 |
|
|
48 |
/**
|
|
49 |
* Returns the line offset we're currently reading
|
|
50 |
*
|
|
51 |
* @return line in the javadoc.
|
|
52 |
*/
|
|
53 | 706 |
public int getLineOffset() |
54 |
{ |
|
55 | 706 |
return _lineOffset;
|
56 |
} |
|
57 |
|
|
58 |
/**
|
|
59 |
* Reads a byte of data. The method will block if no input is available.
|
|
60 |
*
|
|
61 |
* @return the byte read, or -1 if the end of the stream is
|
|
62 |
* reached.
|
|
63 |
* @exception IOException If an I/O error has occurred.
|
|
64 |
*/
|
|
65 | 73786 |
public int read() throws IOException |
66 |
{ |
|
67 | 73786 |
if( atEnd )
|
68 |
{ |
|
69 | 0 |
return -1;
|
70 |
} |
|
71 | 73786 |
if( endOfLine )
|
72 |
{ |
|
73 | 5544 |
endOfLine = false;
|
74 | 5544 |
badChar = true;
|
75 |
} |
|
76 |
|
|
77 | 73786 |
do
|
78 |
{ |
|
79 | 82804 |
if( c == -1 ) {
|
80 |
// will only happen 1st time
|
|
81 | 704 |
c = in.read(); |
82 |
} else {
|
|
83 | 82100 |
c = nextChar; |
84 |
} |
|
85 | 82804 |
if( c == -1 ) {
|
86 | 248 |
return c;
|
87 |
} |
|
88 | 82556 |
nextChar = in.read(); |
89 |
|
|
90 | 82556 |
if( c == '*' && nextChar == '/' )
|
91 |
{ |
|
92 | 456 |
atEnd = true;
|
93 | 456 |
return -1;
|
94 |
} |
|
95 |
// UNIX: \n (LF)
|
|
96 |
// MAC: \r (CR)
|
|
97 |
// PC: \r\n (CR/LF)
|
|
98 |
//
|
|
99 |
// We don't want to interpret \r\n as two newlines
|
|
100 | 82100 |
if( c == '\r' || c == '\n' || c == '\f' )
|
101 |
{ |
|
102 | 4840 |
badChar = false;
|
103 | 4840 |
endOfLine = true;
|
104 | 4840 |
if( !( lastC == '\r' && c == '\n' ) )
|
105 |
{ |
|
106 | 2438 |
_lineOffset++; |
107 |
} |
|
108 |
} |
|
109 |
else
|
|
110 |
{ |
|
111 | 77260 |
if( !( badChar && ( c == '\t' || c == ' ' || c == '*' ) ) )
|
112 |
{ |
|
113 |
// finally found something not a star or spaceish
|
|
114 | 68242 |
badChar = false;
|
115 |
} |
|
116 |
} |
|
117 | 82100 |
lastC = c; |
118 | 82100 |
}while ( badChar && c != -1 );
|
119 | 73082 |
return c;
|
120 |
} |
|
121 |
|
|
122 |
/**
|
|
123 |
* Reads into an array of bytes. Blocks until some input is available.
|
|
124 |
*
|
|
125 |
* @param b the buffer into which the data is read
|
|
126 |
* @param off the start offset of the data
|
|
127 |
* @param len the maximum number of bytes read
|
|
128 |
* @return the actual number of bytes read, -1 is returned when
|
|
129 |
* the end of the stream is reached.
|
|
130 |
* @exception IOException If an I/O error has occurred.
|
|
131 |
*/
|
|
132 | 1404 |
public int read( char[] b, int off, int len ) throws IOException |
133 |
{ |
|
134 | 1404 |
if( atEnd )
|
135 |
{ |
|
136 | 702 |
return -1;
|
137 |
} |
|
138 | 73500 |
for( int i = off; i < len; i++ ) |
139 |
{ |
|
140 | 73500 |
int c = read();
|
141 |
|
|
142 | 73500 |
if( c == -1 )
|
143 |
{ |
|
144 | 702 |
atEnd = true;
|
145 | 702 |
return i - off;
|
146 |
} |
|
147 | 72798 |
b[i] = ( char ) c;
|
148 |
} |
|
149 | 0 |
return len;
|
150 |
} |
|
151 |
|
|
152 |
/**
|
|
153 |
* Skips bytes of input.
|
|
154 |
*
|
|
155 |
* @param n bytes to be skipped
|
|
156 |
* @return actual number of bytes skipped
|
|
157 |
* @exception IOException If an I/O error has occurred.
|
|
158 |
*/
|
|
159 | 0 |
public long skip( long n ) throws IOException |
160 |
{ |
|
161 |
// Can't just read n bytes from 'in' and throw them
|
|
162 |
// away, because n bytes from 'in' doesn't necessarily
|
|
163 |
// correspond to n bytes from 'this'.
|
|
164 | 0 |
for( int i = 1; i <= n; i++ ) |
165 |
{ |
|
166 | 0 |
int c = read();
|
167 |
|
|
168 | 0 |
if( c == -1 )
|
169 |
{ |
|
170 | 0 |
return i - 1;
|
171 |
} |
|
172 |
} |
|
173 | 0 |
return n;
|
174 |
} |
|
175 |
|
|
176 |
/**
|
|
177 |
* Returns the number of bytes that can be read without blocking.
|
|
178 |
*
|
|
179 |
* @return the number of available bytes
|
|
180 |
* @exception IOException Describe the exception
|
|
181 |
*/
|
|
182 | 0 |
public int available() throws IOException |
183 |
{ |
|
184 |
// We don't really know. We can ask 'in', but some of those bytes
|
|
185 |
// are probably whitespace, and it's possible that all of them are.
|
|
186 |
// So we have to be conservative and return zero.
|
|
187 | 0 |
return 0;
|
188 |
} |
|
189 |
} |
|
190 |
|
|