diff options
author | gayanper | 2020-06-19 17:51:51 +0000 |
---|---|---|
committer | Sarika Sinha | 2020-07-27 07:39:40 +0000 |
commit | 090b4084f9723bdda1905bcc4151d15772a0eabc (patch) | |
tree | 047ddcc8cd4af0a8d208c95002ebcfcbf924825c | |
parent | 851653f35a156059a8527fb042e77c571b9826ba (diff) | |
download | eclipse.jdt.debug-090b4084f9723bdda1905bcc4151d15772a0eabc.tar.gz eclipse.jdt.debug-090b4084f9723bdda1905bcc4151d15772a0eabc.tar.xz eclipse.jdt.debug-090b4084f9723bdda1905bcc4151d15772a0eabc.zip |
Bug564486 - Fix variable evaluation for anon classes and lambdasI20200727-1800
The evaluation engine fails when the lambda is inside a anon class and
the evaluation is done inside the lambda. The root cause was the eval
method which is static throws a compilation problem due to it is created
in the anon class. Now the problem is ignored as other problems in
ASTEvaluationEngine
Change-Id: I287cf2d02561e49b90c32f7124c0e1e90d840279
Signed-off-by: gayanper <gayanper@gmail.com>
4 files changed, 84 insertions, 1 deletions
diff --git a/org.eclipse.jdt.debug.tests/java8/Bug564486.java b/org.eclipse.jdt.debug.tests/java8/Bug564486.java new file mode 100644 index 000000000..414dc3b81 --- /dev/null +++ b/org.eclipse.jdt.debug.tests/java8/Bug564486.java @@ -0,0 +1,14 @@ +import java.util.stream.Stream; + +public class Bug564486 { + public static void main(String[] args) { + new Runnable() { + @Override + public void run() { + Stream.of(1, 2, 3).forEach(i -> { + System.out.println(args); + }); + } + }.run(); + } +}
\ No newline at end of file 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 bcce41afc..98a5c47cf 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 @@ -477,6 +477,7 @@ public abstract class AbstractDebugTest extends TestCase implements IEvaluation cfgs.add(createLaunchConfiguration(jp, "Bug562056")); cfgs.add(createLaunchConfiguration(jp, "RemoteEvaluator")); cfgs.add(createLaunchConfiguration(jp, "AnonymousEvaluator")); + cfgs.add(createLaunchConfiguration(jp, "Bug564486")); loaded18 = true; waitForBuild(); } diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/eval/AnonClassEvalTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/eval/AnonClassEvalTests.java new file mode 100644 index 000000000..b0ebe0f0c --- /dev/null +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/eval/AnonClassEvalTests.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * 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.jdt.core.IJavaProject; +import org.eclipse.jdt.debug.core.IJavaThread; +import org.eclipse.jdt.debug.tests.AbstractDebugTest; +import org.eclipse.jdt.internal.debug.core.model.JDIObjectValue; + +public class AnonClassEvalTests extends AbstractDebugTest { + private IJavaThread javaThread; + + @Override + protected IJavaProject getProjectContext() { + return get18Project(); + } + + public AnonClassEvalTests(String name) { + super(name); + } + + public void testEvaluate_OuterVariable_InsideLambda() throws Exception { + debugWithBreakpoint("Bug564486", 9); + String snippet = "args"; + IValue value = doEval(javaThread, snippet); + + assertEquals("wrong type : ", "java.lang.String[]", value.getReferenceTypeName()); + assertEquals("wrong result : ", 0, ((JDIObjectValue) value).getArrayLength()); + } + + public void testEvaluate_LambdaVariable_InsideLambda() throws Exception { + debugWithBreakpoint("Bug564486", 9); + String snippet = "i"; + IValue value = doEval(javaThread, snippet); + + assertEquals("wrong type : ", "java.lang.Integer", value.getReferenceTypeName()); + assertEquals("wrong result : ", "1", ((JDIObjectValue) value).getField("value", false).getValue().toString()); + } + + 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/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTEvaluationEngine.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTEvaluationEngine.java index bdfda786c..5196f71a4 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTEvaluationEngine.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTEvaluationEngine.java @@ -622,7 +622,8 @@ public class ASTEvaluationEngine implements IAstEvaluationEngine { || problemId == IProblem.NotVisibleMethod || problemId == IProblem.NotVisibleConstructor || problemId == IProblem.NotVisibleField - || problemId == IProblem.NotVisibleType) { + || problemId == IProblem.NotVisibleType + || problemId == IProblem.UnexpectedStaticModifierForMethod) { continue; } if (problem.isError()) { |