Skip to content

Commit 474d913

Browse files
Remove API to access symbols generated from stub files (#802)
This reverts commit 7599f2c.
1 parent 65ae69c commit 474d913

File tree

5 files changed

+3
-61
lines changed

5 files changed

+3
-61
lines changed

python-frontend/src/main/java/org/sonar/plugins/python/api/SubscriptionContext.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@
1919
*/
2020
package org.sonar.plugins.python.api;
2121

22-
import com.google.common.annotations.Beta;
2322
import java.io.File;
24-
import java.util.Collection;
2523
import javax.annotation.CheckForNull;
2624
import javax.annotation.Nullable;
27-
import org.sonar.plugins.python.api.symbols.Symbol;
2825
import org.sonar.plugins.python.api.tree.Token;
2926
import org.sonar.plugins.python.api.tree.Tree;
3027

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

4643
PythonFile pythonFile();
4744

48-
/**
49-
* Returns symbols declared in stub files (e.g. typeshed) used in the analyzed project.
50-
*/
51-
@Beta
52-
Collection<Symbol> stubFilesSymbols();
53-
5445
/**
5546
* Returns null in case of Sonarlint context
5647
*/

python-frontend/src/main/java/org/sonar/python/SubscriptionVisitor.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@
3737
import org.sonar.plugins.python.api.PythonSubscriptionCheck;
3838
import org.sonar.plugins.python.api.PythonVisitorContext;
3939
import org.sonar.plugins.python.api.SubscriptionContext;
40-
import org.sonar.plugins.python.api.symbols.Symbol;
4140
import org.sonar.plugins.python.api.tree.FileInput;
4241
import org.sonar.plugins.python.api.tree.Token;
4342
import org.sonar.plugins.python.api.tree.Tree;
4443
import org.sonar.plugins.python.api.tree.Tree.Kind;
45-
import org.sonar.python.types.TypeShed;
4644

4745
public class SubscriptionVisitor {
4846

@@ -142,11 +140,6 @@ public PythonFile pythonFile() {
142140
return pythonVisitorContext.pythonFile();
143141
}
144142

145-
@Override
146-
public Collection<Symbol> stubFilesSymbols() {
147-
return TypeShed.stubFilesSymbols();
148-
}
149-
150143
@Override
151144
@CheckForNull
152145
public File workingDirectory() {

python-frontend/src/main/java/org/sonar/python/types/TypeShed.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.sonar.sslr.api.AstNode;
2323
import java.io.InputStream;
2424
import java.util.Arrays;
25-
import java.util.Collection;
2625
import java.util.Collections;
2726
import java.util.HashMap;
2827
import java.util.HashSet;
@@ -31,8 +30,6 @@
3130
import java.util.Set;
3231
import java.util.function.Function;
3332
import java.util.stream.Collectors;
34-
import javax.annotation.CheckForNull;
35-
import javax.annotation.Nullable;
3633
import org.sonar.plugins.python.api.PythonFile;
3734
import org.sonar.plugins.python.api.symbols.ClassSymbol;
3835
import org.sonar.plugins.python.api.symbols.FunctionSymbol;
@@ -52,6 +49,9 @@
5249
import org.sonar.python.tree.FunctionDefImpl;
5350
import org.sonar.python.tree.PythonTreeMaker;
5451

52+
import javax.annotation.CheckForNull;
53+
import javax.annotation.Nullable;
54+
5555
import static org.sonar.plugins.python.api.types.BuiltinTypes.NONE_TYPE;
5656

5757
public class TypeShed {
@@ -259,12 +259,6 @@ public static ClassSymbol typeShedClass(String fullyQualifiedName) {
259259
return (ClassSymbol) symbol;
260260
}
261261

262-
public static Collection<Symbol> stubFilesSymbols() {
263-
Set<Symbol> symbols = new HashSet<>(TypeShed.builtinSymbols().values());
264-
typeShedSymbols.values().forEach(symbols::addAll);
265-
return symbols;
266-
}
267-
268262
static class ReturnTypeVisitor extends BaseTreeVisitor {
269263

270264
@Override

python-frontend/src/test/java/org/sonar/python/PythonVisitorCheckTest.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.io.IOException;
2424
import java.nio.file.Files;
2525
import java.nio.file.Path;
26-
import java.util.Collection;
2726
import java.util.Collections;
2827
import java.util.List;
2928
import org.junit.Test;
@@ -34,11 +33,9 @@
3433
import org.sonar.plugins.python.api.PythonVisitorCheck;
3534
import org.sonar.plugins.python.api.PythonVisitorContext;
3635
import org.sonar.plugins.python.api.SubscriptionCheck;
37-
import org.sonar.plugins.python.api.symbols.Symbol;
3836
import org.sonar.plugins.python.api.tree.FunctionDef;
3937
import org.sonar.plugins.python.api.tree.Name;
4038
import org.sonar.plugins.python.api.tree.Tree;
41-
import org.sonar.python.types.TypeShed;
4239

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

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

133-
@Test
134-
public void stubFilesSymbols() throws IOException {
135-
Collection<Symbol> symbols = TypeShed.stubFilesSymbols();
136-
PythonVisitorContext context = TestPythonVisitorRunner.createContext(FILE);
137-
138-
SymbolsRecordingCheck check = new SymbolsRecordingCheck();
139-
check.scanFile(context);
140-
SubscriptionVisitor.analyze(Collections.singletonList(check), context);
141-
142-
assertThat(check.symbols).isEqualTo(TypeShed.stubFilesSymbols());
143-
}
144-
145130
private static class TestPythonCheck extends PythonVisitorCheck {
146131

147132
}
148-
149-
private static class SymbolsRecordingCheck extends PythonSubscriptionCheck {
150-
public Collection<Symbol> symbols;
151-
@Override
152-
public void initialize(Context context) {
153-
context.registerSyntaxNodeConsumer(Tree.Kind.FILE_INPUT, ctx -> symbols = ctx.stubFilesSymbols());
154-
}
155-
}
156133
}

python-frontend/src/test/java/org/sonar/python/types/TypeShedTest.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
*/
2020
package org.sonar.python.types;
2121

22-
import java.util.Collection;
2322
import java.util.Map;
24-
import java.util.Set;
2523
import java.util.function.Function;
2624
import java.util.stream.Collectors;
2725
import org.junit.Test;
@@ -195,15 +193,4 @@ public void package_django() {
195193
assertThat(responseSymbol.kind()).isEqualTo(Kind.CLASS);
196194
assertThat(responseSymbol.fullyQualifiedName()).isEqualTo("django.http.response.HttpResponse");
197195
}
198-
199-
@Test
200-
public void stub_files_symbols() {
201-
Set<Symbol> mathSymbols = TypeShed.symbolsForModule("math");
202-
Set<Symbol> djangoHttpSymbols = TypeShed.symbolsForModule("django.http");
203-
204-
Collection<Symbol> symbols = TypeShed.stubFilesSymbols();
205-
assertThat(symbols)
206-
.containsAll(mathSymbols)
207-
.containsAll(djangoHttpSymbols);
208-
}
209196
}

0 commit comments

Comments
 (0)