58
58
import static org .sonar .plugins .python .api .types .BuiltinTypes .NONE_TYPE ;
59
59
import static org .sonar .plugins .python .api .types .BuiltinTypes .STR ;
60
60
import static org .sonar .plugins .python .api .types .BuiltinTypes .TUPLE ;
61
- import static org .sonar .python .types .TypeShedThirdParties .commonSymbols ;
62
61
import static org .sonar .python .types .TypeShedThirdParties .getModuleSymbols ;
63
62
64
63
public class TypeShed {
@@ -73,6 +72,7 @@ public class TypeShed {
73
72
private static final String THIRD_PARTY_3 = "typeshed/third_party/3/" ;
74
73
private static final String CUSTOM_THIRD_PARTY = "custom/" ;
75
74
private static final String PROTOBUF = "protobuf/" ;
75
+ private static final String PROTOBUF_THIRD_PARTY = "protobuf/stubs/" ;
76
76
private static final String BUILTINS_FQN = "builtins" ;
77
77
private static final String BUILTINS_PREFIX = BUILTINS_FQN + "." ;
78
78
// Those fundamentals builtins symbols need not to be ambiguous for the frontend to work properly
@@ -96,7 +96,7 @@ private TypeShed() {
96
96
public static Map <String , Symbol > builtinSymbols () {
97
97
if ((TypeShed .builtins == null )) {
98
98
supportedPythonVersions = ProjectPythonVersion .currentVersions ().stream ().map (PythonVersionUtils .Version ::serializedValue ).collect (Collectors .toSet ());
99
- Map <String , Symbol > builtins = getSymbolsFromProtobufModule (BUILTINS_FQN );
99
+ Map <String , Symbol > builtins = getSymbolsFromProtobufModule (BUILTINS_FQN , false );
100
100
builtins .put (NONE_TYPE , new ClassSymbolImpl (NONE_TYPE , NONE_TYPE ));
101
101
TypeShed .builtins = Collections .unmodifiableMap (builtins );
102
102
TypeShed .builtinGlobalSymbols .put ("" , new HashSet <>(builtins .values ()));
@@ -271,16 +271,13 @@ private static Map<String, Symbol> searchTypeShedForModule(String moduleName) {
271
271
modulesInProgress .remove (moduleName );
272
272
return customSymbols ;
273
273
}
274
- Map <String , Symbol > symbolsFromProtobuf = getSymbolsFromProtobufModule (moduleName );
274
+ Map <String , Symbol > symbolsFromProtobuf = getSymbolsFromProtobufModule (moduleName , false );
275
275
if (!symbolsFromProtobuf .isEmpty ()) {
276
276
modulesInProgress .remove (moduleName );
277
277
return symbolsFromProtobuf ;
278
278
}
279
- Map <String , Symbol > thirdPartySymbols = getModuleSymbols (moduleName , THIRD_PARTY_2AND3 , builtinGlobalSymbols );
280
- if (thirdPartySymbols .isEmpty ()) {
281
- thirdPartySymbols = commonSymbols (getModuleSymbols (moduleName , THIRD_PARTY_2 , builtinGlobalSymbols ),
282
- getModuleSymbols (moduleName , THIRD_PARTY_3 , builtinGlobalSymbols ), moduleName );
283
- }
279
+
280
+ Map <String , Symbol > thirdPartySymbols = getSymbolsFromProtobufModule (moduleName , true );
284
281
modulesInProgress .remove (moduleName );
285
282
return thirdPartySymbols ;
286
283
}
@@ -311,8 +308,9 @@ private static boolean isAmbiguousSymbolOfClasses(Symbol symbol) {
311
308
return false ;
312
309
}
313
310
314
- private static Map <String , Symbol > getSymbolsFromProtobufModule (String moduleName ) {
315
- InputStream resource = TypeShed .class .getResourceAsStream (PROTOBUF + moduleName + ".protobuf" );
311
+ private static Map <String , Symbol > getSymbolsFromProtobufModule (String moduleName , boolean isThirdParty ) {
312
+ String protobufDir = isThirdParty ? PROTOBUF_THIRD_PARTY : PROTOBUF ;
313
+ InputStream resource = TypeShed .class .getResourceAsStream (protobufDir + moduleName + ".protobuf" );
316
314
if (resource == null ) {
317
315
return Collections .emptyMap ();
318
316
}
0 commit comments