From 4eb93c06b10b0f3d1de3dcfcacb0eca575214c68 Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Fri, 31 Oct 2014 15:57:13 +0300 Subject: [PATCH] Write line numbers for bridge methods (line for class header) --- .../jet/backend/common/CodegenUtil.java | 10 +++++++++ .../jet/codegen/ExpressionCodegen.java | 21 ++++++++---------- .../jet/codegen/FunctionCodegen.java | 12 ++++++++++ .../tinyApp/outs/syntheticMethods.out | 10 +++++++++ .../src/stepInto/stepInto/syntheticMethods.kt | 22 +++++++++++++++++++ .../debugger/KotlinSteppingTestGenerated.java | 6 +++++ 6 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 idea/testData/debugger/tinyApp/outs/syntheticMethods.out create mode 100644 idea/testData/debugger/tinyApp/src/stepInto/stepInto/syntheticMethods.kt diff --git a/compiler/backend-common/src/org/jetbrains/jet/backend/common/CodegenUtil.java b/compiler/backend-common/src/org/jetbrains/jet/backend/common/CodegenUtil.java index 52390f8509e..8eab7c45810 100644 --- a/compiler/backend-common/src/org/jetbrains/jet/backend/common/CodegenUtil.java +++ b/compiler/backend-common/src/org/jetbrains/jet/backend/common/CodegenUtil.java @@ -16,6 +16,9 @@ package org.jetbrains.jet.backend.common; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.util.TextRange; +import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.codegen.bridges.BridgesPackage; @@ -202,4 +205,11 @@ public class CodegenUtil { return DescriptorUtils.ENUM_VALUES.equals(functionDescriptor.getName()) && methodTypeParameters.isEmpty(); } + + @Nullable + public static Integer getLineNumberForElement(@NotNull PsiElement statement, boolean markEndOffset) { + Document document = statement.getContainingFile().getViewProvider().getDocument(); + TextRange textRange = statement.getTextRange(); + return document != null ? document.getLineNumber(markEndOffset ? textRange.getEndOffset() : textRange.getStartOffset()) + 1 : null; + } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index ca4c873080f..4881e7917ad 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -28,6 +28,7 @@ import com.intellij.util.Function; import com.intellij.util.containers.Stack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.backend.common.CodegenUtil; import org.jetbrains.jet.codegen.binding.CalculatedClosure; import org.jetbrains.jet.codegen.binding.CodegenBinding; import org.jetbrains.jet.codegen.context.*; @@ -1553,19 +1554,15 @@ public class ExpressionCodegen extends JetVisitor implem } public void markLineNumber(@NotNull JetElement statement, boolean markEndOffset) { - Document document = statement.getContainingFile().getViewProvider().getDocument(); - if (document != null) { - TextRange textRange = statement.getTextRange(); - int lineNumber = document.getLineNumber(markEndOffset ? textRange.getEndOffset() : textRange.getStartOffset()); // 0-based - if (lineNumber == myLastLineNumber) { - return; - } - myLastLineNumber = lineNumber; - - Label label = new Label(); - v.visitLabel(label); - v.visitLineNumber(lineNumber + 1, label); // 1-based + Integer lineNumber = CodegenUtil.getLineNumberForElement(statement, markEndOffset); + if (lineNumber == null || lineNumber == myLastLineNumber) { + return; } + myLastLineNumber = lineNumber; + + Label label = new Label(); + v.visitLabel(label); + v.visitLineNumber(lineNumber, label); } private void doFinallyOnReturn() { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index 7187ff1f467..eb53c543448 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -25,6 +25,7 @@ import com.intellij.util.containers.ContainerUtil; import kotlin.Function1; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.backend.common.CodegenUtil; import org.jetbrains.jet.codegen.binding.CodegenBinding; import org.jetbrains.jet.codegen.bridges.Bridge; import org.jetbrains.jet.codegen.bridges.BridgesPackage; @@ -70,6 +71,7 @@ import static org.jetbrains.jet.codegen.JvmSerializationBindings.*; import static org.jetbrains.jet.codegen.binding.CodegenBinding.isLocalNamedFun; import static org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor.Kind.DECLARATION; import static org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils.callableDescriptorToDeclaration; +import static org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils.classDescriptorToDeclaration; import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isFunctionLiteral; import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isTrait; import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE; @@ -780,6 +782,16 @@ public class FunctionCodegen extends ParentCodegenAware { mv.visitCode(); + PsiElement classElement = classDescriptorToDeclaration(owner.getThisDescriptor()); + if (classElement != null) { + Integer lineNumber = CodegenUtil.getLineNumberForElement(classElement, false); + if (lineNumber != null) { + Label label = new Label(); + mv.visitLabel(label); + mv.visitLineNumber(lineNumber, label); + } + } + Type[] argTypes = bridge.getArgumentTypes(); Type[] originalArgTypes = delegateTo.getArgumentTypes(); diff --git a/idea/testData/debugger/tinyApp/outs/syntheticMethods.out b/idea/testData/debugger/tinyApp/outs/syntheticMethods.out new file mode 100644 index 00000000000..fb19b6abf57 --- /dev/null +++ b/idea/testData/debugger/tinyApp/outs/syntheticMethods.out @@ -0,0 +1,10 @@ +LineBreakpoint created at syntheticMethods.kt:6 +!JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !APP_PATH!\classes;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! syntheticMethods.SyntheticMethodsPackage +Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' +syntheticMethods.kt:6 +syntheticMethods.kt:18 +syntheticMethods.kt:16 +syntheticMethods.kt:7 +Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' + +Process finished with exit code 0 diff --git a/idea/testData/debugger/tinyApp/src/stepInto/stepInto/syntheticMethods.kt b/idea/testData/debugger/tinyApp/src/stepInto/stepInto/syntheticMethods.kt new file mode 100644 index 00000000000..09d74fa8eff --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/stepInto/stepInto/syntheticMethods.kt @@ -0,0 +1,22 @@ +package syntheticMethods + +fun main(args: Array) { + val d: Base = Derived() + //Breakpoint! + d.foo("") + val a = 1 +} + +open class Base { + open fun foo(t: T) { + val a = 1 + } +} + +class Derived: Base() { + override fun foo(t: String) { + val a = 1 + } +} + +// STEP_INTO: 3 \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/debugger/KotlinSteppingTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/debugger/KotlinSteppingTestGenerated.java index c5243c95c54..a816b3c0310 100644 --- a/idea/tests/org/jetbrains/jet/plugin/debugger/KotlinSteppingTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/debugger/KotlinSteppingTestGenerated.java @@ -225,6 +225,12 @@ public class KotlinSteppingTestGenerated extends AbstractKotlinSteppingTest { doStepIntoTest(fileName); } + @TestMetadata("syntheticMethods.kt") + public void testSyntheticMethods() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepInto/stepInto/syntheticMethods.kt"); + doStepIntoTest(fileName); + } + @TestMetadata("whenExpr.kt") public void testWhenExpr() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepInto/stepInto/whenExpr.kt");