SmartStepInto: render kotlin functions properly

This commit is contained in:
Natalia Ukhorskaya
2015-07-22 18:11:31 +03:00
parent e4d5984cf0
commit b76b251489
13 changed files with 82 additions and 16 deletions
@@ -4,7 +4,12 @@ import com.intellij.debugger.actions.SmartStepTarget
import com.intellij.psi.PsiElement
import com.intellij.util.Range
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.idea.JetIcons
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.psi.JetElement
import org.jetbrains.kotlin.psi.JetNamedFunction
import org.jetbrains.kotlin.renderer.ParameterNameRenderingPolicy
import javax.swing.Icon
public class KotlinMethodSmartStepTarget(
val resolvedElement: JetElement,
@@ -12,9 +17,34 @@ public class KotlinMethodSmartStepTarget(
highlightElement: PsiElement,
lines: Range<Int>
): SmartStepTarget(label, highlightElement, false, lines) {
companion object {
fun calcLabel(descriptor: DeclarationDescriptor): String {
return descriptor.getName().asString()
override fun getIcon(): Icon? {
return when {
resolvedElement is JetNamedFunction && resolvedElement.getReceiverTypeReference() != null -> JetIcons.EXTENSION_FUNCTION
else -> JetIcons.FUNCTION
}
}
companion object {
private val renderer = IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.withOptions {
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.NONE
withoutReturnType = true
renderAccessors = true
startFromName = true
modifiers = emptySet()
}
fun calcLabel(descriptor: DeclarationDescriptor): String {
return renderer.render(descriptor)
}
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || other !is KotlinMethodSmartStepTarget) return false
return resolvedElement == other.resolvedElement
}
override fun hashCode() = resolvedElement.hashCode()
}
+1 -1
View File
@@ -7,4 +7,4 @@ class A {
fun get(i: Int) = 1
}
// EXISTS: get(int)
// EXISTS: get(Int)
@@ -8,4 +8,4 @@ class Delegate {
fun get(t: Any?, p: PropertyMetadata) = 1
}
// EXISTS: a.get(Object\, PropertyMetadata)
// EXISTS: a.get(Any?\, PropertyMetadata)
@@ -9,4 +9,4 @@ class A {
fun f2(i: Int) {}
// EXISTS: f1(), f2(int)
// EXISTS: f1(), f2(Int)
+1 -1
View File
@@ -7,4 +7,4 @@ fun foo() {
fun f1(f: () -> Unit) {}
fun f2() {}
// EXISTS: f1(Function0<? extends Unit>), f1: f.invoke()
// EXISTS: f1(() -> Unit), f1: f.invoke()
+1 -1
View File
@@ -9,4 +9,4 @@ class A {
fun f2(i: Int) {}
// EXISTS: f1(int), f2(int)
// EXISTS: f1(Int), f2(Int)
+1 -1
View File
@@ -4,4 +4,4 @@ fun foo() {
inline fun f1(f: () -> Unit) {}
// EXISTS: f1(Function0<? extends Unit>)
// EXISTS: f1(() -> Unit)
+1 -1
View File
@@ -9,4 +9,4 @@ fun f1(vararg i: Int) {}
fun f2() = 1
fun f3() = 1
// EXISTS: f1(int...), f2(), f3()
// EXISTS: f1(vararg Int), f2(), f3()
+1 -1
View File
@@ -5,4 +5,4 @@ fun foo() {
fun f1(i: Int) = 1
fun f2() {}
// EXISTS: f1(int), f2()
// EXISTS: f1(Int), f2()
+1 -1
View File
@@ -15,4 +15,4 @@ val d: Int
return 1
}
// EXISTS: getC(), getD()
// EXISTS: getter for c: Int, getter for d: Int
+28
View File
@@ -0,0 +1,28 @@
fun test() {
<caret>propFoo + foo() + fooWithParam(1.extFoo()) { 2 } + FooClass(1).test() + FooClass().test() + FooClass(1, 2).test()
}
class FooClass(i: Int) {
constructor() : this(1)
constructor(i: Int, s: Int) : this(1)
fun test() = 1
}
fun foo() = 1
fun fooWithParam(i: Int, f: () -> Int) = 1
fun Int.extFoo() = 1
val propFoo: Int
get() {
return 1
}
// EXISTS: getter for propFoo: Int,
// EXISTS: foo()
// EXISTS: fooWithParam(Int\, () -> Int)
// EXISTS: extFoo()
// EXISTS: fooWithParam: f.invoke()
// EXISTS: test()
// EXISTS: constructor FooClass()
// EXISTS: constructor FooClass(Int\, Int)
@@ -47,13 +47,15 @@ public abstract class AbstractSmartStepIntoTest : JetLightCodeInsightFixtureTest
for (actualTargetName in actual) {
assert(actualTargetName in expected) {
"Unexpected step into target was found: $actualTargetName\n${renderTableWithResults(expected, actual)}"
"Unexpected step into target was found: $actualTargetName\n${renderTableWithResults(expected, actual)}" +
"\n // EXISTS: ${actual.joinToString()}"
}
}
for (expectedTargetName in expected) {
assert(expectedTargetName in actual) {
"Missed step into target: $expectedTargetName\n${renderTableWithResults(expected, actual)}"
"Missed step into target: $expectedTargetName\n${renderTableWithResults(expected, actual)}" +
"\n // EXISTS: ${actual.joinToString()}"
}
}
}
@@ -62,8 +64,8 @@ public abstract class AbstractSmartStepIntoTest : JetLightCodeInsightFixtureTest
val sb = StringBuilder()
val maxExtStrSize = (expected.maxBy { it.length() }?.length() ?: 0) + 5
val longerList = if (expected.size() < actual.size()) actual else expected
val shorterList = if (expected.size() < actual.size()) expected else actual
val longerList = (if (expected.size() < actual.size()) actual else expected).sort()
val shorterList = (if (expected.size() < actual.size()) expected else actual).sort()
for ((i, element) in longerList.withIndex()) {
sb.append(element)
sb.append(" ".repeat(maxExtStrSize - element.length()))
@@ -161,6 +161,12 @@ public class SmartStepIntoTestGenerated extends AbstractSmartStepIntoTest {
doTest(fileName);
}
@TestMetadata("renderer.kt")
public void testRenderer() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/smartStepInto/renderer.kt");
doTest(fileName);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/smartStepInto/simple.kt");