From 99f7d605a7c6e43eae9331adf936ea34d7fcf4f0 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Wed, 22 Nov 2017 15:16:10 +0300 Subject: [PATCH] Refactoring: move deprecation information to common place --- .../gradle/GradleDependencyInspection.kt | 52 +++---------------- .../idea/versions/KotlinRuntimeLibraryUtil.kt | 43 ++++++++++++++- 2 files changed, 48 insertions(+), 47 deletions(-) diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/inspections/gradle/GradleDependencyInspection.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/inspections/gradle/GradleDependencyInspection.kt index 844efa8851b..68d12cdc8fb 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/inspections/gradle/GradleDependencyInspection.kt +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/inspections/gradle/GradleDependencyInspection.kt @@ -22,61 +22,21 @@ import com.intellij.openapi.roots.ProjectRootManager import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile import com.intellij.util.text.VersionComparatorUtil -import org.jetbrains.kotlin.idea.configuration.KotlinWithGradleConfigurator import org.jetbrains.kotlin.idea.configuration.allModules import org.jetbrains.kotlin.idea.configuration.getWholeModuleGroup import org.jetbrains.kotlin.idea.inspections.ReplaceStringInDocumentFix +import org.jetbrains.kotlin.idea.versions.LibInfo +import org.jetbrains.kotlin.idea.versions.DEPRECATED_LIBRARIES_INFORMATION +import org.jetbrains.kotlin.idea.versions.DeprecatedLibInfo import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType -import org.jetbrains.kotlin.utils.PathUtil import org.jetbrains.plugins.gradle.codeInspection.GradleBaseInspection import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrCallExpression -data class LibInfo( - val groupId: String, - val name: String -) - -data class OutdatedLibInfo( - val old: LibInfo, - val new: LibInfo, - val outdatedAfterVersion: String, - val message: String -) - -private val outdatedLibrariesInformation = listOf( - outdatedLib( - oldGroupId = KotlinWithGradleConfigurator.GROUP_ID, - oldName = PathUtil.KOTLIN_JAVA_RUNTIME_JRE7_NAME, newName = PathUtil.KOTLIN_JAVA_RUNTIME_JDK7_NAME, - outdatedAfterVersion = "1.2.0-rc-39", - message = "${PathUtil.KOTLIN_JAVA_RUNTIME_JRE7_NAME} is deprecated since 1.2.0 and should be replaced with ${PathUtil.KOTLIN_JAVA_RUNTIME_JDK7_NAME}"), - - outdatedLib( - oldGroupId = KotlinWithGradleConfigurator.GROUP_ID, - oldName = PathUtil.KOTLIN_JAVA_RUNTIME_JRE8_NAME, newName = PathUtil.KOTLIN_JAVA_RUNTIME_JDK8_NAME, - outdatedAfterVersion = "1.2.0-rc-39", - message = "${PathUtil.KOTLIN_JAVA_RUNTIME_JRE8_NAME} is deprecated since 1.2.0 and should be replaced with ${PathUtil.KOTLIN_JAVA_RUNTIME_JDK8_NAME}") -) - private val LibInfo.gradleMarker get() = "$groupId:$name:" -private fun outdatedLib( - oldGroupId: String, - oldName: String, - newGroupId: String = oldGroupId, - newName: String = oldName, - outdatedAfterVersion: String, - message: String): OutdatedLibInfo { - return OutdatedLibInfo( - old = LibInfo(groupId = oldGroupId, name = oldName), - new = LibInfo(groupId = newGroupId, name = newName), - outdatedAfterVersion = outdatedAfterVersion, - message = message - ) -} - class GradleDependencyInspection : GradleBaseInspection() { override fun buildVisitor(): BaseInspectionVisitor = DependencyFinder() @@ -94,7 +54,7 @@ class GradleDependencyInspection : GradleBaseInspection() { } open fun visitDependencyEntry(dependencyStatement: GrCallExpression) { - for (outdatedInfo in outdatedLibrariesInformation) { + for (outdatedInfo in DEPRECATED_LIBRARIES_INFORMATION) { val dependencyText = dependencyStatement.text val libMarker = outdatedInfo.old.gradleMarker @@ -120,8 +80,8 @@ class GradleDependencyInspection : GradleBaseInspection() { } } - private fun reportOnElement(classpathEntry: GrCallExpression, outdatedInfo: OutdatedLibInfo): PsiElement { - val indexOf = classpathEntry.text.indexOf(outdatedInfo.old.name) + private fun reportOnElement(classpathEntry: GrCallExpression, deprecatedInfo: DeprecatedLibInfo): PsiElement { + val indexOf = classpathEntry.text.indexOf(deprecatedInfo.old.name) if (indexOf < 0) return classpathEntry return classpathEntry.findElementAt(indexOf) ?: classpathEntry diff --git a/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.kt b/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.kt index 692d33c2006..4c44eeaf433 100644 --- a/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.kt @@ -370,4 +370,45 @@ val MAVEN_TEST_JUNIT_ID = "kotlin-test-junit" val MAVEN_COMMON_TEST_ID = "kotlin-test-common" val MAVEN_COMMON_TEST_ANNOTATIONS_ID = "kotlin-test-annotations-common" -val LOG = Logger.getInstance("org.jetbrains.kotlin.idea.versions.KotlinRuntimeLibraryUtilKt") \ No newline at end of file +val LOG = Logger.getInstance("org.jetbrains.kotlin.idea.versions.KotlinRuntimeLibraryUtilKt") + +data class LibInfo( + val groupId: String, + val name: String +) + +data class DeprecatedLibInfo( + val old: LibInfo, + val new: LibInfo, + val outdatedAfterVersion: String, + val message: String +) + +private fun deprecatedLib( + oldGroupId: String, + oldName: String, + newGroupId: String = oldGroupId, + newName: String = oldName, + outdatedAfterVersion: String, + message: String): DeprecatedLibInfo { + return DeprecatedLibInfo( + old = LibInfo(groupId = oldGroupId, name = oldName), + new = LibInfo(groupId = newGroupId, name = newName), + outdatedAfterVersion = outdatedAfterVersion, + message = message + ) +} + +val DEPRECATED_LIBRARIES_INFORMATION = listOf( + deprecatedLib( + oldGroupId = "org.jetbrains.kotlin", + oldName = PathUtil.KOTLIN_JAVA_RUNTIME_JRE7_NAME, newName = PathUtil.KOTLIN_JAVA_RUNTIME_JDK7_NAME, + outdatedAfterVersion = "1.2.0-rc-39", + message = "${PathUtil.KOTLIN_JAVA_RUNTIME_JRE7_NAME} is deprecated since 1.2.0 and should be replaced with ${PathUtil.KOTLIN_JAVA_RUNTIME_JDK7_NAME}"), + + deprecatedLib( + oldGroupId = "org.jetbrains.kotlin", + oldName = PathUtil.KOTLIN_JAVA_RUNTIME_JRE8_NAME, newName = PathUtil.KOTLIN_JAVA_RUNTIME_JDK8_NAME, + outdatedAfterVersion = "1.2.0-rc-39", + message = "${PathUtil.KOTLIN_JAVA_RUNTIME_JRE8_NAME} is deprecated since 1.2.0 and should be replaced with ${PathUtil.KOTLIN_JAVA_RUNTIME_JDK8_NAME}") +) \ No newline at end of file