mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-04 15:51:54 +00:00
Collect local declarations under properties (KT-14215); improve presentation of object declarations
#KT-14215 Fixed
This commit is contained in:
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.idea.KotlinDescriptorIconProvider
|
||||
import org.jetbrains.kotlin.psi.KtAnonymousInitializer
|
||||
import org.jetbrains.kotlin.psi.KtModifierListOwner
|
||||
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtPsiUtil
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer.Companion.ONLY_NAMES_WITH_SHORT_TYPES
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils.getAllOverriddenDeclarations
|
||||
@@ -82,6 +83,10 @@ internal class KotlinStructureElementPresentation(
|
||||
}
|
||||
|
||||
private fun getElementText(navigatablePsiElement: NavigatablePsiElement, descriptor: DeclarationDescriptor?): String? {
|
||||
if (navigatablePsiElement is KtObjectDeclaration && navigatablePsiElement.isObjectLiteral()) {
|
||||
return "object" + (navigatablePsiElement.getSuperTypeList()?.text?.let { " : $it" } ?: "")
|
||||
}
|
||||
|
||||
if (descriptor != null) {
|
||||
return ONLY_NAMES_WITH_SHORT_TYPES.render(descriptor)
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ class KotlinStructureViewElement(val element: NavigatablePsiElement,
|
||||
is KtFile -> element.declarations
|
||||
is KtClass -> element.getStructureDeclarations()
|
||||
is KtClassOrObject -> element.declarations
|
||||
is KtFunction, is KtClassInitializer -> element.collectLocalDeclarations()
|
||||
is KtFunction, is KtClassInitializer, is KtProperty -> element.collectLocalDeclarations()
|
||||
else -> emptyList()
|
||||
}
|
||||
|
||||
|
||||
10
idea/testData/structureView/fileStructure/AnonymousObjectMembers.after
vendored
Normal file
10
idea/testData/structureView/fileStructure/AnonymousObjectMembers.after
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
-AnonymousObjectMembers.kt
|
||||
-C
|
||||
-bar(): Unit
|
||||
-object : Runnable
|
||||
run(): Unit
|
||||
xyzzy(): Unit
|
||||
-f: Runnable
|
||||
-object : Runnable
|
||||
run(): Unit
|
||||
xyzzy(): Unit
|
||||
15
idea/testData/structureView/fileStructure/AnonymousObjectMembers.kt
vendored
Normal file
15
idea/testData/structureView/fileStructure/AnonymousObjectMembers.kt
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
class C {
|
||||
val f = object : Runnable {
|
||||
fun run() { }
|
||||
|
||||
fun xyzzy() { }
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
val g = object : Runnable {
|
||||
fun run() { }
|
||||
|
||||
fun xyzzy() { }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,8 @@
|
||||
a: Int
|
||||
a: Int
|
||||
a: String on Comparable<T>
|
||||
b: Any
|
||||
-b: Any
|
||||
object
|
||||
-Enum1
|
||||
FIRST
|
||||
SECOND
|
||||
|
||||
@@ -36,6 +36,12 @@ public class KotlinFileStructureTestGenerated extends AbstractKotlinFileStructur
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/structureView/fileStructure"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("AnonymousObjectMembers.kt")
|
||||
public void testAnonymousObjectMembers() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/structureView/fileStructure/AnonymousObjectMembers.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("CheckLocationForKotlin.kt")
|
||||
public void testCheckLocationForKotlin() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/structureView/fileStructure/CheckLocationForKotlin.kt");
|
||||
|
||||
Reference in New Issue
Block a user