File tree Expand file tree Collapse file tree 3 files changed +13
-5
lines changed
main/java/org/sonar/python/tree
test/java/org/sonar/python/tree
sonar-python-plugin/src/main/java/org/sonar/plugins/python Expand file tree Collapse file tree 3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -48,9 +48,9 @@ public class IPythonTreeMaker extends PythonTreeMaker {
48
48
private Map <Integer , IPythonLocation > offsetMap ;
49
49
50
50
public IPythonTreeMaker () {
51
- this (null );
51
+ this (Map . of () );
52
52
}
53
- public IPythonTreeMaker (@ Nullable Map <Integer , IPythonLocation > offsetMap ) {
53
+ public IPythonTreeMaker (Map <Integer , IPythonLocation > offsetMap ) {
54
54
this .offsetMap = offsetMap ;
55
55
}
56
56
@@ -59,7 +59,7 @@ protected Token toPyToken(@Nullable com.sonar.sslr.api.Token token) {
59
59
if (token == null ) {
60
60
return null ;
61
61
}
62
- if (this .offsetMap != null ) {
62
+ if (this .offsetMap != null && ! this . offsetMap . isEmpty () ) {
63
63
return TokenEnricher .enrichToken (token , offsetMap );
64
64
}
65
65
return new TokenImpl (token );
Original file line number Diff line number Diff line change @@ -301,8 +301,8 @@ void enrichTokens() {
301
301
assertThat (stringLiteral ).hasSize (1 );
302
302
assertThat (stringLiteral .get (0 ).firstToken ().line ()).isEqualTo (7 );
303
303
assertThat (stringLiteral .get (0 ).firstToken ().column ()).isEqualTo (14 );
304
-
305
304
}
305
+
306
306
@ Test
307
307
void toPyTokenShouldReturnNull (){
308
308
//when the token is null
Original file line number Diff line number Diff line change 61
61
import org .sonar .plugins .python .api .tree .FileInput ;
62
62
import org .sonar .plugins .python .cpd .PythonCpdAnalyzer ;
63
63
import org .sonar .plugins .python .indexer .PythonIndexer ;
64
+ import org .sonar .python .IPythonLocation ;
64
65
import org .sonar .python .SubscriptionVisitor ;
65
66
import org .sonar .python .metrics .FileLinesVisitor ;
66
67
import org .sonar .python .metrics .FileMetrics ;
@@ -150,7 +151,14 @@ protected void scanFile(PythonInputFile inputFile) throws IOException {
150
151
}
151
152
152
153
private static PythonTreeMaker getTreeMaker (PythonInputFile inputFile ) {
153
- return Python .KEY .equals (inputFile .wrappedFile ().language ()) ? new PythonTreeMaker () : new IPythonTreeMaker ();
154
+ return Python .KEY .equals (inputFile .wrappedFile ().language ()) ? new PythonTreeMaker () : new IPythonTreeMaker (getOffsetLocations (inputFile ));
155
+ }
156
+
157
+ private static Map <Integer , IPythonLocation > getOffsetLocations (PythonInputFile inputFile ) {
158
+ if (inputFile .kind () == PythonInputFile .Kind .IPYTHON ){
159
+ return ((GeneratedIPythonFile ) inputFile ).locationMap ();
160
+ }
161
+ return Map .of ();
154
162
}
155
163
156
164
@ Override
You can’t perform that action at this time.
0 commit comments