When exloring JS stack frame from Java thread, Eclipse opens JS source

This commit is contained in:
konsoletyper 2014-09-01 17:53:59 +04:00
parent 6675b4745d
commit 491f7ab962
6 changed files with 42 additions and 23 deletions

View File

@ -39,6 +39,10 @@ public class CallFrame {
this.variables = Collections.unmodifiableMap(variables);
}
public JavaScriptLocation getOriginalLocation() {
return originalLocation;
}
public SourceLocation getLocation() {
return location;
}

View File

@ -20,15 +20,9 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
</natures>
</projectDescription>

View File

@ -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,

View File

@ -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;
}
}

View File

@ -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

View File

@ -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 "<native JavaScript code>";
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();
}
}