From 1698ccff9a0650f8e09f7e20ff2ba69b2f4bfa98 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Wed, 10 Apr 2024 12:30:23 +0100 Subject: [PATCH 1/4] Kotlin: Add 2.0.0-RC1 support (and remove 2.0.0-Beta4) --- java/kotlin-extractor/kotlin_plugin_versions.py | 2 +- .../{v_2_0_0-Beta4 => v_2_0_0-RC1}/IrSymbolInternals.kt | 0 .../{v_2_0_0-Beta4 => v_2_0_0-RC1}/JavaBinarySourceElement.kt | 0 .../{v_2_0_0-Beta4 => v_2_0_0-RC1}/JvmDefaultModeEnabled.kt | 0 .../utils/versions/{v_2_0_0-Beta4 => v_2_0_0-RC1}/Psi2Ir.kt | 0 .../utils/versions/{v_2_0_0-Beta4 => v_2_0_0-RC1}/parents.kt | 0 6 files changed, 1 insertion(+), 1 deletion(-) rename java/kotlin-extractor/src/main/kotlin/utils/versions/{v_2_0_0-Beta4 => v_2_0_0-RC1}/IrSymbolInternals.kt (100%) rename java/kotlin-extractor/src/main/kotlin/utils/versions/{v_2_0_0-Beta4 => v_2_0_0-RC1}/JavaBinarySourceElement.kt (100%) rename java/kotlin-extractor/src/main/kotlin/utils/versions/{v_2_0_0-Beta4 => v_2_0_0-RC1}/JvmDefaultModeEnabled.kt (100%) rename java/kotlin-extractor/src/main/kotlin/utils/versions/{v_2_0_0-Beta4 => v_2_0_0-RC1}/Psi2Ir.kt (100%) rename java/kotlin-extractor/src/main/kotlin/utils/versions/{v_2_0_0-Beta4 => v_2_0_0-RC1}/parents.kt (100%) diff --git a/java/kotlin-extractor/kotlin_plugin_versions.py b/java/kotlin-extractor/kotlin_plugin_versions.py index d385eb9e6137..5bae5789e2be 100755 --- a/java/kotlin-extractor/kotlin_plugin_versions.py +++ b/java/kotlin-extractor/kotlin_plugin_versions.py @@ -46,7 +46,7 @@ def version_string_to_version(version): # Version number used by CI. ci_version = '1.9.0' -many_versions = [ '1.5.0', '1.5.10', '1.5.20', '1.5.30', '1.6.0', '1.6.20', '1.7.0', '1.7.20', '1.8.0', '1.9.0-Beta', '1.9.20-Beta', '2.0.0-Beta4', '2.0.255-SNAPSHOT' ] +many_versions = [ '1.5.0', '1.5.10', '1.5.20', '1.5.30', '1.6.0', '1.6.20', '1.7.0', '1.7.20', '1.8.0', '1.9.0-Beta', '1.9.20-Beta', '2.0.0-RC1', '2.0.255-SNAPSHOT' ] many_versions_versions = [version_string_to_version(v) for v in many_versions] many_versions_versions_asc = sorted(many_versions_versions, key = lambda v: v.toTupleWithTag()) diff --git a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-Beta4/IrSymbolInternals.kt b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-RC1/IrSymbolInternals.kt similarity index 100% rename from java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-Beta4/IrSymbolInternals.kt rename to java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-RC1/IrSymbolInternals.kt diff --git a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-Beta4/JavaBinarySourceElement.kt b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-RC1/JavaBinarySourceElement.kt similarity index 100% rename from java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-Beta4/JavaBinarySourceElement.kt rename to java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-RC1/JavaBinarySourceElement.kt diff --git a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-Beta4/JvmDefaultModeEnabled.kt b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-RC1/JvmDefaultModeEnabled.kt similarity index 100% rename from java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-Beta4/JvmDefaultModeEnabled.kt rename to java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-RC1/JvmDefaultModeEnabled.kt diff --git a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-Beta4/Psi2Ir.kt b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-RC1/Psi2Ir.kt similarity index 100% rename from java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-Beta4/Psi2Ir.kt rename to java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-RC1/Psi2Ir.kt diff --git a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-Beta4/parents.kt b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-RC1/parents.kt similarity index 100% rename from java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-Beta4/parents.kt rename to java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-RC1/parents.kt From 7ce7685b912301207f77d5e3ff94c02bf5049249 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Wed, 10 Apr 2024 14:54:15 +0100 Subject: [PATCH 2/4] Kotlin: FirMetadataSource.File.files has been removed In new versions, but not old versions, we want FirMetadataSource.File.fir instead. --- .../utils/versions/v_1_5_0/FirMetadataSourceFirFile.kt | 1 + .../versions/v_1_9_0-Beta/CommentExtractorLighterAST.kt | 3 ++- .../versions/v_1_9_0-Beta/FirMetadataSourceFirFile.kt | 7 +++++++ .../utils/versions/v_1_9_0-Beta/LinesOfCodeLighterAST.kt | 3 ++- .../utils/versions/v_2_0_0-RC1/FirMetadataSourceFirFile.kt | 7 +++++++ 5 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_5_0/FirMetadataSourceFirFile.kt create mode 100644 java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_9_0-Beta/FirMetadataSourceFirFile.kt create mode 100644 java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-RC1/FirMetadataSourceFirFile.kt diff --git a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_5_0/FirMetadataSourceFirFile.kt b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_5_0/FirMetadataSourceFirFile.kt new file mode 100644 index 000000000000..9c103006099f --- /dev/null +++ b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_5_0/FirMetadataSourceFirFile.kt @@ -0,0 +1 @@ +// Nothing to do diff --git a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_9_0-Beta/CommentExtractorLighterAST.kt b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_9_0-Beta/CommentExtractorLighterAST.kt index dd83b0fc4525..ecaa5e232873 100644 --- a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_9_0-Beta/CommentExtractorLighterAST.kt +++ b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_9_0-Beta/CommentExtractorLighterAST.kt @@ -1,6 +1,7 @@ package com.github.codeql.comments import com.github.codeql.* +import com.github.codeql.utils.versions.* import com.intellij.lang.LighterASTNode import com.intellij.util.diff.FlyweightCapableTreeStructure import org.jetbrains.kotlin.fir.backend.FirMetadataSource @@ -26,7 +27,7 @@ class CommentExtractorLighterAST( // Returns true if it extracted the comments; false otherwise. fun extract(): Boolean { val sourceElement = - (file.metadata as? FirMetadataSource.File)?.files?.elementAtOrNull(0)?.source + (file.metadata as? FirMetadataSource.File)?.firFile?.source val treeStructure = sourceElement?.treeStructure if (treeStructure == null) { return false diff --git a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_9_0-Beta/FirMetadataSourceFirFile.kt b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_9_0-Beta/FirMetadataSourceFirFile.kt new file mode 100644 index 000000000000..53fefb30817b --- /dev/null +++ b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_9_0-Beta/FirMetadataSourceFirFile.kt @@ -0,0 +1,7 @@ +package com.github.codeql.utils.versions + +import org.jetbrains.kotlin.fir.backend.FirMetadataSource +import org.jetbrains.kotlin.fir.declarations.FirFile + +val FirMetadataSource.File.firFile: FirFile? + get() = this.files.elementAtOrNull(0) diff --git a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_9_0-Beta/LinesOfCodeLighterAST.kt b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_9_0-Beta/LinesOfCodeLighterAST.kt index 1c2ec1ed6fae..82357d9dfbd6 100644 --- a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_9_0-Beta/LinesOfCodeLighterAST.kt +++ b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_9_0-Beta/LinesOfCodeLighterAST.kt @@ -1,5 +1,6 @@ package com.github.codeql +import com.github.codeql.utils.versions.* import com.intellij.lang.LighterASTNode import com.intellij.util.diff.FlyweightCapableTreeStructure import org.jetbrains.kotlin.KtSourceElement @@ -14,7 +15,7 @@ class LinesOfCodeLighterAST(val logger: FileLogger, val tw: FileTrapWriter, val fun linesOfCodeInFile(id: Label): Boolean { val sourceElement = - (file.metadata as? FirMetadataSource.File)?.files?.elementAtOrNull(0)?.source + (file.metadata as? FirMetadataSource.File)?.firFile?.source if (sourceElement == null) { return false } diff --git a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-RC1/FirMetadataSourceFirFile.kt b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-RC1/FirMetadataSourceFirFile.kt new file mode 100644 index 000000000000..dc47af858b26 --- /dev/null +++ b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_0_0-RC1/FirMetadataSourceFirFile.kt @@ -0,0 +1,7 @@ +package com.github.codeql.utils.versions + +import org.jetbrains.kotlin.fir.backend.FirMetadataSource +import org.jetbrains.kotlin.fir.declarations.FirFile + +val FirMetadataSource.File.firFile: FirFile? + get() = this.fir From 9c573dbee35390801ffbe03ec337c867b871ad87 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Wed, 10 Apr 2024 16:08:29 +0100 Subject: [PATCH 3/4] Kotlin: Update expected result for kotlin-version-too-new test --- .../diagnostics/kotlin-version-too-new/diagnostics.expected | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/ql/integration-tests/all-platforms/kotlin/diagnostics/kotlin-version-too-new/diagnostics.expected b/java/ql/integration-tests/all-platforms/kotlin/diagnostics/kotlin-version-too-new/diagnostics.expected index 345a871375aa..3cb70963c893 100644 --- a/java/ql/integration-tests/all-platforms/kotlin/diagnostics/kotlin-version-too-new/diagnostics.expected +++ b/java/ql/integration-tests/all-platforms/kotlin/diagnostics/kotlin-version-too-new/diagnostics.expected @@ -1,5 +1,5 @@ { - "markdownMessage": "The Kotlin version installed (`999.999.999`) is too recent for this version of CodeQL. Install a version lower than 1.9.30.", + "markdownMessage": "The Kotlin version installed (`999.999.999`) is too recent for this version of CodeQL. Install a version lower than 2.0.10.", "severity": "error", "source": { "extractorName": "java", From 58f825fcb8ac5e4d6f25df10af08651c10719d87 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Wed, 10 Apr 2024 17:57:42 +0100 Subject: [PATCH 4/4] Kotlin: Drop our 2.0.255-SNAPSHOT version It's now older than 2.0.0-RC1 --- java/kotlin-extractor/kotlin_plugin_versions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/kotlin-extractor/kotlin_plugin_versions.py b/java/kotlin-extractor/kotlin_plugin_versions.py index 5bae5789e2be..9dd7b766c7f6 100755 --- a/java/kotlin-extractor/kotlin_plugin_versions.py +++ b/java/kotlin-extractor/kotlin_plugin_versions.py @@ -46,7 +46,7 @@ def version_string_to_version(version): # Version number used by CI. ci_version = '1.9.0' -many_versions = [ '1.5.0', '1.5.10', '1.5.20', '1.5.30', '1.6.0', '1.6.20', '1.7.0', '1.7.20', '1.8.0', '1.9.0-Beta', '1.9.20-Beta', '2.0.0-RC1', '2.0.255-SNAPSHOT' ] +many_versions = [ '1.5.0', '1.5.10', '1.5.20', '1.5.30', '1.6.0', '1.6.20', '1.7.0', '1.7.20', '1.8.0', '1.9.0-Beta', '1.9.20-Beta', '2.0.0-RC1' ] many_versions_versions = [version_string_to_version(v) for v in many_versions] many_versions_versions_asc = sorted(many_versions_versions, key = lambda v: v.toTupleWithTag())