possibility to extend JavaLineBreakpointType
authorNikolay.Tropin <Nikolay.Tropin@jetbrains.com>
Thu, 13 Aug 2015 10:54:23 +0000 (13:54 +0300)
committerNikolay.Tropin <Nikolay.Tropin@jetbrains.com>
Thu, 13 Aug 2015 10:54:23 +0000 (13:54 +0300)
java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaLineBreakpointType.java
java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaLineBreakpointTypeBase.java
java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpoint.java
java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/RunToCursorBreakpoint.java

index 03eadd84385eba014ac2c8e574074f78e88ed94d..dffd9acab330a7643a815b85e9340d8c035e09ab 100644 (file)
@@ -32,8 +32,11 @@ 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 org.jetbrains.annotations.Nls;
+import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
+import org.jetbrains.java.debugger.breakpoints.properties.JavaBreakpointProperties;
 import org.jetbrains.java.debugger.breakpoints.properties.JavaLineBreakpointProperties;
 
 import javax.swing.*;
@@ -50,6 +53,10 @@ public class JavaLineBreakpointType extends JavaLineBreakpointTypeBase<JavaLineB
     super("java-line", DebuggerBundle.message("line.breakpoints.tab.title"));
   }
 
+  protected JavaLineBreakpointType(@NonNls @NotNull String id, @Nls @NotNull String title) {
+    super(id, title);
+  }
+
   //@Override
   protected String getHelpID() {
     return HelpID.LINE_BREAKPOINTS;
@@ -129,6 +136,35 @@ public class JavaLineBreakpointType extends JavaLineBreakpointTypeBase<JavaLineB
     return res;
   }
 
+  public boolean matchesPosition(@NotNull LineBreakpoint breakpoint, @NotNull SourcePosition position) {
+    JavaBreakpointProperties properties = breakpoint.getProperties();
+    if (properties == null || properties instanceof JavaLineBreakpointProperties) {
+      if (properties != null && ((JavaLineBreakpointProperties)properties).getLambdaOrdinal() == null) return true;
+      PsiElement containingMethod = getContainingMethod(breakpoint);
+      if (containingMethod == null) return false;
+      return DebuggerUtilsEx.inTheMethod(position, containingMethod);
+    }
+    return true;
+  }
+
+  @Nullable
+  public PsiElement getContainingMethod(@NotNull LineBreakpoint breakpoint) {
+    SourcePosition position = breakpoint.getSourcePosition();
+    if (position == null) return null;
+
+    JavaBreakpointProperties properties = breakpoint.getProperties();
+    if (properties instanceof JavaLineBreakpointProperties) {
+      Integer ordinal = ((JavaLineBreakpointProperties)properties).getLambdaOrdinal();
+      if (ordinal > -1) {
+        List<PsiLambdaExpression> lambdas = DebuggerUtilsEx.collectLambdas(position, true);
+        if (ordinal < lambdas.size()) {
+          return lambdas.get(ordinal);
+        }
+      }
+    }
+    return DebuggerUtilsEx.getContainingMethod(position);
+  }
+
   class JavaBreakpointVariant extends XLineBreakpointVariant {
     protected final XSourcePosition mySourcePosition;
 
@@ -158,7 +194,7 @@ public class JavaLineBreakpointType extends JavaLineBreakpointTypeBase<JavaLineB
     }
   }
 
-  private class ExactJavaBreakpointVariant extends JavaBreakpointVariant {
+  public class ExactJavaBreakpointVariant extends JavaBreakpointVariant {
     private final PsiElement myElement;
     private final Integer myLambdaOrdinal;
 
@@ -200,7 +236,7 @@ public class JavaLineBreakpointType extends JavaLineBreakpointTypeBase<JavaLineB
       if (ordinal != null) {
         Breakpoint javaBreakpoint = BreakpointManager.getJavaBreakpoint(breakpoint);
         if (javaBreakpoint instanceof LineBreakpoint) {
-          PsiElement method = ((LineBreakpoint)javaBreakpoint).getContainingMethod();
+          PsiElement method = getContainingMethod((LineBreakpoint)javaBreakpoint);
           if (method != null) {
             return method.getTextRange();
           }
index 1943a0999ec7b2cdb3447cdc999a54e8d5296cfa..22022e253539ff2815399f33e18bfd986de47a5f 100644 (file)
@@ -81,7 +81,7 @@ public abstract class JavaLineBreakpointTypeBase<P extends JavaBreakpointPropert
   }
 
   @Override
-  public final boolean canPutAt(@NotNull final VirtualFile file, final int line, @NotNull Project project) {
+  public boolean canPutAt(@NotNull final VirtualFile file, final int line, @NotNull Project project) {
     final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
     // JSPX supports jvm debugging, but not in XHTML files
     if (psiFile == null || psiFile.getViewProvider().getFileType() == StdFileTypes.XHTML) {
index 8a8f8d71118f1d54841bd507adaaf05459231cb1..3f453d24d87d7f1e544de8af3d70a4bd609e3373 100644 (file)
@@ -63,7 +63,6 @@ import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.java.debugger.breakpoints.properties.JavaBreakpointProperties;
-import org.jetbrains.java.debugger.breakpoints.properties.JavaLineBreakpointProperties;
 import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes;
 
 import javax.swing.*;
@@ -210,34 +209,18 @@ public class LineBreakpoint<P extends JavaBreakpointProperties> extends Breakpoi
     return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
       @Override
       public Boolean compute() {
-        if (getProperties() instanceof JavaLineBreakpointProperties) {
-          Integer ordinal = ((JavaLineBreakpointProperties)getProperties()).getLambdaOrdinal();
-          if (ordinal == null) return true;
-          PsiElement containingMethod = getContainingMethod();
-          if (containingMethod == null) return false;
-          SourcePosition position = debugProcess.getPositionManager().getSourcePosition(loc);
-          if (position == null) return false;
-          return DebuggerUtilsEx.inTheMethod(position, containingMethod);
-        }
-        return true;
+        SourcePosition position = debugProcess.getPositionManager().getSourcePosition(loc);
+        if (position == null) return false;
+        JavaLineBreakpointType type = getXBreakpointType();
+        if (type == null) return true;
+        return type.matchesPosition(LineBreakpoint.this, position);
       }
     });
   }
 
   @Nullable
-  public PsiElement getContainingMethod() {
-    SourcePosition position = getSourcePosition();
-    if (position == null) return null;
-    if (getProperties() instanceof JavaLineBreakpointProperties) {
-      Integer ordinal = ((JavaLineBreakpointProperties)getProperties()).getLambdaOrdinal();
-      if (ordinal > -1) {
-        List<PsiLambdaExpression> lambdas = DebuggerUtilsEx.collectLambdas(position, true);
-        if (ordinal < lambdas.size()) {
-          return lambdas.get(ordinal);
-        }
-      }
-    }
-    return DebuggerUtilsEx.getContainingMethod(position);
+  protected JavaLineBreakpointType getXBreakpointType() {
+    return (JavaLineBreakpointType)myXBreakpoint.getType();
   }
 
   private boolean isInScopeOf(DebugProcessImpl debugProcess, String className) {
index bb93a44d9e83268e3a78d56cec91e4a8ebddfbff..ebf9bda914b95f8797b864067a512415f092b951 100644 (file)
@@ -17,15 +17,13 @@ package com.intellij.debugger.ui.breakpoints;
 
 import com.intellij.debugger.SourcePosition;
 import com.intellij.debugger.engine.DebugProcessImpl;
-import com.intellij.debugger.impl.DebuggerUtilsEx;
-import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Computable;
+import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.PsiFile;
 import com.intellij.psi.PsiManager;
+import com.intellij.xdebugger.XDebuggerUtil;
 import com.intellij.xdebugger.XSourcePosition;
-import com.sun.jdi.Location;
-import com.sun.jdi.ReferenceType;
+import com.intellij.xdebugger.breakpoints.XLineBreakpointType;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.java.debugger.breakpoints.properties.JavaBreakpointProperties;
@@ -47,6 +45,7 @@ public class RunToCursorBreakpoint<P extends JavaBreakpointProperties> extends L
     myRestoreBreakpoints = restoreBreakpoints;
   }
 
+  @NotNull
   @Override
   public SourcePosition getSourcePosition() {
     return myCustomPosition;
@@ -125,17 +124,18 @@ public class RunToCursorBreakpoint<P extends JavaBreakpointProperties> extends L
     return false;  // always enabled
   }
 
+  @Nullable
   @Override
-  protected boolean acceptLocation(final DebugProcessImpl debugProcess, ReferenceType classType, final Location loc) {
-    if (!super.acceptLocation(debugProcess, classType, loc)) return false;
-    return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
-      @Override
-      public Boolean compute() {
-        SourcePosition position = debugProcess.getPositionManager().getSourcePosition(loc);
-        if (position == null) return false;
-        return DebuggerUtilsEx.inTheSameMethod(myCustomPosition, position);
+  protected JavaLineBreakpointType getXBreakpointType() {
+    SourcePosition position = getSourcePosition();
+    VirtualFile file = position.getFile().getVirtualFile();
+    int line = position.getLine();
+    for (XLineBreakpointType<?> type : XDebuggerUtil.getInstance().getLineBreakpointTypes()) {
+      if (type instanceof JavaLineBreakpointType && type.canPutAt(file, line, getProject())) {
+        return ((JavaLineBreakpointType)type);
       }
-    });
+    }
+    return null;
   }
 
   @Nullable