From 2866bd84a1736bb684e23d0a93190564bad4ea6c Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Mon, 24 Sep 2018 13:47:51 +0300 Subject: [PATCH] Reformat BaseDiagnosticTest according to code style --- .../kotlin/checkers/BaseDiagnosticsTest.kt | 210 ++++++++++-------- 1 file changed, 112 insertions(+), 98 deletions(-) diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/BaseDiagnosticsTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/BaseDiagnosticsTest.kt index 19e4f4cfb7b..4cadfd146ad 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/BaseDiagnosticsTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/BaseDiagnosticsTest.kt @@ -62,15 +62,15 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava): TestFile = - TestFile(module, fileName, text, directives) + TestFile(module, fileName, text, directives) override fun doMultiFileTest( - file: File, - modules: @JvmSuppressWildcards Map, - testFiles: List + file: File, + modules: @JvmSuppressWildcards Map, + testFiles: List ) { for (moduleAndDependencies in modules.values) { moduleAndDependencies.module.getDependencies().addAll(moduleAndDependencies.dependencies.map { name -> @@ -120,10 +120,10 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava + val module: TestModule?, + val fileName: String, + textWithMarkers: String, + val directives: Map ) { private val diagnosedRanges: List = ArrayList() val actualDiagnostics: MutableList = ArrayList() @@ -150,14 +150,14 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava>, - actualText: StringBuilder, - skipJvmSignatureDiagnostics: Boolean + bindingContext: BindingContext, + implementingModulesBindings: List>, + actualText: StringBuilder, + skipJvmSignatureDiagnostics: Boolean ): Boolean { val ktFile = this.ktFile if (ktFile == null) { @@ -235,10 +234,10 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava file.text }, uncheckedDiagnostics, withNewInferenceDirective) + fun updateUncheckedDiagnostics(diagnostic: CheckerTestUtil.TextDiagnostic, start: Int, end: Int) { + diagnostic.enhanceInferenceCompatibility(invertedInferenceCompatibilityOfTest) + uncheckedDiagnostics.add(PositionalTextDiagnostic(diagnostic, start, end)) + } + }) + + actualText.append( + CheckerTestUtil.addDiagnosticMarkersToText( + ktFile, + diagnostics, + diagnosticToExpectedDiagnostic, + { file -> file.text }, + uncheckedDiagnostics, + withNewInferenceDirective + ) ) stripExtras(actualText) @@ -315,8 +322,10 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava() val declarations = PsiTreeUtil.findChildrenOfType(ktFile, KtDeclaration::class.java) for (declaration in declarations) { - val diagnostics = getJvmSignatureDiagnostics(declaration, bindingContext.diagnostics, - GlobalSearchScope.allScope(project)) ?: continue + val diagnostics = getJvmSignatureDiagnostics( + declaration, bindingContext.diagnostics, + GlobalSearchScope.allScope(project) + ) ?: continue jvmSignatureDiagnostics.addAll(diagnostics.forElement(declaration).map { ActualDiagnostic(it, null, newInferenceEnabled) }) } return jvmSignatureDiagnostics @@ -329,32 +338,32 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava> = setOf( - Errors.UNRESOLVED_REFERENCE, - Errors.UNRESOLVED_REFERENCE_WRONG_RECEIVER, - CheckerTestUtil.SyntaxErrorDiagnosticFactory.INSTANCE, - CheckerTestUtil.DebugInfoDiagnosticFactory.ELEMENT_WITH_ERROR_TYPE, - CheckerTestUtil.DebugInfoDiagnosticFactory.MISSING_UNRESOLVED, - CheckerTestUtil.DebugInfoDiagnosticFactory.UNRESOLVED_WITH_TARGET + Errors.UNRESOLVED_REFERENCE, + Errors.UNRESOLVED_REFERENCE_WRONG_RECEIVER, + CheckerTestUtil.SyntaxErrorDiagnosticFactory.INSTANCE, + CheckerTestUtil.DebugInfoDiagnosticFactory.ELEMENT_WITH_ERROR_TYPE, + CheckerTestUtil.DebugInfoDiagnosticFactory.MISSING_UNRESOLVED, + CheckerTestUtil.DebugInfoDiagnosticFactory.UNRESOLVED_WITH_TARGET ) val DEFAULT_DIAGNOSTIC_TESTS_FEATURES = mapOf( - LanguageFeature.Coroutines to LanguageFeature.State.ENABLED + LanguageFeature.Coroutines to LanguageFeature.State.ENABLED ) val CHECK_TYPE_DIRECTIVE = "CHECK_TYPE" val CHECK_TYPE_PACKAGE = "tests._checkType" private val CHECK_TYPE_DECLARATIONS = "\npackage " + CHECK_TYPE_PACKAGE + - "\nfun checkSubtype(t: T) = t" + - "\nclass Inv" + - "\nfun Inv._() {}" + - "\ninfix fun T.checkType(f: Inv.() -> Unit) {}" + "\nfun checkSubtype(t: T) = t" + + "\nclass Inv" + + "\nfun Inv._() {}" + + "\ninfix fun T.checkType(f: Inv.() -> Unit) {}" val CHECK_TYPE_IMPORT = "import $CHECK_TYPE_PACKAGE.*" val EXPLICIT_FLEXIBLE_TYPES_DIRECTIVE = "EXPLICIT_FLEXIBLE_TYPES" val EXPLICIT_FLEXIBLE_PACKAGE = InternalFlexibleTypeTransformer.FLEXIBLE_TYPE_CLASSIFIER.packageFqName.asString() val EXPLICIT_FLEXIBLE_CLASS_NAME = InternalFlexibleTypeTransformer.FLEXIBLE_TYPE_CLASSIFIER.relativeClassName.asString() private val EXPLICIT_FLEXIBLE_TYPES_DECLARATIONS = "\npackage " + EXPLICIT_FLEXIBLE_PACKAGE + - "\npublic class " + EXPLICIT_FLEXIBLE_CLASS_NAME + "" + "\npublic class " + EXPLICIT_FLEXIBLE_CLASS_NAME + "" private val EXPLICIT_FLEXIBLE_TYPES_IMPORT = "import $EXPLICIT_FLEXIBLE_PACKAGE.$EXPLICIT_FLEXIBLE_CLASS_NAME" val CHECK_LAZY_LOG_DIRECTIVE = "CHECK_LAZY_LOG" val CHECK_LAZY_LOG_DEFAULT = "true" == System.getProperty("check.lazy.logs", "false") @@ -366,20 +375,23 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava, allowUnderscoreUsage: Boolean): Condition { + private fun parseDiagnosticFilterDirective( + directiveMap: Map, + allowUnderscoreUsage: Boolean + ): Condition { val directives = directiveMap[DIAGNOSTICS_DIRECTIVE] val initialCondition = - if (allowUnderscoreUsage) - Condition { it.factory.name != "UNDERSCORE_USAGE_WITHOUT_BACKTICKS" } - else - Conditions.alwaysTrue() + if (allowUnderscoreUsage) + Condition { it.factory.name != "UNDERSCORE_USAGE_WITHOUT_BACKTICKS" } + else + Conditions.alwaysTrue() if (directives == null) { // If "!API_VERSION" is present, disable the NEWER_VERSION_IN_SINCE_KOTLIN diagnostic. // Otherwise it would be reported in any non-trivial test on the @SinceKotlin value. if (API_VERSION_DIRECTIVE in directiveMap) { - return Conditions.and(initialCondition, Condition { - diagnostic -> diagnostic.factory !== Errors.NEWER_VERSION_IN_SINCE_KOTLIN + return Conditions.and(initialCondition, Condition { diagnostic -> + diagnostic.factory !== Errors.NEWER_VERSION_IN_SINCE_KOTLIN }) } return initialCondition @@ -388,13 +400,15 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava = - if (name in setOf("ERROR", "WARNING", "INFO")) { - Condition { diagnostic -> diagnostic.severity == Severity.valueOf(name) } - } - else { - Condition { diagnostic -> name == diagnostic.factory.name } - } + 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") + 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 } @@ -422,13 +437,12 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava condition = Conditions.and(condition, Conditions.not(newCondition)) } first = false - } - while (matcher.find()) + } 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 -> diagnostic.factory in DIAGNOSTICS_TO_INCLUDE_ANYWAY } + condition, + Condition { diagnostic -> diagnostic.factory in DIAGNOSTICS_TO_INCLUDE_ANYWAY } ) } }