@@ -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 }
0 commit comments