Reformat BaseDiagnosticTest according to code style
This commit is contained in:
committed by
Dmitriy Novozhilov
parent
047f9abaf7
commit
2866bd84a1
@@ -62,15 +62,15 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun createTestModule(name: String): TestModule =
|
override fun createTestModule(name: String): TestModule =
|
||||||
TestModule(name)
|
TestModule(name)
|
||||||
|
|
||||||
override fun createTestFile(module: TestModule?, fileName: String, text: String, directives: Map<String, String>): TestFile =
|
override fun createTestFile(module: TestModule?, fileName: String, text: String, directives: Map<String, String>): TestFile =
|
||||||
TestFile(module, fileName, text, directives)
|
TestFile(module, fileName, text, directives)
|
||||||
|
|
||||||
override fun doMultiFileTest(
|
override fun doMultiFileTest(
|
||||||
file: File,
|
file: File,
|
||||||
modules: @JvmSuppressWildcards Map<String, ModuleAndDependencies>,
|
modules: @JvmSuppressWildcards Map<String, ModuleAndDependencies>,
|
||||||
testFiles: List<TestFile>
|
testFiles: List<TestFile>
|
||||||
) {
|
) {
|
||||||
for (moduleAndDependencies in modules.values) {
|
for (moduleAndDependencies in modules.values) {
|
||||||
moduleAndDependencies.module.getDependencies().addAll(moduleAndDependencies.dependencies.map { name ->
|
moduleAndDependencies.module.getDependencies().addAll(moduleAndDependencies.dependencies.map { name ->
|
||||||
@@ -120,10 +120,10 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
|||||||
}
|
}
|
||||||
|
|
||||||
inner class TestFile(
|
inner class TestFile(
|
||||||
val module: TestModule?,
|
val module: TestModule?,
|
||||||
val fileName: String,
|
val fileName: String,
|
||||||
textWithMarkers: String,
|
textWithMarkers: String,
|
||||||
val directives: Map<String, String>
|
val directives: Map<String, String>
|
||||||
) {
|
) {
|
||||||
private val diagnosedRanges: List<CheckerTestUtil.DiagnosedRange> = ArrayList()
|
private val diagnosedRanges: List<CheckerTestUtil.DiagnosedRange> = ArrayList()
|
||||||
val actualDiagnostics: MutableList<ActualDiagnostic> = ArrayList()
|
val actualDiagnostics: MutableList<ActualDiagnostic> = ArrayList()
|
||||||
@@ -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) }
|
||||||
@@ -181,7 +181,7 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
|||||||
get() = "/*extras*/\n$imports/*extras*/\n\n"
|
get() = "/*extras*/\n$imports/*extras*/\n\n"
|
||||||
|
|
||||||
private fun addExtras(text: String): String =
|
private fun addExtras(text: String): String =
|
||||||
addImports(text, extras)
|
addImports(text, extras)
|
||||||
|
|
||||||
private fun stripExtras(actualText: StringBuilder) {
|
private fun stripExtras(actualText: StringBuilder) {
|
||||||
val extras = extras
|
val extras = extras
|
||||||
@@ -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
|
||||||
}
|
}
|
||||||
@@ -212,10 +211,10 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getActualText(
|
fun getActualText(
|
||||||
bindingContext: BindingContext,
|
bindingContext: BindingContext,
|
||||||
implementingModulesBindings: List<Pair<MultiTargetPlatform, BindingContext>>,
|
implementingModulesBindings: List<Pair<MultiTargetPlatform, BindingContext>>,
|
||||||
actualText: StringBuilder,
|
actualText: StringBuilder,
|
||||||
skipJvmSignatureDiagnostics: Boolean
|
skipJvmSignatureDiagnostics: Boolean
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val ktFile = this.ktFile
|
val ktFile = this.ktFile
|
||||||
if (ktFile == null) {
|
if (ktFile == null) {
|
||||||
@@ -235,10 +234,10 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
|||||||
val ok = booleanArrayOf(true)
|
val ok = booleanArrayOf(true)
|
||||||
val withNewInference = newInferenceEnabled && withNewInferenceDirective && !USE_OLD_INFERENCE_DIAGNOSTICS_FOR_NI
|
val withNewInference = newInferenceEnabled && withNewInferenceDirective && !USE_OLD_INFERENCE_DIAGNOSTICS_FOR_NI
|
||||||
val diagnostics = ContainerUtil.filter(
|
val diagnostics = ContainerUtil.filter(
|
||||||
CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(
|
CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(
|
||||||
bindingContext, implementingModulesBindings, ktFile, markDynamicCalls, dynamicCallDescriptors, newInferenceEnabled
|
bindingContext, implementingModulesBindings, ktFile, markDynamicCalls, dynamicCallDescriptors, newInferenceEnabled
|
||||||
) + jvmSignatureDiagnostics,
|
) + jvmSignatureDiagnostics,
|
||||||
{ whatDiagnosticsToConsider.value(it.diagnostic) }
|
{ whatDiagnosticsToConsider.value(it.diagnostic) }
|
||||||
)
|
)
|
||||||
|
|
||||||
actualDiagnostics.addAll(diagnostics)
|
actualDiagnostics.addAll(diagnostics)
|
||||||
@@ -247,56 +246,64 @@ 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 =
|
||||||
override fun missingDiagnostic(diagnostic: CheckerTestUtil.TextDiagnostic, expectedStart: Int, expectedEnd: Int) {
|
CheckerTestUtil.diagnosticsDiff(diagnosedRanges, diagnostics, object : CheckerTestUtil.DiagnosticDiffCallbacks {
|
||||||
if (withNewInferenceDirective && diagnostic.inferenceCompatibility != inferenceCompatibilityOfTest) {
|
override fun missingDiagnostic(diagnostic: CheckerTestUtil.TextDiagnostic, expectedStart: Int, expectedEnd: Int) {
|
||||||
updateUncheckedDiagnostics(diagnostic, expectedStart, expectedEnd)
|
if (withNewInferenceDirective && diagnostic.inferenceCompatibility != inferenceCompatibilityOfTest) {
|
||||||
return
|
updateUncheckedDiagnostics(diagnostic, expectedStart, expectedEnd)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val message = "Missing " + diagnostic.description + PsiDiagnosticUtils.atLocation(
|
||||||
|
ktFile,
|
||||||
|
TextRange(expectedStart, expectedEnd)
|
||||||
|
)
|
||||||
|
System.err.println(message)
|
||||||
|
ok[0] = false
|
||||||
}
|
}
|
||||||
|
|
||||||
val message = "Missing " + diagnostic.description + PsiDiagnosticUtils.atLocation(
|
override fun wrongParametersDiagnostic(
|
||||||
ktFile,
|
|
||||||
TextRange(expectedStart, expectedEnd)
|
|
||||||
)
|
|
||||||
System.err.println(message)
|
|
||||||
ok[0] = false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun wrongParametersDiagnostic(
|
|
||||||
expectedDiagnostic: CheckerTestUtil.TextDiagnostic,
|
expectedDiagnostic: CheckerTestUtil.TextDiagnostic,
|
||||||
actualDiagnostic: CheckerTestUtil.TextDiagnostic,
|
actualDiagnostic: CheckerTestUtil.TextDiagnostic,
|
||||||
start: Int,
|
start: Int,
|
||||||
end: Int
|
end: Int
|
||||||
) {
|
) {
|
||||||
val message = "Parameters of diagnostic not equal at position " +
|
val message = "Parameters of diagnostic not equal at position " +
|
||||||
PsiDiagnosticUtils.atLocation(ktFile, TextRange(start, end)) +
|
PsiDiagnosticUtils.atLocation(ktFile, TextRange(start, end)) +
|
||||||
". Expected: ${expectedDiagnostic.asString()}, actual: $actualDiagnostic"
|
". Expected: ${expectedDiagnostic.asString()}, actual: $actualDiagnostic"
|
||||||
System.err.println(message)
|
System.err.println(message)
|
||||||
ok[0] = false
|
ok[0] = false
|
||||||
}
|
|
||||||
|
|
||||||
override fun unexpectedDiagnostic(diagnostic: CheckerTestUtil.TextDiagnostic, actualStart: Int, actualEnd: Int) {
|
|
||||||
if (withNewInferenceDirective && diagnostic.inferenceCompatibility != inferenceCompatibilityOfTest) {
|
|
||||||
updateUncheckedDiagnostics(diagnostic, actualStart, actualEnd)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val message = "Unexpected ${diagnostic.description}${PsiDiagnosticUtils.atLocation(
|
override fun unexpectedDiagnostic(diagnostic: CheckerTestUtil.TextDiagnostic, actualStart: Int, actualEnd: Int) {
|
||||||
ktFile,
|
if (withNewInferenceDirective && diagnostic.inferenceCompatibility != inferenceCompatibilityOfTest) {
|
||||||
TextRange(actualStart, actualEnd)
|
updateUncheckedDiagnostics(diagnostic, actualStart, actualEnd)
|
||||||
)}"
|
return
|
||||||
System.err.println(message)
|
}
|
||||||
ok[0] = false
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateUncheckedDiagnostics(diagnostic: CheckerTestUtil.TextDiagnostic, start: Int, end: Int) {
|
val message = "Unexpected ${diagnostic.description}${PsiDiagnosticUtils.atLocation(
|
||||||
diagnostic.enhanceInferenceCompatibility(invertedInferenceCompatibilityOfTest)
|
ktFile,
|
||||||
uncheckedDiagnostics.add(PositionalTextDiagnostic(diagnostic, start, end))
|
TextRange(actualStart, actualEnd)
|
||||||
}
|
)}"
|
||||||
})
|
System.err.println(message)
|
||||||
|
ok[0] = false
|
||||||
|
}
|
||||||
|
|
||||||
actualText.append(CheckerTestUtil.addDiagnosticMarkersToText(
|
fun updateUncheckedDiagnostics(diagnostic: CheckerTestUtil.TextDiagnostic, start: Int, end: Int) {
|
||||||
ktFile, diagnostics, diagnosticToExpectedDiagnostic, { file -> file.text }, uncheckedDiagnostics, withNewInferenceDirective)
|
diagnostic.enhanceInferenceCompatibility(invertedInferenceCompatibilityOfTest)
|
||||||
|
uncheckedDiagnostics.add(PositionalTextDiagnostic(diagnostic, start, end))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
actualText.append(
|
||||||
|
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
|
||||||
@@ -329,32 +338,32 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
|||||||
val DIAGNOSTICS_DIRECTIVE = "DIAGNOSTICS"
|
val DIAGNOSTICS_DIRECTIVE = "DIAGNOSTICS"
|
||||||
val DIAGNOSTICS_PATTERN: Pattern = Pattern.compile("([\\+\\-!])(\\w+)\\s*")
|
val DIAGNOSTICS_PATTERN: Pattern = Pattern.compile("([\\+\\-!])(\\w+)\\s*")
|
||||||
val DIAGNOSTICS_TO_INCLUDE_ANYWAY: Set<DiagnosticFactory<*>> = setOf(
|
val DIAGNOSTICS_TO_INCLUDE_ANYWAY: Set<DiagnosticFactory<*>> = setOf(
|
||||||
Errors.UNRESOLVED_REFERENCE,
|
Errors.UNRESOLVED_REFERENCE,
|
||||||
Errors.UNRESOLVED_REFERENCE_WRONG_RECEIVER,
|
Errors.UNRESOLVED_REFERENCE_WRONG_RECEIVER,
|
||||||
CheckerTestUtil.SyntaxErrorDiagnosticFactory.INSTANCE,
|
CheckerTestUtil.SyntaxErrorDiagnosticFactory.INSTANCE,
|
||||||
CheckerTestUtil.DebugInfoDiagnosticFactory.ELEMENT_WITH_ERROR_TYPE,
|
CheckerTestUtil.DebugInfoDiagnosticFactory.ELEMENT_WITH_ERROR_TYPE,
|
||||||
CheckerTestUtil.DebugInfoDiagnosticFactory.MISSING_UNRESOLVED,
|
CheckerTestUtil.DebugInfoDiagnosticFactory.MISSING_UNRESOLVED,
|
||||||
CheckerTestUtil.DebugInfoDiagnosticFactory.UNRESOLVED_WITH_TARGET
|
CheckerTestUtil.DebugInfoDiagnosticFactory.UNRESOLVED_WITH_TARGET
|
||||||
)
|
)
|
||||||
|
|
||||||
val DEFAULT_DIAGNOSTIC_TESTS_FEATURES = mapOf(
|
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_DIRECTIVE = "CHECK_TYPE"
|
||||||
val CHECK_TYPE_PACKAGE = "tests._checkType"
|
val CHECK_TYPE_PACKAGE = "tests._checkType"
|
||||||
private val CHECK_TYPE_DECLARATIONS = "\npackage " + CHECK_TYPE_PACKAGE +
|
private val CHECK_TYPE_DECLARATIONS = "\npackage " + CHECK_TYPE_PACKAGE +
|
||||||
"\nfun <T> checkSubtype(t: T) = t" +
|
"\nfun <T> checkSubtype(t: T) = t" +
|
||||||
"\nclass Inv<T>" +
|
"\nclass Inv<T>" +
|
||||||
"\nfun <E> Inv<E>._() {}" +
|
"\nfun <E> Inv<E>._() {}" +
|
||||||
"\ninfix fun <T> T.checkType(f: Inv<T>.() -> Unit) {}"
|
"\ninfix fun <T> T.checkType(f: Inv<T>.() -> Unit) {}"
|
||||||
val CHECK_TYPE_IMPORT = "import $CHECK_TYPE_PACKAGE.*"
|
val CHECK_TYPE_IMPORT = "import $CHECK_TYPE_PACKAGE.*"
|
||||||
|
|
||||||
val EXPLICIT_FLEXIBLE_TYPES_DIRECTIVE = "EXPLICIT_FLEXIBLE_TYPES"
|
val EXPLICIT_FLEXIBLE_TYPES_DIRECTIVE = "EXPLICIT_FLEXIBLE_TYPES"
|
||||||
val EXPLICIT_FLEXIBLE_PACKAGE = InternalFlexibleTypeTransformer.FLEXIBLE_TYPE_CLASSIFIER.packageFqName.asString()
|
val EXPLICIT_FLEXIBLE_PACKAGE = InternalFlexibleTypeTransformer.FLEXIBLE_TYPE_CLASSIFIER.packageFqName.asString()
|
||||||
val EXPLICIT_FLEXIBLE_CLASS_NAME = InternalFlexibleTypeTransformer.FLEXIBLE_TYPE_CLASSIFIER.relativeClassName.asString()
|
val EXPLICIT_FLEXIBLE_CLASS_NAME = InternalFlexibleTypeTransformer.FLEXIBLE_TYPE_CLASSIFIER.relativeClassName.asString()
|
||||||
private val EXPLICIT_FLEXIBLE_TYPES_DECLARATIONS = "\npackage " + EXPLICIT_FLEXIBLE_PACKAGE +
|
private val EXPLICIT_FLEXIBLE_TYPES_DECLARATIONS = "\npackage " + EXPLICIT_FLEXIBLE_PACKAGE +
|
||||||
"\npublic class " + EXPLICIT_FLEXIBLE_CLASS_NAME + "<L, U>"
|
"\npublic class " + EXPLICIT_FLEXIBLE_CLASS_NAME + "<L, U>"
|
||||||
private val EXPLICIT_FLEXIBLE_TYPES_IMPORT = "import $EXPLICIT_FLEXIBLE_PACKAGE.$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_DIRECTIVE = "CHECK_LAZY_LOG"
|
||||||
val CHECK_LAZY_LOG_DEFAULT = "true" == System.getProperty("check.lazy.logs", "false")
|
val CHECK_LAZY_LOG_DEFAULT = "true" == System.getProperty("check.lazy.logs", "false")
|
||||||
@@ -366,20 +375,23 @@ 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)
|
||||||
Condition<Diagnostic> { it.factory.name != "UNDERSCORE_USAGE_WITHOUT_BACKTICKS" }
|
Condition<Diagnostic> { it.factory.name != "UNDERSCORE_USAGE_WITHOUT_BACKTICKS" }
|
||||||
else
|
else
|
||||||
Conditions.alwaysTrue()
|
Conditions.alwaysTrue()
|
||||||
|
|
||||||
if (directives == null) {
|
if (directives == null) {
|
||||||
// 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
|
||||||
@@ -403,18 +417,19 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
|||||||
val name = matcher.group(2)
|
val name = matcher.group(2)
|
||||||
|
|
||||||
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,13 +437,12 @@ 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(
|
||||||
condition,
|
condition,
|
||||||
Condition { diagnostic -> diagnostic.factory in DIAGNOSTICS_TO_INCLUDE_ANYWAY }
|
Condition { diagnostic -> diagnostic.factory in DIAGNOSTICS_TO_INCLUDE_ANYWAY }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user