From 08f40a644df4c123b9d91e665ddfa6ec4bda4871 Mon Sep 17 00:00:00 2001 From: Christian Schima Date: Tue, 1 Oct 2024 15:22:55 +0200 Subject: [PATCH 1/3] Bugfix for #518 (Setting a breakpoint inside lambda with object). --- .../core/breakpoints/ValidBreakpointLocationLocator.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/ValidBreakpointLocationLocator.java b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/ValidBreakpointLocationLocator.java index a27b230f62..40eb3df37d 100644 --- a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/ValidBreakpointLocationLocator.java +++ b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/ValidBreakpointLocationLocator.java @@ -1066,10 +1066,16 @@ public boolean visit(LambdaExpression node) { } } + + // Lambda body can be a block (which is handled above) or an (arbitrary) expression. So maybe the + // following cases are insufficient and should be replaced by handling the general + // org.eclipse.jdt.core.dom.Expression. } else if (body instanceof LambdaExpression) { body.accept(this); } else if (body instanceof MethodInvocation) { body.accept(this); + } else if (body instanceof ClassInstanceCreation) { + body.accept(this); } } return false; From a9fe90df2eb86dc3626b9bca72c595c91b3c0b0e Mon Sep 17 00:00:00 2001 From: Christian Schima Date: Thu, 14 Nov 2024 23:19:20 +0100 Subject: [PATCH 2/3] Test for #518 (Setting a breakpoint inside lambda with object). --- .../java8/ClassWithLambdas.java | 42 +++++++++++++++++++ .../TestToggleBreakpointsTarget8.java | 26 ++++++++++-- 2 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 org.eclipse.jdt.debug.tests/java8/ClassWithLambdas.java diff --git a/org.eclipse.jdt.debug.tests/java8/ClassWithLambdas.java b/org.eclipse.jdt.debug.tests/java8/ClassWithLambdas.java new file mode 100644 index 0000000000..6ab34763d1 --- /dev/null +++ b/org.eclipse.jdt.debug.tests/java8/ClassWithLambdas.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2024 IBM Corporation 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: + * Christian Schima - initial API and implementation + *******************************************************************************/ +import java.util.Optional; +import java.util.function.Consumer; +import java.util.function.Supplier; + +/** + * Test class with lambdas. + */ +public class ClassWithLambdas { + + private static class Factory { + public static Factory create(Supplier supplier, Consumer consumer) { + return new Factory(); + } + } + + public ClassWithLambdas(String parent) { + Factory.create(() -> Optional.of(""), sample -> new Consumer>() { + + Optional lastSample = Optional.empty(); + + @Override + public void accept(Optional currentSample) { + lastSample.ifPresent(System.out::println); + currentSample.ifPresent(System.out::println); + lastSample = currentSample; + } + }); + } +} \ No newline at end of file diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/TestToggleBreakpointsTarget8.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/TestToggleBreakpointsTarget8.java index 88495e1024..1ca91cbeff 100644 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/TestToggleBreakpointsTarget8.java +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/TestToggleBreakpointsTarget8.java @@ -25,12 +25,8 @@ */ public class TestToggleBreakpointsTarget8 extends AbstractToggleBreakpointsTarget { - - - public TestToggleBreakpointsTarget8(String name) { super(name); - // TODO Auto-generated constructor stub } /** @@ -124,4 +120,26 @@ public void testInterfaceLineBreakpoint() throws Exception { } } + /** + * Tests that a line breakpoints in an lambda expression works. + */ + public void testLineBreakpointInsideLambda() throws Exception { + Listener listener = new Listener(); + IBreakpointManager manager = getBreakpointManager(); + manager.addBreakpointListener(listener); + try { + Path path = new Path("java8/ClassWithLambdas.java"); + final int lineNr = 35; // 0 based offset in document line numbers + toggleBreakpoint(path, lineNr); + TestUtil.waitForJobs(getName(), 100, DEFAULT_TIMEOUT); + IBreakpoint added = listener.getAdded(); + assertTrue("Should be a line breakpoint", added instanceof IJavaLineBreakpoint); + IJavaLineBreakpoint breakpoint = (IJavaLineBreakpoint) added; + assertEquals("Wrong line number", lineNr + 1, breakpoint.getLineNumber()); + assertEquals("Wrong type name", "ClassWithLambdas", breakpoint.getTypeName()); + } finally { + manager.removeBreakpointListener(listener); + removeAllBreakpoints(); + } + } } From 7cebcbda0e69e249023312013ffa0904231c2836 Mon Sep 17 00:00:00 2001 From: Christian Schima Date: Thu, 12 Dec 2024 13:01:22 +0100 Subject: [PATCH 3/3] Bugfix for #518 (Setting a breakpoint inside lambda with object). --- .../java8/ClassWithLambdas.java | 2 +- .../breakpoints/ValidBreakpointLocationLocator.java | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/org.eclipse.jdt.debug.tests/java8/ClassWithLambdas.java b/org.eclipse.jdt.debug.tests/java8/ClassWithLambdas.java index 6ab34763d1..32ba73b923 100644 --- a/org.eclipse.jdt.debug.tests/java8/ClassWithLambdas.java +++ b/org.eclipse.jdt.debug.tests/java8/ClassWithLambdas.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2024 IBM Corporation and others. + * Copyright (c) 2024 Christian Schima. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 diff --git a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/ValidBreakpointLocationLocator.java b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/ValidBreakpointLocationLocator.java index 40eb3df37d..82ac1f3e6a 100644 --- a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/ValidBreakpointLocationLocator.java +++ b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/ValidBreakpointLocationLocator.java @@ -1067,14 +1067,8 @@ public boolean visit(LambdaExpression node) { } } - // Lambda body can be a block (which is handled above) or an (arbitrary) expression. So maybe the - // following cases are insufficient and should be replaced by handling the general - // org.eclipse.jdt.core.dom.Expression. - } else if (body instanceof LambdaExpression) { - body.accept(this); - } else if (body instanceof MethodInvocation) { - body.accept(this); - } else if (body instanceof ClassInstanceCreation) { + // Lambda body can be a block (which is handled above) or an (arbitrary) expression. + } else if (body instanceof Expression) { body.accept(this); } }