From a309be9d463a9d7b2e68d8b301116bb6f3381452 Mon Sep 17 00:00:00 2001 From: Christian Schima Date: Thu, 14 Nov 2024 23:19:20 +0100 Subject: [PATCH] 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(); + } + } }