@@ -77,7 +77,7 @@ public class PythonScanner extends Scanner {
77
77
private final NoSonarFilter noSonarFilter ;
78
78
private final PythonCpdAnalyzer cpdAnalyzer ;
79
79
private final PythonIndexer indexer ;
80
- private final Map <InputFile , Set <PythonCheck >> checksExecutedWithoutParsingByFiles = new HashMap <>();
80
+ private final Map <PythonInputFile , Set <PythonCheck >> checksExecutedWithoutParsingByFiles = new HashMap <>();
81
81
82
82
public PythonScanner (
83
83
SensorContext context , PythonChecks checks ,
@@ -98,10 +98,10 @@ protected String name() {
98
98
}
99
99
100
100
@ Override
101
- protected void scanFile (InputFile inputFile ) {
102
- PythonFile pythonFile = SonarQubePythonFile .create (inputFile );
101
+ protected void scanFile (PythonInputFile inputFile ) {
102
+ PythonFile pythonFile = SonarQubePythonFile .create (inputFile . wrappedFile () );
103
103
PythonVisitorContext visitorContext ;
104
- InputFile .Type fileType = inputFile .type ();
104
+ InputFile .Type fileType = inputFile .wrappedFile (). type ();
105
105
try {
106
106
AstNode astNode = parser .parse (pythonFile .content ());
107
107
PythonTreeMaker treeMaker = getTreeMaker (inputFile );
@@ -122,8 +122,8 @@ protected void scanFile(InputFile inputFile) {
122
122
LOG .error ("Unable to parse file: " + inputFile );
123
123
LOG .error (e .getMessage ());
124
124
context .newAnalysisError ()
125
- .onFile (inputFile )
126
- .at (inputFile .newPointer (e .getLine (), 0 ))
125
+ .onFile (inputFile . wrappedFile () )
126
+ .at (inputFile .wrappedFile (). newPointer (e .getLine (), 0 ))
127
127
.message (e .getMessage ())
128
128
.save ();
129
129
}
@@ -143,18 +143,18 @@ protected void scanFile(InputFile inputFile) {
143
143
saveIssues (inputFile , visitorContext .getIssues ());
144
144
145
145
if (visitorContext .rootTree () != null && !isInSonarLint (context )) {
146
- new SymbolVisitor (context .newSymbolTable ().onFile (inputFile )).visitFileInput (visitorContext .rootTree ());
146
+ new SymbolVisitor (context .newSymbolTable ().onFile (inputFile . wrappedFile () )).visitFileInput (visitorContext .rootTree ());
147
147
new PythonHighlighter (context , inputFile ).scanFile (visitorContext );
148
148
}
149
149
}
150
150
151
- private static PythonTreeMaker getTreeMaker (InputFile inputFile ) {
152
- return Python .KEY .equals (inputFile .language ()) ? new PythonTreeMaker () : new IPythonTreeMaker ();
151
+ private static PythonTreeMaker getTreeMaker (PythonInputFile inputFile ) {
152
+ return Python .KEY .equals (inputFile .wrappedFile (). language ()) ? new PythonTreeMaker () : new IPythonTreeMaker ();
153
153
}
154
154
155
155
@ Override
156
- public boolean scanFileWithoutParsing (InputFile inputFile ) {
157
- InputFile .Type fileType = inputFile .type ();
156
+ public boolean scanFileWithoutParsing (PythonInputFile inputFile ) {
157
+ InputFile .Type fileType = inputFile .wrappedFile (). type ();
158
158
boolean result = true ;
159
159
for (PythonCheck check : checks .all ()) {
160
160
if (!isCheckApplicable (check , fileType )) {
@@ -166,7 +166,7 @@ public boolean scanFileWithoutParsing(InputFile inputFile) {
166
166
result = false ;
167
167
continue ;
168
168
}
169
- PythonFile pythonFile = SonarQubePythonFile .create (inputFile );
169
+ PythonFile pythonFile = SonarQubePythonFile .create (inputFile . wrappedFile () );
170
170
PythonInputFileContext inputFileContext = new PythonInputFileContext (pythonFile , context .fileSystem ().workDir (), indexer .cacheContext (), context .runtime ().getProduct ());
171
171
if (check .scanWithoutParsing (inputFileContext )) {
172
172
Set <PythonCheck > executedChecks = checksExecutedWithoutParsingByFiles .getOrDefault (inputFile , new HashSet <>());
@@ -184,7 +184,7 @@ public boolean scanFileWithoutParsing(InputFile inputFile) {
184
184
return restoreAndPushMeasuresIfApplicable (inputFile );
185
185
}
186
186
187
- private boolean checkRequiresParsingOfImpactedFile (InputFile inputFile , PythonCheck check ) {
187
+ private boolean checkRequiresParsingOfImpactedFile (PythonInputFile inputFile , PythonCheck check ) {
188
188
return !indexer .canBeFullyScannedWithoutParsing (inputFile ) && !check .getClass ().getPackageName ().startsWith ("org.sonar.python.checks" );
189
189
}
190
190
@@ -214,12 +214,12 @@ private static boolean isInSonarLint(SensorContext context) {
214
214
}
215
215
216
216
@ Override
217
- protected void processException (Exception e , InputFile file ) {
217
+ protected void processException (Exception e , PythonInputFile file ) {
218
218
LOG .warn ("Unable to analyze file: " + file , e );
219
219
}
220
220
221
221
@ Override
222
- public boolean canBeScannedWithoutParsing (InputFile inputFile ) {
222
+ public boolean canBeScannedWithoutParsing (PythonInputFile inputFile ) {
223
223
return this .indexer .canBePartiallyScannedWithoutParsing (inputFile );
224
224
}
225
225
@@ -229,7 +229,7 @@ protected void reportStatistics(int numSkippedFiles, int numTotalFiles) {
229
229
numSkippedFiles , numTotalFiles );
230
230
}
231
231
232
- private void saveIssues (InputFile inputFile , List <PreciseIssue > issues ) {
232
+ private void saveIssues (PythonInputFile inputFile , List <PreciseIssue > issues ) {
233
233
for (PreciseIssue preciseIssue : issues ) {
234
234
RuleKey ruleKey = checks .ruleKey (preciseIssue .check ());
235
235
NewIssue newIssue = context
@@ -251,7 +251,7 @@ private void saveIssues(InputFile inputFile, List<PreciseIssue> issues) {
251
251
if (fileId != null ) {
252
252
InputFile issueLocationFile = component (fileId , context );
253
253
if (issueLocationFile != null ) {
254
- secondaryLocationsFlow .addFirst (newLocation (issueLocationFile , newIssue , secondaryLocation ));
254
+ secondaryLocationsFlow .addFirst (newLocation (new PythonInputFileImpl ( issueLocationFile ) , newIssue , secondaryLocation ));
255
255
}
256
256
} else {
257
257
newIssue .addLocation (newLocation (inputFile , newIssue , secondaryLocation ));
@@ -264,7 +264,7 @@ private void saveIssues(InputFile inputFile, List<PreciseIssue> issues) {
264
264
newIssue .addFlow (secondaryLocationsFlow );
265
265
}
266
266
267
- handleQuickFixes (inputFile , ruleKey , newIssue , preciseIssue );
267
+ handleQuickFixes (inputFile . wrappedFile () , ruleKey , newIssue , preciseIssue );
268
268
269
269
newIssue .save ();
270
270
}
@@ -280,15 +280,15 @@ private InputFile component(String fileId, SensorContext sensorContext) {
280
280
return inputFile ;
281
281
}
282
282
283
- private static NewIssueLocation newLocation (InputFile inputFile , NewIssue issue , IssueLocation location ) {
283
+ private static NewIssueLocation newLocation (PythonInputFile inputFile , NewIssue issue , IssueLocation location ) {
284
284
NewIssueLocation newLocation = issue .newLocation ()
285
- .on (inputFile );
285
+ .on (inputFile . wrappedFile () );
286
286
if (location .startLine () != IssueLocation .UNDEFINED_LINE ) {
287
287
TextRange range ;
288
288
if (location .startLineOffset () == IssueLocation .UNDEFINED_OFFSET ) {
289
- range = inputFile .selectLine (location .startLine ());
289
+ range = inputFile .wrappedFile (). selectLine (location .startLine ());
290
290
} else {
291
- range = inputFile .newRange (location .startLine (), location .startLineOffset (), location .endLine (), location .endLineOffset ());
291
+ range = inputFile .wrappedFile (). newRange (location .startLine (), location .startLineOffset (), location .endLine (), location .endLineOffset ());
292
292
}
293
293
newLocation .at (range );
294
294
}
@@ -300,14 +300,14 @@ private static NewIssueLocation newLocation(InputFile inputFile, NewIssue issue,
300
300
return newLocation ;
301
301
}
302
302
303
- private void saveMeasures (InputFile inputFile , PythonVisitorContext visitorContext ) {
303
+ private void saveMeasures (PythonInputFile inputFile , PythonVisitorContext visitorContext ) {
304
304
FileMetrics fileMetrics = new FileMetrics (visitorContext );
305
305
FileLinesVisitor fileLinesVisitor = fileMetrics .fileLinesVisitor ();
306
306
307
- noSonarFilter .noSonarInFile (inputFile , fileLinesVisitor .getLinesWithNoSonar ());
307
+ noSonarFilter .noSonarInFile (inputFile . wrappedFile () , fileLinesVisitor .getLinesWithNoSonar ());
308
308
309
309
if (!isInSonarLint (context )) {
310
- cpdAnalyzer .pushCpdTokens (inputFile , visitorContext );
310
+ cpdAnalyzer .pushCpdTokens (inputFile . wrappedFile () , visitorContext );
311
311
312
312
Set <Integer > linesOfCode = fileLinesVisitor .getLinesOfCode ();
313
313
saveMetricOnFile (inputFile , CoreMetrics .NCLOC , linesOfCode .size ());
@@ -318,7 +318,7 @@ private void saveMeasures(InputFile inputFile, PythonVisitorContext visitorConte
318
318
saveMetricOnFile (inputFile , CoreMetrics .COGNITIVE_COMPLEXITY , fileMetrics .cognitiveComplexity ());
319
319
saveMetricOnFile (inputFile , CoreMetrics .COMMENT_LINES , fileLinesVisitor .getCommentLineCount ());
320
320
321
- FileLinesContext fileLinesContext = fileLinesContextFactory .createFor (inputFile );
321
+ FileLinesContext fileLinesContext = fileLinesContextFactory .createFor (inputFile . wrappedFile () );
322
322
for (int line : linesOfCode ) {
323
323
fileLinesContext .setIntValue (CoreMetrics .NCLOC_DATA_KEY , line , 1 );
324
324
}
@@ -329,19 +329,19 @@ private void saveMeasures(InputFile inputFile, PythonVisitorContext visitorConte
329
329
}
330
330
}
331
331
332
- private boolean restoreAndPushMeasuresIfApplicable (InputFile inputFile ) {
333
- if (inputFile .type () == InputFile .Type .TEST ) {
332
+ private boolean restoreAndPushMeasuresIfApplicable (PythonInputFile inputFile ) {
333
+ if (inputFile .wrappedFile (). type () == InputFile .Type .TEST ) {
334
334
return true ;
335
335
}
336
336
337
- return cpdAnalyzer .pushCachedCpdTokens (inputFile , indexer .cacheContext ());
337
+ return cpdAnalyzer .pushCachedCpdTokens (inputFile . wrappedFile () , indexer .cacheContext ());
338
338
}
339
339
340
- private void saveMetricOnFile (InputFile inputFile , Metric <Integer > metric , Integer value ) {
340
+ private void saveMetricOnFile (PythonInputFile inputFile , Metric <Integer > metric , Integer value ) {
341
341
context .<Integer >newMeasure ()
342
342
.withValue (value )
343
343
.forMetric (metric )
344
- .on (inputFile )
344
+ .on (inputFile . wrappedFile () )
345
345
.save ();
346
346
}
347
347
0 commit comments