SmartStepInto: render kotlin functions properly
This commit is contained in:
+33
-3
@@ -4,7 +4,12 @@ import com.intellij.debugger.actions.SmartStepTarget
|
|||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.util.Range
|
import com.intellij.util.Range
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
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.JetElement
|
||||||
|
import org.jetbrains.kotlin.psi.JetNamedFunction
|
||||||
|
import org.jetbrains.kotlin.renderer.ParameterNameRenderingPolicy
|
||||||
|
import javax.swing.Icon
|
||||||
|
|
||||||
public class KotlinMethodSmartStepTarget(
|
public class KotlinMethodSmartStepTarget(
|
||||||
val resolvedElement: JetElement,
|
val resolvedElement: JetElement,
|
||||||
@@ -12,9 +17,34 @@ public class KotlinMethodSmartStepTarget(
|
|||||||
highlightElement: PsiElement,
|
highlightElement: PsiElement,
|
||||||
lines: Range<Int>
|
lines: Range<Int>
|
||||||
): SmartStepTarget(label, highlightElement, false, lines) {
|
): SmartStepTarget(label, highlightElement, false, lines) {
|
||||||
companion object {
|
override fun getIcon(): Icon? {
|
||||||
fun calcLabel(descriptor: DeclarationDescriptor): String {
|
return when {
|
||||||
return descriptor.getName().asString()
|
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
@@ -7,4 +7,4 @@ class A {
|
|||||||
fun get(i: Int) = 1
|
fun get(i: Int) = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// EXISTS: get(int)
|
// EXISTS: get(Int)
|
||||||
@@ -8,4 +8,4 @@ class Delegate {
|
|||||||
fun get(t: Any?, p: PropertyMetadata) = 1
|
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) {}
|
fun f2(i: Int) {}
|
||||||
|
|
||||||
// EXISTS: f1(), f2(int)
|
// EXISTS: f1(), f2(Int)
|
||||||
+1
-1
@@ -7,4 +7,4 @@ fun foo() {
|
|||||||
fun f1(f: () -> Unit) {}
|
fun f1(f: () -> Unit) {}
|
||||||
fun f2() {}
|
fun f2() {}
|
||||||
|
|
||||||
// EXISTS: f1(Function0<? extends Unit>), f1: f.invoke()
|
// EXISTS: f1(() -> Unit), f1: f.invoke()
|
||||||
+1
-1
@@ -9,4 +9,4 @@ class A {
|
|||||||
|
|
||||||
fun f2(i: Int) {}
|
fun f2(i: Int) {}
|
||||||
|
|
||||||
// EXISTS: f1(int), f2(int)
|
// EXISTS: f1(Int), f2(Int)
|
||||||
@@ -4,4 +4,4 @@ fun foo() {
|
|||||||
|
|
||||||
inline fun f1(f: () -> Unit) {}
|
inline fun f1(f: () -> Unit) {}
|
||||||
|
|
||||||
// EXISTS: f1(Function0<? extends Unit>)
|
// EXISTS: f1(() -> Unit)
|
||||||
+1
-1
@@ -9,4 +9,4 @@ fun f1(vararg i: Int) {}
|
|||||||
fun f2() = 1
|
fun f2() = 1
|
||||||
fun f3() = 1
|
fun f3() = 1
|
||||||
|
|
||||||
// EXISTS: f1(int...), f2(), f3()
|
// EXISTS: f1(vararg Int), f2(), f3()
|
||||||
+1
-1
@@ -5,4 +5,4 @@ fun foo() {
|
|||||||
fun f1(i: Int) = 1
|
fun f1(i: Int) = 1
|
||||||
fun f2() {}
|
fun f2() {}
|
||||||
|
|
||||||
// EXISTS: f1(int), f2()
|
// EXISTS: f1(Int), f2()
|
||||||
+1
-1
@@ -15,4 +15,4 @@ val d: Int
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// EXISTS: getC(), getD()
|
// EXISTS: getter for c: Int, getter for d: Int
|
||||||
@@ -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) {
|
for (actualTargetName in actual) {
|
||||||
assert(actualTargetName in expected) {
|
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) {
|
for (expectedTargetName in expected) {
|
||||||
assert(expectedTargetName in actual) {
|
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 sb = StringBuilder()
|
||||||
|
|
||||||
val maxExtStrSize = (expected.maxBy { it.length() }?.length() ?: 0) + 5
|
val maxExtStrSize = (expected.maxBy { it.length() }?.length() ?: 0) + 5
|
||||||
val longerList = if (expected.size() < actual.size()) actual else expected
|
val longerList = (if (expected.size() < actual.size()) actual else expected).sort()
|
||||||
val shorterList = if (expected.size() < actual.size()) expected else actual
|
val shorterList = (if (expected.size() < actual.size()) expected else actual).sort()
|
||||||
for ((i, element) in longerList.withIndex()) {
|
for ((i, element) in longerList.withIndex()) {
|
||||||
sb.append(element)
|
sb.append(element)
|
||||||
sb.append(" ".repeat(maxExtStrSize - element.length()))
|
sb.append(" ".repeat(maxExtStrSize - element.length()))
|
||||||
|
|||||||
@@ -161,6 +161,12 @@ public class SmartStepIntoTestGenerated extends AbstractSmartStepIntoTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("simple.kt")
|
||||||
public void testSimple() throws Exception {
|
public void testSimple() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/smartStepInto/simple.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/smartStepInto/simple.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user