33
33
import java .io .Writer ;
34
34
import java .lang .reflect .InvocationTargetException ;
35
35
import java .nio .charset .StandardCharsets ;
36
+ import java .nio .file .Files ;
36
37
import java .util .ArrayList ;
37
38
import java .util .Arrays ;
38
39
import java .util .Collections ;
@@ -392,29 +393,31 @@ public static List<AnalyzerFactory> getAnalyzerFactories() {
392
393
return Collections .unmodifiableList (factories );
393
394
}
394
395
396
+ private static final String USED_IN_MULTIPLE_MSG = "' used in multiple analyzers" ;
397
+
395
398
/**
396
399
* Register a {@code FileAnalyzerFactory} instance.
397
400
*/
398
401
private static void registerAnalyzer (AnalyzerFactory factory ) {
399
402
for (String name : factory .getFileNames ()) {
400
403
AnalyzerFactory old = FILE_NAMES .put (name , factory );
401
404
assert old == null :
402
- "name '" + name + "' used in multiple analyzers" ;
405
+ "name '" + name + USED_IN_MULTIPLE_MSG ;
403
406
}
404
407
for (String prefix : factory .getPrefixes ()) {
405
408
AnalyzerFactory old = pre .put (prefix , factory );
406
409
assert old == null :
407
- "prefix '" + prefix + "' used in multiple analyzers" ;
410
+ "prefix '" + prefix + USED_IN_MULTIPLE_MSG ;
408
411
}
409
412
for (String suffix : factory .getSuffixes ()) {
410
413
AnalyzerFactory old = ext .put (suffix , factory );
411
414
assert old == null :
412
- "suffix '" + suffix + "' used in multiple analyzers" ;
415
+ "suffix '" + suffix + USED_IN_MULTIPLE_MSG ;
413
416
}
414
417
for (String magic : factory .getMagicStrings ()) {
415
418
AnalyzerFactory old = magics .put (magic , factory );
416
419
assert old == null :
417
- "magic '" + magic + "' used in multiple analyzers" ;
420
+ "magic '" + magic + USED_IN_MULTIPLE_MSG ;
418
421
}
419
422
matchers .addAll (factory .getMatchers ());
420
423
factories .add (factory );
@@ -596,7 +599,7 @@ public void populateDocument(Document doc, File file, String path, AbstractAnaly
596
599
History history ;
597
600
if ((history = histGuru .getHistory (file )) != null ) {
598
601
List <HistoryEntry > historyEntries = history .getHistoryEntries (1 , 0 );
599
- if (historyEntries .size () > 0 ) {
602
+ if (! historyEntries .isEmpty () ) {
600
603
HistoryEntry histEntry = historyEntries .get (0 );
601
604
doc .add (new TextField (QueryBuilder .LASTREV , histEntry .getRevision (), Store .YES ));
602
605
}
@@ -701,7 +704,7 @@ public static void writeDumpedXref(String contextPath,
701
704
}
702
705
Util .dumpXref (out , xrefTemp , false , contextPath );
703
706
} finally {
704
- xrefTemp .delete ();
707
+ Files .delete (xrefTemp . toPath () );
705
708
}
706
709
}
707
710
@@ -867,19 +870,14 @@ private static AnalyzerFactory findFactory(Class<?> factoryClass)
867
870
*
868
871
* Use if you just want to find file type.
869
872
*
870
- *
871
873
* @param in The input stream containing the data
872
874
* @param file The file name to get the analyzer for
873
875
* @return the analyzer factory to use
874
- * @throws java.io.IOException If a problem occurs while reading the data
876
+ * @throws java.io.IOException If a problem occurred while reading the data
875
877
*/
876
- public static AnalyzerFactory find (InputStream in , String file )
877
- throws IOException {
878
+ public static AnalyzerFactory find (InputStream in , String file ) throws IOException {
878
879
AnalyzerFactory factory = find (file );
879
- // TODO above is not that great, since if 2 analyzers share one extension
880
- // then only the first one registered will own it
881
- // it would be cool if above could return more analyzers and below would
882
- // then decide between them ...
880
+
883
881
if (factory != null ) {
884
882
return factory ;
885
883
}
@@ -1125,8 +1123,7 @@ private static String readOpening(InputStream in, byte[] sig)
1125
1123
int r ;
1126
1124
1127
1125
StringBuilder opening = new StringBuilder ();
1128
- BufferedReader readr = new BufferedReader (
1129
- new InputStreamReader (in , encoding ), OPENING_MAX_CHARS );
1126
+ BufferedReader readr = new BufferedReader (new InputStreamReader (in , encoding ), OPENING_MAX_CHARS );
1130
1127
while ((r = readr .read ()) != -1 ) {
1131
1128
if (++nRead > OPENING_MAX_CHARS ) {
1132
1129
break ;
@@ -1158,10 +1155,8 @@ private static String readOpening(InputStream in, byte[] sig)
1158
1155
1159
1156
// If the opening starts with "#!", then track so that any
1160
1157
// trailing whitespace after the hashbang is ignored.
1161
- if (opening .length () == 2 ) {
1162
- if (opening .charAt (0 ) == '#' && opening .charAt (1 ) == '!' ) {
1163
- postHashbang = true ;
1164
- }
1158
+ if (opening .length () == 2 && opening .charAt (0 ) == '#' && opening .charAt (1 ) == '!' ) {
1159
+ postHashbang = true ;
1165
1160
}
1166
1161
}
1167
1162
@@ -1175,25 +1170,24 @@ private static void addCustomizationKey(String k) {
1175
1170
customizationHashCode = Objects .hash (keys );
1176
1171
}
1177
1172
1178
- private static boolean factoriesDifferent (AnalyzerFactory a ,
1179
- AnalyzerFactory b ) {
1180
- String a_name = null ;
1173
+ private static boolean factoriesDifferent (AnalyzerFactory a , AnalyzerFactory b ) {
1174
+ String aName = null ;
1181
1175
if (a != null ) {
1182
- a_name = a .getName ();
1183
- if (a_name == null ) {
1184
- a_name = a .getClass ().getSimpleName ();
1176
+ aName = a .getName ();
1177
+ if (aName == null ) {
1178
+ aName = a .getClass ().getSimpleName ();
1185
1179
}
1186
1180
}
1187
- String b_name = null ;
1181
+ String bName = null ;
1188
1182
if (b != null ) {
1189
- b_name = b .getName ();
1190
- if (b_name == null ) {
1191
- b_name = b .getClass ().getSimpleName ();
1183
+ bName = b .getName ();
1184
+ if (bName == null ) {
1185
+ bName = b .getClass ().getSimpleName ();
1192
1186
}
1193
1187
}
1194
- if (a_name == null && b_name == null ) {
1188
+ if (aName == null && bName == null ) {
1195
1189
return false ;
1196
1190
}
1197
- return a_name == null || !a_name .equals (b_name );
1191
+ return aName == null || !aName .equals (bName );
1198
1192
}
1199
1193
}
0 commit comments