SmartStepInto from kotlin to java functions
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,7 @@
|
||||
package stepInto;
|
||||
|
||||
public class MyJavaClass {
|
||||
public void testFun() {
|
||||
int i = 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package javaFun
|
||||
|
||||
import stepInto.MyJavaClass
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val klass = MyJavaClass()
|
||||
//Breakpoint!
|
||||
klass.testFun()
|
||||
}
|
||||
@@ -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<KotlinBasicStepMethodFilter> {
|
||||
private fun createSmartStepIntoFilters(): List<BasicStepMethodFilter> {
|
||||
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<MethodSmartStepTarget>()).map {
|
||||
stepTarget ->
|
||||
when (stepTarget) {
|
||||
is KotlinMethodSmartStepTarget -> KotlinBasicStepMethodFilter(stepTarget as KotlinMethodSmartStepTarget)
|
||||
else -> BasicStepMethodFilter(stepTarget.getMethod(), stepTarget.getCallingExpressionLines())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String> options = Arrays.asList("-d", outputDir);
|
||||
JetTestUtils.compileJavaFiles(findJavaFiles(new File(sourcesDir)), options);
|
||||
|
||||
//noinspection AssignmentToStaticFieldFromInstanceMethod
|
||||
IS_TINY_APP_COMPILED = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<File> findJavaFiles(@NotNull File directory) {
|
||||
List<File> result = new ArrayList<File>();
|
||||
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) {
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user