diff --git a/idea/src/org/jetbrains/jet/plugin/debugger/JetPositionManager.java b/idea/src/org/jetbrains/jet/plugin/debugger/JetPositionManager.java index 5460ad0ec66..a0eb96cc562 100644 --- a/idea/src/org/jetbrains/jet/plugin/debugger/JetPositionManager.java +++ b/idea/src/org/jetbrains/jet/plugin/debugger/JetPositionManager.java @@ -158,7 +158,7 @@ public class JetPositionManager implements PositionManager { @NotNull JetFile file, boolean isInLibrary ) { - PsiElement element = PsiTreeUtil.getParentOfType(notPositionedElement, JetClassOrObject.class, JetFunctionLiteral.class, JetNamedFunction.class); + PsiElement element = getElementToCalculateClassName(notPositionedElement); if (element instanceof JetClassOrObject) { return getJvmInternalNameForImpl(typeMapper, (JetClassOrObject) element); @@ -172,11 +172,11 @@ public class JetPositionManager implements PositionManager { } } else if (element instanceof JetNamedFunction) { - PsiElement parent = PsiTreeUtil.getParentOfType(element, JetClassOrObject.class, JetFunctionLiteralExpression.class, JetNamedFunction.class); + PsiElement parent = getElementToCalculateClassName(element); if (parent instanceof JetClassOrObject) { return getJvmInternalNameForImpl(typeMapper, (JetClassOrObject) parent); } - else if (parent instanceof JetFunctionLiteralExpression || parent instanceof JetNamedFunction) { + else if (parent != null) { Type asmType = asmTypeForAnonymousClass(typeMapper.getBindingContext(), (JetElement) element); return asmType.getInternalName(); } @@ -192,6 +192,11 @@ public class JetPositionManager implements PositionManager { return PackagePartClassUtils.getPackagePartInternalName(file); } + @Nullable + private static JetNamedDeclaration getElementToCalculateClassName(@Nullable PsiElement notPositionedElement) { + //noinspection unchecked + return PsiTreeUtil.getParentOfType(notPositionedElement, JetClassOrObject.class, JetFunctionLiteral.class, JetNamedFunction.class); + } @Nullable private static JetElement getElementToCreateTypeMapperForLibraryFile(@Nullable PsiElement notPositionedElement) { diff --git a/idea/testData/debugger/anonymousNamedFunction.kt b/idea/testData/debugger/anonymousNamedFunction.kt new file mode 100644 index 00000000000..40665375cad --- /dev/null +++ b/idea/testData/debugger/anonymousNamedFunction.kt @@ -0,0 +1,7 @@ +package insertInBlock + +fun foo() { + val lambda = { + val a = 1 // insertInBlock/InsertInBlockPackage$foo$lambda$1 + }() +} diff --git a/idea/testData/debugger/functionLiteral.kt b/idea/testData/debugger/functionLiteral.kt new file mode 100644 index 00000000000..47b38d18662 --- /dev/null +++ b/idea/testData/debugger/functionLiteral.kt @@ -0,0 +1,10 @@ +class A { + fun foo() { + { + fun innerFoo() { + "" // A$foo$1$1 + } + innerFoo() + }() + } +} diff --git a/idea/testData/debugger/functionLiteralInVal.kt b/idea/testData/debugger/functionLiteralInVal.kt new file mode 100644 index 00000000000..1adb14b2d48 --- /dev/null +++ b/idea/testData/debugger/functionLiteralInVal.kt @@ -0,0 +1,10 @@ +class A { + fun foo() { + val a = { + fun innerFoo() { + val b = {} // A$foo$a$1$1 + } + innerFoo() + }() + } +} diff --git a/idea/testData/debugger/propertyInitializer.kt b/idea/testData/debugger/propertyInitializer.kt new file mode 100644 index 00000000000..ce896fa7926 --- /dev/null +++ b/idea/testData/debugger/propertyInitializer.kt @@ -0,0 +1,3 @@ +class A { + val foo: Int = 5 // A +} diff --git a/idea/testData/debugger/topLevelPropertyInitializer.kt b/idea/testData/debugger/topLevelPropertyInitializer.kt new file mode 100644 index 00000000000..606e4b9cc2c --- /dev/null +++ b/idea/testData/debugger/topLevelPropertyInitializer.kt @@ -0,0 +1,3 @@ +package prop + +val foo: Int = 5 // prop/PropPackage-topLevelPropertyInitializer diff --git a/idea/tests/org/jetbrains/jet/plugin/debugger/JetPositionManagerTest.java b/idea/tests/org/jetbrains/jet/plugin/debugger/JetPositionManagerTest.java index 9cc4d5733e0..f04b860f36e 100644 --- a/idea/tests/org/jetbrains/jet/plugin/debugger/JetPositionManagerTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/debugger/JetPositionManagerTest.java @@ -63,6 +63,17 @@ public class JetPositionManagerTest extends PositionManagerTestCase { public void testAnonymousFunction() { doTest(); } + public void testAnonymousNamedFunction() { + doTest(); + } + + public void testFunctionLiteral() { + doTest(); + } + + public void testFunctionLiteralInVal() { + doTest(); + } public void testClass() { doTest(); @@ -108,6 +119,14 @@ public class JetPositionManagerTest extends PositionManagerTestCase { doTest(); } + public void testPropertyInitializer() { + doTest(); + } + + public void testTopLevelPropertyInitializer() { + doTest(); + } + public void testTrait() { doTest(); }