From dca64c8ba98d9c871408c93a599ddda3a07b883e Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Thu, 24 Nov 2011 15:18:37 +0400 Subject: [PATCH] Revert "+-JDK and -NOSTDLIB options" This reverts commit 8222011874d6177e1e24f0750518271d6213758c. +- JDK will be restored in next commit removal of -STDLIB was requested by Andrey Breslav --- .../jet/codegen/GenerationState.java | 4 +- .../jet/compiler/CompileSession.java | 2 +- .../jet/lang/resolve/java/AnalyzerFacade.java | 2 +- .../jet/lang/JetSemanticServices.java | 6 +-- .../jet/lang/resolve/AnalyzingUtils.java | 10 ++-- .../jet/lang/types/JetStandardLibrary.java | 50 +++++-------------- .../checkerWithErrorTypes/full/Casts.jet | 4 +- .../jet/checkers/CheckerTestUtilTest.java | 2 +- .../jet/checkers/FullJetPsiCheckerTest.java | 11 +--- .../jet/checkers/QuickJetPsiCheckerTest.java | 8 +-- .../jetbrains/jet/resolve/JetResolveTest.java | 2 +- .../jet/plugin/compiler/JetCompiler.java | 2 +- .../jet/plugin/java/JavaElementFinder.java | 2 +- 13 files changed, 28 insertions(+), 77 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java b/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java index c106eeaed70..56b432cf2c9 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java @@ -30,7 +30,7 @@ public class GenerationState { public GenerationState(Project project, ClassBuilderFactory builderFactory) { this.project = project; - this.standardLibrary = JetStandardLibrary.getJetStandardLibrary(project, true); + this.standardLibrary = JetStandardLibrary.getJetStandardLibrary(project); this.factory = new ClassFileFactory(builderFactory, this); this.intrinsics = new IntrinsicMethods(project, standardLibrary); } @@ -82,7 +82,7 @@ public class GenerationState { public void compile(JetFile psiFile) { final JetNamespace namespace = psiFile.getRootNamespace(); - final BindingContext bindingContext = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS, true).analyzeNamespace(namespace, JetControlFlowDataTraceFactory.EMPTY); + final BindingContext bindingContext = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS).analyzeNamespace(namespace, JetControlFlowDataTraceFactory.EMPTY); AnalyzingUtils.throwExceptionOnErrors(bindingContext); compileCorrectNamespaces(bindingContext, Collections.singletonList(namespace)); // NamespaceCodegen codegen = forNamespace(namespace); diff --git a/compiler/backend/src/org/jetbrains/jet/compiler/CompileSession.java b/compiler/backend/src/org/jetbrains/jet/compiler/CompileSession.java index 43f4661b726..e90fda9eb8a 100644 --- a/compiler/backend/src/org/jetbrains/jet/compiler/CompileSession.java +++ b/compiler/backend/src/org/jetbrains/jet/compiler/CompileSession.java @@ -84,7 +84,7 @@ public class CompileSession { } return false; } - final AnalyzingUtils instance = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS, true); + final AnalyzingUtils instance = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS); List allNamespaces = new ArrayList(mySourceFileNamespaces); allNamespaces.addAll(myLibrarySourceFileNamespaces); myBindingContext = instance.analyzeNamespaces(myEnvironment.getProject(), allNamespaces, Predicates.alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY); diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacade.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacade.java index 9be40fce997..6ad38396927 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacade.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacade.java @@ -34,7 +34,7 @@ public class AnalyzerFacade { } }; - private static final AnalyzingUtils ANALYZING_UTILS = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS, true); + private static final AnalyzingUtils ANALYZING_UTILS = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS); private final static Key> BINDING_CONTEXT = Key.create("BINDING_CONTEXT"); private static final Object lock = new Object(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/JetSemanticServices.java b/compiler/frontend/src/org/jetbrains/jet/lang/JetSemanticServices.java index 9a92d86c8d0..36fadfc8f60 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/JetSemanticServices.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/JetSemanticServices.java @@ -17,11 +17,7 @@ public class JetSemanticServices { } public static JetSemanticServices createSemanticServices(Project project) { - return createSemanticServices(project, true); - } - - public static JetSemanticServices createSemanticServices(Project project, boolean loadFullLibrary) { - return new JetSemanticServices(JetStandardLibrary.getJetStandardLibrary(project, loadFullLibrary)); + return new JetSemanticServices(JetStandardLibrary.getJetStandardLibrary(project)); } private final JetStandardLibrary standardLibrary; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java index 2eb18914627..483a5673739 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java @@ -28,8 +28,8 @@ import java.util.*; * @author abreslav */ public class AnalyzingUtils { - public static AnalyzingUtils getInstance(@NotNull ImportingStrategy importingStrategy, boolean loadStdlib) { - return new AnalyzingUtils(importingStrategy, loadStdlib); + public static AnalyzingUtils getInstance(@NotNull ImportingStrategy importingStrategy) { + return new AnalyzingUtils(importingStrategy); } public static void checkForSyntacticErrors(@NotNull PsiElement root) { @@ -53,11 +53,9 @@ public class AnalyzingUtils { } private final ImportingStrategy importingStrategy; - private final boolean loadStdlib; - private AnalyzingUtils(ImportingStrategy importingStrategy, boolean loadStdlib) { + private AnalyzingUtils(ImportingStrategy importingStrategy) { this.importingStrategy = importingStrategy; - this.loadStdlib = loadStdlib; } public BindingContext analyzeNamespace(@NotNull JetNamespace namespace, @NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) { @@ -73,7 +71,7 @@ public class AnalyzingUtils { @NotNull Predicate filesToAnalyzeCompletely, @NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) { BindingTraceContext bindingTraceContext = new BindingTraceContext(); - JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project, loadStdlib); + JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project); JetScope libraryScope = semanticServices.getStandardLibrary().getLibraryScope(); ModuleDescriptor owner = new ModuleDescriptor(""); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java index c90e935e043..62923713125 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java @@ -29,24 +29,16 @@ import java.util.Set; public class JetStandardLibrary { // TODO : consider releasing this memory - private static JetStandardLibrary cachedFullLibrary = null; - private static JetStandardLibrary cachedQuickLibrary = null; + private static JetStandardLibrary cachedLibrary = null; // private static final Map standardLibraryCache = new HashMap(); // TODO : double checked locking synchronized - public static JetStandardLibrary getJetStandardLibrary(@NotNull Project project, boolean loadFullLibrary) { - if (loadFullLibrary) { - if (cachedFullLibrary == null) { - cachedFullLibrary = new JetStandardLibrary(project, true); - } - return cachedFullLibrary; - } else { - if (cachedQuickLibrary == null) { - cachedQuickLibrary = new JetStandardLibrary(project, false); - } - return cachedQuickLibrary; + public static JetStandardLibrary getJetStandardLibrary(@NotNull Project project) { + if (cachedLibrary == null) { + cachedLibrary = new JetStandardLibrary(project); } + return cachedLibrary; // JetStandardLibrary standardLibrary = standardLibraryCache.get(project); // if (standardLibrary == null) { // standardLibrary = new JetStandardLibrary(project); @@ -55,12 +47,6 @@ public class JetStandardLibrary { // return standardLibrary; } - public static JetStandardLibrary getJetStandardLibrary(@NotNull Project project) { - return getJetStandardLibrary(project, true); - } - - private final boolean loadFullLibrary; - private JetScope libraryScope; private ClassDescriptor numberClass; @@ -136,27 +122,20 @@ public class JetStandardLibrary { private NamespaceDescriptor typeInfoNamespace; private Set typeInfoFunction; - private JetStandardLibrary(@NotNull Project project, boolean loadFullLibrary) { - this.loadFullLibrary = loadFullLibrary; - + private JetStandardLibrary(@NotNull Project project) { + // TODO : review + InputStream stream = JetStandardClasses.class.getClassLoader().getResourceAsStream("jet/Library.jet"); try { - JetFile file = null; - if (loadFullLibrary) { - // TODO : review - InputStream stream = JetStandardClasses.class.getClassLoader().getResourceAsStream("jet/Library.jet"); - //noinspection IOResourceOpenedButNotSafelyClosed - file = (JetFile) PsiFileFactory.getInstance(project).createFileFromText("Library.jet", - JetFileType.INSTANCE, FileUtil.loadTextAndClose(new InputStreamReader(stream))); - } + //noinspection IOResourceOpenedButNotSafelyClosed + JetFile file = (JetFile) PsiFileFactory.getInstance(project).createFileFromText("Library.jet", + JetFileType.INSTANCE, FileUtil.loadTextAndClose(new InputStreamReader(stream))); JetSemanticServices bootstrappingSemanticServices = JetSemanticServices.createSemanticServices(this); BindingTraceContext bindingTraceContext = new BindingTraceContext(); WritableScopeImpl writableScope = new WritableScopeImpl(JetStandardClasses.STANDARD_CLASSES, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, RedeclarationHandler.THROW_EXCEPTION).setDebugName("Root bootstrap scope"); // this.libraryScope = bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations()); // bootstrappingTDA.process(writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace().getDeclarations()); - if (loadFullLibrary) { - TopDownAnalyzer.processStandardLibraryNamespace(bootstrappingSemanticServices, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace()); - } + TopDownAnalyzer.processStandardLibraryNamespace(bootstrappingSemanticServices, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace()); // this.libraryScope = JetStandardClasses.STANDARD_CLASSES_NAMESPACE.getMemberScope(); AnalyzingUtils.throwExceptionOnErrors(bindingTraceContext.getBindingContext()); @@ -174,11 +153,6 @@ public class JetStandardLibrary { private void initStdClasses() { if(libraryScope == null) { this.libraryScope = JetStandardClasses.STANDARD_CLASSES_NAMESPACE.getMemberScope(); - - if (!loadFullLibrary) { - return; - } - this.numberClass = (ClassDescriptor) libraryScope.getClassifier("Number"); this.byteClass = (ClassDescriptor) libraryScope.getClassifier("Byte"); this.charClass = (ClassDescriptor) libraryScope.getClassifier("Char"); diff --git a/compiler/testData/checkerWithErrorTypes/full/Casts.jet b/compiler/testData/checkerWithErrorTypes/full/Casts.jet index e34a90b945a..163619fd4d0 100644 --- a/compiler/testData/checkerWithErrorTypes/full/Casts.jet +++ b/compiler/testData/checkerWithErrorTypes/full/Casts.jet @@ -1,5 +1,3 @@ -// -JDK - fun test() : Unit { var x : Int? = 0 var y : Int = 0 @@ -15,4 +13,4 @@ fun test() : Unit { x as? Int? : Int? y as? Int? : Int? () -} +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/CheckerTestUtilTest.java b/compiler/tests/org/jetbrains/jet/checkers/CheckerTestUtilTest.java index 8663cc4d9fc..06ffed74d04 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/CheckerTestUtilTest.java +++ b/compiler/tests/org/jetbrains/jet/checkers/CheckerTestUtilTest.java @@ -81,7 +81,7 @@ public class CheckerTestUtilTest extends JetLiteFixture { } public void test(PsiFile psiFile) { - BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(ImportingStrategy.NONE, true), (JetFile) psiFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER); + BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(ImportingStrategy.NONE), (JetFile) psiFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER); String expectedText = CheckerTestUtil.addDiagnosticMarkersToText(psiFile, bindingContext).toString(); List diagnosedRanges = Lists.newArrayList(); diff --git a/compiler/tests/org/jetbrains/jet/checkers/FullJetPsiCheckerTest.java b/compiler/tests/org/jetbrains/jet/checkers/FullJetPsiCheckerTest.java index 5b4646d207e..986f6501d10 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/FullJetPsiCheckerTest.java +++ b/compiler/tests/org/jetbrains/jet/checkers/FullJetPsiCheckerTest.java @@ -8,11 +8,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.JetLiteFixture; import org.jetbrains.jet.JetTestCaseBuilder; import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils; -import org.jetbrains.jet.lang.resolve.AnalyzingUtils; import org.jetbrains.jet.lang.resolve.BindingContext; -import org.jetbrains.jet.lang.resolve.ImportingStrategy; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade; -import org.jetbrains.jet.lang.resolve.java.JavaDefaultImports; import java.util.List; @@ -45,13 +42,7 @@ public class FullJetPsiCheckerTest extends JetLiteFixture { String clearText = CheckerTestUtil.parseDiagnosedRanges(expectedText, diagnosedRanges); myFile = createPsiFile(myName, clearText); - - boolean loadStdlib = !expectedText.contains("-STDLIB"); - boolean importJdk = !expectedText.contains("-JDK"); - - ImportingStrategy importingStrategy = importJdk ? JavaDefaultImports.JAVA_DEFAULT_IMPORTS : ImportingStrategy.NONE; - - BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(importingStrategy, loadStdlib), myFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER); + BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(myFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER); CheckerTestUtil.diagnosticsDiff(diagnosedRanges, bindingContext.getDiagnostics(), new CheckerTestUtil.DiagnosticDiffCallbacks() { @Override diff --git a/compiler/tests/org/jetbrains/jet/checkers/QuickJetPsiCheckerTest.java b/compiler/tests/org/jetbrains/jet/checkers/QuickJetPsiCheckerTest.java index a69f04a21c7..d6ead64cdf1 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/QuickJetPsiCheckerTest.java +++ b/compiler/tests/org/jetbrains/jet/checkers/QuickJetPsiCheckerTest.java @@ -13,7 +13,6 @@ import org.jetbrains.jet.lang.resolve.AnalyzingUtils; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.ImportingStrategy; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade; -import org.jetbrains.jet.lang.resolve.java.JavaDefaultImports; import java.util.List; @@ -41,12 +40,7 @@ public class QuickJetPsiCheckerTest extends JetLiteFixture { createAndCheckPsiFile(name, clearText); JetFile jetFile = (JetFile) myFile; - boolean loadStdlib = !expectedText.contains("-STDLIB"); - boolean importJdk = expectedText.contains("+JDK"); - - ImportingStrategy importingStrategy = importJdk ? JavaDefaultImports.JAVA_DEFAULT_IMPORTS : ImportingStrategy.NONE; - - BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(importingStrategy, loadStdlib), jetFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER); + BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(ImportingStrategy.NONE), jetFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER); CheckerTestUtil.diagnosticsDiff(diagnosedRanges, bindingContext.getDiagnostics(), new CheckerTestUtil.DiagnosticDiffCallbacks() { @Override diff --git a/compiler/tests/org/jetbrains/jet/resolve/JetResolveTest.java b/compiler/tests/org/jetbrains/jet/resolve/JetResolveTest.java index f4bf68958a1..ca206ae88c0 100644 --- a/compiler/tests/org/jetbrains/jet/resolve/JetResolveTest.java +++ b/compiler/tests/org/jetbrains/jet/resolve/JetResolveTest.java @@ -44,7 +44,7 @@ public class JetResolveTest extends ExtensibleResolveTestCase { @Override protected ExpectedResolveData getExpectedResolveData() { Project project = getProject(); - JetStandardLibrary lib = JetStandardLibrary.getJetStandardLibrary(project, true); + JetStandardLibrary lib = JetStandardLibrary.getJetStandardLibrary(project); Map nameToDescriptor = new HashMap(); nameToDescriptor.put("std::Int.plus(Int)", standardFunction(lib.getInt(), "plus", lib.getIntType())); FunctionDescriptor descriptorForGet = standardFunction(lib.getArray(), Collections.singletonList(new TypeProjection(lib.getIntType())), "get", lib.getIntType()); diff --git a/idea/src/org/jetbrains/jet/plugin/compiler/JetCompiler.java b/idea/src/org/jetbrains/jet/plugin/compiler/JetCompiler.java index 0a34294d80f..0a16cb56f58 100644 --- a/idea/src/org/jetbrains/jet/plugin/compiler/JetCompiler.java +++ b/idea/src/org/jetbrains/jet/plugin/compiler/JetCompiler.java @@ -80,7 +80,7 @@ public class JetCompiler implements TranslatingCompiler { } } - BindingContext bindingContext = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS, true).analyzeNamespaces( + BindingContext bindingContext = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS).analyzeNamespaces( compileContext.getProject(), namespaces, Predicates.alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY); diff --git a/idea/src/org/jetbrains/jet/plugin/java/JavaElementFinder.java b/idea/src/org/jetbrains/jet/plugin/java/JavaElementFinder.java index 1967f70b22e..7cfa0fe1b86 100644 --- a/idea/src/org/jetbrains/jet/plugin/java/JavaElementFinder.java +++ b/idea/src/org/jetbrains/jet/plugin/java/JavaElementFinder.java @@ -211,7 +211,7 @@ public class JavaElementFinder extends PsiElementFinder { if (dirty.size() > 0) { - final BindingContext context = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS, true).shallowAnalyzeFiles(dirty); + final BindingContext context = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS).shallowAnalyzeFiles(dirty); state.compileCorrectNamespaces(context, AnalyzingUtils.collectRootNamespaces(dirty)); state.getFactory().files(); }