From 0e1161578049bb321e5df079247bbeaa9f8ec64b Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 19 Dec 2016 18:20:55 +0300 Subject: [PATCH] J2K diagnostic tests: prettify --- .../checkers/AbstractDiagnosticsTest.kt | 353 ++++++++---------- .../kotlin/checkers/BaseDiagnosticsTest.kt | 259 ++++++------- .../kotlin/checkers/LoggingStorageManager.kt | 2 +- .../AbstractDiagnosticsTestWithJsStdLib.kt | 56 ++- ...csTestWithJsStdLibAndBackendCompilation.kt | 6 +- .../ir/AbstractPsi2IrDiagnosticsTest.kt | 10 +- 6 files changed, 301 insertions(+), 385 deletions(-) diff --git a/compiler/tests-common/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTest.kt b/compiler/tests-common/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTest.kt index 6be7b1bb94c..a024ee59260 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTest.kt +++ b/compiler/tests-common/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTest.kt @@ -17,12 +17,9 @@ package org.jetbrains.kotlin.checkers import com.google.common.base.Predicate -import com.google.common.collect.Sets import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.text.StringUtil -import com.intellij.psi.PsiElement import com.intellij.psi.search.GlobalSearchScope -import junit.framework.TestCase import org.jetbrains.kotlin.analyzer.AnalysisResult import org.jetbrains.kotlin.analyzer.common.DefaultAnalyzerFacade import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport @@ -31,12 +28,17 @@ import org.jetbrains.kotlin.config.CommonConfigurationKeys import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl -import org.jetbrains.kotlin.container.getService -import org.jetbrains.kotlin.context.* +import org.jetbrains.kotlin.container.get +import org.jetbrains.kotlin.context.ModuleContext +import org.jetbrains.kotlin.context.SimpleGlobalContext +import org.jetbrains.kotlin.context.withModule +import org.jetbrains.kotlin.context.withProject import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.impl.CompositePackageFragmentProvider import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl -import org.jetbrains.kotlin.diagnostics.* +import org.jetbrains.kotlin.diagnostics.Diagnostic +import org.jetbrains.kotlin.diagnostics.DiagnosticFactory +import org.jetbrains.kotlin.diagnostics.DiagnosticUtils import org.jetbrains.kotlin.diagnostics.Errors.* import org.jetbrains.kotlin.frontend.java.di.createContainerForTopDownAnalyzerForJvm import org.jetbrains.kotlin.frontend.java.di.initJvmBuiltInsForTopDownAnalysis @@ -46,12 +48,10 @@ import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.SpecialNames import org.jetbrains.kotlin.platform.JvmBuiltIns -import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.resolve.* import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCall import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall -import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer @@ -63,53 +63,47 @@ import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.util.DescriptorValidator import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator -import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.* -import org.jetbrains.kotlin.utils.rethrow +import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.RECURSIVE +import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.RECURSIVE_ALL import org.junit.Assert import java.io.File import java.util.* abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() { - override fun analyzeAndCheck(testDataFile: File, testFiles: List) { - val groupedByModule = testFiles.groupByTo>>( - LinkedHashMap>() - ) { file -> file.module } - - val checkLazyResolveLog = testFiles.any { file -> file.checkLazyLog } + override fun analyzeAndCheck(testDataFile: File, files: List) { + val groupedByModule = files.groupBy(TestFile::module) var lazyOperationsLog: LazyOperationsLog? = null - val context: GlobalContext val tracker = ExceptionTracker() - if (checkLazyResolveLog) { + val storageManager: StorageManager + if (files.any(TestFile::checkLazyLog)) { lazyOperationsLog = LazyOperationsLog(HASH_SANITIZER) - context = SimpleGlobalContext( - LoggingStorageManager( - LockBasedStorageManager.createWithExceptionHandling(tracker), - lazyOperationsLog.addRecordFunction - ), - tracker + storageManager = LoggingStorageManager( + LockBasedStorageManager.createWithExceptionHandling(tracker), + lazyOperationsLog.addRecordFunction ) } else { - context = SimpleGlobalContext(LockBasedStorageManager.createWithExceptionHandling(tracker), tracker) + storageManager = LockBasedStorageManager.createWithExceptionHandling(tracker) } + val context = SimpleGlobalContext(storageManager, tracker) + val modules = createModules(groupedByModule, context.storageManager) - val moduleBindings = java.util.HashMap() + val moduleBindings = HashMap() for ((testModule, testFilesInModule) in groupedByModule) { + val ktFiles = getKtFiles(testFilesInModule, true) - val jetFiles = getJetFiles(testFilesInModule, true) - - val oldModule = modules.get(testModule) + val oldModule = modules[testModule]!! val languageVersionSettings = loadLanguageVersionSettings(testFilesInModule) val moduleContext = context.withProject(project).withModule(oldModule) - val separateModules = groupedByModule.size == 1 && groupedByModule.keys.iterator().next() == null + val separateModules = groupedByModule.size == 1 && groupedByModule.keys.single() == null val result = analyzeModuleContents( - moduleContext, jetFiles, CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(), + moduleContext, ktFiles, CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(), languageVersionSettings, separateModules ) if (oldModule != result.moduleDescriptor) { @@ -117,36 +111,37 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() { // (its API does not support working with a module created beforehand). // So, we should replace the old (effectively discarded) module with the new one everywhere in dependencies. // TODO: dirty hack, refactor this test so that it doesn't create ModuleDescriptor instances - modules.put(testModule, result.moduleDescriptor) + modules[testModule] = result.moduleDescriptor as ModuleDescriptorImpl for (module in modules.values) { - val it = module.testOnly_AllDependentModules.listIterator() + @Suppress("DEPRECATION") + val it = (module.testOnly_AllDependentModules as MutableList).listIterator() while (it.hasNext()) { if (it.next() == oldModule) { - it.set(result.moduleDescriptor) + it.set(result.moduleDescriptor as ModuleDescriptorImpl) } } } } - moduleBindings.put(testModule, result.bindingContext) - checkAllResolvedCallsAreCompleted(jetFiles, result.bindingContext) + moduleBindings[testModule] = result.bindingContext + checkAllResolvedCallsAreCompleted(ktFiles, result.bindingContext) } // We want to always create a test data file (txt) if it was missing, // but don't want to skip the following checks in case this one fails var exceptionFromLazyResolveLogValidation: Throwable? = null - if (checkLazyResolveLog) { + if (lazyOperationsLog != null) { exceptionFromLazyResolveLogValidation = checkLazyResolveLog(lazyOperationsLog, testDataFile) } else { val lazyLogFile = getLazyLogFile(testDataFile) - TestCase.assertFalse("No lazy log expected, but found: " + lazyLogFile.getAbsolutePath(), lazyLogFile.exists()) + assertFalse("No lazy log expected, but found: ${lazyLogFile.absolutePath}", lazyLogFile.exists()) } var exceptionFromDescriptorValidation: Throwable? = null try { val expectedFile = File(FileUtil.getNameWithoutExtension(testDataFile.absolutePath) + ".txt") - validateAndCompareDescriptorWithFile(expectedFile, testFiles, modules) + validateAndCompareDescriptorWithFile(expectedFile, files, modules) } catch (e: Throwable) { exceptionFromDescriptorValidation = e @@ -156,11 +151,11 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() { var ok = true val actualText = StringBuilder() - for (testFile in testFiles) { + for (testFile in files) { val module = testFile.module - val isCommonModule = modules.get(module).getMultiTargetPlatform() === MultiTargetPlatform.Common + val isCommonModule = modules[module]!!.getMultiTargetPlatform() == MultiTargetPlatform.Common ok = ok and testFile.getActualText( - moduleBindings.get(module), actualText, + moduleBindings[module]!!, actualText, shouldSkipJvmSignatureDiagnostics(groupedByModule) || isCommonModule ) } @@ -168,7 +163,7 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() { var exceptionFromDynamicCallDescriptorsValidation: Throwable? = null try { val expectedFile = File(FileUtil.getNameWithoutExtension(testDataFile.absolutePath) + ".dynamic.txt") - checkDynamicCallDescriptors(expectedFile, testFiles) + checkDynamicCallDescriptors(expectedFile, files) } catch (e: Throwable) { exceptionFromDynamicCallDescriptorsValidation = e @@ -176,41 +171,34 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() { KotlinTestUtils.assertEqualsToFile(testDataFile, actualText.toString()) - TestCase.assertTrue("Diagnostics mismatch. See the output above", ok) + assertTrue("Diagnostics mismatch. See the output above", ok) // now we throw a previously found error, if any - if (exceptionFromDescriptorValidation != null) { - throw rethrow(exceptionFromDescriptorValidation) - } - if (exceptionFromLazyResolveLogValidation != null) { - throw rethrow(exceptionFromLazyResolveLogValidation) - } - if (exceptionFromDynamicCallDescriptorsValidation != null) { - throw rethrow(exceptionFromDynamicCallDescriptorsValidation) - } + exceptionFromDescriptorValidation?.let { throw it } + exceptionFromLazyResolveLogValidation?.let { throw it } + exceptionFromDynamicCallDescriptorsValidation?.let { throw it } - performAdditionalChecksAfterDiagnostics(testDataFile, testFiles, groupedByModule, modules, moduleBindings) + performAdditionalChecksAfterDiagnostics(testDataFile, files, groupedByModule, modules, moduleBindings) } - protected fun performAdditionalChecksAfterDiagnostics( + protected open fun performAdditionalChecksAfterDiagnostics( testDataFile: File, - testFiles: List, - moduleFiles: Map>, - moduleDescriptors: Map, - moduleBindings: Map + testFiles: List, + moduleFiles: Map>, + moduleDescriptors: Map, + moduleBindings: Map ) { // To be overridden by diagnostic-like tests. } - private fun loadLanguageVersionSettings(module: List): LanguageVersionSettings? { + private fun loadLanguageVersionSettings(module: List): LanguageVersionSettings? { var result: LanguageVersionSettings? = null for (file in module) { val current = file.customLanguageVersionSettings if (current != null) { if (result != null && result != current) { Assert.fail( - "More than one file in the module has " + BaseDiagnosticsTest.LANGUAGE_DIRECTIVE + " or " + - BaseDiagnosticsTest.API_VERSION_DIRECTIVE + " directive specified. " + + "More than one file in the module has $LANGUAGE_DIRECTIVE or $API_VERSION_DIRECTIVE directive specified. " + "This is not supported. Please move all directives into one file" ) } @@ -221,59 +209,49 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() { return result } - private fun checkDynamicCallDescriptors(expectedFile: File, testFiles: List) { + private fun checkDynamicCallDescriptors(expectedFile: File, testFiles: List) { val serializer = RecursiveDescriptorComparator(RECURSIVE_ALL) val actualText = StringBuilder() for (testFile in testFiles) { - val dynamicCallDescriptors = testFile.dynamicCallDescriptors - - for (descriptor in dynamicCallDescriptors) { + for (descriptor in testFile.dynamicCallDescriptors) { val actualSerialized = serializer.serializeRecursively(descriptor) actualText.append(actualSerialized) } } - if (actualText.length != 0 || expectedFile.exists()) { + if (actualText.isNotEmpty() || expectedFile.exists()) { KotlinTestUtils.assertEqualsToFile(expectedFile, actualText.toString()) } } - fun shouldSkipJvmSignatureDiagnostics(groupedByModule: Map>): Boolean { - return groupedByModule.size > 1 - } + protected open fun shouldSkipJvmSignatureDiagnostics(groupedByModule: Map>): Boolean = + groupedByModule.size > 1 - private fun checkLazyResolveLog(lazyOperationsLog: LazyOperationsLog, testDataFile: File): Throwable? { - var exceptionFromLazyResolveLogValidation: Throwable? = null - try { - val expectedFile = getLazyLogFile(testDataFile) + private fun checkLazyResolveLog(lazyOperationsLog: LazyOperationsLog, testDataFile: File): Throwable? = + try { + val expectedFile = getLazyLogFile(testDataFile) + KotlinTestUtils.assertEqualsToFile(expectedFile, lazyOperationsLog.getText(), HASH_SANITIZER) + null + } + catch (e: Throwable) { + e + } - KotlinTestUtils.assertEqualsToFile( - expectedFile, - lazyOperationsLog.getText(), - HASH_SANITIZER - ) - } - catch (e: Throwable) { - exceptionFromLazyResolveLogValidation = e - } + private fun getLazyLogFile(testDataFile: File): File = + File(FileUtil.getNameWithoutExtension(testDataFile.absolutePath) + ".lazy.log") - return exceptionFromLazyResolveLogValidation - } - - private fun getLazyLogFile(testDataFile: File): File { - return File(FileUtil.getNameWithoutExtension(testDataFile.absolutePath) + ".lazy.log") - } - - protected fun analyzeModuleContents( + protected open fun analyzeModuleContents( moduleContext: ModuleContext, files: List, moduleTrace: BindingTrace, languageVersionSettings: LanguageVersionSettings?, separateModules: Boolean ): AnalysisResult { + @Suppress("NAME_SHADOWING") var files = files + @Suppress("NAME_SHADOWING") var languageVersionSettings = languageVersionSettings val configuration: CompilerConfiguration if (languageVersionSettings != null) { @@ -305,22 +283,21 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() { val moduleDescriptor = moduleContext.module as ModuleDescriptorImpl val platform = moduleDescriptor.getMultiTargetPlatform() - if (platform === MultiTargetPlatform.Common) { - + if (platform == MultiTargetPlatform.Common) { return DefaultAnalyzerFacade.analyzeFiles( files, moduleDescriptor.name, true, - mapOf, Any>( - MultiTargetPlatform.CAPABILITY.to, MultiTargetPlatform.Common>(MultiTargetPlatform.Common), - MODULE_FILES.to>, List>(files) + mapOf( + MultiTargetPlatform.CAPABILITY to MultiTargetPlatform.Common, + MODULE_FILES to files ) - ) { info, content -> + ) { _, _ -> // TODO PackagePartProvider.Empty } } else if (platform != null) { // TODO: analyze with the correct platform, not always JVM - files = files.plus(getCommonCodeFilesForPlatformSpecificModule(moduleDescriptor)) + files += getCommonCodeFilesForPlatformSpecificModule(moduleDescriptor) } val moduleContentScope = GlobalSearchScope.allScope(moduleContext.project) @@ -336,16 +313,14 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() { moduleClassResolver ) container.initJvmBuiltInsForTopDownAnalysis(moduleDescriptor, languageVersionSettings) - moduleClassResolver.resolver = container.getService(JavaDescriptorResolver::class.java) + moduleClassResolver.resolver = container.get() - moduleDescriptor.initialize(CompositePackageFragmentProvider(Arrays.asList( - container.getService(KotlinCodeAnalyzer::class.java).getPackageFragmentProvider(), - container.getService(JavaDescriptorResolver::class.java).packageFragmentProvider + moduleDescriptor.initialize(CompositePackageFragmentProvider(listOf( + container.get().packageFragmentProvider, + container.get().packageFragmentProvider ))) - container.getService(LazyTopDownAnalyzer::class.java).analyzeDeclarations( - TopDownAnalysisMode.TopLevelDeclarations, files, DataFlowInfo.EMPTY - ) + container.get().analyzeDeclarations(TopDownAnalysisMode.TopLevelDeclarations, files) return AnalysisResult.success(moduleTrace.bindingContext, moduleDescriptor) } @@ -353,14 +328,16 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() { private fun getCommonCodeFilesForPlatformSpecificModule(moduleDescriptor: ModuleDescriptorImpl): List { // We assume that a platform-specific module _implements_ all declarations from common modules which are immediate dependencies. // So we collect all sources from such modules to analyze in the platform-specific module as well + @Suppress("DEPRECATION") val dependencies = moduleDescriptor.testOnly_AllDependentModules // TODO: diagnostics on common code reported during the platform module analysis should be distinguished somehow // E.g. "... val result = ArrayList(0) for (dependency in dependencies) { - if (dependency.getCapability(MultiTargetPlatform.CAPABILITY) === MultiTargetPlatform.Common) { - val files = dependency.getCapability(MODULE_FILES) ?: error("MODULE_FILES should have been set for the common module: " + dependency) + if (dependency.getCapability(MultiTargetPlatform.CAPABILITY) == MultiTargetPlatform.Common) { + val files = dependency.getCapability(MODULE_FILES) + ?: error("MODULE_FILES should have been set for the common module: $dependency") result.addAll(files) } } @@ -370,11 +347,11 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() { private fun validateAndCompareDescriptorWithFile( expectedFile: File, - testFiles: List, - modules: Map + testFiles: List, + modules: Map ) { if (testFiles.any { file -> InTextDirectivesUtils.isDirectiveDefined(file.expectedText, "// SKIP_TXT") }) { - TestCase.assertFalse(".txt file should not exist if SKIP_TXT directive is used: " + expectedFile, expectedFile.exists()) + assertFalse(".txt file should not exist if SKIP_TXT directive is used: $expectedFile", expectedFile.exists()) return } @@ -383,14 +360,24 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() { val isMultiModuleTest = modules.size != 1 val rootPackageText = StringBuilder() - val module = modules.keys.sorted().iterator() + val sortedModules = modules.keys.sortedWith(Comparator { x, y -> + when { + x == null && y == null -> 0 + x == null && y != null -> -1 + x != null && y == null -> 1 + x != null && y != null -> x.compareTo(y) + else -> error("Unreachable") + } + }) + + val module = sortedModules.iterator() while (module.hasNext()) { - val moduleDescriptor = modules[module.next()] + val moduleDescriptor = modules[module.next()]!! val aPackage = moduleDescriptor.getPackage(FqName.ROOT) - TestCase.assertFalse(aPackage.isEmpty()) + assertFalse(aPackage.isEmpty()) if (isMultiModuleTest) { - rootPackageText.append(String.format("// -- Module: %s --\n", moduleDescriptor.getName())) + rootPackageText.append(String.format("// -- Module: %s --\n", moduleDescriptor.name)) } val actualSerialized = comparator.serializeRecursively(aPackage) @@ -403,7 +390,7 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() { val lineCount = StringUtil.getLineBreakCount(rootPackageText) assert(lineCount < 1000) { - "Rendered descriptors of this test take up " + lineCount + " lines. " + + "Rendered descriptors of this test take up $lineCount lines. " + "Please ensure you don't render JRE contents to the .txt file. " + "Such tests are hard to maintain, take long time to execute and are subject to sudden unreviewed changes anyway." } @@ -411,20 +398,19 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() { KotlinTestUtils.assertEqualsToFile(expectedFile, rootPackageText.toString()) } - private fun createdAffectedPackagesConfiguration(testFiles: List, modules: Collection): RecursiveDescriptorComparator.Configuration { - val packagesNames = getTopLevelPackagesFromFileList(getJetFiles(testFiles, false)) + private fun createdAffectedPackagesConfiguration( + testFiles: List, + modules: Collection + ): RecursiveDescriptorComparator.Configuration { + val packagesNames = getTopLevelPackagesFromFileList(getKtFiles(testFiles, false)) val stepIntoFilter = Predicate { descriptor -> val module = DescriptorUtils.getContainingModuleOrNull(descriptor!!) - if (!modules.contains(module)) return@Predicate false + if (module !in modules) return@Predicate false if (descriptor is PackageViewDescriptor) { val fqName = descriptor.fqName - - if (fqName.isRoot) return@Predicate true - - val firstName = fqName.pathSegments()[0] - return@Predicate packagesNames.contains(firstName) + return@Predicate fqName.isRoot || fqName.pathSegments().first() in packagesNames } true @@ -433,21 +419,16 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() { return RECURSIVE.filterRecursion(stepIntoFilter).withValidationStrategy(DescriptorValidator.ValidationVisitor.errorTypesAllowed()) } - private fun getTopLevelPackagesFromFileList(files: List): Set { - val shortNames = LinkedHashSet() - for (file in files) { - val packageFqNameSegments = file.packageFqName.pathSegments() - val name = if (packageFqNameSegments.isEmpty()) SpecialNames.ROOT_PACKAGE else packageFqNameSegments[0] - shortNames.add(name) - } - return shortNames - } + private fun getTopLevelPackagesFromFileList(files: List): Set = + files.mapTo(LinkedHashSet()) { file -> + file.packageFqName.pathSegments().firstOrNull() ?: SpecialNames.ROOT_PACKAGE + } private fun createModules( - groupedByModule: Map>, + groupedByModule: Map>, storageManager: StorageManager - ): Map { - val modules = HashMap() + ): MutableMap { + val modules = HashMap() for (testModule in groupedByModule.keys) { val module = if (testModule == null) @@ -461,11 +442,11 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() { for (testModule in groupedByModule.keys) { if (testModule == null) continue - val module = modules[testModule] + val module = modules[testModule]!! val dependencies = ArrayList() dependencies.add(module) for (dependency in testModule.getDependencies()) { - dependencies.add(modules[dependency]) + dependencies.add(modules[dependency]!!) } dependencies.add(module.builtIns.builtInsModule) @@ -476,98 +457,76 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() { return modules } - protected fun getAdditionalDependencies(module: ModuleDescriptorImpl): List { - return emptyList() - } + protected open fun getAdditionalDependencies(module: ModuleDescriptorImpl): List = + emptyList() - protected fun createModule(moduleName: String, storageManager: StorageManager): ModuleDescriptorImpl { + protected open fun createModule(moduleName: String, storageManager: StorageManager): ModuleDescriptorImpl { val nameSuffix = moduleName.substringAfterLast("-", "") - val platform = if (nameSuffix.isEmpty()) - null - else if (nameSuffix == "common") MultiTargetPlatform.Common else MultiTargetPlatform.Specific(nameSuffix) - val capabilities = if (platform == null) - emptyMap() - else - Collections.singletonMap, MultiTargetPlatform>(MultiTargetPlatform.CAPABILITY, platform) + val platform = + if (nameSuffix.isEmpty()) null + else if (nameSuffix == "common") MultiTargetPlatform.Common else MultiTargetPlatform.Specific(nameSuffix) + val capabilities: Map, Any?> = + if (platform == null) emptyMap() + else mapOf(MultiTargetPlatform.CAPABILITY to platform) return ModuleDescriptorImpl( Name.special("<$moduleName>"), storageManager, JvmBuiltIns(storageManager), - if (platform === MultiTargetPlatform.Common) PlatformKind.DEFAULT else PlatformKind.JVM, + if (platform == MultiTargetPlatform.Common) PlatformKind.DEFAULT else PlatformKind.JVM, SourceKind.TEST, capabilities ) } - protected fun createSealedModule(storageManager: StorageManager): ModuleDescriptorImpl { - val moduleDescriptor = createModule("test-module", storageManager) - moduleDescriptor.setDependencies(moduleDescriptor, moduleDescriptor.builtIns.builtInsModule) - return moduleDescriptor - } - - private fun checkAllResolvedCallsAreCompleted(jetFiles: List, bindingContext: BindingContext) { - for (file in jetFiles) { - if (!AnalyzingUtils.getSyntaxErrorRanges(file).isEmpty()) { - return + protected open fun createSealedModule(storageManager: StorageManager): ModuleDescriptorImpl = + createModule("test-module", storageManager).apply { + setDependencies(this, builtIns.builtInsModule) } - } + + private fun checkAllResolvedCallsAreCompleted(ktFiles: List, bindingContext: BindingContext) { + if (ktFiles.any { file -> AnalyzingUtils.getSyntaxErrorRanges(file).isNotEmpty() }) return val resolvedCallsEntries = bindingContext.getSliceContents(BindingContext.RESOLVED_CALL) - for (entry in resolvedCallsEntries.entries) { - val element = entry.key.callElement - val resolvedCall = entry.value + for ((call, resolvedCall) in resolvedCallsEntries) { + val element = call.callElement val lineAndColumn = DiagnosticUtils.getLineAndColumnInPsiFile(element.containingFile, element.textRange) - TestCase.assertTrue("Resolved call for '" + element.text + "'" + lineAndColumn + " is not completed", - (resolvedCall as MutableResolvedCall<*>).isCompleted) + assertTrue("Resolved call for '${element.text}'$lineAndColumn is not completed", + (resolvedCall as MutableResolvedCall<*>).isCompleted) } checkResolvedCallsInDiagnostics(bindingContext) } private fun checkResolvedCallsInDiagnostics(bindingContext: BindingContext) { - val diagnosticsStoringResolvedCalls1 = Sets.newHashSet>>>( + val diagnosticsStoringResolvedCalls1 = setOf( OVERLOAD_RESOLUTION_AMBIGUITY, NONE_APPLICABLE, CANNOT_COMPLETE_RESOLVE, UNRESOLVED_REFERENCE_WRONG_RECEIVER, - ASSIGN_OPERATOR_AMBIGUITY, ITERATOR_AMBIGUITY) - val diagnosticsStoringResolvedCalls2 = Sets.newHashSet>, Collection>>>( - COMPONENT_FUNCTION_AMBIGUITY, DELEGATE_SPECIAL_FUNCTION_AMBIGUITY, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE) - val diagnostics = bindingContext.diagnostics - for (diagnostic in diagnostics) { - val factory = diagnostic.factory + ASSIGN_OPERATOR_AMBIGUITY, ITERATOR_AMBIGUITY + ) + val diagnosticsStoringResolvedCalls2 = setOf( + COMPONENT_FUNCTION_AMBIGUITY, DELEGATE_SPECIAL_FUNCTION_AMBIGUITY, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE + ) - if (diagnosticsStoringResolvedCalls1.contains(factory)) { - assertResolvedCallsAreCompleted( - diagnostic, DiagnosticFactory.cast(diagnostic, diagnosticsStoringResolvedCalls1).a) - } - - if (diagnosticsStoringResolvedCalls2.contains(factory)) { - assertResolvedCallsAreCompleted( - diagnostic, - DiagnosticFactory.cast>, Collection>>>(diagnostic, diagnosticsStoringResolvedCalls2).b) + for (diagnostic in bindingContext.diagnostics) { + when (diagnostic.factory) { + in diagnosticsStoringResolvedCalls1 -> assertResolvedCallsAreCompleted( + diagnostic, DiagnosticFactory.cast(diagnostic, diagnosticsStoringResolvedCalls1).a + ) + in diagnosticsStoringResolvedCalls2 -> assertResolvedCallsAreCompleted( + diagnostic, DiagnosticFactory.cast(diagnostic, diagnosticsStoringResolvedCalls2).b + ) } } } - private fun assertResolvedCallsAreCompleted( - diagnostic: Diagnostic, resolvedCalls: Collection> - ) { - var allCallsAreCompleted = true - for (resolvedCall in resolvedCalls) { - if (!(resolvedCall as MutableResolvedCall<*>).isCompleted) { - allCallsAreCompleted = false - } - } - + private fun assertResolvedCallsAreCompleted(diagnostic: Diagnostic, resolvedCalls: Collection>) { val element = diagnostic.psiElement val lineAndColumn = DiagnosticUtils.getLineAndColumnInPsiFile(element.containingFile, element.textRange) - TestCase.assertTrue("Resolved calls stored in " + diagnostic.factory.name + "\n" + - "for '" + element.text + "'" + lineAndColumn + " are not completed", - allCallsAreCompleted) + assertTrue("Resolved calls stored in ${diagnostic.factory.name}\nfor '${element.text}'$lineAndColumn are not completed", + resolvedCalls.all { (it as MutableResolvedCall<*>).isCompleted }) } companion object { - private val HASH_SANITIZER = fun(s: String): String { - return s.replace("@(\\d)+".toRegex(), "") - } + private val HASH_SANITIZER = fun(s: String): String = s.replace("@(\\d)+".toRegex(), "") private val MODULE_FILES = ModuleDescriptor.Capability>("") } diff --git a/compiler/tests-common/org/jetbrains/kotlin/checkers/BaseDiagnosticsTest.kt b/compiler/tests-common/org/jetbrains/kotlin/checkers/BaseDiagnosticsTest.kt index c8e23743f60..d2ed7c3697e 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/checkers/BaseDiagnosticsTest.kt +++ b/compiler/tests-common/org/jetbrains/kotlin/checkers/BaseDiagnosticsTest.kt @@ -16,20 +16,17 @@ package org.jetbrains.kotlin.checkers -import com.google.common.collect.ImmutableSet -import com.google.common.collect.Lists import com.intellij.lang.java.JavaLanguage import com.intellij.openapi.util.Condition import com.intellij.openapi.util.Conditions import com.intellij.openapi.util.TextRange -import com.intellij.psi.PsiFile import com.intellij.psi.PsiFileFactory import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.util.PsiTreeUtil -import com.intellij.util.Function import com.intellij.util.containers.ContainerUtil -import com.intellij.util.containers.HashMap -import org.jetbrains.kotlin.asJava.* +import org.jetbrains.kotlin.asJava.getJvmSignatureDiagnostics +import org.jetbrains.kotlin.checkers.BaseDiagnosticsTest.TestFile +import org.jetbrains.kotlin.checkers.BaseDiagnosticsTest.TestModule import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.diagnostics.* @@ -37,106 +34,84 @@ import org.jetbrains.kotlin.load.java.InternalFlexibleTypeTransformer import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.resolve.BindingContext -import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics import org.jetbrains.kotlin.test.KotlinTestUtils -import org.jetbrains.kotlin.utils.* +import org.jetbrains.kotlin.utils.addIfNotNull import org.junit.Assert - import java.io.File import java.util.* -import java.util.regex.Matcher import java.util.regex.Pattern -abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava() { +abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava() { + override fun createTestModule(name: String): TestModule = + TestModule(name) - override fun createTestModule(name: String): TestModule { - return TestModule(name) - } + override fun createTestFile(module: TestModule?, fileName: String, text: String, directives: Map): TestFile = + TestFile(module, fileName, text, directives) - override fun createTestFile(module: TestModule, fileName: String, text: String, directives: Map): TestFile { - return TestFile(module, fileName, text, directives) - } - - override fun doMultiFileTest(file: File, modules: Map.ModuleAndDependencies>, testFiles: List) { + override fun doMultiFileTest( + file: File, + modules: @JvmSuppressWildcards Map, + testFiles: List + ) { for (moduleAndDependencies in modules.values) { - val dependencies = moduleAndDependencies.dependencies.map( - { name -> - val dependency = modules[name] ?: error("Dependency not found: " + - name + - " for module " + - moduleAndDependencies.module.name) - dependency.module - } - ) - moduleAndDependencies.module.getDependencies().addAll(dependencies) + moduleAndDependencies.module.getDependencies().addAll(moduleAndDependencies.dependencies.map { name -> + modules[name]?.module ?: error("Dependency not found: $name for module ${moduleAndDependencies.module.name}") + }) } analyzeAndCheck(file, testFiles) } - protected abstract fun analyzeAndCheck( - testDataFile: File, - files: List - ) + protected abstract fun analyzeAndCheck(testDataFile: File, files: List) - protected fun getJetFiles(testFiles: List, includeExtras: Boolean): List { + protected fun getKtFiles(testFiles: List, includeExtras: Boolean): List { var declareFlexibleType = false var declareCheckType = false - val jetFiles = Lists.newArrayList() + val ktFiles = arrayListOf() for (testFile in testFiles) { - if (testFile.jetFile != null) { - jetFiles.add(testFile.jetFile) - } + ktFiles.addIfNotNull(testFile.ktFile) declareFlexibleType = declareFlexibleType or testFile.declareFlexibleType declareCheckType = declareCheckType or testFile.declareCheckType } if (includeExtras) { if (declareFlexibleType) { - jetFiles.add(KotlinTestUtils.createFile("EXPLICIT_FLEXIBLE_TYPES.kt", EXPLICIT_FLEXIBLE_TYPES_DECLARATIONS, project)) + ktFiles.add(KotlinTestUtils.createFile("EXPLICIT_FLEXIBLE_TYPES.kt", EXPLICIT_FLEXIBLE_TYPES_DECLARATIONS, project)) } if (declareCheckType) { - jetFiles.add(KotlinTestUtils.createFile("CHECK_TYPE.kt", CHECK_TYPE_DECLARATIONS, project)) + ktFiles.add(KotlinTestUtils.createFile("CHECK_TYPE.kt", CHECK_TYPE_DECLARATIONS, project)) } } - return jetFiles + return ktFiles } class TestModule(val name: String) : Comparable { private val dependencies = ArrayList() - fun getDependencies(): MutableList { - return dependencies - } + fun getDependencies(): MutableList = dependencies - override fun compareTo(module: TestModule): Int { - return name.compareTo(module.name) - } + override fun compareTo(other: TestModule): Int = name.compareTo(other.name) - override fun toString(): String { - return name - } + override fun toString(): String = name } class DiagnosticTestLanguageVersionSettings( - private val languageFeatures: Map, override val apiVersion: ApiVersion + private val languageFeatures: Map, + override val apiVersion: ApiVersion ) : LanguageVersionSettings { + override fun supportsFeature(feature: LanguageFeature): Boolean = + languageFeatures[feature] ?: LanguageVersionSettingsImpl.DEFAULT.supportsFeature(feature) - override fun supportsFeature(feature: LanguageFeature): Boolean { - val enabled = languageFeatures[feature] - return enabled ?: LanguageVersionSettingsImpl.DEFAULT.supportsFeature(feature) - } - - override // TODO provide base language version - val languageVersion: LanguageVersion + // TODO provide base language version + override val languageVersion: LanguageVersion get() = throw UnsupportedOperationException("This instance of LanguageVersionSettings should be used for tests only") - override fun equals(obj: Any?): Boolean { - return obj is DiagnosticTestLanguageVersionSettings && - obj.languageFeatures == languageFeatures && - obj.apiVersion == apiVersion - } + override fun equals(other: Any?): Boolean = + other is DiagnosticTestLanguageVersionSettings && other.languageFeatures == languageFeatures && other.apiVersion == apiVersion + + override fun hashCode(): Int = + 31 * languageFeatures.hashCode() + apiVersion.hashCode() } inner class TestFile( @@ -145,14 +120,14 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava ) { - private val diagnosedRanges = Lists.newArrayList() + private val diagnosedRanges: List = ArrayList() val expectedText: String private val clearText: String - val jetFile: KtFile? + val ktFile: KtFile? private val whatDiagnosticsToConsider: Condition - val customLanguageVersionSettings: LanguageVersionSettings - private val declareCheckType: Boolean - private val declareFlexibleType: Boolean + val customLanguageVersionSettings: LanguageVersionSettings? + val declareCheckType: Boolean + val declareFlexibleType: Boolean val checkLazyLog: Boolean private val markDynamicCalls: Boolean val dynamicCallDescriptors: List = ArrayList() @@ -160,46 +135,43 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava() + val diagnosticToExpectedDiagnostic = hashMapOf() CheckerTestUtil.diagnosticsDiff(diagnosticToExpectedDiagnostic, diagnosedRanges, diagnostics, object : CheckerTestUtil.DiagnosticDiffCallbacks { - override fun missingDiagnostic(diagnostic: CheckerTestUtil.TextDiagnostic, expectedStart: Int, expectedEnd: Int) { - val message = "Missing " + diagnostic.name + DiagnosticUtils.atLocation(jetFile, TextRange(expectedStart, expectedEnd)) + val message = "Missing " + diagnostic.name + DiagnosticUtils.atLocation(ktFile, TextRange(expectedStart, expectedEnd)) System.err.println(message) ok[0] = false } @@ -258,21 +230,23 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava { file -> file.text })) + actualText.append( + CheckerTestUtil.addDiagnosticMarkersToText(ktFile, diagnostics, diagnosticToExpectedDiagnostic, { file -> file.text }) + ) stripExtras(actualText) @@ -281,7 +255,7 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava { val jvmSignatureDiagnostics = HashSet() - val declarations = PsiTreeUtil.findChildrenOfType(jetFile, KtDeclaration::class.java) + val declarations = PsiTreeUtil.findChildrenOfType(ktFile, KtDeclaration::class.java) for (declaration in declarations) { val diagnostics = getJvmSignatureDiagnostics(declaration, bindingContext.diagnostics, GlobalSearchScope.allScope(project)) ?: continue @@ -290,16 +264,13 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava> = ImmutableSet.of( + val DIAGNOSTICS_PATTERN: Pattern = Pattern.compile("([\\+\\-!])(\\w+)\\s*") + val DIAGNOSTICS_TO_INCLUDE_ANYWAY: Set> = setOf( Errors.UNRESOLVED_REFERENCE, Errors.UNRESOLVED_REFERENCE_WRONG_RECEIVER, CheckerTestUtil.SyntaxErrorDiagnosticFactory.INSTANCE, @@ -338,9 +309,10 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava() else collectLanguageFeatureMap(directives) + val languageFeatures = directives?.let(this::collectLanguageFeatureMap).orEmpty() return DiagnosticTestLanguageVersionSettings(languageFeatures, apiVersion) } @@ -349,8 +321,8 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava diagnostic.factory !== Errors.NEWER_VERSION_IN_SINCE_KOTLIN } } - return Conditions.alwaysTrue() + return Conditions.alwaysTrue() } + var condition = Conditions.alwaysTrue() val matcher = DIAGNOSTICS_PATTERN.matcher(directives) if (!matcher.find()) { - Assert.fail("Wrong syntax in the '// !" + DIAGNOSTICS_DIRECTIVE + ": ...' directive:\n" + - "found: '" + directives + "'\n" + + Assert.fail("Wrong syntax in the '// !$DIAGNOSTICS_DIRECTIVE: ...' directive:\n" + + "found: '$directives'\n" + "Must be '([+-!]DIAGNOSTIC_FACTORY_NAME|ERROR|WARNING|INFO)+'\n" + "where '+' means 'include'\n" + " '-' means 'exclude'\n" + " '!' means 'exclude everything but this'\n" + "directives are applied in the order of appearance, i.e. !FOO +BAR means include only FOO and BAR") } + var first = true do { val operation = matcher.group(1) val name = matcher.group(2) - var newCondition: Condition - if (ImmutableSet.of("ERROR", "WARNING", "INFO").contains(name)) { - val severity = Severity.valueOf(name) - newCondition = Condition { diagnostic -> diagnostic.severity == severity } - } - else { - newCondition = Condition { diagnostic -> name == diagnostic.factory.name } - } - if ("!" == operation) { - if (!first) { - Assert.fail("'" + operation + name + "' appears in a position rather than the first one, " + - "which effectively cancels all the previous filters in this directive") + val newCondition: Condition = + if (name in setOf("ERROR", "WARNING", "INFO")) { + Condition { diagnostic -> diagnostic.severity == Severity.valueOf(name) } + } + else { + Condition { diagnostic -> name == diagnostic.factory.name } + } + + when (operation) { + "!" -> { + if (!first) { + Assert.fail("'$operation$name' appears in a position rather than the first one, " + + "which effectively cancels all the previous filters in this directive") + } + condition = newCondition } - condition = newCondition - } - else if ("+" == operation) { - condition = Conditions.or(condition, newCondition) - } - else if ("-" == operation) { - condition = Conditions.and(condition, Conditions.not(newCondition)) + "+" -> condition = Conditions.or(condition, newCondition) + "-" -> condition = Conditions.and(condition, Conditions.not(newCondition)) } first = false } while (matcher.find()) + // We always include UNRESOLVED_REFERENCE and SYNTAX_ERROR because they are too likely to indicate erroneous test data return Conditions.or( condition, - Condition { diagnostic -> DIAGNOSTICS_TO_INCLUDE_ANYWAY.contains(diagnostic.factory) }) + Condition { diagnostic -> diagnostic.factory in DIAGNOSTICS_TO_INCLUDE_ANYWAY } + ) } } } diff --git a/compiler/tests-common/org/jetbrains/kotlin/checkers/LoggingStorageManager.kt b/compiler/tests-common/org/jetbrains/kotlin/checkers/LoggingStorageManager.kt index 841fba9ec22..e222c87b0e4 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/checkers/LoggingStorageManager.kt +++ b/compiler/tests-common/org/jetbrains/kotlin/checkers/LoggingStorageManager.kt @@ -23,7 +23,7 @@ import java.lang.reflect.GenericDeclaration class LoggingStorageManager( private val delegate: StorageManager, - private val callHandler: (lambda: Any, call: LoggingStorageManager.CallData?) -> Unit) : ObservableStorageManager(delegate) { + private val callHandler: (lambda: Any, call: LoggingStorageManager.CallData) -> Unit) : ObservableStorageManager(delegate) { class CallData( val fieldOwner: Any?, diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTestWithJsStdLib.kt b/compiler/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTestWithJsStdLib.kt index 783d712eec9..29bb369bc43 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTestWithJsStdLib.kt +++ b/compiler/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTestWithJsStdLib.kt @@ -19,7 +19,6 @@ package org.jetbrains.kotlin.checkers import com.intellij.openapi.util.text.StringUtil import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles import org.jetbrains.kotlin.config.CommonConfigurationKeys -import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.context.ModuleContext import org.jetbrains.kotlin.descriptors.ModuleDescriptor @@ -29,60 +28,55 @@ import org.jetbrains.kotlin.js.analyzer.JsAnalysisResult import org.jetbrains.kotlin.js.config.JSConfigurationKeys import org.jetbrains.kotlin.js.config.JsConfig import org.jetbrains.kotlin.js.config.LibrarySourcesConfig -import org.jetbrains.kotlin.js.resolve.* import org.jetbrains.kotlin.js.resolve.JsPlatform +import org.jetbrains.kotlin.js.resolve.MODULE_KIND import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.resolve.BindingTrace -import org.jetbrains.kotlin.serialization.js.JsModuleDescriptor import org.jetbrains.kotlin.serialization.js.ModuleKind import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.test.KotlinTestUtils - -import java.util.ArrayList +import java.util.* +import kotlin.reflect.jvm.javaField abstract class AbstractDiagnosticsTestWithJsStdLib : AbstractDiagnosticsTest() { - protected var config: JsConfig? = null + protected lateinit var config: JsConfig private set - @Throws(Exception::class) override fun setUp() { super.setUp() - val configuration = environment.configuration.copy() - configuration.put(CommonConfigurationKeys.MODULE_NAME, KotlinTestUtils.TEST_MODULE_NAME) - configuration.put(JSConfigurationKeys.LIBRARY_FILES, LibrarySourcesConfig.JS_STDLIB) - config = LibrarySourcesConfig(project, configuration) + config = LibrarySourcesConfig(project, environment.configuration.copy().apply { + put(CommonConfigurationKeys.MODULE_NAME, KotlinTestUtils.TEST_MODULE_NAME) + put(JSConfigurationKeys.LIBRARY_FILES, LibrarySourcesConfig.JS_STDLIB) + }) } - @Throws(Exception::class) override fun tearDown() { - config = null + (AbstractDiagnosticsTestWithJsStdLib::config).javaField!!.set(this, null) super.tearDown() } - override fun getEnvironmentConfigFiles(): List { - return EnvironmentConfigFiles.JS_CONFIG_FILES - } + override fun getEnvironmentConfigFiles(): List = EnvironmentConfigFiles.JS_CONFIG_FILES override fun analyzeModuleContents( moduleContext: ModuleContext, - ktFiles: List, + files: List, moduleTrace: BindingTrace, languageVersionSettings: LanguageVersionSettings?, separateModules: Boolean ): JsAnalysisResult { // TODO: support LANGUAGE directive in JS diagnostic tests - assert(languageVersionSettings == null) { BaseDiagnosticsTest.LANGUAGE_DIRECTIVE + " directive is not supported in JS diagnostic tests" } - moduleTrace.record(MODULE_KIND, moduleContext.module, getModuleKind(ktFiles)) - return TopDownAnalyzerFacadeForJS.analyzeFilesWithGivenTrace(ktFiles, moduleTrace, moduleContext, config!!) + assert(languageVersionSettings == null) { "$LANGUAGE_DIRECTIVE directive is not supported in JS diagnostic tests" } + moduleTrace.record(MODULE_KIND, moduleContext.module, getModuleKind(files)) + return TopDownAnalyzerFacadeForJS.analyzeFilesWithGivenTrace(files, moduleTrace, moduleContext, config) } private fun getModuleKind(ktFiles: List): ModuleKind { var kind = ModuleKind.PLAIN for (file in ktFiles) { val text = file.text - for (line in StringUtil.splitByLines(text)) { - line = line.trim { it <= ' ' } + for (textLine in StringUtil.splitByLines(text)) { + var line = textLine.trim { it <= ' ' } if (!line.startsWith("//")) continue line = line.substring(2).trim { it <= ' ' } val parts = StringUtil.split(line, ":") @@ -96,21 +90,13 @@ abstract class AbstractDiagnosticsTestWithJsStdLib : AbstractDiagnosticsTest() { return kind } - override fun getAdditionalDependencies(module: ModuleDescriptorImpl): List { - val dependencies = ArrayList() - for (moduleDescriptor in config!!.moduleDescriptors) { - dependencies.add(moduleDescriptor.data) - } - return dependencies - } + override fun getAdditionalDependencies(module: ModuleDescriptorImpl): List = + config.moduleDescriptors.map { it.data } - override fun shouldSkipJvmSignatureDiagnostics(groupedByModule: Map>): Boolean { - return true - } + override fun shouldSkipJvmSignatureDiagnostics(groupedByModule: Map>): Boolean = true - override fun createModule(moduleName: String, storageManager: StorageManager): ModuleDescriptorImpl { - return ModuleDescriptorImpl(Name.special("<$moduleName>"), storageManager, JsPlatform.builtIns) - } + override fun createModule(moduleName: String, storageManager: StorageManager): ModuleDescriptorImpl = + ModuleDescriptorImpl(Name.special("<$moduleName>"), storageManager, JsPlatform.builtIns) override fun createSealedModule(storageManager: StorageManager): ModuleDescriptorImpl { val module = createModule("kotlin-js-test-module", storageManager) diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTestWithJsStdLibAndBackendCompilation.kt b/compiler/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTestWithJsStdLibAndBackendCompilation.kt index 483e99bec50..b4c4e8a495d 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTestWithJsStdLibAndBackendCompilation.kt +++ b/compiler/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTestWithJsStdLibAndBackendCompilation.kt @@ -28,17 +28,17 @@ import org.jetbrains.kotlin.resolve.BindingTrace abstract class AbstractDiagnosticsTestWithJsStdLibAndBackendCompilation : AbstractDiagnosticsTestWithJsStdLib() { override fun analyzeModuleContents( moduleContext: ModuleContext, - ktFiles: MutableList, + files: List, moduleTrace: BindingTrace, languageVersionSettings: LanguageVersionSettings?, separateModules: Boolean ): JsAnalysisResult { - val analysisResult = super.analyzeModuleContents(moduleContext, ktFiles, moduleTrace, languageVersionSettings, separateModules) + val analysisResult = super.analyzeModuleContents(moduleContext, files, moduleTrace, languageVersionSettings, separateModules) val diagnostics = analysisResult.bindingTrace.bindingContext.diagnostics if (!hasError(diagnostics)) { val translator = K2JSTranslator(config) - translator.translate(ktFiles, MainCallParameters.noCall(), analysisResult) + translator.translate(files, MainCallParameters.noCall(), analysisResult) } return analysisResult diff --git a/compiler/tests/org/jetbrains/kotlin/ir/AbstractPsi2IrDiagnosticsTest.kt b/compiler/tests/org/jetbrains/kotlin/ir/AbstractPsi2IrDiagnosticsTest.kt index f0c1a89d536..91fadb7fa68 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/AbstractPsi2IrDiagnosticsTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/ir/AbstractPsi2IrDiagnosticsTest.kt @@ -26,14 +26,14 @@ import java.io.File abstract class AbstractPsi2IrDiagnosticsTest : AbstractDiagnosticsTest() { override fun performAdditionalChecksAfterDiagnostics( testDataFile: File, - testFiles: MutableList, - moduleFiles: MutableMap>, - moduleDescriptors: MutableMap, - moduleBindings: MutableMap + testFiles: List, + moduleFiles: Map>, + moduleDescriptors: Map, + moduleBindings: Map ) { val actualIrDump = StringBuilder() for (module in moduleFiles.keys) { - val ktFiles = moduleFiles[module]?.mapNotNull { it.jetFile } ?: continue + val ktFiles = moduleFiles[module]?.mapNotNull { it.ktFile } ?: continue val moduleDescriptor = moduleDescriptors[module] ?: continue val moduleBindingContext = moduleBindings[module] ?: continue val irModule = AbstractIrGeneratorTestCase.generateIrModule(ktFiles, moduleDescriptor, moduleBindingContext, true)