Collect local declarations under properties (KT-14215); improve presentation of object declarations

#KT-14215 Fixed
This commit is contained in:
Dmitry Jemerov
2016-11-18 12:11:55 +01:00
parent 45077023bb
commit f4ce63f6d7
6 changed files with 39 additions and 2 deletions

View File

@@ -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)
}

View File

@@ -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()
}

View File

@@ -0,0 +1,10 @@
-AnonymousObjectMembers.kt
-C
-bar(): Unit
-object : Runnable
run(): Unit
xyzzy(): Unit
-f: Runnable
-object : Runnable
run(): Unit
xyzzy(): Unit

View 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() { }
}
}
}

View File

@@ -19,7 +19,8 @@
a: Int
a: Int
a: String on Comparable<T>
b: Any
-b: Any
object
-Enum1
FIRST
SECOND

View File

@@ -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");