-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- starting from 242, the plugin works over AnalysisAPI which hides all details about kotlin engine used inside kotlin plugin itself
- Loading branch information
Showing
14 changed files
with
343 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/IC-223/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
src/IC-231/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
src/IC-232/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
src/IC-233/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
src/IC-241/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
32
src/IC-242/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.