Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for #518 (Setting a breakpoint inside lambda with object). #523

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions org.eclipse.jdt.debug.tests/java8/ClassWithLambdas.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2024 Christian Schima.
*
* 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 <T> Factory create(Supplier<T> supplier, Consumer<T> consumer) {
return new Factory();
}
}

public ClassWithLambdas(String parent) {
Factory.create(() -> Optional.of(""), sample -> new Consumer<Optional<String>>() {

Optional<String> lastSample = Optional.empty();

@Override
public void accept(Optional<String> currentSample) {
lastSample.ifPresent(System.out::println);
currentSample.ifPresent(System.out::println);
lastSample = currentSample;
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@
*/
public class TestToggleBreakpointsTarget8 extends AbstractToggleBreakpointsTarget {




public TestToggleBreakpointsTarget8(String name) {
super(name);
// TODO Auto-generated constructor stub
}

/**
Expand Down Expand Up @@ -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
jukzi marked this conversation as resolved.
Show resolved Hide resolved
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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1066,9 +1066,9 @@ public boolean visit(LambdaExpression node) {

}
}
} else if (body instanceof LambdaExpression) {
body.accept(this);
} else if (body instanceof MethodInvocation) {

// Lambda body can be a block (which is handled above) or an (arbitrary) expression.
} else if (body instanceof Expression) {
body.accept(this);
}
}
Expand Down