Skip to content

Commit 78eb695

Browse files
committed
Extract line information as injectible lines
For SymDB we add injectible lines into method scope to provide information about executable line of code where we can put a line probe. We are using the LineNumberTable of each method, sort and make ranges about them.
1 parent 23d468b commit 78eb695

File tree

5 files changed

+88
-17
lines changed

5 files changed

+88
-17
lines changed

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/symbol/Scope.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,16 @@ public Builder scopes(List<Scope> scopes) {
184184

185185
public Scope build() {
186186
return new Scope(
187-
scopeType, sourceFile, startLine, endLine, name, hasInjectibleLines, injectibleLines, languageSpecifics, symbols, scopes);
187+
scopeType,
188+
sourceFile,
189+
startLine,
190+
endLine,
191+
name,
192+
hasInjectibleLines,
193+
injectibleLines,
194+
languageSpecifics,
195+
symbols,
196+
scopes);
188197
}
189198
}
190199
}

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/symbol/SymbolExtractor.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,17 +443,20 @@ static List<Scope.LineRange> buildRanges(List<Integer> sortedLineNo) {
443443
int start = sortedLineNo.get(0);
444444
int previous = start;
445445
int i = 1;
446+
outer:
446447
while (i < sortedLineNo.size()) {
447-
int currentLine = sortedLineNo.get(i);
448-
while (currentLine == previous + 1) {
448+
int currentLineNo = sortedLineNo.get(i);
449+
while (currentLineNo == previous + 1) {
449450
i++;
450451
previous++;
451452
if (i < sortedLineNo.size()) {
452-
currentLine = sortedLineNo.get(i);
453+
currentLineNo = sortedLineNo.get(i);
454+
} else {
455+
break outer;
453456
}
454457
}
455458
ranges.add(new Scope.LineRange(start, previous));
456-
start = currentLine;
459+
start = currentLineNo;
457460
previous = start;
458461
i++;
459462
}
@@ -502,7 +505,8 @@ public static class MethodLineInfo {
502505
final Map<Label, Integer> lineMap;
503506
final List<Scope.LineRange> ranges;
504507

505-
public MethodLineInfo(int start, int end, Map<Label, Integer> lineMap, List<Scope.LineRange> ranges) {
508+
public MethodLineInfo(
509+
int start, int end, Map<Label, Integer> lineMap, List<Scope.LineRange> ranges) {
506510
this.start = start;
507511
this.end = end;
508512
this.lineMap = lineMap;

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/sink/SymbolSinkTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void testSimpleFlush() {
4040
assertEquals("file", symbolContent.getPartName());
4141
assertEquals("file.json", symbolContent.getFileName());
4242
assertEquals(
43-
"{\"language\":\"JAVA\",\"scopes\":[{\"end_line\":0,\"scope_type\":\"JAR\",\"start_line\":0}],\"service\":\"service1\"}",
43+
"{\"language\":\"JAVA\",\"scopes\":[{\"end_line\":0,\"has_injectible_lines\":false,\"scope_type\":\"JAR\",\"start_line\":0}],\"service\":\"service1\"}",
4444
new String(symbolContent.getContent()));
4545
}
4646

@@ -109,12 +109,12 @@ public void splitByJarScopes() {
109109
}
110110

111111
@Test
112-
public void splitTootManyJarScopes() {
112+
public void splitTooManyJarScopes() {
113113
SymbolUploaderMock symbolUploaderMock = new SymbolUploaderMock();
114114
Config config = mock(Config.class);
115115
when(config.getServiceName()).thenReturn("service1");
116116
when(config.isSymbolDatabaseCompressed()).thenReturn(false);
117-
SymbolSink symbolSink = new SymbolSink(config, symbolUploaderMock, 2048);
117+
SymbolSink symbolSink = new SymbolSink(config, symbolUploaderMock, 4096);
118118
final int NUM_JAR_SCOPES = 21;
119119
for (int i = 0; i < NUM_JAR_SCOPES; i++) {
120120
symbolSink.addScope(

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/symbol/SymbolExtractionTransformerTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ public void symbolExtraction01() throws IOException, URISyntaxException {
7373
Scope classScope = symbolSinkMock.jarScopes.get(0).getScopes().get(0);
7474
assertScope(classScope, ScopeType.CLASS, CLASS_NAME, 2, 20, SOURCE_FILE, 2, 0);
7575
assertScope(classScope.getScopes().get(0), ScopeType.METHOD, "<init>", 2, 2, SOURCE_FILE, 0, 0);
76+
assertLineRanges(classScope.getScopes().get(0), "2-2");
7677
Scope mainMethodScope = classScope.getScopes().get(1);
7778
assertScope(mainMethodScope, ScopeType.METHOD, "main", 4, 20, SOURCE_FILE, 1, 1);
79+
assertLineRanges(mainMethodScope, "4-15", "17-17", "19-20");
7880
assertSymbol(
7981
mainMethodScope.getSymbols().get(0), SymbolType.ARG, "arg", String.class.getTypeName(), 4);
8082
Scope mainMethodLocalScope = mainMethodScope.getScopes().get(0);
@@ -140,8 +142,10 @@ public void symbolExtraction02() throws IOException, URISyntaxException {
140142
Scope classScope = symbolSinkMock.jarScopes.get(0).getScopes().get(0);
141143
assertScope(classScope, ScopeType.CLASS, CLASS_NAME, 3, 6, SOURCE_FILE, 2, 0);
142144
assertScope(classScope.getScopes().get(0), ScopeType.METHOD, "<init>", 3, 3, SOURCE_FILE, 0, 0);
145+
assertLineRanges(classScope.getScopes().get(0), "3-3");
143146
Scope mainMethodScope = classScope.getScopes().get(1);
144147
assertScope(mainMethodScope, ScopeType.METHOD, "main", 5, 6, SOURCE_FILE, 1, 1);
148+
assertLineRanges(mainMethodScope, "5-6");
145149
assertSymbol(
146150
mainMethodScope.getSymbols().get(0), SymbolType.ARG, "arg", String.class.getTypeName(), 5);
147151
Scope mainMethodLocalScope = mainMethodScope.getScopes().get(0);
@@ -169,8 +173,10 @@ public void symbolExtraction03() throws IOException, URISyntaxException {
169173
Scope classScope = symbolSinkMock.jarScopes.get(0).getScopes().get(0);
170174
assertScope(classScope, ScopeType.CLASS, CLASS_NAME, 4, 28, SOURCE_FILE, 2, 0);
171175
assertScope(classScope.getScopes().get(0), ScopeType.METHOD, "<init>", 4, 4, SOURCE_FILE, 0, 0);
176+
assertLineRanges(classScope.getScopes().get(0), "4-4");
172177
Scope mainMethodScope = classScope.getScopes().get(1);
173178
assertScope(mainMethodScope, ScopeType.METHOD, "main", 6, 28, SOURCE_FILE, 1, 1);
179+
assertLineRanges(mainMethodScope, "6-21", "23-24", "27-28");
174180
assertSymbol(
175181
mainMethodScope.getSymbols().get(0), SymbolType.ARG, "arg", String.class.getTypeName(), 6);
176182
Scope mainMethodLocalScope = mainMethodScope.getScopes().get(0);
@@ -238,8 +244,10 @@ public void symbolExtraction04() throws IOException, URISyntaxException {
238244
Scope classScope = symbolSinkMock.jarScopes.get(0).getScopes().get(0);
239245
assertScope(classScope, ScopeType.CLASS, CLASS_NAME, 3, 18, SOURCE_FILE, 2, 0);
240246
assertScope(classScope.getScopes().get(0), ScopeType.METHOD, "<init>", 3, 3, SOURCE_FILE, 0, 0);
247+
assertLineRanges(classScope.getScopes().get(0), "3-3");
241248
Scope mainMethodScope = classScope.getScopes().get(1);
242249
assertScope(mainMethodScope, ScopeType.METHOD, "main", 5, 18, SOURCE_FILE, 1, 1);
250+
assertLineRanges(mainMethodScope, "5-12", "14-15", "18-18");
243251
assertSymbol(
244252
mainMethodScope.getSymbols().get(0), SymbolType.ARG, "arg", String.class.getTypeName(), 5);
245253
Scope mainMethodLocalScope = mainMethodScope.getScopes().get(0);
@@ -311,8 +319,10 @@ public void symbolExtraction05() throws IOException, URISyntaxException {
311319
Scope classScope = symbolSinkMock.jarScopes.get(0).getScopes().get(0);
312320
assertScope(classScope, ScopeType.CLASS, CLASS_NAME, 3, 15, SOURCE_FILE, 2, 0);
313321
assertScope(classScope.getScopes().get(0), ScopeType.METHOD, "<init>", 3, 3, SOURCE_FILE, 0, 0);
322+
assertLineRanges(classScope.getScopes().get(0), "3-3");
314323
Scope mainMethodScope = classScope.getScopes().get(1);
315324
assertScope(mainMethodScope, ScopeType.METHOD, "main", 5, 15, SOURCE_FILE, 1, 1);
325+
assertLineRanges(mainMethodScope, "5-15");
316326
assertSymbol(
317327
mainMethodScope.getSymbols().get(0), SymbolType.ARG, "arg", String.class.getTypeName(), 5);
318328
Scope mainMethodLocalScope = mainMethodScope.getScopes().get(0);
@@ -358,8 +368,10 @@ public void symbolExtraction06() throws IOException, URISyntaxException {
358368
Scope classScope = symbolSinkMock.jarScopes.get(0).getScopes().get(0);
359369
assertScope(classScope, ScopeType.CLASS, CLASS_NAME, 3, 13, SOURCE_FILE, 2, 0);
360370
assertScope(classScope.getScopes().get(0), ScopeType.METHOD, "<init>", 3, 3, SOURCE_FILE, 0, 0);
371+
assertLineRanges(classScope.getScopes().get(0), "3-3");
361372
Scope mainMethodScope = classScope.getScopes().get(1);
362373
assertScope(mainMethodScope, ScopeType.METHOD, "main", 5, 13, SOURCE_FILE, 1, 1);
374+
assertLineRanges(mainMethodScope, "5-5", "7-11", "13-13");
363375
assertSymbol(
364376
mainMethodScope.getSymbols().get(0), SymbolType.ARG, "arg", String.class.getTypeName(), 5);
365377
Scope mainMethodLocalScope = mainMethodScope.getScopes().get(0);
@@ -405,8 +417,10 @@ public void symbolExtraction07() throws IOException, URISyntaxException {
405417
Scope classScope = symbolSinkMock.jarScopes.get(0).getScopes().get(0);
406418
assertScope(classScope, ScopeType.CLASS, CLASS_NAME, 3, 10, SOURCE_FILE, 2, 0);
407419
assertScope(classScope.getScopes().get(0), ScopeType.METHOD, "<init>", 3, 3, SOURCE_FILE, 0, 0);
420+
assertLineRanges(classScope.getScopes().get(0), "3-3");
408421
Scope mainMethodScope = classScope.getScopes().get(1);
409422
assertScope(mainMethodScope, ScopeType.METHOD, "main", 5, 10, SOURCE_FILE, 1, 1);
423+
assertLineRanges(mainMethodScope, "5-5", "7-10");
410424
assertSymbol(
411425
mainMethodScope.getSymbols().get(0), SymbolType.ARG, "arg", String.class.getTypeName(), 5);
412426
Scope mainMethodLocalScope = mainMethodScope.getScopes().get(0);
@@ -438,8 +452,10 @@ public void symbolExtraction08() throws IOException, URISyntaxException {
438452
Scope classScope = symbolSinkMock.jarScopes.get(0).getScopes().get(0);
439453
assertScope(classScope, ScopeType.CLASS, CLASS_NAME, 3, 11, SOURCE_FILE, 2, 0);
440454
assertScope(classScope.getScopes().get(0), ScopeType.METHOD, "<init>", 3, 3, SOURCE_FILE, 0, 0);
455+
assertLineRanges(classScope.getScopes().get(0), "3-3");
441456
Scope mainMethodScope = classScope.getScopes().get(1);
442457
assertScope(mainMethodScope, ScopeType.METHOD, "main", 5, 11, SOURCE_FILE, 1, 1);
458+
assertLineRanges(mainMethodScope, "5-5", "7-9", "11-11");
443459
assertSymbol(
444460
mainMethodScope.getSymbols().get(0), SymbolType.ARG, "arg", String.class.getTypeName(), 5);
445461
Scope mainMethodLocalScope = mainMethodScope.getScopes().get(0);
@@ -486,8 +502,10 @@ public void symbolExtraction09() throws IOException, URISyntaxException {
486502
0);
487503
assertScope(
488504
classScope.getScopes().get(0), ScopeType.METHOD, "<init>", 5, 17, SOURCE_FILE, 0, 0);
505+
assertLineRanges(classScope.getScopes().get(0), "5-5", "17-17");
489506
Scope mainMethodScope = classScope.getScopes().get(1);
490507
assertScope(mainMethodScope, ScopeType.METHOD, "main", 8, 14, SOURCE_FILE, 1, 1);
508+
assertLineRanges(mainMethodScope, "8-10", "14-14");
491509
assertSymbol(
492510
mainMethodScope.getSymbols().get(0), SymbolType.ARG, "arg", String.class.getTypeName(), 8);
493511
Scope mainMethodLocalScope = mainMethodScope.getScopes().get(0);
@@ -512,6 +530,7 @@ public void symbolExtraction09() throws IOException, URISyntaxException {
512530
10);
513531
Scope processMethodScope = classScope.getScopes().get(2);
514532
assertScope(processMethodScope, ScopeType.METHOD, "process", 19, 23, SOURCE_FILE, 1, 0);
533+
assertLineRanges(processMethodScope, "19-19", "23-23");
515534
Scope processMethodLocalScope = processMethodScope.getScopes().get(0);
516535
assertScope(processMethodLocalScope, ScopeType.LOCAL, null, 19, 23, SOURCE_FILE, 0, 1);
517536
assertSymbol(
@@ -523,6 +542,7 @@ public void symbolExtraction09() throws IOException, URISyntaxException {
523542
Scope supplierClosureScope = classScope.getScopes().get(3);
524543
assertScope(
525544
supplierClosureScope, ScopeType.CLOSURE, "lambda$process$*", 20, 21, SOURCE_FILE, 1, 0);
545+
assertLineRanges(supplierClosureScope, "20-21");
526546
Scope supplierClosureLocalScope = supplierClosureScope.getScopes().get(0);
527547
assertScope(supplierClosureLocalScope, ScopeType.LOCAL, null, 20, 21, SOURCE_FILE, 0, 1);
528548
assertSymbol(
@@ -533,6 +553,7 @@ public void symbolExtraction09() throws IOException, URISyntaxException {
533553
20);
534554
Scope lambdaClosureScope = classScope.getScopes().get(4);
535555
assertScope(lambdaClosureScope, ScopeType.CLOSURE, "lambda$main$0", 11, 12, SOURCE_FILE, 1, 1);
556+
assertLineRanges(lambdaClosureScope, "11-12");
536557
assertSymbol(
537558
lambdaClosureScope.getSymbols().get(0),
538559
SymbolType.ARG,
@@ -549,6 +570,7 @@ public void symbolExtraction09() throws IOException, URISyntaxException {
549570
11);
550571
Scope clinitMethodScope = classScope.getScopes().get(5);
551572
assertScope(clinitMethodScope, ScopeType.METHOD, "<clinit>", 6, 6, SOURCE_FILE, 0, 0);
573+
assertLineRanges(clinitMethodScope, "6-6");
552574
}
553575

554576
@Test
@@ -567,8 +589,10 @@ public void symbolExtraction10() throws IOException, URISyntaxException {
567589
Scope classScope = symbolSinkMock.jarScopes.get(0).getScopes().get(0);
568590
assertScope(classScope, ScopeType.CLASS, CLASS_NAME, 3, 6, SOURCE_FILE, 2, 0);
569591
assertScope(classScope.getScopes().get(0), ScopeType.METHOD, "<init>", 3, 3, SOURCE_FILE, 0, 0);
592+
assertLineRanges(classScope.getScopes().get(0), "3-3");
570593
Scope mainMethodScope = classScope.getScopes().get(1);
571594
assertScope(mainMethodScope, ScopeType.METHOD, "main", 5, 6, SOURCE_FILE, 1, 1);
595+
assertLineRanges(mainMethodScope, "5-6");
572596
assertSymbol(
573597
mainMethodScope.getSymbols().get(0), SymbolType.ARG, "arg", String.class.getTypeName(), 5);
574598
Scope mainMethodLocalScope = mainMethodScope.getScopes().get(0);
@@ -589,8 +613,10 @@ public void symbolExtraction10() throws IOException, URISyntaxException {
589613
0);
590614
assertScope(
591615
innerClassScope.getScopes().get(0), ScopeType.METHOD, "<init>", 9, 10, SOURCE_FILE, 0, 0);
616+
assertLineRanges(innerClassScope.getScopes().get(0), "9-10");
592617
Scope addToMethod = innerClassScope.getScopes().get(1);
593618
assertScope(addToMethod, ScopeType.METHOD, "addTo", 12, 13, SOURCE_FILE, 1, 1);
619+
assertLineRanges(addToMethod, "12-13");
594620
assertSymbol(
595621
addToMethod.getSymbols().get(0), SymbolType.ARG, "arg", Integer.TYPE.getTypeName(), 12);
596622
Scope addToMethodLocalScope = addToMethod.getScopes().get(0);
@@ -620,8 +646,10 @@ public void symbolExtraction11() throws IOException, URISyntaxException {
620646
assertSymbol(
621647
classScope.getSymbols().get(0), SymbolType.FIELD, "field1", Integer.TYPE.getTypeName(), 0);
622648
assertScope(classScope.getScopes().get(0), ScopeType.METHOD, "<init>", 3, 4, SOURCE_FILE, 0, 0);
649+
assertLineRanges(classScope.getScopes().get(0), "3-4");
623650
Scope mainMethodScope = classScope.getScopes().get(1);
624651
assertScope(mainMethodScope, ScopeType.METHOD, "main", 6, 11, SOURCE_FILE, 1, 1);
652+
assertLineRanges(mainMethodScope, "6-9", "11-11");
625653
assertSymbol(
626654
mainMethodScope.getSymbols().get(0), SymbolType.ARG, "arg", Integer.TYPE.getTypeName(), 6);
627655
Scope mainMethodLocalScope = mainMethodScope.getScopes().get(0);
@@ -653,8 +681,10 @@ public void symbolExtraction12() throws IOException, URISyntaxException {
653681
Scope classScope = symbolSinkMock.jarScopes.get(0).getScopes().get(0);
654682
assertScope(classScope, ScopeType.CLASS, CLASS_NAME, 6, 20, SOURCE_FILE, 7, 0);
655683
assertScope(classScope.getScopes().get(0), ScopeType.METHOD, "<init>", 6, 6, SOURCE_FILE, 0, 0);
684+
assertLineRanges(classScope.getScopes().get(0), "6-6");
656685
Scope mainMethodScope = classScope.getScopes().get(1);
657686
assertScope(mainMethodScope, ScopeType.METHOD, "main", 8, 13, SOURCE_FILE, 1, 1);
687+
assertLineRanges(mainMethodScope, "8-13");
658688
assertSymbol(
659689
mainMethodScope.getSymbols().get(0), SymbolType.ARG, "arg", Integer.TYPE.getTypeName(), 8);
660690
Scope mainMethodLocalScope = mainMethodScope.getScopes().get(0);
@@ -673,11 +703,13 @@ public void symbolExtraction12() throws IOException, URISyntaxException {
673703
12);
674704
Scope fooMethodScope = classScope.getScopes().get(2);
675705
assertScope(fooMethodScope, ScopeType.METHOD, "foo", 17, 20, SOURCE_FILE, 0, 1);
706+
assertLineRanges(fooMethodScope, "17-20");
676707
assertSymbol(
677708
fooMethodScope.getSymbols().get(0), SymbolType.ARG, "arg", Integer.TYPE.getTypeName(), 17);
678709
Scope lambdaFoo3MethodScope = classScope.getScopes().get(3);
679710
assertScope(
680711
lambdaFoo3MethodScope, ScopeType.CLOSURE, "lambda$foo$*", 19, 19, SOURCE_FILE, 0, 1);
712+
assertLineRanges(lambdaFoo3MethodScope, "19-19");
681713
assertSymbol(
682714
lambdaFoo3MethodScope.getSymbols().get(0),
683715
SymbolType.ARG,
@@ -687,6 +719,7 @@ public void symbolExtraction12() throws IOException, URISyntaxException {
687719
Scope lambdaFoo2MethodScope = classScope.getScopes().get(4);
688720
assertScope(
689721
lambdaFoo2MethodScope, ScopeType.CLOSURE, "lambda$foo$*", 19, 19, SOURCE_FILE, 0, 1);
722+
assertLineRanges(lambdaFoo2MethodScope, "19-19");
690723
assertSymbol(
691724
lambdaFoo2MethodScope.getSymbols().get(0),
692725
SymbolType.ARG,
@@ -696,6 +729,7 @@ public void symbolExtraction12() throws IOException, URISyntaxException {
696729
Scope lambdaMain1MethodScope = classScope.getScopes().get(5);
697730
assertScope(
698731
lambdaMain1MethodScope, ScopeType.CLOSURE, "lambda$main$1", 11, 11, SOURCE_FILE, 0, 1);
732+
assertLineRanges(lambdaMain1MethodScope, "11-11");
699733
assertSymbol(
700734
lambdaMain1MethodScope.getSymbols().get(0),
701735
SymbolType.ARG,
@@ -705,6 +739,7 @@ public void symbolExtraction12() throws IOException, URISyntaxException {
705739
Scope lambdaMain0MethodScope = classScope.getScopes().get(6);
706740
assertScope(
707741
lambdaMain0MethodScope, ScopeType.CLOSURE, "lambda$main$0", 11, 11, SOURCE_FILE, 0, 1);
742+
assertLineRanges(lambdaMain0MethodScope, "11-11");
708743
assertSymbol(
709744
lambdaMain0MethodScope.getSymbols().get(0),
710745
SymbolType.ARG,
@@ -1021,6 +1056,18 @@ private void assertSymbol(
10211056
assertEquals(line, symbol.getLine());
10221057
}
10231058

1059+
private void assertLineRanges(Scope scope, String... expectedRanges) {
1060+
assertTrue(scope.hasInjectibleLines());
1061+
assertEquals(expectedRanges.length, scope.getInjectibleLines().size());
1062+
int idx = 0;
1063+
for (String expectedRange : expectedRanges) {
1064+
String[] range = expectedRange.split("-");
1065+
assertEquals(Integer.parseInt(range[0]), scope.getInjectibleLines().get(idx).start);
1066+
assertEquals(Integer.parseInt(range[1]), scope.getInjectibleLines().get(idx).end);
1067+
idx++;
1068+
}
1069+
}
1070+
10241071
private SymbolExtractionTransformer createTransformer(SymbolSink symbolSink) {
10251072
return createTransformer(symbolSink, 1);
10261073
}
Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
11
package com.datadog.debugger.symbol;
22

3+
import static org.junit.jupiter.api.Assertions.*;
4+
35
import java.util.Arrays;
46
import java.util.List;
5-
6-
import static org.junit.jupiter.api.Assertions.*;
7+
import org.junit.jupiter.api.Test;
78

89
class SymbolExtractorTest {
910

11+
@Test
1012
void ranges() {
11-
List<Scope.LineRange> ranges = SymbolExtractor.buildRanges(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
13+
List<Scope.LineRange> ranges =
14+
SymbolExtractor.buildRanges(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
1215
assertEquals(1, ranges.size());
1316
assertEquals(1, ranges.get(0).start);
1417
assertEquals(10, ranges.get(0).end);
1518
ranges = SymbolExtractor.buildRanges(Arrays.asList(1, 3, 5, 7, 9));
1619
assertEquals(5, ranges.size());
17-
assertEquals(1, ranges.get(0).start);
18-
assertEquals(1, ranges.get(0).end);
19-
assertEquals(1, ranges.get(0).start);
20-
assertEquals(1, ranges.get(0).end);
20+
assertLineRange(ranges.get(0), 1, 1);
21+
assertLineRange(ranges.get(1), 3, 3);
22+
assertLineRange(ranges.get(2), 5, 5);
23+
assertLineRange(ranges.get(3), 7, 7);
24+
assertLineRange(ranges.get(4), 9, 9);
25+
ranges = SymbolExtractor.buildRanges(Arrays.asList(1, 2, 4, 5, 7, 9, 10));
26+
assertEquals(4, ranges.size());
27+
assertLineRange(ranges.get(0), 1, 2);
28+
assertLineRange(ranges.get(1), 4, 5);
29+
assertLineRange(ranges.get(2), 7, 7);
30+
assertLineRange(ranges.get(3), 9, 10);
2131
}
2232

2333
private static void assertLineRange(Scope.LineRange range, int expectedStart, int expectedEnd) {
24-
34+
assertEquals(expectedStart, range.start);
35+
assertEquals(expectedEnd, range.end);
2536
}
2637
}

0 commit comments

Comments
 (0)