@@ -179,6 +179,11 @@ public static String normalizedFqn(String fqn) {
179179 }
180180
181181 public static String normalizedFqn (String fqn , String moduleName , String localName ) {
182+ return normalizedFqn (fqn , moduleName , localName , null );
183+ }
184+
185+ public static String normalizedFqn (String fqn , String moduleName , String localName , @ Nullable String containerClassFqn ) {
186+ if (containerClassFqn != null ) return containerClassFqn + "." + localName ;
182187 if (fqn .startsWith (moduleName )) return normalizedFqn (fqn );
183188 return moduleName + "." + localName ;
184189 }
@@ -192,20 +197,20 @@ public static boolean isValidForProjectPythonVersion(List<String> validForPython
192197 return !intersection .isEmpty ();
193198 }
194199
195- public static Set <Symbol > symbolsFromProtobufDescriptors (Set <Object > protobufDescriptors , boolean isInsideClass , String moduleName ) {
200+ public static Set <Symbol > symbolsFromProtobufDescriptors (Set <Object > protobufDescriptors , @ Nullable String containerClassFqn , String moduleName ) {
196201 Set <Symbol > symbols = new HashSet <>();
197202 for (Object descriptor : protobufDescriptors ) {
198203 if (descriptor instanceof SymbolsProtos .ClassSymbol ) {
199204 symbols .add (new ClassSymbolImpl (((SymbolsProtos .ClassSymbol ) descriptor ), moduleName ));
200205 }
201206 if (descriptor instanceof SymbolsProtos .FunctionSymbol ) {
202- symbols .add (new FunctionSymbolImpl (((SymbolsProtos .FunctionSymbol ) descriptor ), isInsideClass , moduleName ));
207+ symbols .add (new FunctionSymbolImpl (((SymbolsProtos .FunctionSymbol ) descriptor ), containerClassFqn , moduleName ));
203208 }
204209 if (descriptor instanceof OverloadedFunctionSymbol ) {
205210 if (((OverloadedFunctionSymbol ) descriptor ).getDefinitionsList ().size () < 2 ) {
206211 throw new IllegalStateException ("Overloaded function symbols should have at least two definitions." );
207212 }
208- symbols .add (fromOverloadedFunction (((OverloadedFunctionSymbol ) descriptor ), isInsideClass , moduleName ));
213+ symbols .add (fromOverloadedFunction (((OverloadedFunctionSymbol ) descriptor ), containerClassFqn , moduleName ));
209214 }
210215 if (descriptor instanceof SymbolsProtos .VarSymbol ) {
211216 SymbolsProtos .VarSymbol varSymbol = (SymbolsProtos .VarSymbol ) descriptor ;
@@ -220,6 +225,24 @@ public static Set<Symbol> symbolsFromProtobufDescriptors(Set<Object> protobufDes
220225 return symbols ;
221226 }
222227
228+
229+ @ CheckForNull
230+ public static SymbolsProtos .ClassSymbol classDescriptorWithFQN (String fullyQualifiedName ) {
231+ String [] fqnSplitByDot = fullyQualifiedName .split ("\\ ." );
232+ String symbolLocalNameFromFqn = fqnSplitByDot [fqnSplitByDot .length - 1 ];
233+ String moduleName = Arrays .stream (fqnSplitByDot , 0 , fqnSplitByDot .length - 1 ).collect (Collectors .joining ("." ));
234+ InputStream resource = TypeShed .class .getResourceAsStream (PROTOBUF + moduleName + ".protobuf" );
235+ if (resource == null ) return null ;
236+ ModuleSymbol moduleSymbol = deserializedModule (moduleName , resource );
237+ if (moduleSymbol == null ) return null ;
238+ for (SymbolsProtos .ClassSymbol classSymbol : moduleSymbol .getClassesList ()) {
239+ if (classSymbol .getName ().equals (symbolLocalNameFromFqn )) {
240+ return classSymbol ;
241+ }
242+ }
243+ return null ;
244+ }
245+
223246 //================================================================================
224247 // Private methods
225248 //================================================================================
@@ -260,7 +283,7 @@ private static Map<String, Symbol> searchTypeShedForModule(String moduleName) {
260283 * This method sort ambiguous symbol by python version and returns the one which is valid for
261284 * the most recent Python version.
262285 */
263- private static Symbol disambiguateWithLatestPythonSymbol (Set <Symbol > alternatives ) {
286+ static Symbol disambiguateWithLatestPythonSymbol (Set <Symbol > alternatives ) {
264287 int max = Integer .MIN_VALUE ;
265288 Symbol latestPythonSymbol = null ;
266289 for (Symbol alternative : alternatives ) {
@@ -322,7 +345,7 @@ static Map<String, Symbol> getSymbolsFromProtobufModule(@Nullable ModuleSymbol m
322345
323346 for (Map .Entry <String , Set <Object >> entry : descriptorsByName .entrySet ()) {
324347 String name = entry .getKey ();
325- Set <Symbol > symbols = symbolsFromProtobufDescriptors (entry .getValue (), false , moduleSymbol .getFullyQualifiedName ());
348+ Set <Symbol > symbols = symbolsFromProtobufDescriptors (entry .getValue (), null , moduleSymbol .getFullyQualifiedName ());
326349 Symbol disambiguatedSymbol = disambiguateSymbolsWithSameName (name , symbols , moduleSymbol .getFullyQualifiedName ());
327350 deserializedSymbols .put (name , disambiguatedSymbol );
328351 }
@@ -356,9 +379,9 @@ private static boolean haveAllTheSameFqn(Set<Symbol> symbols) {
356379 return firstFqn != null && symbols .stream ().map (Symbol ::fullyQualifiedName ).allMatch (firstFqn ::equals );
357380 }
358381
359- private static AmbiguousSymbol fromOverloadedFunction (OverloadedFunctionSymbol overloadedFunctionSymbol , boolean isInsideClass , String moduleName ) {
382+ private static AmbiguousSymbol fromOverloadedFunction (OverloadedFunctionSymbol overloadedFunctionSymbol , @ Nullable String containerClassFqn , String moduleName ) {
360383 Set <Symbol > overloadedSymbols = overloadedFunctionSymbol .getDefinitionsList ().stream ()
361- .map (def -> new FunctionSymbolImpl (def , isInsideClass , overloadedFunctionSymbol .getValidForList (), moduleName ))
384+ .map (def -> new FunctionSymbolImpl (def , containerClassFqn , overloadedFunctionSymbol .getValidForList (), moduleName ))
362385 .collect (Collectors .toSet ());
363386 return AmbiguousSymbolImpl .create (overloadedSymbols );
364387 }
0 commit comments