Skip to content

Commit

Permalink
SONARPY-2219 Fix tests, QG fixes, and reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-serre-sonarsource committed Oct 22, 2024
1 parent a6d4ada commit 715fcaf
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -236,7 +235,7 @@ public void addModuleV2(String fullyQualifiedModuleName, Map<SymbolV2, Set<Pytho
return Map.entry(entry.getKey(), descriptor);
}
)
.filter( entry -> !(!entry.getValue().fullyQualifiedName().startsWith(fullyQualifiedModuleName)
.filter(entry -> !(!Objects.requireNonNull(entry.getValue().fullyQualifiedName()).startsWith(fullyQualifiedModuleName)
|| entry.getKey().usages().stream().anyMatch(u -> u.kind().equals(UsageV2.Kind.IMPORT))))
.map(Map.Entry::getValue)
.collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@

public class LazyTypesContext {
private final Map<String, LazyType> lazyTypes;
private final ProjectLevelTypeTable projectLevelTypeTable;
private final TypeTable typeTable;

public LazyTypesContext(ProjectLevelTypeTable projectLevelTypeTable) {
public LazyTypesContext(ProjectLevelTypeTable typeTable) {
this.lazyTypes = new HashMap<>();
this.projectLevelTypeTable = projectLevelTypeTable;
this.typeTable = typeTable;
}

public TypeWrapper getOrCreateLazyTypeWrapper(String importPath) {
Expand All @@ -49,7 +49,7 @@ public LazyType getOrCreateLazyType(String importPath) {
}

public PythonType resolveLazyType(LazyType lazyType) {
PythonType resolved = projectLevelTypeTable.getType(lazyType.importPath());
PythonType resolved = typeTable.getType(lazyType.importPath());
lazyType.resolve(resolved);
lazyTypes.remove(lazyType.importPath());
return resolved;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.sonar.python.semantic.v2;

import java.util.List;
import org.sonar.python.types.v2.ModuleType;
import org.sonar.python.types.v2.PythonType;

public interface TypeTable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private Descriptor convert(String moduleFqn, String symbolName, FunctionType typ

private Descriptor convert(String moduleFqn, String symbolName, ClassType type) {
Set<Descriptor> memberDescriptors = type.members().stream().map(m -> convert(moduleFqn, m.name(), m.type())).collect(Collectors.toSet());
List<String> superClasses = type.superClasses().stream().map(TypeWrapper::type).map(t -> typeFqn(moduleFqn, t)).collect(Collectors.toList());
List<String> superClasses = type.superClasses().stream().map(TypeWrapper::type).map(t -> typeFqn(moduleFqn, t)).toList();
return new ClassDescriptor(symbolName, symbolFqn(moduleFqn, symbolName),
superClasses,
memberDescriptors,
Expand All @@ -110,7 +110,7 @@ private Descriptor convert(String moduleFqn, String symbolName, UnionType type)
);
}

private Descriptor convert(String moduleFqn, String symbolName, UnknownType.UnresolvedImportType type) {
private static Descriptor convert(String moduleFqn, String symbolName, UnknownType.UnresolvedImportType type) {
return new VariableDescriptor(symbolName,
symbolFqn(moduleFqn, symbolName),
type.importPath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import org.sonar.plugins.python.api.tree.TypeAnnotation;
import org.sonar.python.semantic.v2.ClassTypeBuilder;
import org.sonar.python.semantic.v2.FunctionTypeBuilder;
import org.sonar.python.semantic.v2.ProjectLevelTypeTable;
import org.sonar.python.semantic.v2.SymbolV2;
import org.sonar.python.semantic.v2.TypeTable;
import org.sonar.python.semantic.v2.UsageV2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ void addFile(PythonInputFile inputFile) throws IOException {
projectLevelSymbolTable.addProjectPackage(packageName);
PythonFile pythonFile = SonarQubePythonFile.create(inputFile.wrappedFile());
projectLevelSymbolTable.addModule(astRoot, packageName, pythonFile);


projectLevelSymbolTable.addModuleV2(packageName, pythonFile, astRoot);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void single_file_simple_test() throws IOException {
void multiple_files_simple_test() throws IOException {
var projectLevelSymbolTable = buildProjectLevelSymbolTable("mod1.py", "mod2.py");
assertThat(projectLevelSymbolTable.getDescriptorsFromModule("mod1")).hasSize(1);
assertThat(projectLevelSymbolTable.getDescriptorsFromModuleV2("mod2")).hasSize(2);
assertThat(projectLevelSymbolTable.getDescriptorsFromModuleV2("mod2")).hasSize(1);
}

private ProjectLevelSymbolTable buildProjectLevelSymbolTable(String... files) throws IOException {
Expand Down

0 comments on commit 715fcaf

Please sign in to comment.