IDEA-131134 Support multiple breakpoints within on single line - public API
authorEgor.Ushakov <egor.ushakov@jetbrains.com>
Tue, 16 Jun 2015 16:01:52 +0000 (19:01 +0300)
committerEgor.Ushakov <egor.ushakov@jetbrains.com>
Tue, 16 Jun 2015 16:04:35 +0000 (19:04 +0300)
java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaLineBreakpointType.java
platform/xdebugger-api/src/com/intellij/xdebugger/breakpoints/XLineBreakpointType.java
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerUtilImpl.java
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointVariant.java [deleted file]
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointVariantsProvider.java [deleted file]

index 0eea684d792c7398d9249114b26ad4d35bd6bc9c..bd1faa161d38a8ab1fb6002ad1b834f95f65ee89 100644 (file)
@@ -33,8 +33,6 @@ import com.intellij.xdebugger.breakpoints.XBreakpoint;
 import com.intellij.xdebugger.breakpoints.XLineBreakpoint;
 import com.intellij.xdebugger.breakpoints.ui.XBreakpointGroupingRule;
 import com.intellij.xdebugger.impl.XSourcePositionImpl;
-import com.intellij.xdebugger.impl.breakpoints.XLineBreakpointVariant;
-import com.intellij.xdebugger.impl.breakpoints.XLineBreakpointVariantsProvider;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.java.debugger.breakpoints.properties.JavaLineBreakpointProperties;
@@ -47,8 +45,7 @@ import java.util.List;
  * Base class for java line-connected exceptions (line, method, field)
  * @author egor
  */
-public class JavaLineBreakpointType extends JavaLineBreakpointTypeBase<JavaLineBreakpointProperties>
-  implements JavaBreakpointType, XLineBreakpointVariantsProvider<JavaLineBreakpointType.JavaBreakpointVariant> {
+public class JavaLineBreakpointType extends JavaLineBreakpointTypeBase<JavaLineBreakpointProperties> implements JavaBreakpointType {
   public JavaLineBreakpointType() {
     super("java-line", DebuggerBundle.message("line.breakpoints.tab.title"));
   }
@@ -93,7 +90,7 @@ public class JavaLineBreakpointType extends JavaLineBreakpointTypeBase<JavaLineB
 
   @NotNull
   @Override
-  public List<JavaBreakpointVariant> computeLineBreakpointVariants(@NotNull Project project, @NotNull XSourcePosition position) {
+  public List<JavaBreakpointVariant> computeVariants(@NotNull Project project, @NotNull XSourcePosition position) {
     PsiFile file = PsiManager.getInstance(project).findFile(position.getFile());
     if (file == null) {
       return Collections.emptyList();
index 8bfab167945d61b17be3f616301d2dadc25f5832..814fb0d7da12a36aa2888058eb5fadcb32bb0ea2 100644 (file)
@@ -126,4 +126,22 @@ public abstract class XLineBreakpointType<P extends XBreakpointProperties> exten
   public TextRange getHighlightRange(P properties, Document document, Project project) {
     return null;
   }
+
+  /**
+   * Return a list of variants if there can be more than one breakpoint on the line
+   */
+  @NotNull
+  public List<? extends XLineBreakpointVariant> computeVariants(@NotNull Project project, @NotNull XSourcePosition position) {
+    return Collections.emptyList();
+  }
+
+  public abstract class XLineBreakpointVariant {
+    public abstract String getText();
+
+    public abstract Icon getIcon();
+
+    public abstract TextRange getHighlightRange();
+
+    public abstract P createProperties();
+  }
 }
index d7ee25675e268b4ab2930937ab6c5c54b52fb777..6f4a761df82d0a42fc0e4fd90f87855224553835 100644 (file)
@@ -60,8 +60,6 @@ import com.intellij.xdebugger.frame.XSuspendContext;
 import com.intellij.xdebugger.frame.XValueContainer;
 import com.intellij.xdebugger.impl.breakpoints.XBreakpointUtil;
 import com.intellij.xdebugger.impl.breakpoints.XExpressionImpl;
-import com.intellij.xdebugger.impl.breakpoints.XLineBreakpointVariant;
-import com.intellij.xdebugger.impl.breakpoints.XLineBreakpointVariantsProvider;
 import com.intellij.xdebugger.impl.breakpoints.ui.grouping.XBreakpointFileGroupingRule;
 import com.intellij.xdebugger.impl.evaluate.quick.common.ValueLookupManager;
 import com.intellij.xdebugger.impl.settings.XDebuggerSettingsManager;
@@ -152,91 +150,87 @@ public class XDebuggerUtilImpl extends XDebuggerUtil {
           breakpointManager.removeBreakpoint(breakpoint);
         }
         else {
-          if (type instanceof XLineBreakpointVariantsProvider) {
-            final XLineBreakpointVariantsProvider<XLineBreakpointVariant> provider =
-              (XLineBreakpointVariantsProvider<XLineBreakpointVariant>)type;
-            List<XLineBreakpointVariant> variants = provider.computeLineBreakpointVariants(project, position);
-            if (!variants.isEmpty() && editor != null) {
-              RelativePoint relativePoint = DebuggerUIUtil.calcPopupLocation(editor, line);
-              if (variants.size() > 1 && relativePoint != null) {
-                final AsyncResult<XLineBreakpoint> res = new AsyncResult<XLineBreakpoint>();
-                class MySelectionListener implements ListSelectionListener {
-                  RangeHighlighter myHighlighter = null;
-
-                  @Override
-                  public void valueChanged(ListSelectionEvent e) {
-                    if (!e.getValueIsAdjusting()) {
-                      clearHighlighter();
-                      Object value = ((JList)e.getSource()).getSelectedValue();
-                      if (value instanceof XLineBreakpointVariant) {
-                        TextRange range = ((XLineBreakpointVariant)value).getHighlightRange();
-                        TextRange lineRange = DocumentUtil.getLineTextRange(editor.getDocument(), line);
-                        if (range != null) {
-                          range = range.intersection(lineRange);
-                        }
-                        else {
-                          range = lineRange;
-                        }
-                        if (range != null && !range.isEmpty()) {
-                          EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
-                          TextAttributes attributes = scheme.getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES);
-                          myHighlighter = editor.getMarkupModel().addRangeHighlighter(
-                            range.getStartOffset(), range.getEndOffset(), DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER, attributes,
-                            HighlighterTargetArea.EXACT_RANGE);
-                        }
+          List<? extends XLineBreakpointType<P>.XLineBreakpointVariant> variants = type.computeVariants(project, position);
+          if (!variants.isEmpty() && editor != null) {
+            RelativePoint relativePoint = DebuggerUIUtil.calcPopupLocation(editor, line);
+            if (variants.size() > 1 && relativePoint != null) {
+              final AsyncResult<XLineBreakpoint> res = new AsyncResult<XLineBreakpoint>();
+              class MySelectionListener implements ListSelectionListener {
+                RangeHighlighter myHighlighter = null;
+
+                @Override
+                public void valueChanged(ListSelectionEvent e) {
+                  if (!e.getValueIsAdjusting()) {
+                    clearHighlighter();
+                    Object value = ((JList)e.getSource()).getSelectedValue();
+                    if (value instanceof XLineBreakpointType.XLineBreakpointVariant) {
+                      TextRange range = ((XLineBreakpointType.XLineBreakpointVariant)value).getHighlightRange();
+                      TextRange lineRange = DocumentUtil.getLineTextRange(editor.getDocument(), line);
+                      if (range != null) {
+                        range = range.intersection(lineRange);
+                      }
+                      else {
+                        range = lineRange;
+                      }
+                      if (range != null && !range.isEmpty()) {
+                        EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
+                        TextAttributes attributes = scheme.getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES);
+                        myHighlighter = editor.getMarkupModel().addRangeHighlighter(
+                          range.getStartOffset(), range.getEndOffset(), DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER, attributes,
+                          HighlighterTargetArea.EXACT_RANGE);
                       }
                     }
                   }
+                }
 
-                  private void clearHighlighter() {
-                    if (myHighlighter != null) {
-                      myHighlighter.dispose();
-                    }
+                private void clearHighlighter() {
+                  if (myHighlighter != null) {
+                    myHighlighter.dispose();
                   }
                 }
-                final MySelectionListener selectionListener = new MySelectionListener();
-                ListPopup popup = JBPopupFactory.getInstance().createListPopup(
-                  new BaseListPopupStep<XLineBreakpointVariant>("Create breakpoint for", variants) {
-                    @NotNull
-                    @Override
-                    public String getTextFor(XLineBreakpointVariant value) {
-                      return value.getText();
-                    }
+              }
+              final MySelectionListener selectionListener = new MySelectionListener();
+              ListPopup popup = JBPopupFactory.getInstance().createListPopup(
+                new BaseListPopupStep<XLineBreakpointType.XLineBreakpointVariant>("Create breakpoint for", variants) {
+                  @NotNull
+                  @Override
+                  public String getTextFor(XLineBreakpointType.XLineBreakpointVariant value) {
+                    return value.getText();
+                  }
 
-                    @Override
-                    public Icon getIconFor(XLineBreakpointVariant value) {
-                      return value.getIcon();
-                    }
+                  @Override
+                  public Icon getIconFor(XLineBreakpointType.XLineBreakpointVariant value) {
+                    return value.getIcon();
+                  }
 
-                    @Override
-                    public void canceled() {
-                      selectionListener.clearHighlighter();
-                    }
+                  @Override
+                  public void canceled() {
+                    selectionListener.clearHighlighter();
+                  }
 
-                    @Override
-                    public PopupStep onChosen(final XLineBreakpointVariant selectedValue, boolean finalChoice) {
-                      selectionListener.clearHighlighter();
-                      ApplicationManager.getApplication().runWriteAction(new Runnable() {
-                        @Override
-                        public void run() {
-                          P properties = (P)selectedValue.createProperties();
-                          res.setDone(breakpointManager.addLineBreakpoint(type, file.getUrl(), line, properties, temporary));
-                        }
-                      });
-                      return FINAL_CHOICE;
-                    }
-                  });
-                popup.addListSelectionListener(selectionListener);
-                popup.show(relativePoint);
-                result.setResult(res);
-                return;
-              }
-              else {
-                P properties = (P)variants.get(0).createProperties();
-                result.setResult(AsyncResult.done(
-                  (XLineBreakpoint)breakpointManager.addLineBreakpoint(type, file.getUrl(), line, properties, temporary)));
-                return;
-              }
+                  @Override
+                  public PopupStep onChosen(final XLineBreakpointType.XLineBreakpointVariant selectedValue, boolean finalChoice) {
+                    selectionListener.clearHighlighter();
+                    ApplicationManager.getApplication().runWriteAction(new Runnable() {
+                      @Override
+                      public void run() {
+                        P properties = (P)selectedValue.createProperties();
+                        res.setDone(breakpointManager.addLineBreakpoint(type, file.getUrl(), line, properties, temporary));
+                      }
+                    });
+                    return FINAL_CHOICE;
+                  }
+                });
+              popup.addListSelectionListener(selectionListener);
+              popup.show(relativePoint);
+              result.setResult(res);
+              return;
+            }
+            else {
+              P properties = variants.get(0).createProperties();
+              result.setResult(AsyncResult.done(
+                (XLineBreakpoint)breakpointManager.addLineBreakpoint(type, file.getUrl(), line, properties, temporary)));
+              return;
             }
           }
           P properties = type.createBreakpointProperties(file, line);
diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointVariant.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointVariant.java
deleted file mode 100644 (file)
index 18b4db2..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2000-2015 JetBrains s.r.o.
- *
- * 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 com.intellij.xdebugger.impl.breakpoints;
-
-import com.intellij.openapi.util.TextRange;
-import com.intellij.xdebugger.breakpoints.XBreakpointProperties;
-
-import javax.swing.*;
-
-/**
- * @author egor
- */
-public abstract class XLineBreakpointVariant<P extends XBreakpointProperties> {
-  public abstract String getText();
-
-  public abstract Icon getIcon();
-
-  public abstract TextRange getHighlightRange();
-
-  public abstract P createProperties();
-}
diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointVariantsProvider.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointVariantsProvider.java
deleted file mode 100644 (file)
index 9861ef0..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2000-2015 JetBrains s.r.o.
- *
- * 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 com.intellij.xdebugger.impl.breakpoints;
-
-import com.intellij.openapi.project.Project;
-import com.intellij.xdebugger.XSourcePosition;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.List;
-
-/**
- * @author egor
- */
-public interface XLineBreakpointVariantsProvider<V extends XLineBreakpointVariant> {
-  @NotNull
-  List<V> computeLineBreakpointVariants(@NotNull Project project, @NotNull XSourcePosition position);
-}