correctly map lambdas if there's more than one debugger location is mapped on the...
authorEgor.Ushakov <egor.ushakov@jetbrains.com>
Tue, 23 Jun 2015 13:10:54 +0000 (16:10 +0300)
committerEgor.Ushakov <egor.ushakov@jetbrains.com>
Tue, 23 Jun 2015 13:14:36 +0000 (16:14 +0300)
java/debugger/impl/src/com/intellij/debugger/engine/PositionManagerImpl.java
java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsEx.java
java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/StepIntoBreakpoint.java

index da915026b9d3acec9fc0eccc4ddfbf2f02622d7b..bdf2bfce2bcba098037e6b05f9e3cab449bd370c 100644 (file)
@@ -35,6 +35,7 @@ import com.intellij.psi.*;
 import com.intellij.psi.search.FilenameIndex;
 import com.intellij.psi.search.GlobalSearchScope;
 import com.intellij.psi.util.PsiTreeUtil;
+import com.intellij.util.Function;
 import com.intellij.util.containers.ContainerUtil;
 import com.intellij.util.containers.EmptyIterable;
 import com.intellij.xdebugger.impl.ui.ExecutionPointHighlighter;
@@ -179,25 +180,21 @@ public class PositionManagerImpl implements PositionManager, MultiRequestPositio
     SourcePosition sourcePosition = SourcePosition.createFromLine(psiFile, lineNumber);
     int lambdaOrdinal = -1;
     if (LambdaMethodFilter.isLambdaName(method.name())) {
-      List<Location> lambdas = ContainerUtil.filter(locationsOfLine(location.declaringType(), sourcePosition), new Condition<Location>() {
-        @Override
-        public boolean value(Location location) {
-          return LambdaMethodFilter.isLambdaName(location.method().name());
-        }
-      });
-      if (lambdas.size() > 1) {
-        Collections.sort(lambdas, new Comparator<Location>() {
+      Set<Method> lambdas =
+        ContainerUtil.map2SetNotNull(locationsOfLine(location.declaringType(), sourcePosition), new Function<Location, Method>() {
           @Override
-          public int compare(Location o1, Location o2) {
-            return LambdaMethodFilter.getLambdaOrdinal(o1.method().name()) - LambdaMethodFilter.getLambdaOrdinal(o2.method().name());
-          }
-        });
-        lambdaOrdinal = ContainerUtil.indexOf(lambdas, new Condition<Location>() {
-          @Override
-          public boolean value(Location location) {
-            return location.method().equals(method);
+          public Method fun(Location location) {
+            Method method = location.method();
+            if (LambdaMethodFilter.isLambdaName(method.name())) {
+              return method;
+            }
+            return null;
           }
         });
+      if (lambdas.size() > 1) {
+        ArrayList<Method> lambdasList = new ArrayList<Method>(lambdas);
+        Collections.sort(lambdasList, DebuggerUtilsEx.LAMBDA_ORDINAL_COMPARATOR);
+        lambdaOrdinal = lambdasList.indexOf(method);
       }
     }
     return new JavaSourcePosition(sourcePosition, location.declaringType(), method, lambdaOrdinal);
index ce8a1dfe9a3da1f1f3bdce6565150e69e8987776..f139f137e1d14fa617c2bc20e88d798f3d169c1c 100644 (file)
@@ -24,6 +24,7 @@ import com.intellij.debugger.DebuggerBundle;
 import com.intellij.debugger.SourcePosition;
 import com.intellij.debugger.engine.DebuggerManagerThreadImpl;
 import com.intellij.debugger.engine.DebuggerUtils;
+import com.intellij.debugger.engine.LambdaMethodFilter;
 import com.intellij.debugger.engine.SuspendContextImpl;
 import com.intellij.debugger.engine.evaluation.*;
 import com.intellij.debugger.engine.evaluation.expression.EvaluatorBuilder;
@@ -874,4 +875,11 @@ public abstract class DebuggerUtilsEx extends DebuggerUtils {
     }
     return false;
   }
+
+  public static final Comparator<Method> LAMBDA_ORDINAL_COMPARATOR = new Comparator<Method>() {
+    @Override
+    public int compare(Method m1, Method m2) {
+      return LambdaMethodFilter.getLambdaOrdinal(m1.name()) - LambdaMethodFilter.getLambdaOrdinal(m2.name());
+    }
+  };
 }
index be538d33116d10b4a7109b165af0e174c4f3ddd9..ad56fc217ee9d5869af8898221cdc01cd98601ee 100644 (file)
@@ -22,6 +22,7 @@ import com.intellij.debugger.engine.DebugProcessImpl;
 import com.intellij.debugger.engine.LambdaMethodFilter;
 import com.intellij.debugger.engine.evaluation.EvaluateException;
 import com.intellij.debugger.engine.requests.RequestManagerImpl;
+import com.intellij.debugger.impl.DebuggerUtilsEx;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.Project;
 import com.sun.jdi.*;
@@ -79,11 +80,7 @@ public class StepIntoBreakpoint extends RunToCursorBreakpoint {
             final LambdaMethodFilter lambdaFilter = (LambdaMethodFilter)myFilter;
             if (lambdaFilter.getLambdaOrdinal() < methodsFound) {
               final Method[] candidates = methods.toArray(new Method[methodsFound]);
-              Arrays.sort(candidates, new Comparator<Method>() {
-                public int compare(Method m1, Method m2) {
-                  return LambdaMethodFilter.getLambdaOrdinal(m1.name()) - LambdaMethodFilter.getLambdaOrdinal(m2.name());
-                }
-              });
+              Arrays.sort(candidates, DebuggerUtilsEx.LAMBDA_ORDINAL_COMPARATOR);
               location = candidates[lambdaFilter.getLambdaOrdinal()].location();
             }
           }