diff options
author | gayanper | 2020-04-02 19:58:33 +0000 |
---|---|---|
committer | Sarika Sinha | 2020-04-03 10:06:17 +0000 |
commit | c9eaedc73281724564c0d20525490ea18fb68e29 (patch) | |
tree | 4dbab1305360290c5777bb76f6c00fb98090164e | |
parent | f045f90d05af6ac7b124827097e389e0c9b4caa5 (diff) | |
download | eclipse.jdt.debug-c9eaedc73281724564c0d20525490ea18fb68e29.tar.gz eclipse.jdt.debug-c9eaedc73281724564c0d20525490ea18fb68e29.tar.xz eclipse.jdt.debug-c9eaedc73281724564c0d20525490ea18fb68e29.zip |
Bug 561715 - Fix local variable inspection inside lambda expressionI20200406-0350I20200406-0120I20200405-1800I20200405-0600I20200404-1800I20200404-1220I20200404-0600I20200404-0330I20200403-1800
With the fix given for bug561542 the JDIStackFrame lambda variable
resolution only works for lambda body which is multiline (or least with
one line). This fix will now check for the given lineNo to be inside the
lines that the lambda expression spans over.
Change-Id: Ib1f6cf3567450a9e52ff616f0eb0efc87ae466be
Signed-off-by: gayanper <gayanper@gmail.com>
4 files changed, 75 insertions, 1 deletions
diff --git a/org.eclipse.jdt.debug.tests/java8/Bug561715.java b/org.eclipse.jdt.debug.tests/java8/Bug561715.java new file mode 100644 index 000000000..f2f41f8c4 --- /dev/null +++ b/org.eclipse.jdt.debug.tests/java8/Bug561715.java @@ -0,0 +1,9 @@ +import java.util.Arrays; +import java.util.function.Predicate; + +public class Bug561715 { + public static void main(String[] args) { + String y = "111"; + Arrays.asList("111", "222", "aaa").stream().filter(a -> a.equals(y)).count(); + } +} diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java index ba2c6aec1..08c87d2bc 100644 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java @@ -473,6 +473,7 @@ public abstract class AbstractDebugTest extends TestCase implements IEvaluation cfgs.add(createLaunchConfiguration(jp, "Bug404097BreakpointUsingInnerClass")); cfgs.add(createLaunchConfiguration(jp, "Bug404097BreakpointUsingLocalClass")); cfgs.add(createLaunchConfiguration(jp, "Bug560392")); + cfgs.add(createLaunchConfiguration(jp, "Bug561715")); loaded18 = true; waitForBuild(); } diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/eval/LambdaLocalVarTest.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/eval/LambdaLocalVarTest.java new file mode 100644 index 000000000..4b6e67f3e --- /dev/null +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/eval/LambdaLocalVarTest.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2020 Gayan Perera and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Gayan Perera - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.debug.tests.eval; + +import org.eclipse.debug.core.model.IValue; +import org.eclipse.debug.internal.ui.views.console.ProcessConsole; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.debug.core.IJavaThread; +import org.eclipse.jdt.debug.tests.AbstractDebugTest; +import org.eclipse.jdt.debug.tests.TestUtil; + +public class LambdaLocalVarTest extends AbstractDebugTest { + private IJavaThread javaThread; + + @Override + protected IJavaProject getProjectContext() { + return get18Project(); + } + + public LambdaLocalVarTest(String name) { + super(name); + } + + public void testEvaluate_LambdaFieldVariable() throws Exception { + debugWithBreakpoint("Bug561715", 7); + javaThread.resume(); + TestUtil.waitForJobs(getName(), 1000, DEFAULT_TIMEOUT, ProcessConsole.class); + + String snippet = "a"; + IValue value = doEval(javaThread, snippet); + + assertEquals("wrong type : ", "java.lang.String", value.getReferenceTypeName()); + assertEquals("wrong result : ", "111", value.getValueString()); + } + + private void debugWithBreakpoint(String testClass, int lineNumber) throws Exception { + createLineBreakpoint(lineNumber, testClass); + javaThread = launchToBreakpoint(testClass); + assertNotNull("The program did not suspend", javaThread); + } + + @Override + protected void tearDown() throws Exception { + try { + terminateAndRemove(javaThread); + } finally { + super.tearDown(); + removeAllBreakpoints(); + } + } +} diff --git a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIStackFrame.java b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIStackFrame.java index 59b2931f5..8baa1d776 100644 --- a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIStackFrame.java +++ b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIStackFrame.java @@ -443,7 +443,9 @@ public class JDIStackFrame extends JDIDebugElement implements IJavaStackFrame { @Override public boolean visit(LambdaExpression lambdaExpression) { - if (lineNo != cu.getLineNumber(lambdaExpression.getStartPosition()) + 1) { + // check if the lineNo fall in lambda region, it can either be single or multiline lambda body. + if (lineNo < cu.getLineNumber(lambdaExpression.getStartPosition()) + || lineNo > cu.getLineNumber(lambdaExpression.getStartPosition() + lambdaExpression.getLength())) { return true; } IMethodBinding binding = lambdaExpression.resolveMethodBinding(); |