Bug 561715 - Fix local variable inspection inside lambda expression

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>
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 0000000..f2f41f8
--- /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 ba2c6ae..08c87d2 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 @@
 				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 0000000..4b6e67f
--- /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 59b2931..8baa1d7 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 @@
 
 		@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();