From 7875f693ae6391cbd8b48f1eb2fea16d8c098302 Mon Sep 17 00:00:00 2001 From: Elsa Zacharia Date: Wed, 3 Jan 2024 10:17:24 +0530 Subject: [PATCH 1/2] replace anonymous runnable class with lambda --- .../CompletionProposalPopup2.java | 16 +++---- .../ContextInformationPopup.java | 42 ++++++++----------- 2 files changed, 24 insertions(+), 34 deletions(-) diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java index d48f4bcfe11..f01f839d90f 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java @@ -872,18 +872,14 @@ public void processEvent(VerifyEvent e) { private void filterProposals() { ++ fInvocationCounter; Control control= fViewer.getTextWidget(); - control.getDisplay().asyncExec(new Runnable() { + control.getDisplay().asyncExec(() -> { long fCounter= fInvocationCounter; - @Override - public void run() { - - if (fCounter != fInvocationCounter) - return; - if (fInvocationProcessedCounter == fInvocationCounter) - return; + if (fCounter != fInvocationCounter) + return; + if (fInvocationProcessedCounter == fInvocationCounter) + return; - doFilterProposals(); - } + doFilterProposals(); }); } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java index e9d90400718..9e502723ac5 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java @@ -876,30 +876,24 @@ private void validateContextInformation() { */ if (!isValid(fContextInfoPopup)) return; - - fContextInfoPopup.getDisplay().asyncExec(new Runnable() { - - private ContextFrame fFrame= fContextFrameStack.peek(); - - @Override - public void run() { - // only do this if no other frames have been added in between - if (!fContextFrameStack.isEmpty() && fFrame == fContextFrameStack.peek()) { - int offset= fContentAssistSubjectControlAdapter.getSelectedRange().x; - - // iterate all contexts on the stack - while (isValid(fContextInfoPopup) && !fContextFrameStack.isEmpty()) { - ContextFrame top= fContextFrameStack.peek(); - if (top.fValidator == null || !top.fValidator.isContextInformationValid(offset)) { - hideContextInfoPopup(false); // loop variant: reduces the number of contexts on the stack - } else if (top.fPresenter != null && top.fPresenter.updatePresentation(offset, fTextPresentation)) { - int widgetOffset= fContentAssistSubjectControlAdapter.getWidgetSelectionRange().x; - TextPresentation.applyTextPresentation(fTextPresentation, fContextInfoText); - resize(widgetOffset); - break; - } else - break; - } + fContextInfoPopup.getDisplay().asyncExec(() -> { + ContextFrame fFrame= fContextFrameStack.peek(); + // only do this if no other frames have been added in between + if (!fContextFrameStack.isEmpty() && fFrame == fContextFrameStack.peek()) { + int offset= fContentAssistSubjectControlAdapter.getSelectedRange().x; + + // iterate all contexts on the stack + while (isValid(fContextInfoPopup) && !fContextFrameStack.isEmpty()) { + ContextFrame top= fContextFrameStack.peek(); + if (top.fValidator == null || !top.fValidator.isContextInformationValid(offset)) { + hideContextInfoPopup(false); // loop variant: reduces the number of contexts on the stack + } else if (top.fPresenter != null && top.fPresenter.updatePresentation(offset, fTextPresentation)) { + int widgetOffset= fContentAssistSubjectControlAdapter.getWidgetSelectionRange().x; + TextPresentation.applyTextPresentation(fTextPresentation, fContextInfoText); + resize(widgetOffset); + break; + } else + break; } } }); From 605c8683cc5b4f6431e9fa4712c4c79348ba77ab Mon Sep 17 00:00:00 2001 From: Elsa Zacharia Date: Tue, 9 Jan 2024 10:50:21 +0530 Subject: [PATCH 2/2] fixup: Addressed the review comments --- .../CompletionProposalPopup2.java | 2 +- .../ContextInformationPopup.java | 42 +++++++++++-------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java index f01f839d90f..2d4d5db7789 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java @@ -872,8 +872,8 @@ public void processEvent(VerifyEvent e) { private void filterProposals() { ++ fInvocationCounter; Control control= fViewer.getTextWidget(); + long fCounter= fInvocationCounter; control.getDisplay().asyncExec(() -> { - long fCounter= fInvocationCounter; if (fCounter != fInvocationCounter) return; if (fInvocationProcessedCounter == fInvocationCounter) diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java index 9e502723ac5..e9d90400718 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java @@ -876,24 +876,30 @@ private void validateContextInformation() { */ if (!isValid(fContextInfoPopup)) return; - fContextInfoPopup.getDisplay().asyncExec(() -> { - ContextFrame fFrame= fContextFrameStack.peek(); - // only do this if no other frames have been added in between - if (!fContextFrameStack.isEmpty() && fFrame == fContextFrameStack.peek()) { - int offset= fContentAssistSubjectControlAdapter.getSelectedRange().x; - - // iterate all contexts on the stack - while (isValid(fContextInfoPopup) && !fContextFrameStack.isEmpty()) { - ContextFrame top= fContextFrameStack.peek(); - if (top.fValidator == null || !top.fValidator.isContextInformationValid(offset)) { - hideContextInfoPopup(false); // loop variant: reduces the number of contexts on the stack - } else if (top.fPresenter != null && top.fPresenter.updatePresentation(offset, fTextPresentation)) { - int widgetOffset= fContentAssistSubjectControlAdapter.getWidgetSelectionRange().x; - TextPresentation.applyTextPresentation(fTextPresentation, fContextInfoText); - resize(widgetOffset); - break; - } else - break; + + fContextInfoPopup.getDisplay().asyncExec(new Runnable() { + + private ContextFrame fFrame= fContextFrameStack.peek(); + + @Override + public void run() { + // only do this if no other frames have been added in between + if (!fContextFrameStack.isEmpty() && fFrame == fContextFrameStack.peek()) { + int offset= fContentAssistSubjectControlAdapter.getSelectedRange().x; + + // iterate all contexts on the stack + while (isValid(fContextInfoPopup) && !fContextFrameStack.isEmpty()) { + ContextFrame top= fContextFrameStack.peek(); + if (top.fValidator == null || !top.fValidator.isContextInformationValid(offset)) { + hideContextInfoPopup(false); // loop variant: reduces the number of contexts on the stack + } else if (top.fPresenter != null && top.fPresenter.updatePresentation(offset, fTextPresentation)) { + int widgetOffset= fContentAssistSubjectControlAdapter.getWidgetSelectionRange().x; + TextPresentation.applyTextPresentation(fTextPresentation, fContextInfoText); + resize(widgetOffset); + break; + } else + break; + } } } });