Skip to content

Commit

Permalink
K2 plugin migration (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
akozlova authored Nov 7, 2024
1 parent 123d6d9 commit a84b767
Show file tree
Hide file tree
Showing 20 changed files with 328 additions and 166 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ jobs:

strategy:
matrix:
product: [ "IC-223", "IC-231", "IC-232", "IC-233", "IC-241", "IC-242", "IC-243" ]
product: [ "IC-231", "IC-232", "IC-233", "IC-241", "IC-242", "IC-243" ]
include:
- product: "IC-223"
java: "17"
distribution: "temurin"
- product: "IC-231"
java: "17"
distribution: "temurin"
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ jobs:

strategy:
matrix:
product: [ "IC-223", "IC-231", "IC-232", "IC-233", "IC-241", "IC-242", "IC-243" ]
product: [ "IC-231", "IC-232", "IC-233", "IC-241", "IC-242", "IC-243" ]
include:
- product: "IC-223"
java: "17"
distribution: "temurin"
- product: "IC-231"
java: "17"
distribution: "temurin"
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ jobs:

strategy:
matrix:
product: [ "IC-223", "IC-231", "IC-232", "IC-233", "IC-241", "IC-242", "IC-243" ]
product: [ "IC-231", "IC-232", "IC-233", "IC-241", "IC-242", "IC-243" ]
include:
- product: "IC-223"
java: "17"
distribution: "temurin"
- product: "IC-231"
java: "17"
distribution: "temurin"
Expand Down
17 changes: 8 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ data class PluginDescriptor(
// and 'until' we can use a wildcard eg 213.*

val descriptors = listOf(
PluginDescriptor(
since = "223.4884.69", // this version is 2022.3
until = "223.*",
sdkVersion = "2022.3",
sourceFolder = "IC-223",
useInstaller = true,
),
PluginDescriptor(
since = "231.8109.163", // this version is 2023.1 release
until = "231.*",
Expand Down Expand Up @@ -83,7 +76,7 @@ val descriptors = listOf(
PluginDescriptor(
since = "242.*", // this version is 2024.2.x
until = "243.*",
sdkVersion = "2024.2",
sdkVersion = "2024.2.2",
sourceFolder = "IC-242",
useInstaller = true,
),
Expand Down Expand Up @@ -111,6 +104,12 @@ val runWithCustomSandbox by intellijPlatformTesting.runIde.registering {
}
}

val runWithK2Mode by intellijPlatformTesting.runIde.registering {
task {
jvmArgs = listOf("-Didea.kotlin.plugin.use.k2=true")
}
}

intellijPlatform {
buildSearchableOptions = false
projectName = project.name
Expand Down Expand Up @@ -165,7 +164,7 @@ dependencies {
// testRuntimeOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1")
}

configurations.all {
configurations.runtimeOnly {
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core-jvm")
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core")
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-jdk8")
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ version=1.1.0

org.gradle.caching=true
sandbox = /tmp/

kotlin.stdlib.default.dependency = false
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
kotlin = "1.9.25"
kotlin = "2.0.21"
runtime-kotest = "4.2.0"
# We separate these from the actual runtime dependencies
test-kotest = "5.9.1"
Expand Down
33 changes: 0 additions & 33 deletions src/IC-223/kotlin/io/kotest/plugin/intellij/files.kt

This file was deleted.

36 changes: 36 additions & 0 deletions src/IC-231/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.kotest.plugin.intellij.psi

import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.types.typeUtil.supertypes

/**
* Recursively returns the list of classes and interfaces extended or implemented by the class.
*/
fun KtClassOrObject.getAllSuperClasses(): List<FqName> {
return superTypeListEntries
.mapNotNull { it.typeReference }
.mapNotNull {
runCatching {
val bindingContext = it.analyze()
bindingContext.get(BindingContext.TYPE, it)
}.getOrNull()
}.flatMap {
runCatching {
it.supertypes() + it
}.getOrElse { emptyList() }
}.mapNotNull {
runCatching {
it.constructor.declarationDescriptor.classId
}.getOrNull()
}.mapNotNull {
runCatching {
val packageName = it.packageFqName
val simpleName = it.relativeClassName
FqName("$packageName.$simpleName")
}.getOrNull()
}.filterNot { it.toString() == "kotlin.Any" }
}
36 changes: 36 additions & 0 deletions src/IC-232/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.kotest.plugin.intellij.psi

import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.types.typeUtil.supertypes

/**
* Recursively returns the list of classes and interfaces extended or implemented by the class.
*/
fun KtClassOrObject.getAllSuperClasses(): List<FqName> {
return superTypeListEntries
.mapNotNull { it.typeReference }
.mapNotNull {
runCatching {
val bindingContext = it.analyze()
bindingContext.get(BindingContext.TYPE, it)
}.getOrNull()
}.flatMap {
runCatching {
it.supertypes() + it
}.getOrElse { emptyList() }
}.mapNotNull {
runCatching {
it.constructor.declarationDescriptor.classId
}.getOrNull()
}.mapNotNull {
runCatching {
val packageName = it.packageFqName
val simpleName = it.relativeClassName
FqName("$packageName.$simpleName")
}.getOrNull()
}.filterNot { it.toString() == "kotlin.Any" }
}
36 changes: 36 additions & 0 deletions src/IC-233/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.kotest.plugin.intellij.psi

import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.types.typeUtil.supertypes

/**
* Recursively returns the list of classes and interfaces extended or implemented by the class.
*/
fun KtClassOrObject.getAllSuperClasses(): List<FqName> {
return superTypeListEntries
.mapNotNull { it.typeReference }
.mapNotNull {
runCatching {
val bindingContext = it.analyze()
bindingContext.get(BindingContext.TYPE, it)
}.getOrNull()
}.flatMap {
runCatching {
it.supertypes() + it
}.getOrElse { emptyList() }
}.mapNotNull {
runCatching {
it.constructor.declarationDescriptor.classId
}.getOrNull()
}.mapNotNull {
runCatching {
val packageName = it.packageFqName
val simpleName = it.relativeClassName
FqName("$packageName.$simpleName")
}.getOrNull()
}.filterNot { it.toString() == "kotlin.Any" }
}
36 changes: 36 additions & 0 deletions src/IC-241/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.kotest.plugin.intellij.psi

import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.types.typeUtil.supertypes

/**
* Recursively returns the list of classes and interfaces extended or implemented by the class.
*/
fun KtClassOrObject.getAllSuperClasses(): List<FqName> {
return superTypeListEntries
.mapNotNull { it.typeReference }
.mapNotNull {
runCatching {
val bindingContext = it.analyze()
bindingContext.get(BindingContext.TYPE, it)
}.getOrNull()
}.flatMap {
runCatching {
it.supertypes() + it
}.getOrElse { emptyList() }
}.mapNotNull {
runCatching {
it.constructor.declarationDescriptor.classId
}.getOrNull()
}.mapNotNull {
runCatching {
val packageName = it.packageFqName
val simpleName = it.relativeClassName
FqName("$packageName.$simpleName")
}.getOrNull()
}.filterNot { it.toString() == "kotlin.Any" }
}
32 changes: 32 additions & 0 deletions src/IC-242/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.kotest.plugin.intellij.psi

import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.permissions.KaAllowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.permissions.allowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.types.symbol
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.psi.KtClassOrObject

/**
* Recursively returns the list of classes and interfaces extended or implemented by the class.
*/
@OptIn(KaAllowAnalysisOnEdt::class)
fun KtClassOrObject.getAllSuperClasses(): List<FqName> {
return superTypeListEntries.mapNotNull { it.typeReference }
.flatMap { ref ->
// SurroundSelectionWithFunctionIntention.isAvailable is called in EDT before the intention is applied
// unfortunately API to avoid this was introduced in 23.2 only
// this we need to move intentions to the facade or accept EDT here until 23.2- are still supported
allowAnalysisOnEdt {
analyze(this) {
val kaType = ref.type
val superTypes = (kaType.allSupertypes(false) + kaType).toList()
superTypes.mapNotNull {
val classId = it.symbol?.classId?.takeIf { id -> id != StandardClassIds.Any }
classId?.asSingleFqName()
}
}
}
}
}
32 changes: 32 additions & 0 deletions src/IC-243/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.kotest.plugin.intellij.psi

import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.permissions.KaAllowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.permissions.allowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.types.symbol
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.psi.KtClassOrObject

/**
* Recursively returns the list of classes and interfaces extended or implemented by the class.
*/
@OptIn(KaAllowAnalysisOnEdt::class)
fun KtClassOrObject.getAllSuperClasses(): List<FqName> {
return superTypeListEntries.mapNotNull { it.typeReference }
.flatMap { ref ->
// SurroundSelectionWithFunctionIntention.isAvailable is called in EDT before the intention is applied
// unfortunately API to avoid this was introduced in 23.2 only
// this we need to move intentions to the facade or accept EDT here until 23.2- are still supported
allowAnalysisOnEdt {
analyze(this) {
val kaType = ref.type
val superTypes = (kaType.allSupertypes(false) + kaType).toList()
superTypes.mapNotNull {
val classId = it.symbol?.classId?.takeIf { id -> id != StandardClassIds.Any }
classId?.asSingleFqName()
}
}
}
}
}
32 changes: 0 additions & 32 deletions src/main/kotlin/io/kotest/plugin/intellij/psi/classes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.asJava.classes.KtLightClass
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtObjectDeclaration
import org.jetbrains.kotlin.psi.psiUtil.getChildrenOfType
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.psi.psiUtil.isAbstract
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.types.typeUtil.supertypes

/**
* Returns the [KtClass] from this light class, otherwise null.
Expand Down Expand Up @@ -46,34 +42,6 @@ fun PsiElement.enclosingKtClass(): KtClass? = getStrictParentOfType()
fun PsiElement.enclosingKtClassOrObject(): KtClassOrObject? =
PsiTreeUtil.getParentOfType(this, KtClassOrObject::class.java)

/**
* Recursively returns the list of classes and interfaces extended or implemented by the class.
*/
fun KtClassOrObject.getAllSuperClasses(): List<FqName> {
return superTypeListEntries
.mapNotNull { it.typeReference }
.mapNotNull {
runCatching {
val bindingContext = it.analyze()
bindingContext.get(BindingContext.TYPE, it)
}.getOrNull()
}.flatMap {
runCatching {
it.supertypes() + it
}.getOrElse { emptyList() }
}.mapNotNull {
runCatching {
it.constructor.declarationDescriptor.classId
}.getOrNull()
}.mapNotNull {
runCatching {
val packageName = it.packageFqName
val simpleName = it.relativeClassName
FqName("$packageName.$simpleName")
}.getOrNull()
}.filterNot { it.toString() == "kotlin.Any" }
}

/**
* Returns true if this [KtClassOrObject] points to a runnable spec object.
*/
Expand Down
Loading

0 comments on commit a84b767

Please sign in to comment.