AbstractLocalInspectionTest: add LANGUAGE_VERSION support

Related to KT-17164
This commit is contained in:
Mikhail Glukhikh
2017-05-16 14:15:22 +03:00
committed by Mikhail Glukhikh
parent 9990550429
commit 51af18608f
16 changed files with 34 additions and 12 deletions
@@ -1,4 +1,4 @@
// ERROR: The feature "array literals in annotations" is only available since language version 1.2
// LANGUAGE_VERSION: 1.2
annotation class Some(val strings: Array<String>)
@@ -1,4 +1,4 @@
// ERROR: The feature "array literals in annotations" is only available since language version 1.2
// LANGUAGE_VERSION: 1.2
annotation class Some(val strings: Array<String>)
@@ -1,3 +1,3 @@
// ERROR: The feature "array literals in annotations" is only available since language version 1.2
// LANGUAGE_VERSION: 1.2
annotation class Some(val strings: Array<String> = <caret>arrayOf("default"))
@@ -1,3 +1,3 @@
// ERROR: The feature "array literals in annotations" is only available since language version 1.2
// LANGUAGE_VERSION: 1.2
annotation class Some(val strings: Array<String> = ["default"])
@@ -1,2 +1,3 @@
// LANGUAGE_VERSION: 1.2
// PROBLEM: none
class Some(val strings: Array<String> = <caret>arrayOf("default"))
@@ -1,4 +1,4 @@
// ERROR: The feature "array literals in annotations" is only available since language version 1.2
// LANGUAGE_VERSION: 1.2
annotation class Some(val strings: Array<String>)
@@ -1,4 +1,4 @@
// ERROR: The feature "array literals in annotations" is only available since language version 1.2
// LANGUAGE_VERSION: 1.2
annotation class Some(val strings: Array<String>)
@@ -1,4 +1,4 @@
// ERROR: The feature "array literals in annotations" is only available since language version 1.2
// LANGUAGE_VERSION: 1.2
annotation class Some(val nums: IntArray)
@@ -1,4 +1,4 @@
// ERROR: The feature "array literals in annotations" is only available since language version 1.2
// LANGUAGE_VERSION: 1.2
annotation class Some(val nums: IntArray)
@@ -1,3 +1,4 @@
// LANGUAGE_VERSION: 1.2
// PROBLEM: none
fun foo() {
@@ -1,3 +1,4 @@
// LANGUAGE_VERSION: 1.2
// PROBLEM: none
// ERROR: Type mismatch: inferred type is Int but Array<String> was expected
@@ -1,4 +1,4 @@
// ERROR: The feature "array literals in annotations" is only available since language version 1.2
// LANGUAGE_VERSION: 1.2
annotation class Some(val strings: Array<String>)
@@ -1,4 +1,4 @@
// ERROR: The feature "array literals in annotations" is only available since language version 1.2
// LANGUAGE_VERSION: 1.2
annotation class Some(val strings: Array<String>)
@@ -1,4 +1,4 @@
// ERROR: The feature "array literals in annotations" is only available since language version 1.2
// LANGUAGE_VERSION: 1.2
annotation class Some(vararg val strings: String)
@@ -1,4 +1,4 @@
// ERROR: The feature "array literals in annotations" is only available since language version 1.2
// LANGUAGE_VERSION: 1.2
annotation class Some(vararg val strings: String)
@@ -18,11 +18,16 @@ package org.jetbrains.kotlin.idea.inspections
import com.google.common.collect.Lists
import com.intellij.codeInspection.ProblemDescriptor
import com.intellij.openapi.application.WriteAction
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl
import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.vfs.VirtualFile
import junit.framework.ComparisonFailure
import junit.framework.TestCase
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.idea.facet.configureFacet
import org.jetbrains.kotlin.idea.facet.getOrCreateFacet
import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
@@ -73,6 +78,20 @@ abstract class AbstractLocalInspectionTest : KotlinLightCodeInsightFixtureTestCa
val fileText = FileUtil.loadFile(mainFile, true)
TestCase.assertTrue("\"<caret>\" is missing in file \"$mainFile\"", fileText.contains("<caret>"))
val version = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// LANGUAGE_VERSION: ")
if (version != null) {
val accessToken = WriteAction.start()
try {
val modelsProvider = IdeModifiableModelsProviderImpl(project)
val facet = module.getOrCreateFacet(modelsProvider, useProjectSettings = false)
facet.configureFacet(version, LanguageFeature.State.DISABLED, null, modelsProvider)
modelsProvider.commit()
}
finally {
accessToken.finish()
}
}
val minJavaVersion = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// MIN_JAVA_VERSION: ")
if (minJavaVersion != null && !SystemInfo.isJavaVersionAtLeast(minJavaVersion)) return