Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
*/
package org.sonar.plugins.python.api;

import com.google.common.annotations.Beta;
import java.io.File;
import java.util.Collection;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.plugins.python.api.symbols.Symbol;
import org.sonar.plugins.python.api.tree.Token;
import org.sonar.plugins.python.api.tree.Tree;

Expand All @@ -45,12 +42,6 @@ public interface SubscriptionContext {

PythonFile pythonFile();

/**
* Returns symbols declared in stub files (e.g. typeshed) used in the analyzed project.
*/
@Beta
Collection<Symbol> stubFilesSymbols();

/**
* Returns null in case of Sonarlint context
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@
import org.sonar.plugins.python.api.PythonSubscriptionCheck;
import org.sonar.plugins.python.api.PythonVisitorContext;
import org.sonar.plugins.python.api.SubscriptionContext;
import org.sonar.plugins.python.api.symbols.Symbol;
import org.sonar.plugins.python.api.tree.FileInput;
import org.sonar.plugins.python.api.tree.Token;
import org.sonar.plugins.python.api.tree.Tree;
import org.sonar.plugins.python.api.tree.Tree.Kind;
import org.sonar.python.types.TypeShed;

public class SubscriptionVisitor {

Expand Down Expand Up @@ -142,11 +140,6 @@ public PythonFile pythonFile() {
return pythonVisitorContext.pythonFile();
}

@Override
public Collection<Symbol> stubFilesSymbols() {
return TypeShed.stubFilesSymbols();
}

@Override
@CheckForNull
public File workingDirectory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.sonar.sslr.api.AstNode;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -31,8 +30,6 @@
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.plugins.python.api.PythonFile;
import org.sonar.plugins.python.api.symbols.ClassSymbol;
import org.sonar.plugins.python.api.symbols.FunctionSymbol;
Expand All @@ -52,6 +49,9 @@
import org.sonar.python.tree.FunctionDefImpl;
import org.sonar.python.tree.PythonTreeMaker;

import javax.annotation.CheckForNull;
import javax.annotation.Nullable;

import static org.sonar.plugins.python.api.types.BuiltinTypes.NONE_TYPE;

public class TypeShed {
Expand Down Expand Up @@ -259,12 +259,6 @@ public static ClassSymbol typeShedClass(String fullyQualifiedName) {
return (ClassSymbol) symbol;
}

public static Collection<Symbol> stubFilesSymbols() {
Set<Symbol> symbols = new HashSet<>(TypeShed.builtinSymbols().values());
typeShedSymbols.values().forEach(symbols::addAll);
return symbols;
}

static class ReturnTypeVisitor extends BaseTreeVisitor {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
Expand All @@ -34,11 +33,9 @@
import org.sonar.plugins.python.api.PythonVisitorCheck;
import org.sonar.plugins.python.api.PythonVisitorContext;
import org.sonar.plugins.python.api.SubscriptionCheck;
import org.sonar.plugins.python.api.symbols.Symbol;
import org.sonar.plugins.python.api.tree.FunctionDef;
import org.sonar.plugins.python.api.tree.Name;
import org.sonar.plugins.python.api.tree.Tree;
import org.sonar.python.types.TypeShed;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down Expand Up @@ -130,27 +127,7 @@ public void initialize(SubscriptionCheck.Context context) {
SubscriptionVisitor.analyze(Collections.singletonList(check), context);
}

@Test
public void stubFilesSymbols() throws IOException {
Collection<Symbol> symbols = TypeShed.stubFilesSymbols();
PythonVisitorContext context = TestPythonVisitorRunner.createContext(FILE);

SymbolsRecordingCheck check = new SymbolsRecordingCheck();
check.scanFile(context);
SubscriptionVisitor.analyze(Collections.singletonList(check), context);

assertThat(check.symbols).isEqualTo(TypeShed.stubFilesSymbols());
}

private static class TestPythonCheck extends PythonVisitorCheck {

}

private static class SymbolsRecordingCheck extends PythonSubscriptionCheck {
public Collection<Symbol> symbols;
@Override
public void initialize(Context context) {
context.registerSyntaxNodeConsumer(Tree.Kind.FILE_INPUT, ctx -> symbols = ctx.stubFilesSymbols());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
*/
package org.sonar.python.types;

import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.junit.Test;
Expand Down Expand Up @@ -195,15 +193,4 @@ public void package_django() {
assertThat(responseSymbol.kind()).isEqualTo(Kind.CLASS);
assertThat(responseSymbol.fullyQualifiedName()).isEqualTo("django.http.response.HttpResponse");
}

@Test
public void stub_files_symbols() {
Set<Symbol> mathSymbols = TypeShed.symbolsForModule("math");
Set<Symbol> djangoHttpSymbols = TypeShed.symbolsForModule("django.http");

Collection<Symbol> symbols = TypeShed.stubFilesSymbols();
assertThat(symbols)
.containsAll(mathSymbols)
.containsAll(djangoHttpSymbols);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.