mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
[kotlin] Support JvmName annotation nested in file annotation list
#KTIJ-24266 Fixed GitOrigin-RevId: 76468cd4e2808167b61eedfc80ac7b29eabab09a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
733462bfa3
commit
190583b658
@@ -5,6 +5,7 @@ package org.jetbrains.kotlin.idea.stubindex
|
||||
import com.intellij.psi.StubBasedPsiElement
|
||||
import com.intellij.psi.stubs.IndexSink
|
||||
import com.intellij.psi.stubs.NamedStub
|
||||
import com.intellij.psi.stubs.StubElement
|
||||
import com.intellij.psi.tree.TokenSet
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
|
||||
import org.jetbrains.kotlin.idea.base.psi.KotlinPsiHeuristics
|
||||
@@ -145,18 +146,22 @@ fun indexJvmNameAnnotation(stub: KotlinAnnotationEntryStub, sink: IndexSink) {
|
||||
if (stub.getShortName() != JvmFileClassUtil.JVM_NAME_SHORT) return
|
||||
|
||||
val jvmName = JvmFileClassUtil.stringFromAnnotation(stub.psi) ?: return
|
||||
val annotatedElementName = when (val grandParentStub = stub.parentStub.parentStub) {
|
||||
is KotlinFileStub -> grandParentStub.psi.name
|
||||
is NamedStub -> grandParentStub.getName() ?: ""
|
||||
is KotlinPropertyAccessorStub -> grandParentStub.parentStub.safeAs<KotlinPropertyStub>()?.name ?: ""
|
||||
else -> return
|
||||
}
|
||||
val annotatedElementName = stub.parentStub.parentStub.annotatedJvmNameElementName ?: return
|
||||
|
||||
if (annotatedElementName != jvmName) {
|
||||
sink.occurrence(KotlinJvmNameAnnotationIndex.key, jvmName)
|
||||
}
|
||||
}
|
||||
|
||||
private val StubElement<*>.annotatedJvmNameElementName: String?
|
||||
get() = when (this) {
|
||||
is KotlinFileStub -> psi.name
|
||||
is NamedStub -> name ?: ""
|
||||
is KotlinPropertyAccessorStub -> parentStub.safeAs<KotlinPropertyStub>()?.name ?: ""
|
||||
is KotlinPlaceHolderStub -> parentStub?.annotatedJvmNameElementName
|
||||
else -> null
|
||||
}
|
||||
|
||||
private val KotlinStubWithFqName<*>.modifierList: KotlinModifierListStub?
|
||||
get() = findChildStubByType(KtStubElementTypes.MODIFIER_LIST)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ package org.jetbrains.kotlin.idea.presentation
|
||||
|
||||
import com.intellij.navigation.ItemPresentation
|
||||
import com.intellij.navigation.ItemPresentationProvider
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.util.parentOfType
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
|
||||
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
|
||||
@@ -15,14 +16,19 @@ class KtJvmNameAnnotationPresenter : ItemPresentationProvider<KtAnnotationEntry>
|
||||
override fun getPresentation(annotationEntry: KtAnnotationEntry): ItemPresentation? {
|
||||
if (annotationEntry.shortName?.asString() != JvmFileClassUtil.JVM_NAME_SHORT) return null
|
||||
|
||||
return when (val grandParent = annotationEntry.parent.parent) {
|
||||
return annotationEntry.parent.parent.toItemPresentation(annotationEntry)
|
||||
}
|
||||
|
||||
private fun PsiElement.toItemPresentation(annotationEntry: KtAnnotationEntry): ItemPresentation? {
|
||||
return when (this) {
|
||||
is KtFile -> KtJvmNameAnnotatedFilePresentation(annotationEntry)
|
||||
is KtFunction -> KotlinFunctionPresentation(grandParent, JvmFileClassUtil.getLiteralStringFromAnnotation(annotationEntry))
|
||||
is KtNamedDeclaration -> getDeclarationPresentation(grandParent, annotationEntry)
|
||||
is KtFunction -> KotlinFunctionPresentation(this, JvmFileClassUtil.getLiteralStringFromAnnotation(annotationEntry))
|
||||
is KtNamedDeclaration -> getDeclarationPresentation(this, annotationEntry)
|
||||
is KtPropertyAccessor -> {
|
||||
val property = grandParent.parentOfType<KtProperty>() ?: return null
|
||||
val property = this.parentOfType<KtProperty>() ?: return null
|
||||
getDeclarationPresentation(property, annotationEntry)
|
||||
}
|
||||
is KtFileAnnotationList -> parent.toItemPresentation(annotationEntry)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,6 +118,11 @@ public abstract class KotlinGotoTestGenerated extends AbstractKotlinGotoTest {
|
||||
runTest("testData/navigation/gotoSymbol/jvmNameAnnotatedFile.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jvmNameAnnotatedFileMultiAnnotations.kt")
|
||||
public void testJvmNameAnnotatedFileMultiAnnotations() throws Exception {
|
||||
runTest("testData/navigation/gotoSymbol/jvmNameAnnotatedFileMultiAnnotations.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jvmNameAnnotatedFilesKt.kt")
|
||||
public void testJvmNameAnnotatedFilesKt() throws Exception {
|
||||
runTest("testData/navigation/gotoSymbol/jvmNameAnnotatedFilesKt.kt");
|
||||
|
||||
@@ -98,6 +98,11 @@ public class KotlinProjectViewTestGenerated extends AbstractKotlinProjectViewTes
|
||||
runTest("testData/projectView/OneFileMultifileFacadeInternalClass.test");
|
||||
}
|
||||
|
||||
@TestMetadata("OneFileMultifileFacadeInternalClassAnnotationListWithSources.test")
|
||||
public void testOneFileMultifileFacadeInternalClassAnnotationListWithSources() throws Exception {
|
||||
runTest("testData/projectView/OneFileMultifileFacadeInternalClassAnnotationListWithSources.test");
|
||||
}
|
||||
|
||||
@TestMetadata("OneFileMultifileFacadeInternalClassWithSources.test")
|
||||
public void testOneFileMultifileFacadeInternalClassWithSources() throws Exception {
|
||||
runTest("testData/projectView/OneFileMultifileFacadeInternalClassWithSources.test");
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
@file:[JvmName("MyCustomFacade")]
|
||||
|
||||
// SEARCH_TEXT: MyCustomFacade
|
||||
// REF: jvmNameAnnotatedFileMultiAnnotations.kt in <root>.MyCustomFacade
|
||||
@@ -0,0 +1 @@
|
||||
// PATH: MyCustomFacade2__FacadeKt.class
|
||||
@@ -0,0 +1,7 @@
|
||||
// LIBRARY_NAME: myLibraryWithFacade2
|
||||
// WITH_SOURCES
|
||||
// FILE: facade.kt
|
||||
|
||||
@file:[JvmName("MyCustomFacade2") JvmMultifileClass]
|
||||
|
||||
fun myFun() = Unit
|
||||
@@ -0,0 +1,19 @@
|
||||
Node: MyCustomFacade2__FacadeKt
|
||||
User object class: KtInternalFileTreeNode
|
||||
|
||||
Value: KtLightClassForDecompiledDeclaration of PsiFile:MyCustomFacade2__FacadeKt.class
|
||||
Value file: myLibraryWithFacade2.jar!/MyCustomFacade2__FacadeKt.class
|
||||
|
||||
Navigation item #0: KtFile: facade.kt
|
||||
Navigation item file #0: lib/sources/facade.kt
|
||||
|
||||
|
||||
-Project
|
||||
+PsiDirectory: src
|
||||
-External Libraries
|
||||
+Library: < java 11 >
|
||||
-Library: myLibraryWithFacade2
|
||||
-PsiDirectory: myLibraryWithFacade2.jar
|
||||
+PsiDirectory: META-INF
|
||||
MyCustomFacade2
|
||||
[MyCustomFacade2__FacadeKt]
|
||||
Reference in New Issue
Block a user