Skip to content

Commit c6f0939

Browse files
ahornaceVladimir Kotal
authored andcommitted
Code cleanup
1 parent e4c9c2b commit c6f0939

File tree

163 files changed

+897
-1532
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+897
-1532
lines changed

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,20 +187,17 @@ public class AnalyzerGuru {
187187
/**
188188
* Descending string length comparator for magics.
189189
*/
190-
private static final Comparator<String> descStrlenComparator =
191-
new Comparator<String>() {
192-
@Override public int compare(String s1, String s2) {
193-
// DESC: s2 length <=> s1 length
194-
int cmp = Integer.compare(s2.length(), s1.length());
195-
if (cmp != 0) {
196-
return cmp;
197-
}
198-
199-
// the Comparator must also be "consistent with equals", so check
200-
// string contents too when (length)cmp == 0. (ASC: s1 <=> s2.)
201-
cmp = s1.compareTo(s2);
190+
private static final Comparator<String> descStrlenComparator = (s1, s2) -> {
191+
// DESC: s2 length <=> s1 length
192+
int cmp = Integer.compare(s2.length(), s1.length());
193+
if (cmp != 0) {
202194
return cmp;
203195
}
196+
197+
// the Comparator must also be "consistent with equals", so check
198+
// string contents too when (length)cmp == 0. (ASC: s1 <=> s2.)
199+
cmp = s1.compareTo(s2);
200+
return cmp;
204201
};
205202

206203
/**

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

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.opengrok.indexer.util.StringUtils;
2727

2828
import java.util.ArrayList;
29+
import java.util.Comparator;
2930
import java.util.List;
3031
import java.util.Locale;
3132
import java.util.Map;
@@ -182,40 +183,31 @@ private static String[] splitLines(String str, int width) {
182183
b.setLength(0);
183184
}
184185

185-
return res.stream().toArray(String[]::new);
186+
return res.toArray(String[]::new);
186187
}
187188

188189
private static List<MappedFactory> byKey(Map<String, AnalyzerFactory> mapped) {
189-
190-
List<MappedFactory> res = mapped.entrySet().stream().map((t) -> {
191-
return new MappedFactory(t.getKey(), t.getValue());
192-
}).collect(Collectors.toList());
193-
194-
res.sort((mf1, mf2) -> {
195-
return mf1.key.toLowerCase(Locale.ROOT).compareTo(
196-
mf2.key.toLowerCase(Locale.ROOT));
197-
});
198-
return res;
190+
return mapped.entrySet().stream()
191+
.map(t -> new MappedFactory(t.getKey(), t.getValue()))
192+
.sorted(Comparator.comparing(mf -> mf.key.toLowerCase(Locale.ROOT)))
193+
.collect(Collectors.toList());
199194
}
200195

201196
private static List<MappedFactory> byFactory(Map<String, AnalyzerFactory> mapped) {
202-
203-
List<MappedFactory> res = mapped.entrySet().stream().map((t) -> {
204-
return new MappedFactory(t.getKey(), t.getValue());
205-
}).collect(Collectors.toList());
206-
207-
res.sort((mf1, mf2) -> {
208-
String r1 = reportable(mf1.fac);
209-
String r2 = reportable(mf2.fac);
210-
int cmp = r1.toLowerCase(Locale.ROOT).compareTo(
211-
r2.toLowerCase(Locale.ROOT));
212-
if (cmp != 0) {
213-
return cmp;
214-
}
215-
return mf1.key.toLowerCase(Locale.ROOT).compareTo(
216-
mf2.key.toLowerCase(Locale.ROOT));
217-
});
218-
return res;
197+
return mapped.entrySet().stream()
198+
.map(t -> new MappedFactory(t.getKey(), t.getValue()))
199+
.sorted((mf1, mf2) -> {
200+
String r1 = reportable(mf1.fac);
201+
String r2 = reportable(mf2.fac);
202+
int cmp = r1.toLowerCase(Locale.ROOT).compareTo(
203+
r2.toLowerCase(Locale.ROOT));
204+
if (cmp != 0) {
205+
return cmp;
206+
}
207+
return mf1.key.toLowerCase(Locale.ROOT).compareTo(
208+
mf2.key.toLowerCase(Locale.ROOT));
209+
})
210+
.collect(Collectors.toList());
219211
}
220212

221213
private static class MappedFactory {

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

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

2020
/*
21-
* Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.analysis;
@@ -115,15 +115,12 @@ public static int translate(String line, int column, int tabSize) {
115115
int newColumn = 0;
116116
for (int i = 0; i < column; ++i) {
117117
char c = line.charAt(i);
118-
switch (c) {
119-
case '\t':
120-
// Fill up with spaces up to the next tab stop
121-
newColumn += tabSize - (newColumn % tabSize);
122-
break;
123-
default:
124-
// \r or \n are not expected so do not handle specially.
125-
++newColumn;
126-
break;
118+
if (c == '\t') {
119+
// Fill up with spaces up to the next tab stop
120+
newColumn += tabSize - (newColumn % tabSize);
121+
} else {
122+
// \r or \n are not expected so do not handle specially.
123+
++newColumn;
127124
}
128125
}
129126

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, 2018, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.analysis;
2525

2626
import java.io.IOException;
2727
import java.io.InputStream;
28-
import java.util.Arrays;
2928
import java.util.Collections;
3029
import java.util.List;
3130

@@ -82,7 +81,7 @@ private static <T> List<T> asList(T[] a) {
8281
if (a == null) {
8382
return Collections.emptyList();
8483
}
85-
return Collections.unmodifiableList(Arrays.asList(a));
84+
return List.of(a);
8685
}
8786

8887
@Override

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

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

2020
/*
21-
* Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2011, Jens Elkner.
2323
* Portions Copyright (c) 2017, 2020, Chris Fraire <[email protected]>.
2424
*/
@@ -144,8 +144,7 @@ public static String disjointSpan(Writer out, String className,
144144
* @return generated span id
145145
*/
146146
public static String generateId(Scope scope) {
147-
String name = Integer.toString(scope.getLineFrom()) + scope.getName()
148-
+ scope.getSignature();
147+
String name = scope.getLineFrom() + scope.getName() + scope.getSignature();
149148
int hash = name.hashCode();
150149
return "scope_id_" + Integer.toHexString(hash);
151150
}
@@ -344,27 +343,16 @@ public static void writeSymbolTable(Writer out, Definitions defs)
344343
}
345344

346345
// We want the symbol table to be sorted
347-
Comparator<Tag> cmp = (Tag tag1, Tag tag2) -> {
348-
// Order by symbol name, and then by line number if multiple
349-
// definitions use the same symbol name
350-
int ret = tag1.symbol.compareTo(tag2.symbol);
351-
if (ret == 0) {
352-
ret = tag1.line - tag2.line;
353-
}
354-
return ret;
355-
};
346+
// Order by symbol name, and then by line number if multiple
347+
// definitions use the same symbol name
348+
Comparator<Tag> cmp = Comparator.comparing((Tag tag) -> tag.symbol).thenComparingInt(tag -> tag.line);
356349

357-
Map<String, SortedSet<Tag>> symbols
358-
= new HashMap<>();
350+
Map<String, SortedSet<Tag>> symbols = new HashMap<>();
359351

360352
for (Tag tag : defs.getTags()) {
361353
XrefStyle style = XrefStyle.getStyle(tag.type);
362354
if (style != null && style.title != null) {
363-
SortedSet<Tag> tags = symbols.get(style.name);
364-
if (tags == null) {
365-
tags = new TreeSet<>(cmp);
366-
symbols.put(style.name, tags);
367-
}
355+
SortedSet<Tag> tags = symbols.computeIfAbsent(style.name, k -> new TreeSet<>(cmp));
368356
tags.add(tag);
369357
}
370358
}

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

Lines changed: 1 addition & 5 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) 2018, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.analysis;
@@ -132,8 +132,4 @@ public void reset() throws IOException {
132132
startPosition = 0;
133133
}
134134

135-
@Override
136-
public final void close() throws IOException {
137-
super.close();
138-
}
139135
}

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

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

2020
/*
21-
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opengrok.indexer.analysis;
2424

@@ -73,7 +73,7 @@ public boolean matches(int line) {
7373

7474
@Override
7575
public int compareTo(Scope o) {
76-
return lineFrom < o.lineFrom ? -1 : lineFrom > o.lineFrom ? 1 : 0;
76+
return Integer.compare(lineFrom, o.lineFrom);
7777
}
7878

7979
public int getLineFrom() {
@@ -121,7 +121,7 @@ public void setSignature(String signature) {
121121
public static final Scope GLOBAL_SCOPE = new Scope(0, 0, "global", null, null);
122122

123123
// tree of scopes sorted by starting line
124-
private TreeSet<Scope> scopes = new TreeSet<>();
124+
private final TreeSet<Scope> scopes = new TreeSet<>();
125125

126126
public Scopes() {
127127
// nothing to do here

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/document/MandocRunner.java

Lines changed: 4 additions & 6 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
* Copyright (c) 2017, 2018, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.analysis.document;
@@ -70,7 +70,7 @@ public void setOSOverride( String value ) {
7070
}
7171

7272
/**
73-
* Starts a run of the mandoc binary to receive input from {@link write}.
73+
* Starts a run of the mandoc binary to receive input from {@link #write}.
7474
* @throws IOException thrown if a read or write to the mandoc process
7575
* fails.
7676
* @throws MandocException if no mandoc binary is defined
@@ -102,9 +102,7 @@ public void start() throws IOException, MandocException {
102102

103103
if (LOGGER.isLoggable(Level.FINER)) {
104104
StringBuilder sb = new StringBuilder();
105-
command.forEach((s) -> {
106-
sb.append(s).append(" ");
107-
});
105+
command.forEach(s -> sb.append(s).append(" "));
108106
String cmd = sb.toString();
109107
LOGGER.log(Level.FINER, "Executing mandoc command [{0}]", cmd);
110108
}
@@ -175,7 +173,7 @@ public String finish() throws IOException, MandocException {
175173
* Writes a character to the input of the run of mandoc.
176174
* @param s the string to write.
177175
* @throws IllegalStateException thrown if the runner was not successfully
178-
* {@link start}ed.
176+
* {@link #start}ed.
179177
* @throws IOException thrown if a write to the mandoc process fails.
180178
*/
181179
public void write(String s) throws IOException {

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/executables/ELFAnalyzer.java

Lines changed: 2 additions & 5 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) 2018, 2020, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.analysis.executables;
@@ -166,10 +166,7 @@ public String parseELF(FileChannel fch) throws IOException {
166166
}
167167

168168
private boolean isReadable(int c) {
169-
if (c > ' ' && c <= 127) {
170-
return true;
171-
}
172-
return false;
169+
return c > ' ' && c <= 127;
173170
}
174171

175172
private String getName(int tab, int stroff, MappedByteBuffer fmap) {

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/plain/PlainAnalyzerFactory.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, 2018, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.analysis.plain;
2525

2626
import java.io.IOException;
2727
import java.io.InputStream;
28+
import java.nio.charset.StandardCharsets;
29+
2830
import org.opengrok.indexer.analysis.AbstractAnalyzer;
2931
import org.opengrok.indexer.analysis.AnalyzerFactory;
3032
import org.opengrok.indexer.analysis.FileAnalyzerFactory;
@@ -66,7 +68,7 @@ private boolean isPlainText(byte[] content) throws IOException {
6668
if (lengthBOM > 0) {
6769
return true;
6870
}
69-
String ascii = new String(content, "US-ASCII");
71+
String ascii = new String(content, StandardCharsets.US_ASCII);
7072
return isPlainText(ascii);
7173
}
7274

0 commit comments

Comments
 (0)