Report jre deprecated warning when version is set implicitly (KT-26933)

#KT-26933 Fixed
This commit is contained in:
Nikolay Krasko
2018-07-09 17:35:10 +03:00
parent 3f2c73b4a9
commit 9f16e4f709
2 changed files with 45 additions and 1 deletions
@@ -37,7 +37,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlo
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrCallExpression
private val LibInfo.gradleMarker get() = "$groupId:$name:"
private val LibInfo.gradleMarker get() = "$groupId:$name"
class DeprecatedGradleDependencyInspection : GradleBaseInspection() {
override fun buildVisitor(): BaseInspectionVisitor = DependencyFinder()
@@ -62,6 +62,11 @@ class DeprecatedGradleDependencyInspection : GradleBaseInspection() {
val libMarker = outdatedInfo.old.gradleMarker
if (dependencyText.contains(libMarker)) {
val afterMarkerChar = dependencyText.substringAfter(libMarker).getOrNull(0)
if (!(afterMarkerChar == '\'' || afterMarkerChar == '"' || afterMarkerChar == ':')) {
continue
}
val libVersion =
DifferentStdlibGradleVersionInspection.getResolvedLibVersion(
dependencyStatement.containingFile, outdatedInfo.old.groupId, listOf(outdatedInfo.old.name)
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.idea.inspections.gradle.DifferentKotlinGradleVersion
import org.jetbrains.kotlin.idea.inspections.gradle.DifferentStdlibGradleVersionInspection
import org.jetbrains.kotlin.idea.inspections.gradle.GradleKotlinxCoroutinesDeprecationInspection
import org.jetbrains.kotlin.idea.inspections.runInspection
import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions
import org.junit.Assert
import org.junit.Test
@@ -344,6 +345,44 @@ class GradleInspectionTest : GradleImportingTestCase() {
)
}
@TargetVersions("4.9+")
@Test
fun testJreIsDeprecatedWithoutImplicitVersion() {
val localFile = createProjectSubFile(
"build.gradle", """
group 'Again'
version '1.0-SNAPSHOT'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.0")
}
}
apply plugin: 'kotlin'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8"
}
"""
)
importProject()
val tool = DeprecatedGradleDependencyInspection()
val problems = getInspectionResult(tool, localFile)
Assert.assertTrue(problems.size == 1)
Assert.assertEquals(
"kotlin-stdlib-jre8 is deprecated since 1.2.0 and should be replaced with kotlin-stdlib-jdk8",
problems.single()
)
}
@Test
fun testObsoleteCoroutinesUsage() {
val localFile = createProjectSubFile(