From 95f532aca68af37a8d098b92a94d517be13b2b22 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Thu, 14 Aug 2014 12:20:23 +0400 Subject: [PATCH] Minor fixes & refactoring --- .../java/org/teavm/debugging/Debugger.java | 31 ++++++++++++------- teavm-eclipse-plugin/META-INF/MANIFEST.MF | 3 +- teavm-eclipse-plugin/plugin.xml | 4 +-- .../org/teavm/eclipse/TeaVMEclipsePlugin.java | 2 ++ .../eclipse/debugger/TeaVMDebugConstants.java | 19 ++++++++++++ .../eclipse/debugger/TeaVMDebugTarget.java | 12 +++---- .../eclipse/debugger/TeaVMStackFrame.java | 2 +- .../teavm/eclipse/debugger/TeaVMThread.java | 2 +- .../teavm/eclipse/debugger/TeaVMValue.java | 2 +- .../teavm/eclipse/debugger/TeaVMVariable.java | 7 +++-- .../{ => ui}/TeaVMDebugModelPresentation.java | 3 +- .../teavm/eclipse/debugger/ui/TeaVMTab.java | 4 +-- .../eclipse/debugger/ui/TeaVMTabGroup.java | 2 +- 13 files changed, 61 insertions(+), 32 deletions(-) create mode 100644 teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMDebugConstants.java rename teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/{ => ui}/TeaVMDebugModelPresentation.java (94%) diff --git a/teavm-core/src/main/java/org/teavm/debugging/Debugger.java b/teavm-core/src/main/java/org/teavm/debugging/Debugger.java index dcb5ef39d..0b3a4aa32 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/Debugger.java +++ b/teavm-core/src/main/java/org/teavm/debugging/Debugger.java @@ -148,11 +148,13 @@ public class Debugger { } public Breakpoint createBreakpoint(SourceLocation location) { - Breakpoint breakpoint = new Breakpoint(this, location); - breakpoints.put(breakpoint, dummyObject); - updateInternalBreakpoints(breakpoint); - updateBreakpointStatus(breakpoint, false); - return breakpoint; + synchronized (breakpoints) { + Breakpoint breakpoint = new Breakpoint(this, location); + breakpoints.put(breakpoint, dummyObject); + updateInternalBreakpoints(breakpoint); + updateBreakpointStatus(breakpoint, false); + return breakpoint; + } } public Set getBreakpoints() { @@ -160,6 +162,9 @@ public class Debugger { } void updateInternalBreakpoints(Breakpoint breakpoint) { + if (breakpoint.isDestroyed()) { + return; + } for (JavaScriptBreakpoint jsBreakpoint : breakpoint.jsBreakpoints) { breakpointMap.remove(jsBreakpoint); jsBreakpoint.destroy(); @@ -263,9 +268,11 @@ public class Debugger { } private void updateBreakpoints() { - for (Breakpoint breakpoint : breakpoints.keySet()) { - updateInternalBreakpoints(breakpoint); - updateBreakpointStatus(breakpoint, true); + synchronized (breakpointMap) { + for (Breakpoint breakpoint : breakpoints.keySet()) { + updateInternalBreakpoints(breakpoint); + updateBreakpointStatus(breakpoint, true); + } } } @@ -298,9 +305,11 @@ public class Debugger { } private void fireAttached() { - for (Breakpoint breakpoint : breakpoints.keySet()) { - updateInternalBreakpoints(breakpoint); - updateBreakpointStatus(breakpoint, false); + synchronized (breakpointMap) { + for (Breakpoint breakpoint : breakpoints.keySet()) { + updateInternalBreakpoints(breakpoint); + updateBreakpointStatus(breakpoint, false); + } } for (DebuggerListener listener : getListeners()) { listener.attached(); diff --git a/teavm-eclipse-plugin/META-INF/MANIFEST.MF b/teavm-eclipse-plugin/META-INF/MANIFEST.MF index 94276f4f3..06e466a44 100644 --- a/teavm-eclipse-plugin/META-INF/MANIFEST.MF +++ b/teavm-eclipse-plugin/META-INF/MANIFEST.MF @@ -52,5 +52,4 @@ Bundle-ClassPath: ., lib/websocket-common-9.2.1.v20140609.jar, lib/websocket-server-9.2.1.v20140609.jar, lib/websocket-servlet-9.2.1.v20140609.jar -Export-Package: org.teavm.eclipse.debugger, - org.teavm.eclipse.debugger.ui +Export-Package: org.teavm.eclipse.debugger diff --git a/teavm-eclipse-plugin/plugin.xml b/teavm-eclipse-plugin/plugin.xml index 744b84a5d..49ce6ea39 100644 --- a/teavm-eclipse-plugin/plugin.xml +++ b/teavm-eclipse-plugin/plugin.xml @@ -34,8 +34,8 @@ + class="org.teavm.eclipse.debugger.ui.TeaVMDebugModelPresentation" + id="org.teavm.eclipse.debugger.frame"> \ No newline at end of file diff --git a/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMEclipsePlugin.java b/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMEclipsePlugin.java index c9ba97c59..cc579e473 100644 --- a/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMEclipsePlugin.java +++ b/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMEclipsePlugin.java @@ -20,4 +20,6 @@ public class TeaVMEclipsePlugin extends Plugin { public static TeaVMEclipsePlugin getDefault() { return defaultInstance; } + + public static final String ID = "org.teavm.eclipse"; } diff --git a/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMDebugConstants.java b/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMDebugConstants.java new file mode 100644 index 000000000..78cf5f3ad --- /dev/null +++ b/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMDebugConstants.java @@ -0,0 +1,19 @@ +package org.teavm.eclipse.debugger; + +/** + * + * @author Alexey Andreev + */ +public interface 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"; + + public static final String THREAD_ID = DEBUG_TARGET_ID + ".thread"; + + public static final String STACK_FRAME_ID = DEBUG_TARGET_ID + ".frame"; + + public static final String VALUE_ID = DEBUG_TARGET_ID + ".value"; + + public static final String VARIABLE_ID = DEBUG_TARGET_ID + ".variable"; +} diff --git a/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMDebugTarget.java b/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMDebugTarget.java index 0bec93917..8aa63a239 100644 --- a/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMDebugTarget.java +++ b/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMDebugTarget.java @@ -15,6 +15,8 @@ import org.teavm.debugging.Breakpoint; import org.teavm.debugging.Debugger; import org.teavm.debugging.DebuggerListener; import org.teavm.debugging.JavaScriptDebugger; +import static org.teavm.eclipse.debugger.TeaVMDebugConstants.*; + /** * @@ -80,10 +82,10 @@ public class TeaVMDebugTarget implements IDebugTarget, IStep { IJavaLineBreakpoint breakpoint = breakpointBackMap.get(teavmBreakpoint); if (breakpoint != null) { try { - if (!teavmBreakpoint.isValid() && teavmDebugger.isAttached()) { - breakpoint.getMarker().setAttribute("org.eclipse.jdt.debug.core.installCount", 0); + if (!teavmBreakpoint.isValid() || !teavmDebugger.isAttached()) { + breakpoint.getMarker().setAttribute(JAVA_BREAKPOINT_INSTALL_COUNT, 0); } else { - breakpoint.getMarker().setAttribute("org.eclipse.jdt.debug.core.installCount", 1); + breakpoint.getMarker().setAttribute(JAVA_BREAKPOINT_INSTALL_COUNT, 1); } DebugPlugin.getDefault().getBreakpointManager().fireBreakpointChanged(breakpoint); } catch (CoreException e) { @@ -140,8 +142,6 @@ public class TeaVMDebugTarget implements IDebugTarget, IStep { @Override public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta markerDelta) { - breakpointRemoved(breakpoint, markerDelta); - breakpointAdded(breakpoint); } @Override @@ -200,7 +200,7 @@ public class TeaVMDebugTarget implements IDebugTarget, IStep { @Override public String getModelIdentifier() { - return "org.teavm.eclipse.debugger"; + return DEBUG_TARGET_ID; } @Override diff --git a/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMStackFrame.java b/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMStackFrame.java index cf3ebd9e9..bd69abe6b 100644 --- a/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMStackFrame.java +++ b/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMStackFrame.java @@ -111,7 +111,7 @@ public class TeaVMStackFrame implements IStackFrame { @Override public String getModelIdentifier() { - return thread.getModelIdentifier() + ".thread"; + return TeaVMDebugConstants.STACK_FRAME_ID; } @Override diff --git a/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMThread.java b/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMThread.java index a2afa3b17..c1f8022ea 100644 --- a/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMThread.java +++ b/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMThread.java @@ -164,7 +164,7 @@ public class TeaVMThread implements IThread { @Override public String getModelIdentifier() { - return debugTarget.getModelIdentifier(); + return TeaVMDebugConstants.THREAD_ID; } @Override diff --git a/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMValue.java b/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMValue.java index 3c0770572..351fea2af 100644 --- a/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMValue.java +++ b/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMValue.java @@ -34,7 +34,7 @@ public class TeaVMValue implements IValue { @Override public String getModelIdentifier() { - return "org.teavm.eclipse.debugger.value"; + return TeaVMDebugConstants.VALUE_ID; } @SuppressWarnings("rawtypes") diff --git a/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMVariable.java b/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMVariable.java index 3fdc9aa61..498352dc3 100644 --- a/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMVariable.java +++ b/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMVariable.java @@ -7,6 +7,7 @@ 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.Variable; +import org.teavm.eclipse.TeaVMEclipsePlugin; /** * @@ -25,12 +26,12 @@ public class TeaVMVariable implements IVariable { @Override public void setValue(IValue arg0) throws DebugException { - throw new DebugException(new Status(Status.ERROR, "org.teavm.eclipse", "Can't set value")); + 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, "org.teavm.eclipse", "Can't set value")); + throw new DebugException(new Status(Status.ERROR, TeaVMEclipsePlugin.ID, "Can't set value")); } @Override @@ -60,7 +61,7 @@ public class TeaVMVariable implements IVariable { @Override public String getModelIdentifier() { - return "org.teavm.eclipse.debugger.variable"; + return TeaVMDebugConstants.VARIABLE_ID; } @SuppressWarnings("rawtypes") diff --git a/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMDebugModelPresentation.java b/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/TeaVMDebugModelPresentation.java similarity index 94% rename from teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMDebugModelPresentation.java rename to teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/TeaVMDebugModelPresentation.java index 802a04b60..3dd635081 100644 --- a/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMDebugModelPresentation.java +++ b/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/TeaVMDebugModelPresentation.java @@ -1,4 +1,4 @@ -package org.teavm.eclipse.debugger; +package org.teavm.eclipse.debugger.ui; import org.eclipse.core.resources.IFile; import org.eclipse.debug.core.model.ILineBreakpoint; @@ -9,6 +9,7 @@ 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.eclipse.debugger.TeaVMStackFrame; /** * diff --git a/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/TeaVMTab.java b/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/TeaVMTab.java index 201fae30d..fd68c7a71 100644 --- a/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/TeaVMTab.java +++ b/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/TeaVMTab.java @@ -7,7 +7,6 @@ import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; @@ -23,6 +22,7 @@ public class TeaVMTab extends AbstractLaunchConfigurationTab { @Override public void createControl(Composite container) { Composite root = new Composite(container, SWT.NONE); + setControl(root); GridLayout layout = new GridLayout(); layout.verticalSpacing = 6; layout.numColumns = 2; @@ -31,10 +31,8 @@ public class TeaVMTab extends AbstractLaunchConfigurationTab { Label portLabel = new Label(root, SWT.NONE); portLabel.setText("&Port"); - portLabel.setLayoutData(new GridData(GridData.BEGINNING)); portField = new Text(root, SWT.SINGLE | SWT.BORDER); - portField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); portField.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent event) { updateLaunchConfigurationDialog(); diff --git a/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/TeaVMTabGroup.java b/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/TeaVMTabGroup.java index a64bf090e..1e67f7abe 100644 --- a/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/TeaVMTabGroup.java +++ b/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/ui/TeaVMTabGroup.java @@ -13,6 +13,6 @@ import org.eclipse.debug.ui.sourcelookup.SourceLookupTab; public class TeaVMTabGroup extends AbstractLaunchConfigurationTabGroup { @Override public void createTabs(ILaunchConfigurationDialog dialog, String mode) { - setTabs(new ILaunchConfigurationTab[] { new SourceLookupTab(), new CommonTab() }); + setTabs(new ILaunchConfigurationTab[] { new TeaVMTab(), new SourceLookupTab(), new CommonTab() }); } }