Skip to content

Commit c998263

Browse files
author
Vladimir Kotal
committed
refactor for better readability
1 parent 4cb07dc commit c998263

File tree

1 file changed

+27
-34
lines changed

1 file changed

+27
-34
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexDatabase.java

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,8 +1075,6 @@ private void indexDown(File dir, String parent, IndexDownArgs args)
10751075
}
10761076
Arrays.sort(files, FILENAME_COMPARATOR);
10771077

1078-
final boolean[] outIsXrefWriter = new boolean[1];
1079-
10801078
for (File file : files) {
10811079
String path = parent + File.separator + file.getName();
10821080
if (!accept(dir, file, outLocalRelPath)) {
@@ -1122,15 +1120,11 @@ private void indexDown(File dir, String parent, IndexDownArgs args)
11221120
}
11231121
}
11241122

1125-
/**
1126-
* If the file was not modified, probably skip to the
1127-
* next one.
1128-
*/
1129-
if (uidIter != null && uidIter.term() != null
1130-
&& uidIter.term().bytesEquals(buid)) {
1131-
boolean chkres = chkSettings(outIsXrefWriter, file,
1132-
path) && (!outIsXrefWriter[0] ||
1133-
checkXrefExistence(path));
1123+
// If the file was not modified, probably skip to the next one.
1124+
if (uidIter != null && uidIter.term() != null &&
1125+
uidIter.term().bytesEquals(buid)) {
1126+
1127+
boolean chkres = checkSettings(file, path);
11341128
if (!chkres) {
11351129
removeFile(false);
11361130
}
@@ -1666,16 +1660,15 @@ private void finishWriting() throws IOException {
16661660
/**
16671661
* Verify TABSIZE, and evaluate AnalyzerGuru version together with ZVER --
16681662
* or return a value to indicate mismatch.
1669-
* @param outIsXrefWriter boolean array. After return its first member will
1670-
* contain return value of {@code isXrefWriter()}
1671-
* for the file analyzer matching given file
16721663
* @param file the source file object
16731664
* @param path the source file path
16741665
* @return {@code false} if a mismatch is detected
16751666
*/
1676-
private boolean chkSettings(boolean[] outIsXrefWriter, File file,
1677-
String path) throws IOException {
1667+
private boolean checkSettings(File file,
1668+
String path) throws IOException {
16781669

1670+
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
1671+
boolean outIsXrefWriter = false;
16791672
int reqTabSize = project != null && project.hasTabSizeSetting() ?
16801673
project.getTabSize() : 0;
16811674
Integer actTabSize = settings.getTabSize();
@@ -1697,7 +1690,7 @@ private boolean chkSettings(boolean[] outIsXrefWriter, File file,
16971690

16981691
long reqGuruVersion = AnalyzerGuru.getVersionNo();
16991692
Long actGuruVersion = settings.getAnalyzerGuruVersion();
1700-
/**
1693+
/*
17011694
* For an older OpenGrok index that does not yet have a defined,
17021695
* stored analyzerGuruVersion, break so that no extra work is done.
17031696
* After a re-index, the guru version check will be active.
@@ -1722,7 +1715,7 @@ private boolean chkSettings(boolean[] outIsXrefWriter, File file,
17221715
fa = fac.getAnalyzer();
17231716
}
17241717
} else {
1725-
/**
1718+
/*
17261719
* If the stored guru version does not match, re-verify the
17271720
* selection of analyzer or return a value to indicate the
17281721
* analyzer is now mis-matched.
@@ -1753,7 +1746,7 @@ private boolean chkSettings(boolean[] outIsXrefWriter, File file,
17531746
}
17541747

17551748
if (fa != null) {
1756-
outIsXrefWriter[0] = isXrefWriter(fa);
1749+
outIsXrefWriter = isXrefWriter(fa);
17571750
}
17581751

17591752
// The versions checks have passed.
@@ -1764,8 +1757,16 @@ private boolean chkSettings(boolean[] outIsXrefWriter, File file,
17641757
return false;
17651758
}
17661759

1767-
// Assume "true" if otherwise no discrepancies were observed.
1768-
return true;
1760+
// If the economy mode is on, this should be treated as a match.
1761+
if (!env.isGenerateHtml()) {
1762+
if (xrefExistsFor(path)) {
1763+
LOGGER.log(Level.FINEST, "Extraneous {0} , removing its xref file", path);
1764+
removeXrefFile(path);
1765+
}
1766+
return true;
1767+
}
1768+
1769+
return (!outIsXrefWriter || xrefExistsFor(path));
17691770
}
17701771

17711772
private void writeAnalysisSettings() throws IOException {
@@ -1785,22 +1786,14 @@ private IndexAnalysisSettings2 readAnalysisSettings() throws IOException {
17851786
return dao.read(reader);
17861787
}
17871788

1788-
private boolean checkXrefExistence(String path) {
1789+
private boolean xrefExistsFor(String path) {
17891790
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
1790-
boolean chkres = whatXrefFile(path, env.isCompressXref()).exists();
1791-
1792-
if (!env.isGenerateHtml()) {
1793-
if (chkres) {
1794-
LOGGER.log(Level.FINEST, "Extraneous {0}", path);
1795-
removeXrefFile(path);
1796-
}
1797-
return true;
1798-
}
1799-
1800-
if (!chkres) {
1791+
if (!whatXrefFile(path, env.isCompressXref()).exists()) {
18011792
LOGGER.log(Level.FINEST, "Missing {0}", path);
1793+
return false;
18021794
}
1803-
return chkres;
1795+
1796+
return true;
18041797
}
18051798

18061799
private class IndexDownArgs {

0 commit comments

Comments
 (0)