Write line numbers for bridge methods (line for class header)

This commit is contained in:
Natalia Ukhorskaya
2014-10-31 15:57:13 +03:00
parent 0047655ed3
commit 4eb93c06b1
6 changed files with 69 additions and 12 deletions
@@ -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;
}
}
@@ -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<StackValue, StackValue> 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() {
@@ -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();
@@ -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
@@ -0,0 +1,22 @@
package syntheticMethods
fun main(args: Array<String>) {
val d: Base<String> = Derived()
//Breakpoint!
d.foo("")
val a = 1
}
open class Base<T> {
open fun foo(t: T) {
val a = 1
}
}
class Derived: Base<String>() {
override fun foo(t: String) {
val a = 1
}
}
// STEP_INTO: 3
@@ -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");