Skip to content

Commit ae1c323

Browse files
vladakahornace
authored andcommitted
reduce field visibility in SearchHelper
1 parent 5e1eac9 commit ae1c323

File tree

11 files changed

+263
-184
lines changed

11 files changed

+263
-184
lines changed

dev/checkstyle/suppressions.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ Portions Copyright (c) 2018-2020, Chris Fraire <[email protected]>.
4040

4141
<suppress checks="ParameterNumber" files="CtagsReader\.java|Definitions\.java|
4242
|JFlexXrefUtils\.java|FileAnalyzerFactory\.java|SearchController\.java|
43-
|Context\.java|HistoryContext\.java|Suggester\.java|ProjectHelperTestBase\.java" />
43+
|Context\.java|HistoryContext\.java|Suggester\.java|
44+
|ProjectHelperTestBase\.java|SearchHelper\.java" />
4445

4546
<suppress checks="FileLength" files="RuntimeEnvironment\.java" />
4647

opengrok-indexer/src/main/java/org/opengrok/indexer/search/Results.java

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.opengrok.indexer.configuration.RuntimeEnvironment;
5656
import org.opengrok.indexer.history.HistoryException;
5757
import org.opengrok.indexer.logger.LoggerFactory;
58+
import org.opengrok.indexer.search.context.HistoryContext;
5859
import org.opengrok.indexer.util.IOUtils;
5960
import org.opengrok.indexer.util.TandemPath;
6061
import org.opengrok.indexer.web.Prefix;
@@ -161,28 +162,29 @@ public static void prettyPrint(Writer out, SearchHelper sh, int start,
161162
long end)
162163
throws HistoryException, IOException, ClassNotFoundException {
163164
Project p;
164-
String ctxE = Util.URIEncodePath(sh.contextPath);
165-
String xrefPrefix = sh.contextPath + Prefix.XREF_P;
166-
String morePrefix = sh.contextPath + Prefix.MORE_P;
165+
String contextPath = sh.getContextPath();
166+
String ctxE = Util.URIEncodePath(contextPath);
167+
String xrefPrefix = contextPath + Prefix.XREF_P;
168+
String morePrefix = contextPath + Prefix.MORE_P;
167169
String xrefPrefixE = ctxE + Prefix.XREF_P;
168-
File xrefDataDir = new File(sh.dataRoot, Prefix.XREF_P.toString());
170+
File xrefDataDir = new File(sh.getDataRoot(), Prefix.XREF_P.toString());
169171

170172
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
171173

172174
boolean evenRow = true;
173175
out.write("<tbody class=\"search-result\">");
174176
for (Map.Entry<String, ArrayList<Integer>> entry :
175-
createMap(sh.searcher, sh.hits, start, end).entrySet()) {
177+
createMap(sh.getSearcher(), sh.getHits(), start, end).entrySet()) {
176178
String parent = entry.getKey();
177179
out.write("<tr class=\"dir\"><td colspan=\"3\"><a href=\"");
178180
out.write(xrefPrefixE);
179181
out.write(Util.URIEncodePath(parent));
180182
out.write("/\">");
181183
out.write(htmlize(parent));
182184
out.write("/</a>");
183-
if (sh.desc != null) {
185+
if (sh.getDesc() != null) {
184186
out.write(" - <i>");
185-
out.write(sh.desc.get(parent));
187+
out.write(sh.getDesc().get(parent));
186188
out.write("</i>");
187189
}
188190

@@ -201,7 +203,7 @@ public static void prettyPrint(Writer out, SearchHelper sh, int start,
201203

202204
out.write("</td></tr>");
203205
for (int docId : entry.getValue()) {
204-
Document doc = sh.searcher.doc(docId);
206+
Document doc = sh.getSearcher().doc(docId);
205207
String rpath = doc.get(QueryBuilder.PATH);
206208
String rpathE = Util.URIEncodePath(rpath);
207209
if (evenRow) {
@@ -210,7 +212,7 @@ public static void prettyPrint(Writer out, SearchHelper sh, int start,
210212
out.write("<tr>");
211213
}
212214
evenRow = !evenRow;
213-
Util.writeHAD(out, sh.contextPath, rpathE, false);
215+
Util.writeHAD(out, sh.getContextPath(), rpathE, false);
214216
out.write("<td class=\"f\"><a href=\"");
215217
out.write(xrefPrefixE);
216218
out.write(rpathE);
@@ -222,26 +224,28 @@ public static void prettyPrint(Writer out, SearchHelper sh, int start,
222224
out.write(htmlize(rpath.substring(rpath.lastIndexOf('/') + 1)));
223225
out.write("</a>");
224226
out.write("</td><td><code class=\"con\">");
225-
if (sh.sourceContext != null) {
227+
if (sh.getSourceContext() != null) {
226228
AbstractAnalyzer.Genre genre = AbstractAnalyzer.Genre.get(
227229
doc.get(QueryBuilder.T));
228-
if (AbstractAnalyzer.Genre.XREFABLE == genre && sh.summarizer != null) {
230+
Summarizer summarizer = sh.getSummarizer();
231+
if (AbstractAnalyzer.Genre.XREFABLE == genre && summarizer != null) {
229232
String xtags = getTags(xrefDataDir, rpath, env.isCompressXref());
230233
// FIXME use Highlighter from lucene contrib here,
231234
// instead of summarizer, we'd also get rid of
232235
// apache lucene in whole source ...
233-
out.write(sh.summarizer.getSummary(xtags).toString());
234-
} else if (AbstractAnalyzer.Genre.HTML == genre && sh.summarizer != null) {
235-
String htags = getTags(sh.sourceRoot, rpath, false);
236-
out.write(sh.summarizer.getSummary(htags).toString());
236+
out.write(summarizer.getSummary(xtags).toString());
237+
} else if (AbstractAnalyzer.Genre.HTML == genre && summarizer != null) {
238+
String htags = getTags(sh.getSourceRoot(), rpath, false);
239+
out.write(summarizer.getSummary(htags).toString());
237240
} else if (genre == AbstractAnalyzer.Genre.PLAIN) {
238241
printPlain(fargs, doc, docId, rpath);
239242
}
240243
}
241244

242-
if (sh.historyContext != null) {
243-
sh.historyContext.getContext(new File(sh.sourceRoot, rpath),
244-
rpath, out, sh.contextPath);
245+
HistoryContext historyContext = sh.getHistoryContext();
246+
if (historyContext != null) {
247+
historyContext.getContext(new File(sh.getSourceRoot(), rpath),
248+
rpath, out, sh.getContextPath());
245249
}
246250
out.write("</code></td></tr>\n");
247251
}
@@ -265,10 +269,10 @@ private static void printLastEditedDate(final Writer out, final Document doc) th
265269
private static void printPlain(PrintPlainFinalArgs fargs, Document doc,
266270
int docId, String rpath) throws ClassNotFoundException, IOException {
267271

268-
fargs.shelp.sourceContext.toggleAlt();
272+
fargs.shelp.getSourceContext().toggleAlt();
269273

270-
boolean didPresentNew = fargs.shelp.sourceContext.getContext2(fargs.env,
271-
fargs.shelp.searcher, docId, fargs.out, fargs.xrefPrefix,
274+
boolean didPresentNew = fargs.shelp.getSourceContext().getContext2(fargs.env,
275+
fargs.shelp.getSearcher(), docId, fargs.out, fargs.xrefPrefix,
272276
fargs.morePrefix, true, fargs.tabSize);
273277

274278
if (!didPresentNew) {
@@ -289,12 +293,12 @@ private static void printPlain(PrintPlainFinalArgs fargs, Document doc,
289293
} else {
290294
scopes = new Scopes();
291295
}
292-
boolean isDefSearch = fargs.shelp.builder.isDefSearch();
296+
boolean isDefSearch = fargs.shelp.getBuilder().isDefSearch();
293297
// SRCROOT is read with UTF-8 as a default.
294-
File sourceFile = new File(fargs.shelp.sourceRoot, rpath);
298+
File sourceFile = new File(fargs.shelp.getSourceRoot(), rpath);
295299
try (FileInputStream fis = new FileInputStream(sourceFile);
296300
Reader r = IOUtils.createBOMStrippedReader(fis, StandardCharsets.UTF_8.name())) {
297-
fargs.shelp.sourceContext.getContext(r, fargs.out,
301+
fargs.shelp.getSourceContext().getContext(r, fargs.out,
298302
fargs.xrefPrefix, fargs.morePrefix, rpath, tags, true,
299303
isDefSearch, null, scopes);
300304
} catch (IOException ex) {

opengrok-indexer/src/main/java/org/opengrok/indexer/web/Prefix.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public enum Prefix {
6363
DOWNLOAD_P("/download"),
6464
/** Raw file display (link prefix). */
6565
RAW_P("/raw"),
66-
/** Full blown search from main page or top bar (link prefix). */
66+
/** Full-blown search from main page or top bar (link prefix). */
6767
SEARCH_P("/search"),
6868
/** Search from cross reference, can lead to direct match (which opens
6969
* directly) or to a matches Summary page. */

0 commit comments

Comments
 (0)