46
46
import org .sonar .python .types .v2 .FunctionType ;
47
47
import org .sonar .python .types .v2 .PythonType ;
48
48
import org .sonar .python .types .v2 .TriBool ;
49
+ import org .sonar .python .types .v2 .TypeCheckBuilder ;
49
50
import org .sonar .python .types .v2 .TypeChecker ;
50
51
import org .sonar .python .types .v2 .UnknownType ;
51
52
@@ -223,11 +224,21 @@ public Collection<Symbol> stubFilesSymbols() {
223
224
private class DjangoViewsVisitor extends BaseTreeVisitor {
224
225
225
226
String fullyQualifiedModuleName ;
227
+ private TypeCheckBuilder confPathCall = null ;
228
+ private TypeCheckBuilder pathCall = null ;
226
229
227
230
public DjangoViewsVisitor (String fullyQualifiedModuleName ) {
228
231
this .fullyQualifiedModuleName = fullyQualifiedModuleName ;
229
232
}
230
233
234
+ @ Override
235
+ public void visitFileInput (FileInput fileInput ) {
236
+ TypeChecker typeChecker = new TypeChecker (new BasicTypeTable (new ProjectLevelTypeTable (ProjectLevelSymbolTable .this )));
237
+ confPathCall = typeChecker .typeCheckBuilder ().isTypeWithName ("django.urls.conf.path" );
238
+ pathCall = typeChecker .typeCheckBuilder ().isTypeWithName ("django.urls.path" );
239
+ super .visitFileInput (fileInput );
240
+ }
241
+
231
242
@ Override
232
243
public void visitCallExpression (CallExpression callExpression ) {
233
244
super .visitCallExpression (callExpression );
@@ -246,9 +257,8 @@ public void visitCallExpression(CallExpression callExpression) {
246
257
}
247
258
248
259
private boolean isCallRegisteringDjangoView (CallExpression callExpression ) {
249
- TypeChecker typeChecker = new TypeChecker (new BasicTypeTable (new ProjectLevelTypeTable (ProjectLevelSymbolTable .this )));
250
- TriBool isConfPathCall = typeChecker .typeCheckBuilder ().isTypeWithName ("django.urls.conf.path" ).check (callExpression .callee ().typeV2 ());
251
- TriBool isPathCall = typeChecker .typeCheckBuilder ().isTypeWithName ("django.urls.path" ).check (callExpression .callee ().typeV2 ());
260
+ TriBool isConfPathCall = confPathCall .check (callExpression .callee ().typeV2 ());
261
+ TriBool isPathCall = pathCall .check (callExpression .callee ().typeV2 ());
252
262
return isConfPathCall .equals (TriBool .TRUE ) || isPathCall .equals (TriBool .TRUE );
253
263
}
254
264
}
0 commit comments