From 68c77e63844fe23930830a0651b3f8db853621ca Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Mon, 28 Apr 2014 10:19:26 +0400 Subject: [PATCH] SmartStepInto from kotlin to java functions --- .../org/jetbrains/jet/MockLibraryUtil.java | 2 +- .../debugger/KotlinSmartStepIntoHandler.kt | 4 +++ .../debugger/tinyApp/outs/javaFun.out | 8 +++++ .../tinyApp/src/stepInto/MyJavaClass.java | 7 ++++ .../debugger/tinyApp/src/stepInto/javaFun.kt | 9 +++++ .../debugger/AbstractKotlinSteppingTest.kt | 12 +++++-- .../debugger/KotlinDebuggerTestCase.java | 33 +++++++++++++++++-- .../debugger/KotlinSteppingTestGenerated.java | 10 ++++++ 8 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 idea/testData/debugger/tinyApp/outs/javaFun.out create mode 100644 idea/testData/debugger/tinyApp/src/stepInto/MyJavaClass.java create mode 100644 idea/testData/debugger/tinyApp/src/stepInto/javaFun.kt diff --git a/compiler/tests/org/jetbrains/jet/MockLibraryUtil.java b/compiler/tests/org/jetbrains/jet/MockLibraryUtil.java index 3aa90cd682b..17ef44cad13 100644 --- a/compiler/tests/org/jetbrains/jet/MockLibraryUtil.java +++ b/compiler/tests/org/jetbrains/jet/MockLibraryUtil.java @@ -98,7 +98,7 @@ public class MockLibraryUtil { //noinspection IOResourceOpenedButNotSafelyClosed Enum invocationResult = (Enum) execMethod .invoke(compilerObject, new PrintStream(outStream), - new String[] {"-src", sourcesPath, "-output", outDir.getAbsolutePath()}); + new String[] {"-src", sourcesPath, "-output", outDir.getAbsolutePath(), "-classpath", sourcesPath}); assertEquals(new String(outStream.toByteArray()), ExitCode.OK.name(), invocationResult.name()); } diff --git a/idea/src/org/jetbrains/jet/plugin/debugger/KotlinSmartStepIntoHandler.kt b/idea/src/org/jetbrains/jet/plugin/debugger/KotlinSmartStepIntoHandler.kt index a22cf3bc24e..6975ea42d0e 100644 --- a/idea/src/org/jetbrains/jet/plugin/debugger/KotlinSmartStepIntoHandler.kt +++ b/idea/src/org/jetbrains/jet/plugin/debugger/KotlinSmartStepIntoHandler.kt @@ -42,6 +42,7 @@ import com.intellij.psi.PsiFile import com.intellij.openapi.editor.Editor import org.jetbrains.jet.plugin.codeInsight.CodeInsightUtils import com.intellij.psi.PsiDocumentManager +import com.intellij.psi.PsiClass public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() { @@ -173,6 +174,9 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() { result.add(KotlinMethodSmartStepTarget(function, psiMethod, null, expression, false, lines)) } } + else if (function is PsiMethod) { + result.add(MethodSmartStepTarget(function, null, expression, false, lines)) + } } } }, null) diff --git a/idea/testData/debugger/tinyApp/outs/javaFun.out b/idea/testData/debugger/tinyApp/outs/javaFun.out new file mode 100644 index 00000000000..edb7f0e2c9e --- /dev/null +++ b/idea/testData/debugger/tinyApp/outs/javaFun.out @@ -0,0 +1,8 @@ +LineBreakpoint created at javaFun.kt:8 +!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!;!RT_JAR! javaFun.JavaFunPackage +Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' +javaFun.kt:7 +MyJavaClass.java:4 +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/MyJavaClass.java b/idea/testData/debugger/tinyApp/src/stepInto/MyJavaClass.java new file mode 100644 index 00000000000..df0ea610358 --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/stepInto/MyJavaClass.java @@ -0,0 +1,7 @@ +package stepInto; + +public class MyJavaClass { + public void testFun() { + int i = 1; + } +} diff --git a/idea/testData/debugger/tinyApp/src/stepInto/javaFun.kt b/idea/testData/debugger/tinyApp/src/stepInto/javaFun.kt new file mode 100644 index 00000000000..a9179f47505 --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/stepInto/javaFun.kt @@ -0,0 +1,9 @@ +package javaFun + +import stepInto.MyJavaClass + +fun main(args: Array) { + val klass = MyJavaClass() + //Breakpoint! + klass.testFun() +} diff --git a/idea/tests/org/jetbrains/jet/plugin/debugger/AbstractKotlinSteppingTest.kt b/idea/tests/org/jetbrains/jet/plugin/debugger/AbstractKotlinSteppingTest.kt index a96e9e29e4f..c475b718c03 100644 --- a/idea/tests/org/jetbrains/jet/plugin/debugger/AbstractKotlinSteppingTest.kt +++ b/idea/tests/org/jetbrains/jet/plugin/debugger/AbstractKotlinSteppingTest.kt @@ -31,6 +31,8 @@ import com.intellij.psi.PsiFile import org.jetbrains.jet.lang.resolve.java.PackageClassUtils import org.jetbrains.jet.lang.resolve.name.FqName import java.io.File +import com.intellij.debugger.actions.MethodSmartStepTarget +import com.intellij.debugger.engine.BasicStepMethodFilter abstract class AbstractKotlinSteppingTest : KotlinDebuggerTestCase() { @@ -84,7 +86,7 @@ abstract class AbstractKotlinSteppingTest : KotlinDebuggerTestCase() { } } - private fun createSmartStepIntoFilters(): List { + private fun createSmartStepIntoFilters(): List { val breakpointManager = DebuggerManagerEx.getInstanceEx(getProject())?.getBreakpointManager() val breakpoint = breakpointManager?.getBreakpoints()?.first { it is LineBreakpoint } @@ -97,6 +99,12 @@ abstract class AbstractKotlinSteppingTest : KotlinDebuggerTestCase() { val stepTargets = KotlinSmartStepIntoHandler().findSmartStepTargets(position) - return stepTargets.filter { it is KotlinMethodSmartStepTarget }.map { KotlinBasicStepMethodFilter(it as KotlinMethodSmartStepTarget) } + return stepTargets.filterIsInstance(javaClass()).map { + stepTarget -> + when (stepTarget) { + is KotlinMethodSmartStepTarget -> KotlinBasicStepMethodFilter(stepTarget as KotlinMethodSmartStepTarget) + else -> BasicStepMethodFilter(stepTarget.getMethod(), stepTarget.getCallingExpressionLines()) + } + } } } diff --git a/idea/tests/org/jetbrains/jet/plugin/debugger/KotlinDebuggerTestCase.java b/idea/tests/org/jetbrains/jet/plugin/debugger/KotlinDebuggerTestCase.java index dcfdd648720..149492f7b15 100644 --- a/idea/tests/org/jetbrains/jet/plugin/debugger/KotlinDebuggerTestCase.java +++ b/idea/tests/org/jetbrains/jet/plugin/debugger/KotlinDebuggerTestCase.java @@ -25,7 +25,6 @@ import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor; import com.intellij.openapi.util.Computable; -import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.PsiClass; @@ -33,6 +32,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.testFramework.UsefulTestCase; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.MockLibraryUtil; import org.jetbrains.jet.asJava.KotlinLightClassForPackage; import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime; @@ -44,6 +44,9 @@ import org.jetbrains.jet.plugin.framework.JavaRuntimeLibraryDescription; import org.jetbrains.jet.testing.ConfigLibraryUtil; import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; public abstract class KotlinDebuggerTestCase extends DebuggerTestCase { protected static final String TINY_APP = PluginTestCaseBase.getTestDataPathBase() + "/debugger/tinyApp"; @@ -90,12 +93,38 @@ public abstract class KotlinDebuggerTestCase extends DebuggerTestCase { protected void ensureCompiledAppExists() throws Exception { if (!IS_TINY_APP_COMPILED) { String modulePath = getTestAppPath(); - MockLibraryUtil.compileKotlin(modulePath + File.separator + "src", new File(modulePath + File.separator + "classes")); + + String outputDir = modulePath + File.separator + "classes"; + String sourcesDir = modulePath + File.separator + "src"; + + MockLibraryUtil.compileKotlin(sourcesDir, new File(outputDir)); + + List options = Arrays.asList("-d", outputDir); + JetTestUtils.compileJavaFiles(findJavaFiles(new File(sourcesDir)), options); + //noinspection AssignmentToStaticFieldFromInstanceMethod IS_TINY_APP_COMPILED = true; } } + private static List findJavaFiles(@NotNull File directory) { + List result = new ArrayList(); + if (directory.isDirectory()) { + File[] files = directory.listFiles(); + if (files != null) { + for (File file : files) { + if (file.isDirectory()) { + result.addAll(findJavaFiles(file)); + } + else if (file.getName().endsWith(".java")) { + result.add(file); + } + } + } + } + return result; + } + private static class KotlinOutputChecker extends OutputChecker { public KotlinOutputChecker(@NotNull String appPath) { diff --git a/idea/tests/org/jetbrains/jet/plugin/debugger/KotlinSteppingTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/debugger/KotlinSteppingTestGenerated.java index 1e1b8391e69..1c5224c0a13 100644 --- a/idea/tests/org/jetbrains/jet/plugin/debugger/KotlinSteppingTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/debugger/KotlinSteppingTestGenerated.java @@ -53,6 +53,11 @@ public class KotlinSteppingTestGenerated extends AbstractKotlinSteppingTest { doStepIntoTest("idea/testData/debugger/tinyApp/src/stepInto/extFun.kt"); } + @TestMetadata("javaFun.kt") + public void testJavaFun() throws Exception { + doStepIntoTest("idea/testData/debugger/tinyApp/src/stepInto/javaFun.kt"); + } + @TestMetadata("memberFunFromClass.kt") public void testMemberFunFromClass() throws Exception { doStepIntoTest("idea/testData/debugger/tinyApp/src/stepInto/memberFunFromClass.kt"); @@ -121,6 +126,11 @@ public class KotlinSteppingTestGenerated extends AbstractKotlinSteppingTest { doSmartStepIntoTest("idea/testData/debugger/tinyApp/src/stepInto/extFun.kt"); } + @TestMetadata("javaFun.kt") + public void testJavaFun() throws Exception { + doSmartStepIntoTest("idea/testData/debugger/tinyApp/src/stepInto/javaFun.kt"); + } + @TestMetadata("memberFunFromClass.kt") public void testMemberFunFromClass() throws Exception { doSmartStepIntoTest("idea/testData/debugger/tinyApp/src/stepInto/memberFunFromClass.kt");