Skip to content

Commit 4323bb1

Browse files
author
Vladimir Kotal
authored
Sonar fixes in Definitions (#3807)
* rename variables * use addAll() * more camel casing * make the used field private * rename symbols to more descriptive name * remove extraneous keywords * retain field names for serialization
1 parent 0516dd2 commit 4323bb1

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected LineTagMap() {
6666
this.sym_tags = new HashMap<>();
6767
}
6868
}
69-
// line -> tag_map
69+
// line number -> tag map
7070
private final Map<Integer, LineTagMap> line_maps;
7171

7272
/**
@@ -128,9 +128,9 @@ public boolean hasDefinitionAt(String symbol, int lineNumber, String[] strs) {
128128

129129
// Get tag info
130130
if (lines != null && lines.contains(lineNumber)) {
131-
LineTagMap line_map = line_maps.get(lineNumber);
132-
if (line_map != null) {
133-
for (Tag tag : line_map.sym_tags.get(symbol)) {
131+
LineTagMap lineMap = line_maps.get(lineNumber);
132+
if (lineMap != null) {
133+
for (Tag tag : lineMap.sym_tags.get(symbol)) {
134134
if (tag.used) {
135135
continue;
136136
}
@@ -183,15 +183,13 @@ public List<Tag> getTags() {
183183
* @return list of tags
184184
*/
185185
public List<Tag> getTags(int line) {
186-
LineTagMap line_map = line_maps.get(line);
186+
LineTagMap lineMap = line_maps.get(line);
187187
List<Tag> result = null;
188188

189-
if (line_map != null) {
189+
if (lineMap != null) {
190190
result = new ArrayList<>();
191-
for (Set<Tag> ltags : line_map.sym_tags.values()) {
192-
for (Tag tag : ltags) {
193-
result.add(tag);
194-
}
191+
for (Set<Tag> ltags : lineMap.sym_tags.values()) {
192+
result.addAll(ltags);
195193
}
196194
}
197195

@@ -243,7 +241,7 @@ public static class Tag implements Serializable {
243241
/**
244242
* A non-serialized marker for marking a tag to avoid its reuse.
245243
*/
246-
public transient boolean used;
244+
private transient boolean used;
247245

248246
protected Tag(int line, String symbol, String type, String text,
249247
String namespace, String signature, int lineStart,
@@ -266,9 +264,9 @@ public void addTag(int line, String symbol, String type, String text,
266264

267265
public void addTag(int line, String symbol, String type, String text,
268266
String namespace, String signature, int lineStart, int lineEnd) {
269-
Tag new_tag = new Tag(line, symbol, type, text, namespace, signature,
267+
Tag newTag = new Tag(line, symbol, type, text, namespace, signature,
270268
lineStart, lineEnd);
271-
tags.add(new_tag);
269+
tags.add(newTag);
272270
Set<Integer> lines = symbols.get(symbol);
273271
if (lines == null) {
274272
lines = new HashSet<>();
@@ -278,19 +276,19 @@ public void addTag(int line, String symbol, String type, String text,
278276
lines.add(aLine);
279277

280278
// Get per line map
281-
LineTagMap line_map = line_maps.get(aLine);
282-
if (line_map == null) {
283-
line_map = new LineTagMap();
284-
line_maps.put(aLine, line_map);
279+
LineTagMap lineMap = line_maps.get(aLine);
280+
if (lineMap == null) {
281+
lineMap = new LineTagMap();
282+
line_maps.put(aLine, lineMap);
285283
}
286284

287285
// Insert sym->tag map for this line
288-
Set<Tag> ltags = line_map.sym_tags.get(symbol);
286+
Set<Tag> ltags = lineMap.sym_tags.get(symbol);
289287
if (ltags == null) {
290288
ltags = new HashSet<>();
291-
line_map.sym_tags.put(symbol, ltags);
289+
lineMap.sym_tags.put(symbol, ltags);
292290
}
293-
ltags.add(new_tag);
291+
ltags.add(newTag);
294292
}
295293

296294
/**

opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/pascal/PascalXrefTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@
3232
/**
3333
* Tests the {@link PascalXref} class.
3434
*/
35-
public class PascalXrefTest extends XrefTestBase {
35+
class PascalXrefTest extends XrefTestBase {
3636

3737
@Test
38-
public void sampleTest() throws IOException {
38+
void sampleTest() throws IOException {
3939
writeAndCompare(new PascalAnalyzerFactory(),
4040
"analysis/pascal/sample.pas",
4141
"analysis/pascal/sample_xref.html",
4242
readTagsFromResource("analysis/pascal/sampletags"), 423);
4343
}
4444

4545
@Test
46-
public void shouldCloseTruncatedStringSpan() throws IOException {
46+
void shouldCloseTruncatedStringSpan() throws IOException {
4747
writeAndCompare(new PascalAnalyzerFactory(),
4848
"analysis/pascal/truncated.pas",
4949
"analysis/pascal/truncated_xref.html", null, 1);

0 commit comments

Comments
 (0)