Skip to content

Commit 55582cc

Browse files
author
Vladimir Kotal
authored
cleanup some issues reported by Sonar (#3790)
1 parent 6824aaa commit 55582cc

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/CtagsReader.java

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, 2020, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.analysis;
@@ -40,24 +40,23 @@ public class CtagsReader {
4040
/**
4141
* Matches the Unicode word that occurs last in a string, ignoring any
4242
* trailing whitespace or non-word characters, and makes it accessible as
43-
* the first capture, {@code mtch.groups(1)}.
43+
* the first capture, {@code match.group(1)}.
4444
*/
45-
private static final Pattern LAST_UWORD = Pattern.compile("(?U)(\\w+)[\\W\\s]*$");
45+
private static final Pattern LAST_UNICODE_WORD = Pattern.compile("(?U)(\\w+)[\\W\\s]*$");
4646

4747
/**
4848
* Matches a Unicode word character.
4949
*/
5050
private static final Pattern WORD_CHAR = Pattern.compile("(?U)\\w");
5151

52-
private static final Logger LOGGER = LoggerFactory.getLogger(
53-
CtagsReader.class);
52+
private static final Logger LOGGER = LoggerFactory.getLogger(CtagsReader.class);
5453

5554
/** A value indicating empty method body in tags, so skip it. */
5655
private static final int MIN_METHOD_LINE_LENGTH = 6;
5756

5857
/**
5958
* 96 is used by universal ctags for some lines, but it's too low,
60-
* OpenGrok can theoretically handle 50000 with 8G heap. Also this might
59+
* OpenGrok can theoretically handle 50000 with 8G heap. Also, this might
6160
* break scopes functionality, if set too low.
6261
*/
6362
private static final int MAX_METHOD_LINE_LENGTH = 1030;
@@ -198,7 +197,6 @@ public void readLine(String tagLine) {
198197

199198
int p = tagLine.indexOf('\t');
200199
if (p <= 0) {
201-
//log.fine("SKIPPING LINE - NO TAB");
202200
return;
203201
}
204202
String def = tagLine.substring(0, p);
@@ -208,9 +206,7 @@ public void readLine(String tagLine) {
208206

209207
int lp = tagLine.length();
210208
while ((p = tagLine.lastIndexOf('\t', lp - 1)) > 0) {
211-
//log.fine(" p = " + p + " lp = " + lp);
212209
String fld = tagLine.substring(p + 1, lp);
213-
//log.fine("FIELD===" + fld);
214210
lp = p;
215211

216212
int sep = fld.indexOf(':');
@@ -243,26 +239,24 @@ public void readLine(String tagLine) {
243239
LOGGER.log(Level.FINEST, "Ctags: stripping method" +
244240
" body for def {0} line {1}(scopes/highlight" +
245241
" might break)", new Object[]{def, lnum});
246-
match = whole.substring(0, MAX_METHOD_LINE_LENGTH).replaceAll(
247-
"[ \t]+", " ");
242+
match = whole.substring(0, MAX_METHOD_LINE_LENGTH).replaceAll("[ \t]+", " ");
248243
}
249-
} else { //tag is wrong format; cannot extract tagaddress from it; skip
244+
} else { // tag is in wrong format; cannot extract tagaddress from it; skip
250245
return;
251246
}
252247

253248
// Bug #809: Keep track of which symbols have already been
254249
// seen to prevent duplicating them in memory.
255250

256-
final String type = classInher == null ? kind : kind + " in " +
257-
classInher;
251+
final String type = classInher == null ? kind : kind + " in " + classInher;
258252

259253
int lineno;
260254
try {
261255
lineno = Integer.parseUnsignedInt(lnum);
262256
} catch (NumberFormatException e) {
263257
lineno = 0;
264258
LOGGER.log(Level.WARNING, "CTags line number parsing problem(but" +
265-
" I will continue with line # 0) for symbol {0}", def);
259+
" will continue with line # 0) for symbol {0}", def);
266260
}
267261

268262
CpatIndex cidx = bestIndexOfTag(lineno, whole, def);
@@ -305,7 +299,7 @@ public void readLine(String tagLine) {
305299
cidx = bestIndexOfArg(lineno, whole, arg);
306300

307301
String name = null;
308-
Matcher mname = LAST_UWORD.matcher(arg);
302+
Matcher mname = LAST_UNICODE_WORD.matcher(arg);
309303
if (mname.find()) {
310304
name = mname.group(1);
311305
} else if (arg.equals("...")) {
@@ -324,8 +318,7 @@ public void readLine(String tagLine) {
324318
}
325319
}
326320
}
327-
// log.fine("Read = " + def + " : " + lnum + " = " + kind + " IS " +
328-
// inher + " M " + match);
321+
329322
fields.clear();
330323
}
331324

@@ -339,7 +332,7 @@ private static String cutPattern(String tagLine, int startTab, int endTab) {
339332
// Three lead character represents "\t/^".
340333
String cut = tagLine.substring(startTab + 3, endTab);
341334

342-
/**
335+
/*
343336
* Formerly this class cut four characters from the end, but my testing
344337
* revealed a bug for short lines in files with macOS endings (e.g.
345338
* cyrus-sasl mac/libdes/src/des_enc.c) where the pattern-ending $ is
@@ -351,7 +344,7 @@ private static String cutPattern(String tagLine, int startTab, int endTab) {
351344
} else if (cut.endsWith("/;\"")) {
352345
cut = cut.substring(0, cut.length() - 3);
353346
} else {
354-
/**
347+
/*
355348
* The former logic did the following without the inspections above.
356349
* Leaving this here as a fallback.
357350
*/
@@ -412,7 +405,7 @@ private CpatIndex bestIndexOfTag(int lineno, String whole, String str) {
412405
}
413406

414407
if (woff < 0) {
415-
/** At this point, do a lax search of the substring. */
408+
/* At this point, do a lax search of the substring. */
416409
woff = whole.indexOf(str);
417410
}
418411
}
@@ -422,7 +415,7 @@ private CpatIndex bestIndexOfTag(int lineno, String whole, String str) {
422415
e = ExpandTabsReader.translate(whole, woff + str.length(), t);
423416
return new CpatIndex(lineno, s, e);
424417
}
425-
/**
418+
/*
426419
* When ctags has truncated a pattern, or when it spans multiple lines,
427420
* then `str' might not be found in `whole'. In that case, return an
428421
* imprecise index for the last character as the best we can do.
@@ -496,7 +489,7 @@ private CpatIndex bestIndexOfArg(int lineno, String whole, String arg) {
496489
LOGGER.log(Level.FINE, "Odd arg:{0}|versus:{1}|line {2}",
497490
new Object[]{arg, whole, lineno});
498491
}
499-
/**
492+
/*
500493
* When no fuzzy match can be generated, return an imprecise index
501494
* for the first character as the best we can do.
502495
*/
@@ -529,7 +522,7 @@ private CpatIndex bestIndexOfArg(int lineno, String whole, String arg) {
529522
}
530523
}
531524

532-
/**
525+
/*
533526
* When no match is found, return an imprecise index for the last
534527
* character as the best we can do.
535528
*/
@@ -575,7 +568,7 @@ private int strictIndexOf(String whole, String substr) {
575568

576569
spos = woff + 1;
577570
String onechar;
578-
/**
571+
/*
579572
* Reject if the previous character is a word character, as that
580573
* would not accord with a clean symbol break
581574
*/
@@ -585,7 +578,7 @@ private int strictIndexOf(String whole, String substr) {
585578
continue;
586579
}
587580
}
588-
/**
581+
/*
589582
* Reject if the following character is a word character, as that
590583
* would not accord with a clean symbol break
591584
*/
@@ -613,7 +606,7 @@ private PatResult strictMatch(String whole, String substr, Pattern pat) {
613606
Matcher m = pat.matcher(whole);
614607
while (m.find()) {
615608
String onechar;
616-
/**
609+
/*
617610
* Reject if the previous character is a word character, as that
618611
* would not accord with a clean symbol break
619612
*/
@@ -623,7 +616,7 @@ private PatResult strictMatch(String whole, String substr, Pattern pat) {
623616
continue;
624617
}
625618
}
626-
/**
619+
/*
627620
* Reject if the following character is a word character, as that
628621
* would not accord with a clean symbol break
629622
*/
@@ -656,7 +649,7 @@ private CpatIndex bestLineOfMatch(int lineno, PatResult pr, String cut) {
656649
int t = tabSize;
657650
int resIndex = mIndex;
658651
int contentLength = 0;
659-
/**
652+
/*
660653
* Initialize the following just to silence warnings but with values
661654
* that will be detected as "bad fuzzy" later.
662655
*/
@@ -690,7 +683,7 @@ private CpatIndex bestLineOfMatch(int lineno, PatResult pr, String cut) {
690683
return new CpatIndex(resIndex + 1, s, e);
691684
}
692685

693-
/**
686+
/*
694687
* This should not happen -- but if it does, log it and return an
695688
* imprecise index for the first character as the best we can do.
696689
*/

0 commit comments

Comments
 (0)