Reformat BaseDiagnosticTest according to code style

This commit is contained in:
Dmitriy Novozhilov
2018-09-24 13:47:51 +03:00
committed by Dmitriy Novozhilov
parent 047f9abaf7
commit 2866bd84a1
@@ -150,14 +150,14 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
this.declareFlexibleType = EXPLICIT_FLEXIBLE_TYPES_DIRECTIVE in directives this.declareFlexibleType = EXPLICIT_FLEXIBLE_TYPES_DIRECTIVE in directives
this.markDynamicCalls = MARK_DYNAMIC_CALLS_DIRECTIVE in directives this.markDynamicCalls = MARK_DYNAMIC_CALLS_DIRECTIVE in directives
this.withNewInferenceDirective = WITH_NEW_INFERENCE_DIRECTIVE in directives this.withNewInferenceDirective = WITH_NEW_INFERENCE_DIRECTIVE in directives
this.newInferenceEnabled = customLanguageVersionSettings?.supportsFeature(LanguageFeature.NewInference) ?: shouldUseNewInferenceForTests() this.newInferenceEnabled = customLanguageVersionSettings?.supportsFeature(LanguageFeature.NewInference) ?:
shouldUseNewInferenceForTests()
if (fileName.endsWith(".java")) { if (fileName.endsWith(".java")) {
// TODO: check there are no syntax errors in .java sources // TODO: check there are no syntax errors in .java sources
this.createKtFile = lazyOf(null) this.createKtFile = lazyOf(null)
this.clearText = textWithMarkers this.clearText = textWithMarkers
this.expectedText = this.clearText this.expectedText = this.clearText
} } else {
else {
this.expectedText = textWithMarkers this.expectedText = textWithMarkers
this.clearText = CheckerTestUtil.parseDiagnosedRanges(addExtras(expectedText), diagnosedRanges) this.clearText = CheckerTestUtil.parseDiagnosedRanges(addExtras(expectedText), diagnosedRanges)
this.createKtFile = lazy { TestCheckerUtil.createCheckAndReturnPsiFile(fileName, clearText, project) } this.createKtFile = lazy { TestCheckerUtil.createCheckAndReturnPsiFile(fileName, clearText, project) }
@@ -198,8 +198,7 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
if (matcher.find()) { if (matcher.find()) {
// add imports after the package directive // add imports after the package directive
result = result.substring(0, matcher.end()) + imports + result.substring(matcher.end()) result = result.substring(0, matcher.end()) + imports + result.substring(matcher.end())
} } else {
else {
// add imports at the beginning // add imports at the beginning
result = imports + result result = imports + result
} }
@@ -247,7 +246,8 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
val inferenceCompatibilityOfTest = asInferenceCompatibility(withNewInference) val inferenceCompatibilityOfTest = asInferenceCompatibility(withNewInference)
val invertedInferenceCompatibilityOfTest = asInferenceCompatibility(!withNewInference) val invertedInferenceCompatibilityOfTest = asInferenceCompatibility(!withNewInference)
val diagnosticToExpectedDiagnostic = CheckerTestUtil.diagnosticsDiff(diagnosedRanges, diagnostics, object : CheckerTestUtil.DiagnosticDiffCallbacks { val diagnosticToExpectedDiagnostic =
CheckerTestUtil.diagnosticsDiff(diagnosedRanges, diagnostics, object : CheckerTestUtil.DiagnosticDiffCallbacks {
override fun missingDiagnostic(diagnostic: CheckerTestUtil.TextDiagnostic, expectedStart: Int, expectedEnd: Int) { override fun missingDiagnostic(diagnostic: CheckerTestUtil.TextDiagnostic, expectedStart: Int, expectedEnd: Int) {
if (withNewInferenceDirective && diagnostic.inferenceCompatibility != inferenceCompatibilityOfTest) { if (withNewInferenceDirective && diagnostic.inferenceCompatibility != inferenceCompatibilityOfTest) {
updateUncheckedDiagnostics(diagnostic, expectedStart, expectedEnd) updateUncheckedDiagnostics(diagnostic, expectedStart, expectedEnd)
@@ -295,8 +295,15 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
} }
}) })
actualText.append(CheckerTestUtil.addDiagnosticMarkersToText( actualText.append(
ktFile, diagnostics, diagnosticToExpectedDiagnostic, { file -> file.text }, uncheckedDiagnostics, withNewInferenceDirective) CheckerTestUtil.addDiagnosticMarkersToText(
ktFile,
diagnostics,
diagnosticToExpectedDiagnostic,
{ file -> file.text },
uncheckedDiagnostics,
withNewInferenceDirective
)
) )
stripExtras(actualText) stripExtras(actualText)
@@ -315,8 +322,10 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
val jvmSignatureDiagnostics = HashSet<ActualDiagnostic>() val jvmSignatureDiagnostics = HashSet<ActualDiagnostic>()
val declarations = PsiTreeUtil.findChildrenOfType(ktFile, KtDeclaration::class.java) val declarations = PsiTreeUtil.findChildrenOfType(ktFile, KtDeclaration::class.java)
for (declaration in declarations) { for (declaration in declarations) {
val diagnostics = getJvmSignatureDiagnostics(declaration, bindingContext.diagnostics, val diagnostics = getJvmSignatureDiagnostics(
GlobalSearchScope.allScope(project)) ?: continue declaration, bindingContext.diagnostics,
GlobalSearchScope.allScope(project)
) ?: continue
jvmSignatureDiagnostics.addAll(diagnostics.forElement(declaration).map { ActualDiagnostic(it, null, newInferenceEnabled) }) jvmSignatureDiagnostics.addAll(diagnostics.forElement(declaration).map { ActualDiagnostic(it, null, newInferenceEnabled) })
} }
return jvmSignatureDiagnostics return jvmSignatureDiagnostics
@@ -366,7 +375,10 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
// Change it to "true" to load diagnostics for old inference to test new inference (ignore diagnostics with <NI; prefix) // Change it to "true" to load diagnostics for old inference to test new inference (ignore diagnostics with <NI; prefix)
val USE_OLD_INFERENCE_DIAGNOSTICS_FOR_NI = false val USE_OLD_INFERENCE_DIAGNOSTICS_FOR_NI = false
private fun parseDiagnosticFilterDirective(directiveMap: Map<String, String>, allowUnderscoreUsage: Boolean): Condition<Diagnostic> { private fun parseDiagnosticFilterDirective(
directiveMap: Map<String, String>,
allowUnderscoreUsage: Boolean
): Condition<Diagnostic> {
val directives = directiveMap[DIAGNOSTICS_DIRECTIVE] val directives = directiveMap[DIAGNOSTICS_DIRECTIVE]
val initialCondition = val initialCondition =
if (allowUnderscoreUsage) if (allowUnderscoreUsage)
@@ -378,8 +390,8 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
// If "!API_VERSION" is present, disable the NEWER_VERSION_IN_SINCE_KOTLIN diagnostic. // 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. // Otherwise it would be reported in any non-trivial test on the @SinceKotlin value.
if (API_VERSION_DIRECTIVE in directiveMap) { if (API_VERSION_DIRECTIVE in directiveMap) {
return Conditions.and(initialCondition, Condition { return Conditions.and(initialCondition, Condition { diagnostic ->
diagnostic -> diagnostic.factory !== Errors.NEWER_VERSION_IN_SINCE_KOTLIN diagnostic.factory !== Errors.NEWER_VERSION_IN_SINCE_KOTLIN
}) })
} }
return initialCondition return initialCondition
@@ -388,13 +400,15 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
var condition = initialCondition var condition = initialCondition
val matcher = DIAGNOSTICS_PATTERN.matcher(directives) val matcher = DIAGNOSTICS_PATTERN.matcher(directives)
if (!matcher.find()) { if (!matcher.find()) {
Assert.fail("Wrong syntax in the '// !$DIAGNOSTICS_DIRECTIVE: ...' directive:\n" + Assert.fail(
"Wrong syntax in the '// !$DIAGNOSTICS_DIRECTIVE: ...' directive:\n" +
"found: '$directives'\n" + "found: '$directives'\n" +
"Must be '([+-!]DIAGNOSTIC_FACTORY_NAME|ERROR|WARNING|INFO)+'\n" + "Must be '([+-!]DIAGNOSTIC_FACTORY_NAME|ERROR|WARNING|INFO)+'\n" +
"where '+' means 'include'\n" + "where '+' means 'include'\n" +
" '-' means 'exclude'\n" + " '-' means 'exclude'\n" +
" '!' means 'exclude everything but this'\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") "directives are applied in the order of appearance, i.e. !FOO +BAR means include only FOO and BAR"
)
} }
var first = true var first = true
@@ -405,16 +419,17 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
val newCondition: Condition<Diagnostic> = val newCondition: Condition<Diagnostic> =
if (name in setOf("ERROR", "WARNING", "INFO")) { if (name in setOf("ERROR", "WARNING", "INFO")) {
Condition { diagnostic -> diagnostic.severity == Severity.valueOf(name) } Condition { diagnostic -> diagnostic.severity == Severity.valueOf(name) }
} } else {
else {
Condition { diagnostic -> name == diagnostic.factory.name } Condition { diagnostic -> name == diagnostic.factory.name }
} }
when (operation) { when (operation) {
"!" -> { "!" -> {
if (!first) { if (!first) {
Assert.fail("'$operation$name' appears in a position rather than the first one, " + Assert.fail(
"which effectively cancels all the previous filters in this directive") "'$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
} }
@@ -422,8 +437,7 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
"-" -> condition = Conditions.and(condition, Conditions.not(newCondition)) "-" -> condition = Conditions.and(condition, Conditions.not(newCondition))
} }
first = false 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 // We always include UNRESOLVED_REFERENCE and SYNTAX_ERROR because they are too likely to indicate erroneous test data
return Conditions.or( return Conditions.or(