show local functions in structure view

#KT-13473 Fixed
This commit is contained in:
Dmitry Jemerov
2016-08-24 20:15:00 +02:00
parent 509142089c
commit 8ff0814221
4 changed files with 36 additions and 0 deletions
@@ -89,6 +89,23 @@ class KotlinStructureViewElement(val element: NavigatablePsiElement,
is KtFile -> element.declarations
is KtClass -> element.getPrimaryConstructorParameters().filter { it.hasValOrVar() } + element.declarations
is KtClassOrObject -> element.declarations
is KtFunction -> element.collectLocalDeclarations()
else -> emptyList()
}
private fun KtFunction.collectLocalDeclarations(): List<KtDeclaration> {
val result = mutableListOf<KtDeclaration>()
acceptChildren(object : KtTreeVisitorVoid() {
override fun visitClassOrObject(classOrObject: KtClassOrObject) {
result.add(classOrObject)
}
override fun visitNamedFunction(function: KtNamedFunction) {
result.add(function)
}
})
return result
}
}
@@ -0,0 +1,5 @@
-LocalElements.kt
-foo(): Unit
bar(): Unit
-X
xyzzy(): Unit
@@ -0,0 +1,8 @@
fun foo() {
fun bar() { }
class X {
fun xyzzy() {
}
}
}
@@ -113,6 +113,12 @@ public class KotlinFileStructureTestGenerated extends AbstractKotlinFileStructur
doTest(fileName);
}
@TestMetadata("LocalElements.kt")
public void testLocalElements() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/structureView/fileStructure/LocalElements.kt");
doTest(fileName);
}
@TestMetadata("Render.kt")
public void testRender() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/structureView/fileStructure/Render.kt");