@@ -307,15 +307,6 @@ protected boolean acceptOneOfThenPut(char ch1, char ch2) {
307307 return false ;
308308 }
309309
310- /**
311- * Test if the current character is a line terminator.
312- *
313- * @return true if current character is a line terminator.
314- */
315- private boolean isEOLN () {
316- return isOneOf ('\n' , '\r' );
317- }
318-
319310 /**
320311 * Skip and process a line terminator sequence.
321312 */
@@ -1094,7 +1085,7 @@ public Token readToken() {
10941085 if (scannerDebug ) {
10951086 System .out .println ("nextToken(" + pos
10961087 + "," + endPos + ")=|" +
1097- new String ( getRawCharacters ( pos , endPos ) )
1088+ getRawString ( pos , endPos )
10981089 + "|" );
10991090 }
11001091 }
@@ -1146,13 +1137,11 @@ protected Tokens.Comment processComment(int pos, int endPos, CommentStyle style)
11461137 if (scannerDebug ) {
11471138 System .out .println ("processComment(" + pos
11481139 + "," + endPos + "," + style + ")=|"
1149- + new String ( getRawCharacters ( pos , endPos ) )
1140+ + getRawString ( pos , endPos )
11501141 + "|" );
11511142 }
11521143
1153- char [] buf = getRawCharacters (pos , endPos );
1154-
1155- return new BasicComment (style , fac , buf , pos );
1144+ return new BasicComment (style ,this , pos , endPos );
11561145 }
11571146
11581147 /**
@@ -1167,8 +1156,8 @@ protected Tokens.Comment processComment(int pos, int endPos, CommentStyle style)
11671156 protected void processWhiteSpace (int pos , int endPos ) {
11681157 if (scannerDebug ) {
11691158 System .out .println ("processWhitespace(" + pos
1170- + "," + endPos + ")=|" +
1171- new String ( getRawCharacters ( pos , endPos ) )
1159+ + "," + endPos + ")=|"
1160+ + getRawString ( pos , endPos )
11721161 + "|" );
11731162 }
11741163 }
@@ -1182,8 +1171,8 @@ protected void processWhiteSpace(int pos, int endPos) {
11821171 protected void processLineTerminator (int pos , int endPos ) {
11831172 if (scannerDebug ) {
11841173 System .out .println ("processTerminator(" + pos
1185- + "," + endPos + ")=|" +
1186- new String ( getRawCharacters ( pos , endPos ) )
1174+ + "," + endPos + ")=|"
1175+ + getRawString ( pos , endPos )
11871176 + "|" );
11881177 }
11891178 }
@@ -1206,9 +1195,6 @@ public Position.LineMap getLineMap() {
12061195 protected static class BasicComment extends PositionTrackingReader implements Comment {
12071196 /**
12081197 * Style of comment
1209- * LINE starting with //
1210- * BLOCK starting with /*
1211- * JAVADOC starting with /**
12121198 */
12131199 CommentStyle cs ;
12141200
@@ -1225,13 +1211,13 @@ protected static class BasicComment extends PositionTrackingReader implements Co
12251211 /**
12261212 * Constructor.
12271213 *
1228- * @param cs comment style
1229- * @param sf Scan factory.
1230- * @param array Array containing contents of source .
1231- * @param offset Position offset in original source buffer.
1214+ * @param cs comment style
1215+ * @param reader existing reader
1216+ * @param pos start of meaningful content in buffer .
1217+ * @param endPos end of meaningful content in buffer.
12321218 */
1233- protected BasicComment (CommentStyle cs , ScannerFactory sf , char [] array , int offset ) {
1234- super (sf , array , offset );
1219+ protected BasicComment (CommentStyle cs , UnicodeReader reader , int pos , int endPos ) {
1220+ super (reader , pos , endPos );
12351221 this .cs = cs ;
12361222 }
12371223
@@ -1247,8 +1233,7 @@ public String getText() {
12471233 /**
12481234 * Return buffer position in original buffer mapped from buffer position in comment.
12491235 *
1250- * @param pos buffer position in comment.
1251- *
1236+ * @param pos buffer position in comment.
12521237 * @return buffer position in original buffer.
12531238 */
12541239 public int getSourcePos (int pos ) {
@@ -1257,11 +1242,8 @@ public int getSourcePos(int pos) {
12571242
12581243 /**
12591244 * Return style of comment.
1260- * LINE starting with //
1261- * BLOCK starting with /*
1262- * JAVADOC starting with /**
12631245 *
1264- * @return
1246+ * @return style of comment.
12651247 */
12661248 public CommentStyle getStyle () {
12671249 return cs ;
@@ -1273,76 +1255,110 @@ public CommentStyle getStyle() {
12731255 * @return true if comment contains @deprecated.
12741256 */
12751257 public boolean isDeprecated () {
1276- if (!scanned && cs == CommentStyle . JAVADOC ) {
1258+ if (!scanned ) {
12771259 scanDocComment ();
12781260 }
1279-
12801261 return deprecatedFlag ;
12811262 }
12821263
12831264 /**
1284- * Scan JAVADOC comment for details.
1265+ * Remove closing star(s) slash from comment.
1266+ *
1267+ * @param line line reader
1268+ *
1269+ * @return new line reader if detected otherwise original line reader.
12851270 */
1286- protected void scanDocComment () {
1287- try {
1288- boolean deprecatedPrefix = false ;
1289- accept ("/**" );
1271+ UnicodeReader trimEndOfComment (UnicodeReader line ) {
1272+ int pos = line .position ();
1273+ boolean allWhitespace = true ;
12901274
1291- forEachLine :
1292- while (isAvailable ()) {
1293- // Skip optional WhiteSpace at beginning of line
1294- skipWhitespace ();
1275+ while (line .isAvailable ()) {
1276+ int endPos = line .position ();
12951277
1296- // Skip optional consecutive Stars
1297- while (accept ('*' )) {
1298- if (is ('/' )) {
1299- return ;
1300- }
1301- }
1278+ if (line .skip ('*' ) != 0 && line .is ('/' )) {
1279+ return line .lineReader (allWhitespace ? endPos : pos , endPos );
1280+ } else {
1281+ allWhitespace = allWhitespace && line .isWhitespace ();
1282+ line .next ();
1283+ }
1284+ }
13021285
1303- // Skip optional WhiteSpace after Stars
1304- skipWhitespace ();
1286+ line .reset (pos );
13051287
1306- // At beginning of line in the JavaDoc sense.
1307- deprecatedPrefix = deprecatedFlag || accept ( "@deprecated" );
1288+ return line ;
1289+ }
13081290
1309- if (deprecatedPrefix && isAvailable ()) {
1310- if (Character .isWhitespace (get ())) {
1311- deprecatedFlag = true ;
1312- } else if (accept ('*' )) {
1313- if (is ('/' )) {
1314- deprecatedFlag = true ;
1315- return ;
1316- }
1317- }
1318- }
1291+ /**
1292+ * Trim the first part of the JavaDoc comment.
1293+ *
1294+ * @param line line reader
1295+ *
1296+ * @return modified line reader
1297+ */
1298+ UnicodeReader trimJavadocComment (UnicodeReader line ) {
1299+ line = trimEndOfComment (line );
1300+ int pos = line .position ();
1301+ line .skipWhitespace ();
13191302
1320- // Skip rest of line
1321- while (isAvailable ()) {
1322- switch (get ()) {
1323- case '*' :
1324- next ();
1303+ if (!line .isAvailable ()) {
1304+ return line ;
1305+ }
13251306
1326- if (is ( '/' ) ) {
1327- return ;
1328- }
1307+ if (line . skip ( '*' ) == 0 ) {
1308+ line . reset ( pos ) ;
1309+ }
13291310
1330- break ;
1331- case '\r' : // (Spec 3.4)
1332- case '\n' : // (Spec 3.4)
1333- accept ('\r' );
1334- accept ('\n' );
1335- continue forEachLine ;
1311+ return line ;
1312+ }
13361313
1337- default :
1338- next ();
1339- break ;
1340- }
1341- } // rest of line
1342- } // forEachLine
1343- return ;
1344- } finally {
1314+ /**
1315+ * Put the line into the buffer.
1316+ *
1317+ * @param line line reader
1318+ */
1319+ protected void putLine (UnicodeReader line ) {
1320+ // ignore, overridden in subclass
1321+ }
1322+
1323+ /**
1324+ * Scan document comment for content.
1325+ */
1326+ protected void scanDocComment () {
1327+ if (!scanned ) {
1328+ deprecatedFlag = false ;
13451329 scanned = true ;
1330+
1331+ if (!accept ("/**" )) {
1332+ return ;
1333+ }
1334+
1335+ skip ('*' );
1336+ skipWhitespace ();
1337+
1338+ if (isEOLN ()) {
1339+ accept ('\r' );
1340+ accept ('\n' );
1341+ }
1342+
1343+ while (isAvailable ()) {
1344+ UnicodeReader line = lineReader ();
1345+ line = trimJavadocComment (line );
1346+
1347+ // If standalone @deprecated tag
1348+ int pos = line .position ();
1349+ line .skipWhitespace ();
1350+
1351+ if (line .accept ("@deprecated" ) &&
1352+ (!line .isAvailable () ||
1353+ line .isWhitespace () ||
1354+ line .isEOLN () ||
1355+ line .get () == EOI )) {
1356+ deprecatedFlag = true ;
1357+ }
1358+
1359+ line .reset (pos );
1360+ putLine (line );
1361+ }
13461362 }
13471363 }
13481364 }
0 commit comments