-
Notifications
You must be signed in to change notification settings - Fork 62
Fix Possible UI Freeze By Avoiding Source Lookup For Lambda Frames #933
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
...jdt.debug.tests/testfiles/DebugSelectionTests/src/selectiontests/LambdaSelectionTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2026 Simeon Andreev 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: | ||
| * Simeon Andreev - initial API and implementation | ||
| *******************************************************************************/ | ||
| package selectiontests; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * The test resumes at lambda chain and at each resume expects selecting the next lambda expression. | ||
| */ | ||
| public class LambdaSelectionTest { | ||
|
|
||
| public static void main(String[] main) { | ||
| List<String> list = Arrays.asList("A"); | ||
| list.stream() | ||
| .map(s -> s.toLowerCase()).filter(s -> s.equals("b")).forEach(System.out::println); // line 27, test breakpoint is set here | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/DebugSelectionTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2026 Simeon Andreev 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: | ||
| * Simeon Andreev - initial API and implementation | ||
| *******************************************************************************/ | ||
|
|
||
| package org.eclipse.jdt.debug.tests.ui; | ||
|
|
||
| import org.eclipse.debug.core.ILaunchConfiguration; | ||
| import org.eclipse.jdt.core.IJavaProject; | ||
| import org.eclipse.jdt.debug.core.IJavaThread; | ||
| import org.eclipse.jdt.debug.testplugin.JavaProjectHelper; | ||
| import org.eclipse.jdt.debug.tests.TestUtil; | ||
| import org.eclipse.jface.text.ITextSelection; | ||
| import org.eclipse.test.OrderedTestSuite; | ||
| import org.eclipse.ui.texteditor.ITextEditor; | ||
|
|
||
| import junit.framework.Test; | ||
|
|
||
| public class DebugSelectionTests extends AbstractDebugUiTests { | ||
|
|
||
| public static Test suite() { | ||
| return new OrderedTestSuite(DebugSelectionTests.class); | ||
| } | ||
|
|
||
| private IJavaProject project; | ||
|
|
||
| public DebugSelectionTests(String name) { | ||
| super(name); | ||
| } | ||
|
|
||
| @Override | ||
| protected IJavaProject getProjectContext() { | ||
| return project; | ||
| } | ||
|
|
||
| @Override | ||
| public void setUp() throws Exception { | ||
| super.setUp(); | ||
| project = createProject("DebugSelectionTests", "testfiles/DebugSelectionTests/", JavaProjectHelper.JAVA_SE_1_8_EE_NAME, false); | ||
| waitForBuild(); | ||
| } | ||
|
|
||
| @Override | ||
| public void tearDown() throws Exception { | ||
| closeAllEditors(); | ||
| project.getProject().delete(true, null); | ||
| super.tearDown(); | ||
| } | ||
|
|
||
| /** | ||
| * Resume at lambda chain and at each resume expect selecting the next lambda expression. | ||
| */ | ||
| public void testLambdaEditorSelection() throws Exception { | ||
| IJavaThread thread = null; | ||
| try { | ||
| String typeName = "selectiontests.LambdaSelectionTest"; | ||
| createLineBreakpoint(27, typeName); | ||
| ILaunchConfiguration config = createLaunchConfiguration(project, typeName); | ||
| thread = launchAndSuspend(config); | ||
| resume(thread); | ||
| waitForSelection("s -> s.toLowerCase()", 10_000L); | ||
trancexpress marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| resume(thread); | ||
| waitForSelection("s -> s.equals(\"b\")", 10_000L); | ||
| } finally { | ||
| removeAllBreakpoints(); | ||
| if (thread != null) { | ||
| terminateAndRemove(thread); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static void waitForSelection(String expectedSelection, long timeout) throws InterruptedException { | ||
| long s = System.currentTimeMillis(); | ||
| while (System.currentTimeMillis() - s < timeout) { | ||
| if (expectedSelection.equals(getActiveEditorSelectionText())) { | ||
| return; | ||
| } | ||
| TestUtil.runEventLoop(); | ||
| Thread.sleep(50L); | ||
| } | ||
| assertEquals("Timed out while waiting for selection", expectedSelection, getActiveEditorSelectionText()); | ||
| } | ||
|
|
||
| private static String getActiveEditorSelectionText() { | ||
| return callInUi(() -> { | ||
| ITextEditor editor = (ITextEditor) getActivePage().getActiveEditor(); | ||
| if (editor != null) { | ||
| ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); | ||
| if (selection != null) { | ||
| return selection.getText(); | ||
| } | ||
| } | ||
| return ""; | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...ipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JavaStackFrameEditorPresenter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2026 IBM Corporation. | ||
| * | ||
| * 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: | ||
| * IBM Corporation - initial API and implementation | ||
| *******************************************************************************/ | ||
| package org.eclipse.jdt.internal.debug.ui; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.eclipse.core.runtime.CoreException; | ||
| import org.eclipse.debug.core.model.IStackFrame; | ||
| import org.eclipse.debug.core.model.IThread; | ||
| import org.eclipse.debug.ui.IDebugEditorPresentation; | ||
| import org.eclipse.jdt.core.dom.IMethodBinding; | ||
| import org.eclipse.jdt.core.dom.LambdaExpression; | ||
| import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; | ||
| import org.eclipse.jdt.internal.debug.core.model.JDIStackFrame; | ||
| import org.eclipse.jdt.internal.debug.ui.actions.ToggleBreakpointAdapter; | ||
| import org.eclipse.jdt.ui.JavaUI; | ||
| import org.eclipse.jface.text.BadLocationException; | ||
| import org.eclipse.jface.text.IDocument; | ||
| import org.eclipse.jface.text.IRegion; | ||
| import org.eclipse.ui.IEditorInput; | ||
| import org.eclipse.ui.IEditorPart; | ||
| import org.eclipse.ui.texteditor.IDocumentProvider; | ||
| import org.eclipse.ui.texteditor.ITextEditor; | ||
|
|
||
| /** | ||
| * Handles specialized selection of Java editors during debugging, such as selecting lambda expressions on a breakpoint hit. | ||
| */ | ||
| public class JavaStackFrameEditorPresenter implements IDebugEditorPresentation { | ||
|
|
||
| @Override | ||
| public boolean addAnnotations(IEditorPart editor, IStackFrame frame) { | ||
| try { | ||
| if (editor instanceof ITextEditor textEditor && frame instanceof JDIStackFrame jdiFrame | ||
| && org.eclipse.jdt.internal.debug.core.model.LambdaUtils.isLambdaFrame(jdiFrame)) { | ||
| IEditorInput editorInput = editor.getEditorInput(); | ||
| IDocumentProvider provider = textEditor.getDocumentProvider(); | ||
| IDocument document = provider.getDocument(editorInput); | ||
| if (document != null && JavaUI.getEditorInputJavaElement(editorInput) != null) { | ||
| IRegion region = document.getLineInformation(jdiFrame.getLineNumber() - 1); | ||
| List<LambdaExpression> inLineLambdas = ToggleBreakpointAdapter.findLambdaExpressions(textEditor, region); | ||
| for (LambdaExpression exp : inLineLambdas) { | ||
| String key = getMethodBindingKey(exp); | ||
| if (key != null && key.contains(jdiFrame.getName())) { | ||
| textEditor.selectAndReveal(exp.getStartPosition(), exp.getLength()); | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } catch (CoreException | BadLocationException e) { | ||
| JDIDebugPlugin.log(e); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public void removeAnnotations(IEditorPart editorPart, IThread thread) { | ||
| // nothing to clean up | ||
| } | ||
|
|
||
| private static String getMethodBindingKey(LambdaExpression exp) { | ||
trancexpress marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| String key = null; | ||
| IMethodBinding methodBinding = exp.resolveMethodBinding(); | ||
| if (methodBinding != null) { | ||
| key = methodBinding.getKey(); | ||
| } | ||
| return key; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 0 additions & 73 deletions
73
.../org/eclipse/jdt/internal/debug/ui/sourcelookup/LambdaStackFrameSourceDisplayAdapter.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.