18
18
*/
19
19
20
20
/*
21
- * Copyright (c) 2005, 2017 , Oracle and/or its affiliates. All rights reserved.
21
+ * Copyright (c) 2005, 2018 , Oracle and/or its affiliates. All rights reserved.
22
22
* Portions Copyright (c) 2017-2018, Chris Fraire <[email protected] >.
23
23
*/
24
24
package org .opensolaris .opengrok .analysis ;
@@ -189,7 +189,9 @@ public class AnalyzerGuru {
189
189
@ Override public int compare (String s1 , String s2 ) {
190
190
// DESC: s2 length <=> s1 length
191
191
int cmp = Integer .compare (s2 .length (), s1 .length ());
192
- if (cmp != 0 ) return cmp ;
192
+ if (cmp != 0 ) {
193
+ return cmp ;
194
+ }
193
195
194
196
// the Comparator must also be "consistent with equals", so check
195
197
// string contents too when (length)cmp == 0. (ASC: s1 <=> s2.)
@@ -496,7 +498,7 @@ public static FileAnalyzer getAnalyzer(InputStream in, String file) throws IOExc
496
498
FileAnalyzer defaultAnalyzer = getAnalyzer ();
497
499
if (LOGGER .isLoggable (Level .FINE )) {
498
500
LOGGER .log (Level .FINE , "{0}: fallback {1}" ,
499
- new Object []{ file ,
501
+ new Object []{file ,
500
502
defaultAnalyzer .getClass ().getSimpleName () });
501
503
}
502
504
return defaultAnalyzer ;
@@ -568,8 +570,7 @@ public void populateDocument(Document doc, File file, String path,
568
570
if (fa != null ) {
569
571
Genre g = fa .getGenre ();
570
572
if (g == Genre .PLAIN || g == Genre .XREFABLE || g == Genre .HTML ) {
571
- doc .add (new Field (QueryBuilder .T , g .typeName (),
572
- string_ft_stored_nanalyzed_norms ));
573
+ doc .add (new Field (QueryBuilder .T , g .typeName (), string_ft_stored_nanalyzed_norms ));
573
574
}
574
575
fa .analyze (doc , StreamSource .fromFile (file ), xrefOut );
575
576
@@ -859,7 +860,7 @@ public static FileAnalyzerFactory find(String file) {
859
860
if (factory != null ) {
860
861
if (LOGGER .isLoggable (Level .FINER )) {
861
862
LOGGER .log (Level .FINER , "{0}: chosen by prefix: {1}" ,
862
- new Object []{ file ,
863
+ new Object []{file ,
863
864
factory .getClass ().getSimpleName () });
864
865
}
865
866
return factory ;
@@ -874,7 +875,7 @@ public static FileAnalyzerFactory find(String file) {
874
875
if (factory != null ) {
875
876
if (LOGGER .isLoggable (Level .FINER )) {
876
877
LOGGER .log (Level .FINER , "{0}: chosen by suffix: {1}" ,
877
- new Object []{ file ,
878
+ new Object []{file ,
878
879
factory .getClass ().getSimpleName () });
879
880
}
880
881
return factory ;
@@ -957,7 +958,7 @@ private static FileAnalyzerFactory findForStream(InputStream in,
957
958
if (LOGGER .isLoggable (Level .FINER )) {
958
959
LOGGER .log (Level .FINER ,
959
960
"{0}: chosen by imprecise magic: {1}" ,
960
- new Object []{ file ,
961
+ new Object []{file ,
961
962
fac .getClass ().getSimpleName () });
962
963
}
963
964
return fac ;
@@ -978,7 +979,7 @@ private static FileAnalyzerFactory findMagicString(String opening,
978
979
if (fac != null ) {
979
980
if (LOGGER .isLoggable (Level .FINER )) {
980
981
LOGGER .log (Level .FINER , "{0}: chosen by magic {2}: {1}" ,
981
- new Object []{ file , fac .getClass ().getSimpleName (),
982
+ new Object []{file , fac .getClass ().getSimpleName (),
982
983
fragment });
983
984
}
984
985
return fac ;
@@ -990,7 +991,7 @@ private static FileAnalyzerFactory findMagicString(String opening,
990
991
if (fac != null ) {
991
992
if (LOGGER .isLoggable (Level .FINER )) {
992
993
LOGGER .log (Level .FINER , "{0}: chosen by magic {2}: {1}" ,
993
- new Object []{ file , fac .getClass ().getSimpleName (),
994
+ new Object []{file , fac .getClass ().getSimpleName (),
994
995
fragment });
995
996
}
996
997
return fac ;
@@ -1025,12 +1026,16 @@ private static FileAnalyzerFactory findMagicString(String opening,
1025
1026
* @return The extracted words or <code>""</code>
1026
1027
*/
1027
1028
private static String getWords (String value , int n ) {
1028
- if (n < 1 ) return "" ;
1029
+ if (n < 1 ) {
1030
+ return "" ;
1031
+ }
1029
1032
int l = 0 ;
1030
1033
while (n -- > 0 ) {
1031
1034
int o = l > 0 ? l + 1 : l ;
1032
1035
int i = value .indexOf (' ' , o );
1033
- if (i == -1 ) return value ;
1036
+ if (i == -1 ) {
1037
+ return value ;
1038
+ }
1034
1039
l = i ;
1035
1040
}
1036
1041
return value .substring (0 , l );
@@ -1074,20 +1079,28 @@ private static String readOpening(InputStream in, byte[] sig)
1074
1079
BufferedReader readr = new BufferedReader (
1075
1080
new InputStreamReader (in , encoding ), OPENING_MAX_CHARS );
1076
1081
while ((r = readr .read ()) != -1 ) {
1077
- if (++nRead > OPENING_MAX_CHARS ) break ;
1082
+ if (++nRead > OPENING_MAX_CHARS ) {
1083
+ break ;
1084
+ }
1078
1085
char c = (char )r ;
1079
1086
boolean isWhitespace = Character .isWhitespace (c );
1080
1087
if (!sawNonWhitespace ) {
1081
- if (isWhitespace ) continue ;
1088
+ if (isWhitespace ) {
1089
+ continue ;
1090
+ }
1082
1091
sawNonWhitespace = true ;
1083
1092
}
1084
- if (c == '\n' ) break ;
1093
+ if (c == '\n' ) {
1094
+ break ;
1095
+ }
1085
1096
1086
1097
if (isWhitespace ) {
1087
1098
// Track `lastWhitespace' to condense stretches of whitespace,
1088
1099
// and use ' ' regardless of actual whitespace character to
1089
1100
// accord with magic string definitions.
1090
- if (!lastWhitespace && !postHashbang ) opening .append (' ' );
1101
+ if (!lastWhitespace && !postHashbang ) {
1102
+ opening .append (' ' );
1103
+ }
1091
1104
} else {
1092
1105
opening .append (c );
1093
1106
postHashbang = false ;
0 commit comments