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); this.variables = Collections.unmodifiableMap(variables);
} }
public JavaScriptLocation getOriginalLocation() {
return originalLocation;
}
public SourceLocation getLocation() { public SourceLocation getLocation() {
return location; return location;
} }

View File

@ -20,15 +20,9 @@
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.eclipse.pde.PluginNature</nature> <nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
</natures> </natures>
</projectDescription> </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.editors;bundle-version="[3.8.0,4.0.0)",
org.eclipse.ui.ide;bundle-version="[3.8.2,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.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: ., Bundle-ClassPath: .,
lib/asm-5.0.1.jar, lib/asm-5.0.1.jar,
lib/asm-commons-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 java.util.Arrays;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant; import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant;
import org.teavm.debugging.CallFrame;
import org.teavm.debugging.information.SourceLocation; import org.teavm.debugging.information.SourceLocation;
import org.teavm.debugging.javascript.JavaScriptLocation; import org.teavm.debugging.javascript.JavaScriptLocation;
@ -33,7 +34,11 @@ public class TeaVMSourceLookupParticipant extends AbstractSourceLookupParticipan
if (object instanceof TeaVMStackFrame) { if (object instanceof TeaVMStackFrame) {
TeaVMStackFrame stackFrame = (TeaVMStackFrame)object; TeaVMStackFrame stackFrame = (TeaVMStackFrame)object;
SourceLocation location = stackFrame.callFrame.getLocation(); 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) { } else if (object instanceof TeaVMJSStackFrame) {
TeaVMJSStackFrame stackFrame = (TeaVMJSStackFrame)object; TeaVMJSStackFrame stackFrame = (TeaVMJSStackFrame)object;
JavaScriptLocation location = stackFrame.callFrame.getLocation(); JavaScriptLocation location = stackFrame.callFrame.getLocation();
@ -50,6 +55,19 @@ public class TeaVMSourceLookupParticipant extends AbstractSourceLookupParticipan
TeaVMJSStackFrame stackFrame = (TeaVMJSStackFrame)object; TeaVMJSStackFrame stackFrame = (TeaVMJSStackFrame)object;
JavaScriptLocation location = stackFrame.getCallFrame().getLocation(); JavaScriptLocation location = stackFrame.getCallFrame().getLocation();
if (location != null) { if (location != null) {
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; URL url;
try { try {
url = new URL(location.getScript()); url = new URL(location.getScript());
@ -57,11 +75,9 @@ public class TeaVMSourceLookupParticipant extends AbstractSourceLookupParticipan
url = null; url = null;
} }
if (url != null) { if (url != null) {
result = Arrays.copyOf(result, result.length + 1); elements = Arrays.copyOf(elements, elements.length + 1);
result[result.length - 1] = url; elements[elements.length - 1] = url;
} }
} return elements;
}
return result;
} }
} }

View File

@ -146,7 +146,8 @@ public class TeaVMStackFrame implements IStackFrame {
@Override @Override
public int getLineNumber() throws DebugException { public int getLineNumber() throws DebugException {
return callFrame.getLocation() != null ? callFrame.getLocation().getLine() : -1; return callFrame.getLocation() != null ? callFrame.getLocation().getLine() :
callFrame.getOriginalLocation().getLine();
} }
@Override @Override

View File

@ -33,6 +33,7 @@ import org.eclipse.ui.ide.FileStoreEditorInput;
import org.eclipse.ui.part.FileEditorInput; import org.eclipse.ui.part.FileEditorInput;
import org.teavm.debugging.CallFrame; import org.teavm.debugging.CallFrame;
import org.teavm.debugging.javascript.JavaScriptCallFrame; import org.teavm.debugging.javascript.JavaScriptCallFrame;
import org.teavm.debugging.javascript.JavaScriptLocation;
import org.teavm.eclipse.debugger.TeaVMJSStackFrame; import org.teavm.eclipse.debugger.TeaVMJSStackFrame;
import org.teavm.eclipse.debugger.TeaVMStackFrame; import org.teavm.eclipse.debugger.TeaVMStackFrame;
import org.teavm.model.MethodDescriptor; import org.teavm.model.MethodDescriptor;
@ -97,7 +98,7 @@ public class TeaVMDebugModelPresentation extends LabelProvider implements IDebug
private String callFrameAsString(CallFrame callFrame) { private String callFrameAsString(CallFrame callFrame) {
MethodReference method = callFrame.getMethod(); MethodReference method = callFrame.getMethod();
if (method == null) { if (method == null) {
return "<native JavaScript code>"; return locationAsString(callFrame.getOriginalLocation());
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(classAsString(method.getClassName())).append('.').append(method.getName()).append('('); 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) { private String callFrameAsString(JavaScriptCallFrame callFrame) {
return locationAsString(callFrame.getLocation());
}
private String locationAsString(JavaScriptLocation location) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String script = callFrame.getLocation().getScript(); String script = location.getScript();
sb.append(script.substring(script.lastIndexOf('/') + 1)); sb.append(script.substring(script.lastIndexOf('/') + 1));
sb.append(" at ").append(callFrame.getLocation().getLine() + 1).append(";") sb.append(" at ").append(location.getLine() + 1).append(";").append(location.getColumn() + 1);
.append(callFrame.getLocation().getColumn() + 1);
return sb.toString(); return sb.toString();
} }
} }