diff --git a/platform/xdebugger-api/src/com/intellij/xdebugger/breakpoints/XBreakpointManager.java b/platform/xdebugger-api/src/com/intellij/xdebugger/breakpoints/XBreakpointManager.java index 75b8e47bf94b..d9bb56fd71f3 100644 --- a/platform/xdebugger-api/src/com/intellij/xdebugger/breakpoints/XBreakpointManager.java +++ b/platform/xdebugger-api/src/com/intellij/xdebugger/breakpoints/XBreakpointManager.java @@ -50,6 +50,8 @@ public interface XBreakpointManager { XLineBreakpoint

findBreakpointAtLine(@NotNull XLineBreakpointType

type, @NotNull VirtualFile file, int line); + boolean isDefaultBreakpoint(@NotNull XBreakpoint breakpoint); + , P extends XBreakpointProperties> void addBreakpointListener(@NotNull XBreakpointType type, @NotNull XBreakpointListener listener); diff --git a/platform/xdebugger-api/src/com/intellij/xdebugger/breakpoints/XBreakpointType.java b/platform/xdebugger-api/src/com/intellij/xdebugger/breakpoints/XBreakpointType.java index cdcc335c128f..2ed9f463dc4e 100644 --- a/platform/xdebugger-api/src/com/intellij/xdebugger/breakpoints/XBreakpointType.java +++ b/platform/xdebugger-api/src/com/intellij/xdebugger/breakpoints/XBreakpointType.java @@ -39,8 +39,9 @@ import java.util.Comparator; * <extensions defaultExtensionNs="com.intellij">
*   <xdebugger.breakpointType implementation="qualified-class-name"/>
* </extensions> + *

* - * Use this class only for breakpoints like an exception breakpoints in Java. If a breakpoint will be put on some line in a file use + * Use this class only for breakpoints like exception breakpoints in Java. If a breakpoint will be put on some line in a file use * {@link XLineBreakpointType} instead * * @author nik @@ -145,6 +146,17 @@ public abstract class XBreakpointType, P extends XBreak return null; } + /** + * Returns properties of the default breakpoint. The default breakpoints cannot be deleted and is always shown on top of the breakpoints + * list in the dialog. It is disabled by default. + * + * @return a default breakpoint properties or {@code null} if default breakpoint isn't supported + */ + @Nullable + public P createDefaultBreakpointProperties() { + return null; + } + @Nullable @NonNls public String getBreakpointsDialogHelpTopic() { return null; diff --git a/platform/xdebugger-api/src/com/intellij/xdebugger/breakpoints/XLineBreakpointType.java b/platform/xdebugger-api/src/com/intellij/xdebugger/breakpoints/XLineBreakpointType.java index d0df07be9aeb..c867184bfa0a 100644 --- a/platform/xdebugger-api/src/com/intellij/xdebugger/breakpoints/XLineBreakpointType.java +++ b/platform/xdebugger-api/src/com/intellij/xdebugger/breakpoints/XLineBreakpointType.java @@ -39,7 +39,7 @@ import java.util.Collections; * <extensions defaultExtensionNs="com.intellij">
*   <xdebugger.breakpointType implementation="qualified-class-name"/>
* </extensions> - * + *

* In order to support actual setting breakpoints in a debugging process create a {@link XBreakpointHandler} implementation and return it * from {@link com.intellij.xdebugger.XDebugProcess#getBreakpointHandlers()} method * @@ -85,6 +85,14 @@ public abstract class XLineBreakpointType

exten return XDebuggerUtil.getInstance().getDefaultLineBreakpointComparator(); } + /** + * Default line breakpoints cannot be supported + */ + @Override + public final P createDefaultBreakpointProperties() { + return null; + } + public List getAdditionalPopupMenuActions(@NotNull XLineBreakpoint

breakpoint, @Nullable XDebugSession currentSession) { return Collections.emptyList(); } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java index ccae800efd12..08a4edf99255 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java @@ -18,19 +18,24 @@ package com.intellij.xdebugger.impl.breakpoints; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.PersistentStateComponent; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.startup.StartupManager; +import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.MultiValuesMap; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.ex.http.HttpFileSystem; import com.intellij.openapi.vfs.ex.http.HttpVirtualFileListener; import com.intellij.util.EventDispatcher; +import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters; +import com.intellij.util.xmlb.XmlSerializer; import com.intellij.util.xmlb.annotations.AbstractCollection; import com.intellij.util.xmlb.annotations.MapAnnotation; import com.intellij.util.xmlb.annotations.Tag; import com.intellij.xdebugger.XSourcePosition; import com.intellij.xdebugger.breakpoints.*; import com.intellij.xdebugger.impl.XDebuggerManagerImpl; +import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -41,7 +46,10 @@ import java.util.*; * @author nik */ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentStateComponent { + private static final Logger LOG = Logger.getInstance("#com.intellij.xdebugger.impl.breakpoints.XBreakpointManagerImpl"); + public static final SkipDefaultValuesSerializationFilters SERIALIZATION_FILTER = new SkipDefaultValuesSerializationFilters(); private final MultiValuesMap> myBreakpoints = new MultiValuesMap>(true); + private final Map> myDefaultBreakpoints = new LinkedHashMap>(); private final Map> myDispatchers = new HashMap>(); private final Map, XBreakpointTypeDialogState> myBreakpointsDialogSettings = new HashMap, XBreakpointTypeDialogState>(); private final EventDispatcher myAllBreakpointsDispatcher; @@ -99,15 +107,29 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta @NotNull public XBreakpoint addBreakpoint(final XBreakpointType,T> type, @Nullable final T properties) { ApplicationManager.getApplication().assertWriteAccessAllowed(); - XBreakpointBase.BreakpointState state = new XBreakpointBase.BreakpointState,T,XBreakpointType,T>>(true, type.getId()); + return addBreakpoint(type, properties, false, true); + } + + private XBreakpointBase addBreakpoint(XBreakpointType, T> type, + T properties, + final boolean defaultBreakpoint, + final boolean initUI) { + XBreakpointBase.BreakpointState state = new XBreakpointBase.BreakpointState,T,XBreakpointType,T>>(!defaultBreakpoint, type.getId()); XBreakpointBase breakpoint = new XBreakpointBase,T, XBreakpointBase.BreakpointState>(type, this, properties, state); - addBreakpoint(breakpoint, true); + addBreakpoint(breakpoint, defaultBreakpoint, initUI); return breakpoint; } - private void addBreakpoint(final XBreakpointBase breakpoint, boolean initUI) { + private void addBreakpoint(final XBreakpointBase breakpoint, final boolean defaultBreakpoint, + boolean initUI) { XBreakpointType type = breakpoint.getType(); - myBreakpoints.put(type, breakpoint); + if (defaultBreakpoint) { + LOG.assertTrue(!myDefaultBreakpoints.containsKey(type), "Cannot have more than one default breakpoint (type " + type.getId() + ")"); + myDefaultBreakpoints.put(type, breakpoint); + } + else { + myBreakpoints.put(type, breakpoint); + } if (breakpoint instanceof XLineBreakpointImpl) { myLineBreakpointManager.registerBreakpoint((XLineBreakpointImpl)breakpoint, initUI); } @@ -138,6 +160,10 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta public void removeBreakpoint(@NotNull final XBreakpoint breakpoint) { ApplicationManager.getApplication().assertWriteAccessAllowed(); + doRemoveBreakpoint(breakpoint); + } + + private void doRemoveBreakpoint(XBreakpoint breakpoint) { XBreakpointType type = breakpoint.getType(); XBreakpointBase breakpointBase = (XBreakpointBase)breakpoint; myBreakpoints.remove(type, breakpointBase); @@ -158,26 +184,32 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta final int line, @Nullable final T properties) { ApplicationManager.getApplication().assertWriteAccessAllowed(); XLineBreakpointImpl breakpoint = new XLineBreakpointImpl(type, this, fileUrl, line, properties); - addBreakpoint(breakpoint, true); + addBreakpoint(breakpoint, false, true); return breakpoint; } @NotNull public XBreakpointBase[] getAllBreakpoints() { ApplicationManager.getApplication().assertReadAccessAllowed(); - Collection> breakpoints = myBreakpoints.values(); + List> breakpoints = new ArrayList>(); + breakpoints.addAll(myDefaultBreakpoints.values()); + breakpoints.addAll(myBreakpoints.values()); return breakpoints.toArray(new XBreakpointBase[breakpoints.size()]); } + @SuppressWarnings({"unchecked"}) @NotNull public > Collection getBreakpoints(@NotNull final XBreakpointType type) { ApplicationManager.getApplication().assertReadAccessAllowed(); Collection> breakpoints = myBreakpoints.get(type); - if (breakpoints == null) { - return Collections.emptyList(); - } - //noinspection unchecked - return Collections.unmodifiableCollection((Collection)breakpoints); + Collection regular = breakpoints != null ? Collections.unmodifiableCollection((Collection)breakpoints) : Collections.emptyList(); + + final XBreakpointBase defaultBreakpoint = myDefaultBreakpoints.get(type); + if (defaultBreakpoint == null) return regular; + List result = new ArrayList(); + result.add((B)defaultBreakpoint); + result.addAll(regular); + return result; } @Nullable @@ -196,6 +228,12 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta return null; } + @Override + public boolean isDefaultBreakpoint(@NotNull XBreakpoint breakpoint) { + //noinspection SuspiciousMethodCalls + return myDefaultBreakpoints.values().contains(breakpoint); + } + private EventDispatcher getOrCreateDispatcher(final XBreakpointType type) { EventDispatcher dispatcher = myDispatchers.get(type); if (dispatcher == null) { @@ -242,6 +280,12 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta public BreakpointManagerState getState() { myDependentBreakpointManager.saveState(); BreakpointManagerState state = new BreakpointManagerState(); + for (XBreakpointBase breakpoint : myDefaultBreakpoints.values()) { + final XBreakpointBase.BreakpointState breakpointState = breakpoint.getState(); + if (differsFromDefault(breakpoint.getType(), breakpointState)) { + state.getDefaultBreakpoints().add(breakpointState); + } + } for (XBreakpointBase breakpoint : myBreakpoints.values()) { state.getBreakpoints().add(breakpoint.getState()); } @@ -251,6 +295,19 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta return state; } + private static

boolean differsFromDefault(XBreakpointType type, + XBreakpointBase.BreakpointState state) { + final P defaultProperties = type.createDefaultBreakpointProperties(); + if (defaultProperties == null) { + return false; + } + XBreakpointBase.BreakpointState defaultState = new XBreakpointBase.BreakpointState(false, type.getId()); + defaultState.setPropertiesElement(XmlSerializer.serialize(defaultProperties)); + Element defaultElement = XmlSerializer.serialize(defaultState, SERIALIZATION_FILTER); + Element currentElement = XmlSerializer.serialize(state, SERIALIZATION_FILTER); + return !JDOMUtil.areElementsEqual(defaultElement, currentElement); + } + public void loadState(final BreakpointManagerState state) { myBreakpointsDialogSettings.clear(); for (Map.Entry entry : state.getBreakpointTypeDialogProperties().entrySet()) { @@ -260,17 +317,41 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta } } - removeAllBreakpoints(); - for (XBreakpointBase.BreakpointState breakpointState : state.getBreakpoints()) { - XBreakpointBase breakpoint = createBreakpoint(breakpointState); - if (breakpoint != null) { - addBreakpoint(breakpoint, false); + myDefaultBreakpoints.clear(); + for (XBreakpointBase.BreakpointState breakpointState : state.getDefaultBreakpoints()) { + loadBreakpoint(breakpointState, true); + } + for (XBreakpointType type : XBreakpointUtil.getBreakpointTypes()) { + if (!myDefaultBreakpoints.containsKey(type)) { + addDefaultBreakpoint(type); } } + + for (XBreakpointBase breakpoint : myBreakpoints.values()) { + doRemoveBreakpoint(breakpoint); + } + for (XBreakpointBase.BreakpointState breakpointState : state.getBreakpoints()) { + loadBreakpoint(breakpointState, false); + } myDependentBreakpointManager.loadState(); myLineBreakpointManager.updateBreakpointsUI(); } + private

void addDefaultBreakpoint(XBreakpointType type) { + final P properties = type.createDefaultBreakpointProperties(); + if (properties != null) { + //noinspection unchecked + addBreakpoint((XBreakpointType, P>)type, properties, true, false); + } + } + + private void loadBreakpoint(XBreakpointBase.BreakpointState breakpointState, final boolean defaultBreakpoint) { + XBreakpointBase breakpoint = createBreakpoint(breakpointState); + if (breakpoint != null) { + addBreakpoint(breakpoint, defaultBreakpoint, false); + } + } + @Nullable public XBreakpointTypeDialogState getDialogState(@NotNull XBreakpointType type) { return myBreakpointsDialogSettings.get(type); @@ -280,27 +361,30 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta myBreakpointsDialogSettings.put(type, dialogState); } - private void removeAllBreakpoints() { - for (XBreakpointBase breakpoint : myBreakpoints.values()) { - removeBreakpoint(breakpoint); - } - } - @Nullable private XBreakpointBase createBreakpoint(final XBreakpointBase.BreakpointState breakpointState) { XBreakpointType type = XBreakpointUtil.findType(breakpointState.getTypeId()); - if (type == null) return null; + if (type == null) return null; + //noinspection unchecked return breakpointState.createBreakpoint(type, this); } @Tag("breakpoint-manager") public static class BreakpointManagerState { + private List myDefaultBreakpoints = new ArrayList(); private List myBreakpoints = new ArrayList(); private Map myBreakpointTypeDialogProperties = new HashMap(); + @Tag("default-breakpoints") + @AbstractCollection(surroundWithTag = false) + public List getDefaultBreakpoints() { + return myDefaultBreakpoints; + } + @Tag("breakpoints") - @AbstractCollection(surroundWithTag = false, elementTypes = {XBreakpointBase.BreakpointState.class, XLineBreakpointImpl.LineBreakpointState.class}) + @AbstractCollection(surroundWithTag = false, + elementTypes = {XBreakpointBase.BreakpointState.class, XLineBreakpointImpl.LineBreakpointState.class}) public List getBreakpoints() { return myBreakpoints; } @@ -316,6 +400,10 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta myBreakpoints = breakpoints; } + public void setDefaultBreakpoints(List defaultBreakpoints) { + myDefaultBreakpoints = defaultBreakpoints; + } + public void setBreakpointTypeDialogProperties(final Map breakpointTypeDialogProperties) { myBreakpointTypeDialogProperties = breakpointTypeDialogProperties; } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XBreakpointsPanel.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XBreakpointsPanel.java index 2ed69ef9f7db..5c47dac8d657 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XBreakpointsPanel.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XBreakpointsPanel.java @@ -69,7 +69,7 @@ public class XBreakpointsPanel> extends AbstractBreakpo myAllGroupingRules = new ArrayList>(myType.getGroupingRules()); mySelectedGroupingRules = getInitialGroupingRules(); - myTree = XBreakpointsTree.createTree(myType, mySelectedGroupingRules, myParentDialog); + myTree = XBreakpointsTree.createTree(myType, mySelectedGroupingRules, myParentDialog, getBreakpointManager()); myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(final TreeSelectionEvent e) { onSelectionChanged(); diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XBreakpointsTree.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XBreakpointsTree.java index e3371b4621f3..11f1f701d63b 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XBreakpointsTree.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XBreakpointsTree.java @@ -25,6 +25,7 @@ import com.intellij.ui.SimpleTextAttributes; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.tree.TreeUtil; import com.intellij.xdebugger.breakpoints.XBreakpoint; +import com.intellij.xdebugger.breakpoints.XBreakpointManager; import com.intellij.xdebugger.breakpoints.XBreakpointType; import com.intellij.xdebugger.breakpoints.ui.XBreakpointGroup; import com.intellij.xdebugger.breakpoints.ui.XBreakpointGroupingRule; @@ -53,11 +54,13 @@ public class XBreakpointsTree> extends CheckboxTree { private final MultiValuesMap, XBreakpointGroup> myGroups = new MultiValuesMap, XBreakpointGroup>(); private XBreakpointsTree(final XBreakpointType type, final CheckedTreeNode root, - Collection> groupingRules, DialogWrapper parentDialog) { + Collection> groupingRules, + DialogWrapper parentDialog, + XBreakpointManager breakpointManager) { super(new BreakpointsTreeCellRenderer(), root); myRoot = root; myParentDialog = parentDialog; - myComparator = new TreeNodeComparator(type); + myComparator = new TreeNodeComparator(type, breakpointManager); setGroupingRulesInternal(groupingRules); } @@ -68,8 +71,8 @@ public class XBreakpointsTree> extends CheckboxTree { public static > XBreakpointsTree createTree(final XBreakpointType type, final Collection> groupingRules, - DialogWrapper parentDialog) { - return new XBreakpointsTree(type, new CheckedTreeNode("root"), groupingRules, parentDialog); + DialogWrapper parentDialog, XBreakpointManager breakpointManager) { + return new XBreakpointsTree(type, new CheckedTreeNode("root"), groupingRules, parentDialog, breakpointManager); } public void buildTree(@NotNull Collection breakpoints) { @@ -254,15 +257,23 @@ public class XBreakpointsTree> extends CheckboxTree { private static class TreeNodeComparator> implements Comparator { private final Comparator myBreakpointComparator; + private final XBreakpointManager myBreakpointManager; - public TreeNodeComparator(final XBreakpointType type) { + public TreeNodeComparator(final XBreakpointType type, XBreakpointManager breakpointManager) { + myBreakpointManager = breakpointManager; myBreakpointComparator = type.getBreakpointComparator(); } public int compare(final TreeNode o1, final TreeNode o2) { if (o1 instanceof BreakpointNode && o2 instanceof BreakpointNode) { + //noinspection unchecked B b1 = (B)((BreakpointNode)o1).getBreakpoint(); + //noinspection unchecked B b2 = (B)((BreakpointNode)o2).getBreakpoint(); + boolean default1 = myBreakpointManager.isDefaultBreakpoint(b1); + boolean default2 = myBreakpointManager.isDefaultBreakpoint(b2); + if (default1 && !default2) return -1; + if (!default1 && default2) return 1; return myBreakpointComparator.compare(b1, b2); } if (o1 instanceof BreakpointsGroupNode && o2 instanceof BreakpointsGroupNode) { diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/actions/RemoveBreakpointAction.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/actions/RemoveBreakpointAction.java index 13661e228a47..f7cf0f960170 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/actions/RemoveBreakpointAction.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/actions/RemoveBreakpointAction.java @@ -38,7 +38,12 @@ public class RemoveBreakpointAction> extends XBreakpoin } public boolean isEnabled(@NotNull final Collection breakpoints) { - return !breakpoints.isEmpty(); + for (B breakpoint : breakpoints) { + if (!myBreakpointsPanel.getBreakpointManager().isDefaultBreakpoint(breakpoint)) { + return true; + } + } + return false; } public void perform(@NotNull final Collection breakpoints) { @@ -46,7 +51,9 @@ public class RemoveBreakpointAction> extends XBreakpoin new WriteAction() { protected void run(final Result result) { for (B breakpoint : breakpoints) { - breakpointManager.removeBreakpoint(breakpoint); + if (!breakpointManager.isDefaultBreakpoint(breakpoint)) { + breakpointManager.removeBreakpoint(breakpoint); + } } } }.execute(); diff --git a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XBreakpointManagerTest.java b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XBreakpointManagerTest.java index 21115b46efc6..a6e23eb0fee2 100644 --- a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XBreakpointManagerTest.java +++ b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XBreakpointManagerTest.java @@ -35,12 +35,12 @@ public class XBreakpointManagerTest extends XBreakpointsTestCase { assertSameElements(myBreakpointManager.getAllBreakpoints(), breakpoint, lineBreakpoint); assertSame(lineBreakpoint, assertOneElement(myBreakpointManager.getBreakpoints(MY_LINE_BREAKPOINT_TYPE))); - assertSame(breakpoint, assertOneElement(myBreakpointManager.getBreakpoints(MY_SIMPLE_BREAKPOINT_TYPE))); + assertSame(breakpoint, getSingleBreakpoint()); myBreakpointManager.removeBreakpoint(lineBreakpoint); assertSame(breakpoint, assertOneElement(myBreakpointManager.getAllBreakpoints())); assertTrue(myBreakpointManager.getBreakpoints(MY_LINE_BREAKPOINT_TYPE).isEmpty()); - assertSame(breakpoint, assertOneElement(myBreakpointManager.getBreakpoints(MY_SIMPLE_BREAKPOINT_TYPE))); + assertSame(breakpoint, getSingleBreakpoint()); myBreakpointManager.removeBreakpoint(breakpoint); assertEquals(0, myBreakpointManager.getAllBreakpoints().length); @@ -56,13 +56,14 @@ public class XBreakpointManagerTest extends XBreakpointsTestCase { breakpoint.setLogMessage(true); myBreakpointManager.addBreakpoint(MY_SIMPLE_BREAKPOINT_TYPE, new MyBreakpointProperties("123")); - Element element = save(); - //System.out.println(JDOMUtil.writeElement(element, SystemProperties.getLineSeparator())); - load(element); + reload(); XBreakpoint[] breakpoints = myBreakpointManager.getAllBreakpoints(); - assertEquals(2, breakpoints.length); + assertEquals(3, breakpoints.length); - XLineBreakpoint lineBreakpoint = assertInstanceOf(breakpoints[0], XLineBreakpoint.class); + assertTrue(myBreakpointManager.isDefaultBreakpoint(breakpoints[0])); + assertEquals("default", assertInstanceOf(breakpoints[0].getProperties(), MyBreakpointProperties.class).myOption); + + XLineBreakpoint lineBreakpoint = assertInstanceOf(breakpoints[1], XLineBreakpoint.class); assertEquals(239, lineBreakpoint.getLine()); assertEquals("myurl", lineBreakpoint.getFileUrl()); assertEquals("abc", assertInstanceOf(lineBreakpoint.getProperties(), MyBreakpointProperties.class).myOption); @@ -71,9 +72,36 @@ public class XBreakpointManagerTest extends XBreakpointsTestCase { assertTrue(lineBreakpoint.isLogMessage()); assertEquals(SuspendPolicy.NONE, lineBreakpoint.getSuspendPolicy()); - assertEquals("123", assertInstanceOf(breakpoints[1].getProperties(), MyBreakpointProperties.class).myOption); - assertEquals(SuspendPolicy.ALL, breakpoints[1].getSuspendPolicy()); - assertFalse(breakpoints[1].isLogMessage()); + assertEquals("123", assertInstanceOf(breakpoints[2].getProperties(), MyBreakpointProperties.class).myOption); + assertEquals(SuspendPolicy.ALL, breakpoints[2].getSuspendPolicy()); + assertFalse(breakpoints[2].isLogMessage()); + } + + public void testDoNotSaveUnmodifiedDefaultBreakpoint() throws Exception { + reload(); + + assertEquals("default", getSingleBreakpoint().getProperties().myOption); + Element element = save(); + assertEquals(0, element.getContent().size()); + } + + public void testSaveEnabledDefaultBreakpoint() throws Exception { + reload(); + final XBreakpoint breakpoint = getSingleBreakpoint(); + breakpoint.setEnabled(true); + + assertFalse(save().getContent().isEmpty()); + reload(); + assertTrue(getSingleBreakpoint().isEnabled()); + } + + public void testSaveDefaultBreakpointWithModifiedProperties() throws Exception { + reload(); + getSingleBreakpoint().getProperties().myOption = "changed"; + + assertFalse(save().getContent().isEmpty()); + reload(); + assertEquals("changed", getSingleBreakpoint().getProperties().myOption); } public void testListener() throws Exception { @@ -106,4 +134,13 @@ public class XBreakpointManagerTest extends XBreakpointsTestCase { myBreakpointManager.addLineBreakpoint(MY_LINE_BREAKPOINT_TYPE, "url", 239, new MyBreakpointProperties("a")); assertEquals("", out.toString()); } + + private XBreakpoint getSingleBreakpoint() { + return assertOneElement(myBreakpointManager.getBreakpoints(MY_SIMPLE_BREAKPOINT_TYPE)); + } + + private void reload() { + Element element = save(); + load(element); + } } diff --git a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestCase.java b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestCase.java index 1918086be9c5..d6b37c35569c 100644 --- a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestCase.java +++ b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestCase.java @@ -88,6 +88,11 @@ public abstract class XDebuggerTestCase extends PlatformLiteFixture { public MyBreakpointProperties createProperties() { return new MyBreakpointProperties(); } + + @Override + public MyBreakpointProperties createDefaultBreakpointProperties() { + return new MyBreakpointProperties("default"); + } } protected static class MyBreakpointProperties extends XBreakpointProperties {