diff --git a/ant.debugger/nbproject/project.xml b/ant.debugger/nbproject/project.xml --- a/ant.debugger/nbproject/project.xml +++ b/ant.debugger/nbproject/project.xml @@ -64,6 +64,7 @@ 1 + 1.36 diff --git a/ant.debugger/src/org/netbeans/modules/ant/debugger/WatchesModel.java b/ant.debugger/src/org/netbeans/modules/ant/debugger/WatchesModel.java --- a/ant.debugger/src/org/netbeans/modules/ant/debugger/WatchesModel.java +++ b/ant.debugger/src/org/netbeans/modules/ant/debugger/WatchesModel.java @@ -44,26 +44,17 @@ package org.netbeans.modules.ant.debugger; -import java.lang.reflect.Method; import java.util.Vector; -import javax.swing.Action; -import org.apache.tools.ant.module.api.support.TargetLister; -import org.netbeans.api.debugger.DebuggerManager; import org.netbeans.api.debugger.Watch; import org.netbeans.spi.debugger.ContextProvider; import org.netbeans.spi.viewmodel.ModelEvent; -import org.netbeans.spi.viewmodel.NodeActionsProvider; import org.netbeans.spi.viewmodel.NodeModel; import org.netbeans.spi.viewmodel.TableModel; import org.netbeans.spi.viewmodel.ModelListener; import org.netbeans.spi.viewmodel.UnknownTypeException; import org.netbeans.spi.debugger.ui.Constants; import org.netbeans.spi.viewmodel.NodeModelFilter; -import org.openide.text.Annotatable; - -import org.openide.text.Line; -import org.openide.util.Exceptions; import org.openide.util.NbBundle; /** @@ -125,7 +116,7 @@ */ public String getShortDescription (NodeModel model, Object node) throws UnknownTypeException { if (node instanceof Watch) { - if (!isWatchEnabled((Watch) node)) { + if (!((Watch) node).isEnabled()) { return NbBundle.getMessage(WatchesModel.class, "CTL_WatchDisabled"); } String expression = ((Watch) node).getExpression (); @@ -159,7 +150,7 @@ columnID == Constants.WATCH_VALUE_COLUMN_ID ) { if (node instanceof Watch) { - if (!isWatchEnabled((Watch) node)) { + if (!((Watch) node).isEnabled()) { return NbBundle.getMessage(WatchesModel.class, "CTL_WatchDisabled"); } String expression = ((Watch) node).getExpression (); @@ -246,14 +237,4 @@ ); } - private static boolean isWatchEnabled(Watch watch) { - try { - Method isEnabledMethod = watch.getClass().getDeclaredMethod("isEnabled"); - isEnabledMethod.setAccessible(true); - return (Boolean) isEnabledMethod.invoke(watch); - } catch (Exception ex) { - Exceptions.printStackTrace(ex); - return true; - } - } } diff --git a/api.debugger/apichanges.xml b/api.debugger/apichanges.xml --- a/api.debugger/apichanges.xml +++ b/api.debugger/apichanges.xml @@ -75,6 +75,20 @@ + + + API for changing enabled state of a Watch + + + + + + Two method are added to Watch class: isEnabled() and setEnabled(boolean). + When the enabled state changes, PROP_ENABLED event is fired. + + + + Use of some generic types in API; ContextProvider implemented more broadly; DebuggerManager.join diff --git a/api.debugger/manifest.mf b/api.debugger/manifest.mf --- a/api.debugger/manifest.mf +++ b/api.debugger/manifest.mf @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.api.debugger/1 OpenIDE-Module-Localizing-Bundle: org/netbeans/api/debugger/Bundle.properties -OpenIDE-Module-Specification-Version: 1.35 +OpenIDE-Module-Specification-Version: 1.36 OpenIDE-Module-Layer: org/netbeans/api/debugger/layer.xml diff --git a/api.debugger/src/org/netbeans/api/debugger/Watch.java b/api.debugger/src/org/netbeans/api/debugger/Watch.java --- a/api.debugger/src/org/netbeans/api/debugger/Watch.java +++ b/api.debugger/src/org/netbeans/api/debugger/Watch.java @@ -60,8 +60,9 @@ public static final String PROP_EXPRESSION = "expression"; // NOI18N /** Name of the property for the value of the watched expression. This constant is not used at all. */ public static final String PROP_VALUE = "value"; // NOI18N - /** Name of the property for the enabled status of the watch. */ - static final String PROP_ENABLED = "enabled"; // NOI18N + /** Name of the property for the enabled status of the watch. + * @since 1.36 */ + public static final String PROP_ENABLED = "enabled"; // NOI18N private String expression; private boolean enabled = true; @@ -78,8 +79,9 @@ * * @return true if the watch is enabled, * false otherwise. + * @since 1.36 */ - synchronized boolean isEnabled () { + public synchronized boolean isEnabled () { return enabled; } @@ -87,8 +89,9 @@ * Set enabled state of the watch. * @param enabled true if this watch should be enabled, * false otherwise + * @since 1.36 */ - void setEnabled(boolean enabled) { + public void setEnabled(boolean enabled) { synchronized(this) { if (enabled == this.enabled) return ; this.enabled = enabled; diff --git a/debugger.jpda/nbproject/project.xml b/debugger.jpda/nbproject/project.xml --- a/debugger.jpda/nbproject/project.xml +++ b/debugger.jpda/nbproject/project.xml @@ -55,7 +55,7 @@ 1 - 1.35 + 1.36 diff --git a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/WatchesModel.java b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/WatchesModel.java --- a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/WatchesModel.java +++ b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/WatchesModel.java @@ -44,14 +44,12 @@ package org.netbeans.modules.debugger.jpda.models; -import com.sun.jdi.ObjectReference; import com.sun.jdi.PrimitiveValue; import com.sun.jdi.Value; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.lang.ref.WeakReference; -import java.lang.reflect.Method; import java.util.*; import javax.security.auth.RefreshFailedException; import javax.security.auth.Refreshable; @@ -72,9 +70,7 @@ import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl; import org.netbeans.modules.debugger.jpda.expr.EvaluatorExpression; -import org.netbeans.modules.debugger.jpda.jdi.ObjectReferenceWrapper; import org.netbeans.spi.debugger.DebuggerServiceRegistration; -import org.openide.util.Exceptions; import org.openide.util.NbBundle; import org.openide.util.RequestProcessor.Task; import org.openide.util.WeakListeners; @@ -183,7 +179,7 @@ if (node == ROOT) return false; if (node instanceof JPDAWatchEvaluating) { JPDAWatchEvaluating jwe = (JPDAWatchEvaluating) node; - if (!isWatchEnabled(jwe.getWatch())) { + if (!jwe.getWatch().isEnabled()) { return true; } if (!jwe.isCurrent()) { @@ -291,7 +287,7 @@ this.model = model; this.w = w; this.debugger = debugger; - if (isWatchEnabled(w)) { + if (w.isEnabled()) { parseExpression(w.getExpression()); } if (cloneNumber == 0) { @@ -341,7 +337,7 @@ public void expressionChanged() { setEvaluated(null); - if (isWatchEnabled(w)) { + if (w.isEnabled()) { parseExpression(w.getExpression()); } } @@ -364,7 +360,7 @@ @Override public String getToStringValue() throws InvalidExpressionException { - if (!isWatchEnabled(w)) { + if (!w.isEnabled()) { return NbBundle.getMessage(WatchesModel.class, "CTL_WatchDisabled"); } JPDAWatch evaluatedWatch; @@ -407,7 +403,7 @@ } private String getValue(JPDAWatch[] watchRef) { - if (!isWatchEnabled(w)) { + if (!w.isEnabled()) { return NbBundle.getMessage(WatchesModel.class, "CTL_WatchDisabled"); } synchronized (evaluating) { @@ -582,7 +578,7 @@ // We already have watchAdded & watchRemoved. Ignore PROP_WATCHES: // We care only about the current call stack frame change and watch expression change here... if (!(JPDADebugger.PROP_STATE.equals(propName) || Watch.PROP_EXPRESSION.equals(propName) || - "enabled".equals(propName) || JPDADebugger.PROP_CURRENT_CALL_STACK_FRAME.equals(propName))) return; + Watch.PROP_ENABLED.equals(propName) || JPDADebugger.PROP_CURRENT_CALL_STACK_FRAME.equals(propName))) return; final WatchesModel m = getModel (); if (m == null) return; if (JPDADebugger.PROP_STATE.equals(propName) && @@ -699,24 +695,4 @@ } } - public static void setWatchEnabled(Watch watch, boolean enabled) { - try { - Method setEnabledMethod = watch.getClass().getDeclaredMethod("setEnabled", Boolean.TYPE); - setEnabledMethod.setAccessible(true); - setEnabledMethod.invoke(watch, enabled); - } catch (Exception ex) { - Exceptions.printStackTrace(ex); - } - } - - public static boolean isWatchEnabled(Watch watch) { - try { - Method isEnabledMethod = watch.getClass().getDeclaredMethod("isEnabled"); - isEnabledMethod.setAccessible(true); - return (Boolean) isEnabledMethod.invoke(watch); - } catch (Exception ex) { - Exceptions.printStackTrace(ex); - return true; - } - } } diff --git a/spi.debugger.ui/nbproject/project.xml b/spi.debugger.ui/nbproject/project.xml --- a/spi.debugger.ui/nbproject/project.xml +++ b/spi.debugger.ui/nbproject/project.xml @@ -55,7 +55,7 @@ 1 - 1.22 + 1.36 diff --git a/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/WatchesReader.java b/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/WatchesReader.java --- a/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/WatchesReader.java +++ b/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/WatchesReader.java @@ -44,11 +44,9 @@ package org.netbeans.modules.debugger.ui; -import java.lang.reflect.Method; import org.netbeans.api.debugger.DebuggerManager; import org.netbeans.api.debugger.Properties; import org.netbeans.api.debugger.Watch; -import org.openide.util.Exceptions; /** @@ -68,7 +66,7 @@ Watch watch = DebuggerManager.getDebuggerManager ().createWatch ( properties.getString (Watch.PROP_EXPRESSION, null) ); - setWatchEnabled(watch, properties.getBoolean("enabled", true)); + watch.setEnabled(properties.getBoolean(Watch.PROP_ENABLED, true)); return watch; } return null; @@ -80,28 +78,8 @@ Watch.PROP_EXPRESSION, ((Watch) object).getExpression () ); - properties.setBoolean("enabled", isWatchEnabled((Watch) object)); + properties.setBoolean(Watch.PROP_ENABLED, ((Watch) object).isEnabled()); } } - public static void setWatchEnabled(Watch watch, boolean enabled) { - try { - Method setEnabledMethod = watch.getClass().getDeclaredMethod("setEnabled", Boolean.TYPE); - setEnabledMethod.setAccessible(true); - setEnabledMethod.invoke(watch, enabled); - } catch (Exception ex) { - Exceptions.printStackTrace(ex); - } - } - - public static boolean isWatchEnabled(Watch watch) { - try { - Method isEnabledMethod = watch.getClass().getDeclaredMethod("isEnabled"); - isEnabledMethod.setAccessible(true); - return (Boolean) isEnabledMethod.invoke(watch); - } catch (Exception ex) { - Exceptions.printStackTrace(ex); - return true; - } - } } diff --git a/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/models/WatchesNodeModel.java b/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/models/WatchesNodeModel.java --- a/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/models/WatchesNodeModel.java +++ b/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/models/WatchesNodeModel.java @@ -312,7 +312,7 @@ public Boolean isSelected(Object node) throws UnknownTypeException { Watch w = getWatch(node); if (w != null) { - return WatchesReader.isWatchEnabled(w); + return w.isEnabled(); } else { throw new UnknownTypeException(node); } @@ -322,7 +322,7 @@ public void setSelected(Object node, Boolean selected) throws UnknownTypeException { Watch w = getWatch(node); if (w != null) { - WatchesReader.setWatchEnabled(w, selected); + w.setEnabled(selected); } else { throw new UnknownTypeException(node); } diff --git a/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/WatchesTest.java b/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/WatchesTest.java --- a/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/WatchesTest.java +++ b/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/WatchesTest.java @@ -46,6 +46,7 @@ import org.netbeans.api.debugger.test.TestDebuggerManagerListener; import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.util.Arrays; import java.util.List; @@ -182,5 +183,46 @@ } assertTrue(exThrown); } + + public void testEnableDisable() throws Exception { + DebuggerManager dm = DebuggerManager.getDebuggerManager(); + Watch w1 = dm.createWatch("w1"); + assertTrue(w1.isEnabled()); // Watches are enabled by default. + final PropertyChangeEvent[] eventPtr = new PropertyChangeEvent[] { null }; + w1.addPropertyChangeListener(new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + eventPtr[0] = evt; + } + }); + w1.setEnabled(false); + assertNotNull("Event not fired when watch disabled.", eventPtr[0]); + assertEquals(Watch.PROP_ENABLED, eventPtr[0].getPropertyName()); + assertEquals(false, eventPtr[0].getNewValue()); + assertFalse(w1.isEnabled()); + eventPtr[0] = null; + w1.setEnabled(true); + assertNotNull("Event not fired when watch enabled.", eventPtr[0]); + assertEquals(Watch.PROP_ENABLED, eventPtr[0].getPropertyName()); + assertEquals(true, eventPtr[0].getNewValue()); + assertTrue(w1.isEnabled()); + } + + public void testWatchPersistence() throws Exception { + DebuggerManager dm = DebuggerManager.getDebuggerManager(); + Watch w1 = dm.createWatch("w1"); + Properties p = Properties.getDefault(); + p.setObject("watch1", w1); + Watch w2 = dm.createWatch("w2"); + w2.setEnabled(false); + p.setObject("watch2", w2); + + w1 = (Watch) p.getObject("watch1", null); + assertEquals("w1", w1.getExpression()); + assertEquals(true, w1.isEnabled()); + w2 = (Watch) p.getObject("watch2", null); + assertEquals("w2", w2.getExpression()); + assertEquals(false, w2.isEnabled()); + } } diff --git a/web.client.tools.impl/nbproject/project.xml b/web.client.tools.impl/nbproject/project.xml --- a/web.client.tools.impl/nbproject/project.xml +++ b/web.client.tools.impl/nbproject/project.xml @@ -11,7 +11,7 @@ 1 - 1.12 + 1.36 diff --git a/web.client.tools.impl/src/org/netbeans/modules/web/client/javascript/debugger/models/NbJSWatchesModel.java b/web.client.tools.impl/src/org/netbeans/modules/web/client/javascript/debugger/models/NbJSWatchesModel.java --- a/web.client.tools.impl/src/org/netbeans/modules/web/client/javascript/debugger/models/NbJSWatchesModel.java +++ b/web.client.tools.impl/src/org/netbeans/modules/web/client/javascript/debugger/models/NbJSWatchesModel.java @@ -47,7 +47,6 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.lang.ref.WeakReference; -import java.lang.reflect.Method; import org.netbeans.api.debugger.DebuggerManager; import org.netbeans.api.debugger.DebuggerManagerAdapter; import org.netbeans.api.debugger.Watch; @@ -67,7 +66,6 @@ import static org.netbeans.spi.debugger.ui.Constants.WATCH_TO_STRING_COLUMN_ID; import static org.netbeans.spi.debugger.ui.Constants.WATCH_TYPE_COLUMN_ID; import static org.netbeans.spi.debugger.ui.Constants.WATCH_VALUE_COLUMN_ID; -import org.openide.util.Exceptions; public final class NbJSWatchesModel extends NbJSVariablesModel { @@ -103,7 +101,7 @@ return false; } else if (node instanceof Watch) { Watch watch = (Watch)node; - if (!isWatchEnabled(watch)) { + if (!watch.isEnabled()) { return true; } JSProperty property = eval(watch.getExpression()); @@ -165,7 +163,7 @@ return getMessage("CTL_CallstackModel.Column.Name.Desc"); } else if (node instanceof Watch) { Watch watch = (Watch)node; - if (!isWatchEnabled(watch)) { + if (!watch.isEnabled()) { return NbBundle.getMessage(NbJSWatchesModel.class, "CTL_WatchDisabled"); } JSProperty property = eval(watch.getExpression()); @@ -183,7 +181,7 @@ UnknownTypeException { if(node instanceof Watch) { Watch watch = (Watch)node; - if (!isWatchEnabled(watch)) { + if (!watch.isEnabled()) { return NbBundle.getMessage(NbJSWatchesModel.class, "CTL_WatchDisabled"); } JSProperty property = eval(watch.getExpression()); @@ -214,7 +212,7 @@ public boolean isReadOnly(Object node, String columnID) throws UnknownTypeException { if (WATCH_VALUE_COLUMN_ID.equals(columnID) && node instanceof Watch) { Watch watch = (Watch)node; - if (!isWatchEnabled(watch)) { + if (!watch.isEnabled()) { return true; } JSProperty property = eval(watch.getExpression()); @@ -325,14 +323,4 @@ return NbBundle.getMessage(NbJSWatchesModel.class, key); } - private static boolean isWatchEnabled(Watch watch) { - try { - Method isEnabledMethod = watch.getClass().getDeclaredMethod("isEnabled"); - isEnabledMethod.setAccessible(true); - return (Boolean) isEnabledMethod.invoke(watch); - } catch (Exception ex) { - Exceptions.printStackTrace(ex); - return true; - } - } } diff --git a/web.debug/nbproject/project.xml b/web.debug/nbproject/project.xml --- a/web.debug/nbproject/project.xml +++ b/web.debug/nbproject/project.xml @@ -55,6 +55,7 @@ 1 + 1.36 diff --git a/web.debug/src/org/netbeans/modules/web/debug/watchesfiltering/JspElWatch.java b/web.debug/src/org/netbeans/modules/web/debug/watchesfiltering/JspElWatch.java --- a/web.debug/src/org/netbeans/modules/web/debug/watchesfiltering/JspElWatch.java +++ b/web.debug/src/org/netbeans/modules/web/debug/watchesfiltering/JspElWatch.java @@ -52,8 +52,6 @@ import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; -import java.lang.reflect.Method; -import org.openide.util.Exceptions; import org.openide.util.NbBundle; /** @@ -81,6 +79,9 @@ } public String getType() { + if (!watch.isEnabled()) { + return ""; + } if (!evaluated) { evaluate(); } @@ -88,7 +89,7 @@ } public String getValue() { - if (!isWatchEnabled(watch)) { + if (!watch.isEnabled()) { return NbBundle.getMessage(JspElWatch.class, "CTL_WatchDisabled"); } if (!evaluated) { @@ -98,6 +99,9 @@ } public String getExceptionDescription() { + if (!watch.isEnabled()) { + return null; + } if (!evaluated) { evaluate(); } @@ -137,14 +141,4 @@ evaluated = false; } - private static boolean isWatchEnabled(Watch watch) { - try { - Method isEnabledMethod = watch.getClass().getDeclaredMethod("isEnabled"); - isEnabledMethod.setAccessible(true); - return (Boolean) isEnabledMethod.invoke(watch); - } catch (Exception ex) { - Exceptions.printStackTrace(ex); - return true; - } - } }