From 491f7ab962d4114f56c2f460020d2c05b592c424 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Mon, 1 Sep 2014 17:53:59 +0400 Subject: [PATCH] When exloring JS stack frame from Java thread, Eclipse opens JS source --- .../java/org/teavm/debugging/CallFrame.java | 4 ++ teavm-eclipse/teavm-eclipse-plugin/.project | 6 --- .../teavm-eclipse-plugin/META-INF/MANIFEST.MF | 2 +- .../TeaVMSourceLookupParticipant.java | 38 +++++++++++++------ .../eclipse/debugger/TeaVMStackFrame.java | 3 +- .../ui/TeaVMDebugModelPresentation.java | 12 ++++-- 6 files changed, 42 insertions(+), 23 deletions(-) diff --git a/teavm-core/src/main/java/org/teavm/debugging/CallFrame.java b/teavm-core/src/main/java/org/teavm/debugging/CallFrame.java index 96a8c84c9..9787a1925 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/CallFrame.java +++ b/teavm-core/src/main/java/org/teavm/debugging/CallFrame.java @@ -39,6 +39,10 @@ public class CallFrame { this.variables = Collections.unmodifiableMap(variables); } + public JavaScriptLocation getOriginalLocation() { + return originalLocation; + } + public SourceLocation getLocation() { return location; } diff --git a/teavm-eclipse/teavm-eclipse-plugin/.project b/teavm-eclipse/teavm-eclipse-plugin/.project index f53f80956..f240a85f5 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/.project +++ b/teavm-eclipse/teavm-eclipse-plugin/.project @@ -20,15 +20,9 @@ - - net.sf.eclipsecs.core.CheckstyleBuilder - - - org.eclipse.pde.PluginNature org.eclipse.jdt.core.javanature - net.sf.eclipsecs.core.CheckstyleNature diff --git a/teavm-eclipse/teavm-eclipse-plugin/META-INF/MANIFEST.MF b/teavm-eclipse/teavm-eclipse-plugin/META-INF/MANIFEST.MF index ef26e5020..8e2cbf0c9 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/META-INF/MANIFEST.MF +++ b/teavm-eclipse/teavm-eclipse-plugin/META-INF/MANIFEST.MF @@ -18,7 +18,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.8.0,4.0)", org.eclipse.ui.editors;bundle-version="[3.8.0,4.0.0)", org.eclipse.ui.ide;bundle-version="[3.8.2,4.0.0)", org.eclipse.jdt.ui;bundle-version="[3.8.2,4.0.0)", - org.eclipse.core.filesystem;bundle-version="1.4.0" + org.eclipse.core.filesystem;bundle-version="[1.3.200,1.5.0)" Bundle-ClassPath: ., lib/asm-5.0.1.jar, lib/asm-commons-5.0.1.jar, diff --git a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMSourceLookupParticipant.java b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMSourceLookupParticipant.java index c5007fd5b..1bd063c6d 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMSourceLookupParticipant.java +++ b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMSourceLookupParticipant.java @@ -20,6 +20,7 @@ import java.net.URL; import java.util.Arrays; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant; +import org.teavm.debugging.CallFrame; import org.teavm.debugging.information.SourceLocation; import org.teavm.debugging.javascript.JavaScriptLocation; @@ -33,7 +34,11 @@ public class TeaVMSourceLookupParticipant extends AbstractSourceLookupParticipan if (object instanceof TeaVMStackFrame) { TeaVMStackFrame stackFrame = (TeaVMStackFrame)object; SourceLocation location = stackFrame.callFrame.getLocation(); - return location != null ? location.getFileName() : null; + if (location != null) { + return location.getFileName(); + } + JavaScriptLocation jsLocation = stackFrame.callFrame.getOriginalLocation(); + return jsLocation != null ? jsLocation.getScript() : null; } else if (object instanceof TeaVMJSStackFrame) { TeaVMJSStackFrame stackFrame = (TeaVMJSStackFrame)object; JavaScriptLocation location = stackFrame.callFrame.getLocation(); @@ -50,18 +55,29 @@ public class TeaVMSourceLookupParticipant extends AbstractSourceLookupParticipan TeaVMJSStackFrame stackFrame = (TeaVMJSStackFrame)object; JavaScriptLocation location = stackFrame.getCallFrame().getLocation(); if (location != null) { - URL url; - try { - url = new URL(location.getScript()); - } catch (MalformedURLException e) { - url = null; - } - if (url != null) { - result = Arrays.copyOf(result, result.length + 1); - result[result.length - 1] = url; - } + result = addElement(result, location); + } + } else if (object instanceof TeaVMStackFrame) { + TeaVMStackFrame stackFrame = (TeaVMStackFrame)object; + CallFrame callFrame = stackFrame.getCallFrame(); + if (callFrame.getMethod() == null && callFrame.getLocation() != null) { + result = addElement(result, callFrame.getOriginalLocation()); } } return result; } + + private Object[] addElement(Object[] elements, JavaScriptLocation location) { + URL url; + try { + url = new URL(location.getScript()); + } catch (MalformedURLException e) { + url = null; + } + if (url != null) { + elements = Arrays.copyOf(elements, elements.length + 1); + elements[elements.length - 1] = url; + } + return elements; + } } diff --git a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMStackFrame.java b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMStackFrame.java index 7243e91d1..fc86a678a 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMStackFrame.java +++ b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMStackFrame.java @@ -146,7 +146,8 @@ public class TeaVMStackFrame implements IStackFrame { @Override public int getLineNumber() throws DebugException { - return callFrame.getLocation() != null ? callFrame.getLocation().getLine() : -1; + return callFrame.getLocation() != null ? callFrame.getLocation().getLine() : + callFrame.getOriginalLocation().getLine(); } @Override diff --git a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/TeaVMDebugModelPresentation.java b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/TeaVMDebugModelPresentation.java index 3f7a42c15..9c359d625 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/TeaVMDebugModelPresentation.java +++ b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/TeaVMDebugModelPresentation.java @@ -33,6 +33,7 @@ import org.eclipse.ui.ide.FileStoreEditorInput; import org.eclipse.ui.part.FileEditorInput; import org.teavm.debugging.CallFrame; import org.teavm.debugging.javascript.JavaScriptCallFrame; +import org.teavm.debugging.javascript.JavaScriptLocation; import org.teavm.eclipse.debugger.TeaVMJSStackFrame; import org.teavm.eclipse.debugger.TeaVMStackFrame; import org.teavm.model.MethodDescriptor; @@ -97,7 +98,7 @@ public class TeaVMDebugModelPresentation extends LabelProvider implements IDebug private String callFrameAsString(CallFrame callFrame) { MethodReference method = callFrame.getMethod(); if (method == null) { - return ""; + return locationAsString(callFrame.getOriginalLocation()); } StringBuilder sb = new StringBuilder(); sb.append(classAsString(method.getClassName())).append('.').append(method.getName()).append('('); @@ -166,11 +167,14 @@ public class TeaVMDebugModelPresentation extends LabelProvider implements IDebug } private String callFrameAsString(JavaScriptCallFrame callFrame) { + return locationAsString(callFrame.getLocation()); + } + + private String locationAsString(JavaScriptLocation location) { StringBuilder sb = new StringBuilder(); - String script = callFrame.getLocation().getScript(); + String script = location.getScript(); sb.append(script.substring(script.lastIndexOf('/') + 1)); - sb.append(" at ").append(callFrame.getLocation().getLine() + 1).append(";") - .append(callFrame.getLocation().getColumn() + 1); + sb.append(" at ").append(location.getLine() + 1).append(";").append(location.getColumn() + 1); return sb.toString(); } }