Add license header. Add JavaScript thread

This commit is contained in:
konsoletyper 2014-08-31 11:07:45 +04:00
parent 351d14e275
commit 238cb69fb9
24 changed files with 1039 additions and 6 deletions

View File

@ -20,9 +20,15 @@
<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

@ -1,3 +1,18 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse;
import org.eclipse.core.runtime.Plugin;

View File

@ -1,10 +1,28 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger;
/**
*
* @author Alexey Andreev
*/
public interface TeaVMDebugConstants {
public final class TeaVMDebugConstants {
private TeaVMDebugConstants() {
}
public static final String JAVA_BREAKPOINT_INSTALL_COUNT = "org.eclipse.jdt.debug.core.installCount";
public static final String DEBUG_TARGET_ID = "org.teavm.eclipse.debugger";

View File

@ -1,3 +1,18 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger;
import java.util.HashMap;

View File

@ -1,3 +1,18 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger;
import static org.teavm.eclipse.debugger.TeaVMDebugConstants.DEBUG_TARGET_ID;
@ -18,7 +33,6 @@ import org.teavm.debugging.Debugger;
import org.teavm.debugging.DebuggerListener;
import org.teavm.debugging.javascript.JavaScriptDebugger;
/**
*
* @author Alexey Andreev <konsoletyper@gmail.com>
@ -32,15 +46,19 @@ public class TeaVMDebugTarget implements IDebugTarget, IStep {
private volatile boolean terminated;
private TeaVMDebugProcess process;
private TeaVMThread thread;
private TeaVMJSThread jsThread;
ConcurrentMap<IBreakpoint, Breakpoint> breakpointMap = new ConcurrentHashMap<>();
ConcurrentMap<Breakpoint, IJavaLineBreakpoint> breakpointBackMap = new ConcurrentHashMap<>();
public TeaVMDebugTarget(ILaunch launch, final Debugger teavmDebugger, ChromeRDPServer server) {
public TeaVMDebugTarget(ILaunch launch, final Debugger teavmDebugger, JavaScriptDebugger jsDebugger,
ChromeRDPServer server) {
this.launch = launch;
this.teavmDebugger = teavmDebugger;
this.jsDebugger = jsDebugger;
this.server = server;
this.process = new TeaVMDebugProcess(launch, this);
this.thread = new TeaVMThread(this);
this.jsThread = new TeaVMJSThread(this);
DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this);
for (IBreakpoint breakpoint : DebugPlugin.getDefault().getBreakpointManager().getBreakpoints()) {
breakpointAdded(breakpoint);
@ -116,6 +134,8 @@ public class TeaVMDebugTarget implements IDebugTarget, IStep {
server.stop();
fireEvent(new DebugEvent(thread, DebugEvent.TERMINATE));
fireEvent(new DebugEvent(thread, DebugEvent.CHANGE));
fireEvent(new DebugEvent(jsThread, DebugEvent.TERMINATE));
fireEvent(new DebugEvent(jsThread, DebugEvent.CHANGE));
fireEvent(new DebugEvent(process, DebugEvent.TERMINATE));
fireEvent(new DebugEvent(this, DebugEvent.TERMINATE));
}
@ -228,7 +248,7 @@ public class TeaVMDebugTarget implements IDebugTarget, IStep {
@Override
public IThread[] getThreads() throws DebugException {
return !terminated ? new IThread[] { thread } : new IThread[0];
return !terminated ? new IThread[] { thread, jsThread } : new IThread[0];
}
@Override

View File

@ -0,0 +1,188 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.model.*;
import org.teavm.debugging.javascript.JavaScriptCallFrame;
/**
*
* @author Alexey Andreev <konsoletyper@gmail.com>
*/
public class TeaVMJSStackFrame implements IStackFrame {
TeaVMJSThread thread;
JavaScriptCallFrame callFrame;
private TeaVMJSVariablesHolder variablesHolder;
public TeaVMJSStackFrame(TeaVMJSThread thread, JavaScriptCallFrame callFrame) {
this.thread = thread;
this.callFrame = callFrame;
this.variablesHolder = new TeaVMJSVariablesHolder(thread.debugTarget, callFrame.getVariables().values());
}
public JavaScriptCallFrame getCallFrame() {
return callFrame;
}
@Override
public boolean canTerminate() {
return thread.canTerminate();
}
@Override
public boolean isTerminated() {
return thread.isTerminated();
}
@Override
public void terminate() throws DebugException {
thread.terminate();
}
@Override
public Object getAdapter(@SuppressWarnings("rawtypes") Class type) {
return null;
}
@Override
public boolean canStepInto() {
return thread.getTopStackFrame() == this;
}
@Override
public boolean canStepOver() {
return thread.getTopStackFrame() == this;
}
@Override
public boolean canStepReturn() {
return thread.getTopStackFrame() == this;
}
@Override
public boolean isStepping() {
return false;
}
@Override
public void stepInto() throws DebugException {
thread.stepInto();
}
@Override
public void stepOver() throws DebugException {
thread.stepOver();
}
@Override
public void stepReturn() throws DebugException {
thread.stepReturn();
}
@Override
public boolean canResume() {
return thread.getTopStackFrame() == this;
}
@Override
public boolean canSuspend() {
return thread.getTopStackFrame() == this;
}
@Override
public boolean isSuspended() {
return thread.isSuspended();
}
@Override
public void resume() throws DebugException {
thread.resume();
}
@Override
public void suspend() throws DebugException {
thread.suspend();
}
@Override
public IDebugTarget getDebugTarget() {
return thread.getDebugTarget();
}
@Override
public ILaunch getLaunch() {
return thread.getLaunch();
}
@Override
public String getModelIdentifier() {
return TeaVMDebugConstants.STACK_FRAME_ID;
}
@Override
public int getCharEnd() throws DebugException {
return callFrame.getLocation() != null ? callFrame.getLocation().getColumn() + 2 : -1;
}
@Override
public int getCharStart() throws DebugException {
return callFrame.getLocation() != null ? callFrame.getLocation().getColumn() + 1 : -1;
}
@Override
public int getLineNumber() throws DebugException {
return callFrame.getLocation() != null ? callFrame.getLocation().getLine() + 1 : -1;
}
@Override
public String getName() {
StringBuilder sb = new StringBuilder();
String fileName = callFrame.getLocation() != null ? callFrame.getLocation().getScript(): null;
sb.append(fileName != null ? fileName : "unknown");
if (callFrame.getLocation() != null) {
sb.append(" at ").append(callFrame.getLocation().getLine() + 1).append(";").append(
callFrame.getLocation().getColumn() + 1);
}
return sb.toString();
}
@Override
public IRegisterGroup[] getRegisterGroups() throws DebugException {
return null;
}
@Override
public IThread getThread() {
return thread;
}
@Override
public IVariable[] getVariables() throws DebugException {
return variablesHolder.getVariables();
}
@Override
public boolean hasRegisterGroups() throws DebugException {
return false;
}
@Override
public boolean hasVariables() throws DebugException {
return true;
}
}

View File

@ -0,0 +1,221 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.core.model.IStackFrame;
import org.eclipse.debug.core.model.IThread;
import org.teavm.debugging.javascript.JavaScriptBreakpoint;
import org.teavm.debugging.javascript.JavaScriptCallFrame;
import org.teavm.debugging.javascript.JavaScriptDebugger;
import org.teavm.debugging.javascript.JavaScriptDebuggerListener;
/**
*
* @author Alexey Andreev <konsoletyper@gmail.com>
*/
public class TeaVMJSThread implements IThread {
private JavaScriptDebugger jsDebugger;
TeaVMDebugTarget debugTarget;
private volatile TeaVMJSStackFrame[] stackTrace;
public TeaVMJSThread(TeaVMDebugTarget debugTarget) {
this.debugTarget = debugTarget;
this.jsDebugger = debugTarget.jsDebugger;
jsDebugger.addListener(new JavaScriptDebuggerListener() {
@Override
public void scriptAdded(String name) {
}
@Override
public void resumed() {
updateStackTrace();
fireEvent(new DebugEvent(TeaVMJSThread.this, DebugEvent.RESUME));
}
@Override
public void paused() {
updateStackTrace();
fireEvent(new DebugEvent(TeaVMJSThread.this, DebugEvent.SUSPEND));
}
@Override
public void detached() {
}
@Override
public void breakpointChanged(JavaScriptBreakpoint breakpoint) {
}
@Override
public void attached() {
}
});
}
private void updateStackTrace() {
if (jsDebugger.getCallStack() == null) {
this.stackTrace = null;
} else {
JavaScriptCallFrame[] jsCallStack = jsDebugger.getCallStack();
TeaVMJSStackFrame[] stackTrace = new TeaVMJSStackFrame[jsCallStack.length];
for (int i = 0; i < jsCallStack.length; ++i) {
JavaScriptCallFrame jsFrame = jsCallStack[i];
stackTrace[i] = new TeaVMJSStackFrame(this, jsFrame);
}
this.stackTrace = stackTrace;
}
fireEvent(new DebugEvent(this, DebugEvent.CHANGE));
}
private void fireEvent(DebugEvent event) {
DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { event });
}
@Override
public boolean canTerminate() {
return debugTarget.canTerminate();
}
@Override
public boolean isTerminated() {
return debugTarget.isTerminated();
}
@Override
public void terminate() throws DebugException {
debugTarget.terminate();
}
@SuppressWarnings("rawtypes")
@Override
public Object getAdapter(Class type) {
return null;
}
@Override
public boolean canResume() {
return debugTarget.canResume();
}
@Override
public boolean canSuspend() {
return debugTarget.canSuspend();
}
@Override
public boolean isSuspended() {
return jsDebugger.isSuspended();
}
@Override
public void resume() throws DebugException {
jsDebugger.resume();
}
@Override
public void suspend() throws DebugException {
jsDebugger.suspend();
}
@Override
public boolean canStepInto() {
return debugTarget.canStepInto();
}
@Override
public boolean canStepOver() {
return debugTarget.canStepOver();
}
@Override
public boolean canStepReturn() {
return debugTarget.canStepReturn();
}
@Override
public boolean isStepping() {
return debugTarget.isStepping();
}
@Override
public void stepInto() throws DebugException {
jsDebugger.stepInto();
}
@Override
public void stepOver() throws DebugException {
jsDebugger.stepOver();
}
@Override
public void stepReturn() throws DebugException {
jsDebugger.stepOut();
}
@Override
public IDebugTarget getDebugTarget() {
return debugTarget;
}
@Override
public ILaunch getLaunch() {
return debugTarget.launch;
}
@Override
public String getModelIdentifier() {
return TeaVMDebugConstants.THREAD_ID;
}
@Override
public IBreakpoint[] getBreakpoints() {
return debugTarget.breakpointMap.keySet().toArray(new IBreakpoint[0]);
}
@Override
public String getName() throws DebugException {
return "JavaScript";
}
@Override
public int getPriority() throws DebugException {
return 0;
}
@Override
public IStackFrame[] getStackFrames() throws DebugException {
if (isTerminated()) {
return new IStackFrame[0];
}
TeaVMJSStackFrame[] stackTrace = this.stackTrace;
return stackTrace != null ? stackTrace.clone() : new IStackFrame[0];
}
@Override
public IStackFrame getTopStackFrame() {
if (isTerminated()) {
return null;
}
TeaVMJSStackFrame[] stackTrace = this.stackTrace;
return stackTrace != null && stackTrace.length > 0 ? stackTrace[0] : null;
}
@Override
public boolean hasStackFrames() throws DebugException {
return !isTerminated() && stackTrace != null;
}
}

View File

@ -0,0 +1,87 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.core.model.IValue;
import org.eclipse.debug.core.model.IVariable;
import org.teavm.debugging.javascript.JavaScriptValue;
/**
*
* @author Alexey Andreev <konsoletyper@gmail.com>
*/
public class TeaVMJSValue implements IValue {
TeaVMDebugTarget debugTarget;
private JavaScriptValue teavmValue;
private TeaVMJSVariablesHolder variablesHolder;
private boolean innerStructure;
public TeaVMJSValue(TeaVMDebugTarget debugTarget, JavaScriptValue teavmValue) {
this.debugTarget = debugTarget;
this.teavmValue = teavmValue;
this.innerStructure = teavmValue.hasInnerStructure();
this.variablesHolder = new TeaVMJSVariablesHolder(debugTarget, teavmValue.getProperties().values());
}
@Override
public IDebugTarget getDebugTarget() {
return debugTarget;
}
@Override
public ILaunch getLaunch() {
return debugTarget.getLaunch();
}
@Override
public String getModelIdentifier() {
return TeaVMDebugConstants.VALUE_ID;
}
@SuppressWarnings("rawtypes")
@Override
public Object getAdapter(Class arg0) {
return null;
}
@Override
public String getReferenceTypeName() throws DebugException {
return teavmValue.getClassName();
}
@Override
public String getValueString() throws DebugException {
return teavmValue.getRepresentation();
}
@Override
public IVariable[] getVariables() throws DebugException {
return variablesHolder.getVariables();
}
@Override
public boolean hasVariables() throws DebugException {
return innerStructure;
}
@Override
public boolean isAllocated() throws DebugException {
return true;
}
}

View File

@ -0,0 +1,107 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.core.model.IValue;
import org.eclipse.debug.core.model.IVariable;
import org.teavm.debugging.javascript.JavaScriptVariable;
import org.teavm.eclipse.TeaVMEclipsePlugin;
/**
*
* @author Alexey Andreev <konsoletyper@gmail.com>
*/
public class TeaVMJSVariable implements IVariable {
private TeaVMDebugTarget debugTarget;
private JavaScriptVariable var;
private TeaVMJSValue value;
public TeaVMJSVariable(TeaVMDebugTarget debugTarget, JavaScriptVariable var) {
this.debugTarget = debugTarget;
this.var = var;
this.value = new TeaVMJSValue(debugTarget, var.getValue());
}
@Override
public void setValue(IValue arg0) throws DebugException {
throw new DebugException(new Status(Status.ERROR, TeaVMEclipsePlugin.ID, "Can't set value"));
}
@Override
public void setValue(String arg0) throws DebugException {
throw new DebugException(new Status(Status.ERROR, TeaVMEclipsePlugin.ID, "Can't set value"));
}
@Override
public boolean supportsValueModification() {
return false;
}
@Override
public boolean verifyValue(IValue arg0) throws DebugException {
return false;
}
@Override
public boolean verifyValue(String arg0) throws DebugException {
return false;
}
@Override
public IDebugTarget getDebugTarget() {
return debugTarget;
}
@Override
public ILaunch getLaunch() {
return debugTarget.getLaunch();
}
@Override
public String getModelIdentifier() {
return TeaVMDebugConstants.VARIABLE_ID;
}
@SuppressWarnings("rawtypes")
@Override
public Object getAdapter(Class arg0) {
return null;
}
@Override
public String getName() throws DebugException {
return var.getName();
}
@Override
public String getReferenceTypeName() throws DebugException {
return var.getValue().getClassName();
}
@Override
public IValue getValue() throws DebugException {
return value;
}
@Override
public boolean hasValueChanged() throws DebugException {
return false;
}
}

View File

@ -0,0 +1,52 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import org.teavm.debugging.javascript.JavaScriptVariable;
/**
*
* @author Alexey Andreev <konsoletyper@gmail.com>
*/
public class TeaVMJSVariablesHolder {
private TeaVMDebugTarget debugTarget;
private Collection<JavaScriptVariable> teavmVariables;
private AtomicReference<TeaVMJSVariable[]> variables = new AtomicReference<>();
public TeaVMJSVariablesHolder(TeaVMDebugTarget debugTarget, Collection<JavaScriptVariable> teavmVariables) {
this.debugTarget = debugTarget;
this.teavmVariables = teavmVariables;
}
public TeaVMJSVariable[] getVariables() {
if (variables.get() == null) {
TeaVMJSVariable[] newVariables = new TeaVMJSVariable[teavmVariables.size()];
List<JavaScriptVariable> teavmVarList = new ArrayList<>(teavmVariables);
Collections.sort(teavmVarList, new Comparator<JavaScriptVariable>() {
@Override public int compare(JavaScriptVariable o1, JavaScriptVariable o2) {
return o1.getName().compareTo(o2.getName());
}
});
for (int i = 0; i < teavmVarList.size(); ++i) {
newVariables[i] = new TeaVMJSVariable(debugTarget, teavmVarList.get(i));
}
variables.compareAndSet(null, newVariables);
}
return variables.get();
}
}

View File

@ -1,3 +1,18 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger;
import org.eclipse.core.runtime.CoreException;
@ -33,7 +48,7 @@ public class TeaVMLaunchConfigurationDelegate implements ILaunchConfigurationDel
server.start();
}
}.start();
TeaVMDebugTarget target = new TeaVMDebugTarget(launch, debugger, server);
TeaVMDebugTarget target = new TeaVMDebugTarget(launch, debugger, jsDebugger, server);
launch.addDebugTarget(target);
launch.addProcess(target.getProcess());
}

View File

@ -1,3 +1,18 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger;
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector;

View File

@ -1,3 +1,18 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger;
import org.eclipse.core.runtime.CoreException;

View File

@ -1,3 +1,18 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger;
import java.util.ArrayList;

View File

@ -1,3 +1,18 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger;
import org.eclipse.debug.core.DebugException;
@ -20,6 +35,10 @@ public class TeaVMStackFrame implements IStackFrame {
this.variablesHolder = new TeaVMVariablesHolder(thread.debugTarget, callFrame.getVariables().values());
}
public CallFrame getCallFrame() {
return callFrame;
}
@Override
public boolean canTerminate() {
return thread.canTerminate();

View File

@ -1,3 +1,18 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger;
import org.eclipse.debug.core.IStreamListener;

View File

@ -1,3 +1,18 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger;
import java.io.IOException;

View File

@ -1,3 +1,18 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger;
import org.eclipse.debug.core.DebugEvent;

View File

@ -1,3 +1,18 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger;
import org.eclipse.debug.core.DebugException;

View File

@ -1,3 +1,18 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger;
import org.eclipse.core.runtime.Status;

View File

@ -1,3 +1,18 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger;
import java.util.*;

View File

@ -1,3 +1,18 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger.ui;
import org.eclipse.core.resources.IFile;
@ -9,7 +24,13 @@ import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.part.FileEditorInput;
import org.teavm.debugging.CallFrame;
import org.teavm.debugging.javascript.JavaScriptCallFrame;
import org.teavm.eclipse.debugger.TeaVMJSStackFrame;
import org.teavm.eclipse.debugger.TeaVMStackFrame;
import org.teavm.model.MethodDescriptor;
import org.teavm.model.MethodReference;
import org.teavm.model.ValueType;
/**
*
@ -46,8 +67,92 @@ public class TeaVMDebugModelPresentation extends LabelProvider implements IDebug
@Override
public String getText(Object element) {
if (element instanceof TeaVMStackFrame) {
return ((TeaVMStackFrame)element).getName();
TeaVMStackFrame stackFrame = (TeaVMStackFrame)element;
return callFrameAsString(stackFrame.getCallFrame());
} else if (element instanceof TeaVMJSStackFrame) {
TeaVMJSStackFrame stackFrame = (TeaVMJSStackFrame)element;
return callFrameAsString(stackFrame.getCallFrame());
}
return super.getText(element);
}
private String callFrameAsString(CallFrame callFrame) {
MethodReference method = callFrame.getMethod();
if (method == null) {
return "<native JavaScript code>";
}
StringBuilder sb = new StringBuilder();
sb.append(classAsString(method.getClassName())).append('.').append(method.getName()).append('(');
MethodDescriptor desc = method.getDescriptor();
for (int i = 0; i < desc.parameterCount(); ++i) {
if (i > 0) {
sb.append(',');
}
sb.append(typeAsString(desc.parameterType(i)));
}
sb.append(')');
if (callFrame.getLocation() != null && callFrame.getLocation().getLine() >= 0) {
sb.append(" line " + callFrame.getLocation().getLine());
} else {
sb.append(" unknown line");
}
return sb.toString();
}
private String typeAsString(ValueType type) {
int arrayDegree = 0;
StringBuilder sb = new StringBuilder();
while (type instanceof ValueType.Array) {
++arrayDegree;
type = ((ValueType.Array)type).getItemType();
}
if (type instanceof ValueType.Primitive) {
switch (((ValueType.Primitive)type).getKind()) {
case BOOLEAN:
sb.append("boolean");
break;
case BYTE:
sb.append("byte");
break;
case SHORT:
sb.append("short");
break;
case CHARACTER:
sb.append("char");
break;
case INTEGER:
sb.append("int");
break;
case LONG:
sb.append("long");
break;
case FLOAT:
sb.append("float");
break;
case DOUBLE:
sb.append("double");
break;
}
} else if (type instanceof ValueType.Object) {
String className = ((ValueType.Object)type).getClassName();
sb.append(classAsString(className));
}
while (arrayDegree-- > 0) {
sb.append("[]");
}
return sb.toString();
}
private String classAsString(String className) {
return className.substring(className.lastIndexOf('.') + 1);
}
private String callFrameAsString(JavaScriptCallFrame callFrame) {
StringBuilder sb = new StringBuilder();
String script = callFrame.getLocation().getScript();
sb.append(script.substring(script.lastIndexOf('/') + 1));
sb.append(" at ").append(callFrame.getLocation().getLine() + 1).append(";")
.append(callFrame.getLocation().getColumn() + 1);
return sb.toString();
}
}

View File

@ -1,3 +1,18 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger.ui;
import org.eclipse.core.runtime.CoreException;

View File

@ -1,3 +1,18 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.eclipse.debugger.ui;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;