Josh Friend
04/16/2024, 7:09 PMAnton Yalyshev [JB]
04/16/2024, 7:10 PMRoman Golyshev
04/16/2024, 7:34 PMJosh Friend
04/16/2024, 7:36 PM<depends>org.jetbrains.kotlin</depends>Roman Golyshev
04/16/2024, 7:40 PMimport org.jetbrains.kotlinKtDescriptorBindingContextResolutionFacadeJosh Friend
04/16/2024, 7:49 PMorg.jetbrains.kotlin.idea.actions.JavaToKotlinAction
org.jetbrains.kotlin.idea.configuration.ExperimentalFeatures
org.jetbrains.kotlin.idea.core.getPackage
org.jetbrains.kotlin.idea.KotlinBundle
org.jetbrains.kotlin.j2k.getContainingClass
org.jetbrains.kotlin.j2k.getContainingMethod
org.jetbrains.kotlin.j2k.J2kConverterExtension
org.jetbrains.kotlin.psi.KtClass
org.jetbrains.kotlin.psi.KtNamedFunction
org.jetbrains.kotlin.psi.psiUtil.getParentOfType
org.jetbrains.kotlin.util.prefixIfNotKtClassKtNamedFunctionRoman Golyshev
04/16/2024, 8:20 PMJosh Friend
04/16/2024, 8:21 PM*.ktJosh Friend
04/16/2024, 8:23 PMJosh Friend
04/16/2024, 8:24 PM/**
 * Given a [PsiElement], returns the containing method name once found (null otherwise).
 *
 * For Java, there's a convenience method named "getContainingMethod" that returns a PsiMethod.
 * For Kotlin, there's no convenience, so we have use PsiTreeUtil to find the parent [KtNamedFunction].
 */
val PsiElement.containingMethodName: String?
  get() = getContainingMethod()?.name ?: getParentOfType<KtNamedFunction>(false)?.name
/**
 * Given a [PsiElement], returns a list of annotations mapped to a list of human readable strings.
 * This method will only return the annotation name itself, even if the method is annotated with a
 * fully-qualified annotation (i.e. will return "Test" for either "@Test" or "@org.junit.Test")
 *
 * Result will be mapped to a string representation of PsiAnnotations on a Java class, falling back to
 * a string representation of KtAnnotationEntries on a Kotlin class. emptyList() if none are found.
 */
val PsiElement.annotationNames: List<String>
  get() = getContainingMethod()?.annotations
    ?.map { it.qualifiedName.toString().substringAfterLast(".") }
    ?: getParentOfType<KtNamedFunction>(false)?.annotationEntries?.map { it.shortName.toString() }
    ?: emptyList()
/**
 * Given a [PsiElement], returns the containing class name once found (null otherwise).
 *
 * For Java, return a [PsiClass] from a containing class.
 * For Kotlin, walk up the tree to find the first instance of a [KtClass].
 */
val PsiElement.containingClassName: String?
  get() = getContainingClass()?.name ?: getParentOfType<KtClass>(false)?.nameJosh Friend
04/16/2024, 8:26 PMJ2kConverterExtension.extension(useNewJ2k = ExperimentalFeatures.NewJ2k.isEnabled).doCheckBeforeConversion(project, module)Roman Golyshev
04/16/2024, 8:30 PMWhat is required of plugin authors to support K2 mode for intellij plugins?We do not have an “official” recommendation/API at the moment; however, we’re going to provide some migration guidance for the plugins authors in the foreseeable future Currently, any plugin which depends on Kotlin is disabled automatically to avoid exceptions and unexpected behaviours
Emil Kantis
05/21/2024, 5:20 PMhenrik
05/24/2024, 11:26 AM