Skip to content

Commit

Permalink
Make selection of possible duplicate descriptors deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-dequenne-sonarsource committed Dec 6, 2024
1 parent 562ecdc commit ee46413
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -210,12 +208,9 @@ public Collection<Symbol> stubFilesSymbols() {
if (cachedSymbols != null) {
return cachedSymbols;
}
List<Descriptor> stubDescriptors = new ArrayList<>(typeShedDescriptorsProvider.stubFilesDescriptors());

Map<String, Symbol> 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<>()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -133,9 +135,9 @@ static ModuleSymbol deserializedModule(String moduleName, InputStream resource)
}
}

public Set<Descriptor> stubFilesDescriptors() {
Set<Descriptor> descriptors = new HashSet<>(builtinDescriptors().values());
cachedDescriptors.values().forEach(entry -> descriptors.addAll(entry.values()));
public List<Descriptor> stubFilesDescriptors() {
List<Descriptor> descriptors = new ArrayList<>(new TreeMap<>(builtinDescriptors()).values());
new TreeMap<>(cachedDescriptors).values().forEach(entry -> descriptors.addAll(new TreeMap<>(entry).values()));
return descriptors;
}
}

0 comments on commit ee46413

Please sign in to comment.