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

fix ClassCastException in ContinuousTypingCompletionTest #1835 #1837

Merged
merged 1 commit into from
Dec 6, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@

public class ContinuousTypingCompletionTest extends AbstractCompletionTest {
private final static class CompletionSelectionTracker implements ICompletionListener {
private ICompletionProposal fSelectedProposal;
private AbstractJavaCompletionProposal fSelectedProposal;

@Override
public void selectionChanged(ICompletionProposal proposal, boolean smartToggle) {
this.fSelectedProposal= proposal;
if (proposal instanceof AbstractJavaCompletionProposal p) {
this.setSelectedProposal(p);
}
}

@Override
Expand All @@ -56,8 +58,12 @@ public void assistSessionEnded(ContentAssistEvent event) {
// not used
}

public AbstractJavaCompletionProposal getSelectedProposal() {
return (AbstractJavaCompletionProposal) this.fSelectedProposal;
public synchronized AbstractJavaCompletionProposal getSelectedProposal() {
return this.fSelectedProposal;
}

public synchronized void setSelectedProposal(AbstractJavaCompletionProposal selectedProposal) {
fSelectedProposal = selectedProposal;
}
}

Expand All @@ -84,11 +90,23 @@ public void testContinousTypingSelectsTopProposal() throws Exception {
CompletionSelectionTracker selectionTracker= new CompletionSelectionTracker();
((JavaSourceViewer) fEditor.getViewer()).getContentAssistantFacade().addCompletionListener(selectionTracker);
fEditor.getAction(ITextEditorActionConstants.CONTENT_ASSIST).run();
new DisplayHelper() {
@Override
public boolean condition() {
return selectionTracker.getSelectedProposal()!=null;
}
}.waitForCondition(display, 10000);
assertEquals("ab", selectionTracker.getSelectedProposal().getJavaElement().getElementName());
IDocument document= fEditor.getViewer().getDocument();
document.replace(completionOffset, 0, "b");
selectionTracker.setSelectedProposal(null);
fEditor.getViewer().setSelectedRange(completionOffset + 1, 0);
DisplayHelper.sleep(display, 500);
new DisplayHelper() {
@Override
public boolean condition() {
return selectionTracker.getSelectedProposal()!=null;
}
}.waitForCondition(display, 10000);
assertEquals("ba", selectionTracker.getSelectedProposal().getJavaElement().getElementName());
}

Expand Down
Loading