Android Lint: Fix constant evaluation in annotation parameter

#KT-17785 Fixed Target Versions 1.1.5
This commit is contained in:
Vyacheslav Gerasimov
2017-08-22 14:33:12 +03:00
parent 2e1edaf3d4
commit aedb4c0ade
6 changed files with 89 additions and 7 deletions
@@ -16,9 +16,12 @@
package org.jetbrains.kotlin.android.lint
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl
import com.intellij.util.PathUtil
import org.jetbrains.android.inspections.klint.AndroidLintInspectionBase
import org.jetbrains.kotlin.android.KotlinAndroidTestCase
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import org.jetbrains.kotlin.test.InTextDirectivesUtils.findStringWithPrefixes
import java.io.File
@@ -26,9 +29,9 @@ abstract class AbstractKotlinLintTest : KotlinAndroidTestCase() {
override fun setUp() {
super.setUp()
ConfigLibraryUtil.configureKotlinRuntime(myModule)
AndroidLintInspectionBase.invalidateInspectionShortName2IssueMap()
// needs access to .class files in kotlin runtime jar
(myFixture as CodeInsightTestFixtureImpl).setVirtualFileFilter { false } // Allow access to tree elements.
ConfigLibraryUtil.configureKotlinRuntime(myModule)
}
override fun tearDown() {
@@ -36,9 +39,11 @@ abstract class AbstractKotlinLintTest : KotlinAndroidTestCase() {
super.tearDown()
}
fun doTest(filename: String) {
val ktFile = File(filename)
val mainInspectionClassName = findStringWithPrefixes(ktFile.readText(), "// INSPECTION_CLASS: ") ?: error("Empty class name")
fun doTest(path: String) {
val ktFile = File(path)
val fileText = ktFile.readText()
val mainInspectionClassName = findStringWithPrefixes(fileText, "// INSPECTION_CLASS: ") ?: error("Empty class name")
val dependency = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// DEPENDENCY: ")
val inspectionClassNames = mutableListOf(mainInspectionClassName)
for (i in 2..100) {
@@ -63,9 +68,14 @@ abstract class AbstractKotlinLintTest : KotlinAndroidTestCase() {
}
}
val virtualFile = myFixture.copyFileToProject(ktFile.absolutePath, "src/" + getTestName(true) + ".kt")
val virtualFile = myFixture.copyFileToProject(ktFile.absolutePath, "src/${PathUtil.getFileName(path)}")
myFixture.configureFromExistingVirtualFile(virtualFile)
if (dependency != null) {
val (dependencyFile, dependencyTargetPath) = dependency.split(" -> ").map(String::trim)
myFixture.copyFileToProject("${PathUtil.getParentPath(path)}/$dependencyFile", "src/$dependencyTargetPath")
}
myFixture.checkHighlighting(true, false, false)
}
}
@@ -138,6 +138,12 @@ public class KotlinLintTestGenerated extends AbstractKotlinLintTest {
doTest(fileName);
}
@TestMetadata("supportAnnotation.kt")
public void testSupportAnnotation() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/supportAnnotation.kt");
doTest(fileName);
}
@TestMetadata("systemServices.kt")
public void testSystemServices() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/systemServices.kt");