-
Notifications
You must be signed in to change notification settings - Fork 30
K2 plugin migration #321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
K2 plugin migration #321
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,5 @@ version=1.1.0 | |
|
|
||
| org.gradle.caching=true | ||
| sandbox = /tmp/ | ||
|
|
||
| kotlin.stdlib.default.dependency = false | ||
| 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" } | ||
| } |
| 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" } | ||
| } |
| 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" } | ||
| } |
| 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" } | ||
| } |
| 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" } | ||
| } |
| 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() | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you clarify this comment, it doesn't quite make sense to me (about the intention)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the comment on allowing resolve on EDT which is prohibited, because it might be slow and lead to freezes of the whole IDE. It's possible to avoid this suppression if we would rewrite |
||
| 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() | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this impact users or does it not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's impossible to use 1.9.x version with kotlin jars from 243 platform anymore, because they were compiled with 2.1 already. Unfortunately, I think, I missed one version indeed: it seems, 223 was build with 1.8 and it won't be compatible with 2.0. Can we drop 223 or do I need to provide logic to make the version dependant on the platform version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can drop 223
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then there should be no problems with later versions