diff --git a/python-frontend/src/main/java/org/sonar/python/semantic/ProjectLevelSymbolTable.java b/python-frontend/src/main/java/org/sonar/python/semantic/ProjectLevelSymbolTable.java index 4d7c5ce617..22225626e0 100644 --- a/python-frontend/src/main/java/org/sonar/python/semantic/ProjectLevelSymbolTable.java +++ b/python-frontend/src/main/java/org/sonar/python/semantic/ProjectLevelSymbolTable.java @@ -16,12 +16,10 @@ */ package org.sonar.python.semantic; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; @@ -210,12 +208,9 @@ public Collection stubFilesSymbols() { if (cachedSymbols != null) { return cachedSymbols; } - List stubDescriptors = new ArrayList<>(typeShedDescriptorsProvider.stubFilesDescriptors()); - Map symbolsByFqn = new HashMap<>(); cachedSymbols = new HashSet<>(); - - for (Descriptor descriptor : stubDescriptors) { + for (Descriptor descriptor : typeShedDescriptorsProvider.stubFilesDescriptors()) { if (descriptor.fullyQualifiedName() != null) { Symbol symbol = symbolsByFqn.computeIfAbsent(descriptor.fullyQualifiedName(), k -> DescriptorUtils.symbolFromDescriptor(descriptor, this, null, new HashMap<>(), new HashMap<>())); diff --git a/python-frontend/src/main/java/org/sonar/python/semantic/v2/typeshed/TypeShedDescriptorsProvider.java b/python-frontend/src/main/java/org/sonar/python/semantic/v2/typeshed/TypeShedDescriptorsProvider.java index f2fc8df2af..7c1623d421 100644 --- a/python-frontend/src/main/java/org/sonar/python/semantic/v2/typeshed/TypeShedDescriptorsProvider.java +++ b/python-frontend/src/main/java/org/sonar/python/semantic/v2/typeshed/TypeShedDescriptorsProvider.java @@ -18,12 +18,14 @@ import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.TreeMap; import java.util.function.Predicate; import java.util.stream.Stream; import javax.annotation.CheckForNull; @@ -133,9 +135,9 @@ static ModuleSymbol deserializedModule(String moduleName, InputStream resource) } } - public Set stubFilesDescriptors() { - Set descriptors = new HashSet<>(builtinDescriptors().values()); - cachedDescriptors.values().forEach(entry -> descriptors.addAll(entry.values())); + public List stubFilesDescriptors() { + List descriptors = new ArrayList<>(new TreeMap<>(builtinDescriptors()).values()); + new TreeMap<>(cachedDescriptors).values().forEach(entry -> descriptors.addAll(new TreeMap<>(entry).values())); return descriptors; } }