32
32
import java .util .List ;
33
33
import java .util .Queue ;
34
34
import java .util .Set ;
35
- import java .util .function .BooleanSupplier ;
36
35
import java .util .stream .Collectors ;
37
36
38
37
import org .junit .jupiter .api .AfterEach ;
46
45
47
46
import org .eclipse .swt .SWT ;
48
47
import org .eclipse .swt .custom .ST ;
49
- import org .eclipse .swt .custom .StyledText ;
50
48
import org .eclipse .swt .widgets .Composite ;
51
49
import org .eclipse .swt .widgets .Control ;
52
50
import org .eclipse .swt .widgets .Display ;
@@ -87,7 +85,7 @@ public class CompletionTest extends AbstratGenericEditorTest {
87
85
@ DisabledOnOs (value = OS .MAC , disabledReason = "test fails on Mac, see https://github.com/eclipse-platform/eclipse.platform.ui/issues/906" )
88
86
public void testCompletion () throws Exception {
89
87
editor .selectAndReveal (3 , 0 );
90
- this .completionShell = openConentAssist ( );
88
+ this .completionShell = openContentAssist ( true );
91
89
final Table completionProposalList = findCompletionSelectionControl (completionShell );
92
90
checkCompletionContent (completionProposalList );
93
91
// TODO find a way to actually trigger completion and verify result against
@@ -102,7 +100,7 @@ public void testDefaultContentAssistBug570488() throws Exception {
102
100
TestLogListener listener = new TestLogListener ();
103
101
log .addLogListener (listener );
104
102
createAndOpenFile ("Bug570488.txt" , "bar 'bar'" );
105
- openConentAssist (false );
103
+ openContentAssist (false );
106
104
DisplayHelper .runEventLoop (Display .getCurrent (), 0 );
107
105
assertFalse (listener .messages .stream ().anyMatch (s -> s .matches (IStatus .ERROR )), "There are errors in the log" );
108
106
log .removeLogListener (listener );
@@ -120,10 +118,10 @@ public void testCompletionService() throws Exception {
120
118
new Hashtable <>(Collections .singletonMap ("contentType" , "org.eclipse.ui.genericeditor.tests.content-type" )));
121
119
DisplayHelper .runEventLoop (Display .getCurrent (), 0 );
122
120
editor .selectAndReveal (3 , 0 );
123
- this .completionShell = openConentAssist ( );
121
+ this .completionShell = openContentAssist ( true );
124
122
final Table completionProposalList = findCompletionSelectionControl (completionShell );
125
- checkCompletionContent (completionProposalList );
126
123
assertTrue (service .called , "Service was not called!" );
124
+ checkCompletionContent (completionProposalList );
127
125
registration .unregister ();
128
126
}
129
127
@@ -132,17 +130,12 @@ public void testCompletionService() throws Exception {
132
130
public void testCompletionUsingViewerSelection () throws Exception {
133
131
editor .getDocumentProvider ().getDocument (editor .getEditorInput ()).set ("abc" );
134
132
editor .selectAndReveal (0 , 3 );
135
- this .completionShell = openConentAssist ( );
133
+ this .completionShell = openContentAssist ( true );
136
134
final Table completionProposalList = findCompletionSelectionControl (completionShell );
137
- waitForProposalRelatedCondition ("Proposal list did not contain expected item: ABC" , completionProposalList ,
138
- () -> Arrays .stream (completionProposalList .getItems ()).map (TableItem ::getText ).anyMatch ("ABC" ::equals ), 5_000 );
139
- }
140
-
141
- private static void waitForProposalRelatedCondition (String errorMessage , Table completionProposalList , BooleanSupplier condition , int timeoutInMsec ) {
142
- assertTrue (DisplayHelper .waitForCondition (completionProposalList .getDisplay (), timeoutInMsec , () -> {
135
+ assertTrue (DisplayHelper .waitForCondition (completionProposalList .getDisplay (), 5000 , () -> {
143
136
assertFalse (completionProposalList .isDisposed (), "Completion proposal list was unexpectedly disposed" );
144
- return condition . getAsBoolean ( );
145
- }), errorMessage );
137
+ return Arrays . stream ( completionProposalList . getItems ()). map ( TableItem :: getText ). anyMatch ( "ABC" :: equals );
138
+ }), "Proposal list did not contain expected item: ABC" );
146
139
}
147
140
148
141
@ Test
@@ -151,20 +144,17 @@ public void testEnabledWhenCompletion() throws Exception {
151
144
EnabledPropertyTester .setEnabled (false );
152
145
createAndOpenFile ("enabledWhen.txt" , "bar 'bar'" );
153
146
editor .selectAndReveal (3 , 0 );
154
- assertNull (openConentAssist (false ), "A new shell was found" );
147
+ assertNull (openContentAssist (false ), "A new shell was found" );
155
148
cleanFileAndEditor ();
156
149
157
150
// Confirm that when enabled, a completion shell is present
158
151
EnabledPropertyTester .setEnabled (true );
159
152
createAndOpenFile ("enabledWhen.txt" , "bar 'bar'" );
160
153
editor .selectAndReveal (3 , 0 );
161
- assertNotNull (openConentAssist ( ));
154
+ assertNotNull (openContentAssist ( true ));
162
155
}
163
156
164
- private Shell openConentAssist () {
165
- return openConentAssist (true );
166
- }
167
- private Shell openConentAssist (boolean expectShell ) {
157
+ private Shell openContentAssist (boolean expectShell ) {
168
158
ContentAssistAction action = (ContentAssistAction ) editor .getAction (ITextEditorActionConstants .CONTENT_ASSIST );
169
159
action .update ();
170
160
final Set <Shell > beforeShells = Arrays .stream (editor .getSite ().getShell ().getDisplay ().getShells ()).filter (Shell ::isVisible ).collect (Collectors .toSet ());
@@ -183,19 +173,22 @@ private Shell openConentAssist(boolean expectShell) {
183
173
*/
184
174
private void checkCompletionContent (final Table completionProposalList ) {
185
175
// should be instantaneous, but happens to go asynchronous on CI so let's allow a wait
186
- waitForProposalRelatedCondition ("Proposal list did not show two initial items" , completionProposalList ,
187
- () -> completionProposalList .getItemCount () == 2 , 200 );
188
- assertTrue (isComputingInfoEntry (completionProposalList .getItem (0 )), "Missing computing info entry" );
176
+ assertTrue (DisplayHelper .waitForCondition (completionProposalList .getDisplay (), 200 , () -> {
177
+ assertFalse (completionProposalList .isDisposed (), "Completion proposal list was unexpectedly disposed" );
178
+ return completionProposalList .getItemCount () == 2 && completionProposalList .getItem (1 ).getData () != null ;
179
+ }), "Proposal list did not show two initial items" );
189
180
assertTrue (isComputingInfoEntry (completionProposalList .getItem (0 )), "Missing computing info entry in proposal list" );
190
181
final TableItem initialProposalItem = completionProposalList .getItem (1 );
182
+ System .out .println (initialProposalItem .toString ());
191
183
final String initialProposalString = ((ICompletionProposal )initialProposalItem .getData ()).getDisplayString ();
192
184
assertThat ("Unexpected initial proposal item" ,
193
185
BAR_CONTENT_ASSIST_PROPOSAL , endsWith (initialProposalString ));
194
186
completionProposalList .setSelection (initialProposalItem );
195
187
// asynchronous
196
- waitForProposalRelatedCondition ("Proposal list did not show two items after finishing computing" , completionProposalList ,
197
- () -> !isComputingInfoEntry (completionProposalList .getItem (0 )) && completionProposalList .getItemCount () == 2 ,
198
- LongRunningBarContentAssistProcessor .DELAY + 200 );
188
+ assertTrue (DisplayHelper .waitForCondition (completionProposalList .getDisplay (), LongRunningBarContentAssistProcessor .DELAY * 2 , () -> {
189
+ assertFalse (completionProposalList .isDisposed (), "Completion proposal list was unexpectedly disposed" );
190
+ return !isComputingInfoEntry (completionProposalList .getItem (0 )) && completionProposalList .getItemCount () == 2 ;
191
+ }), "Proposal list did not show two items after finishing computing" );
199
192
final TableItem firstCompletionProposalItem = completionProposalList .getItem (0 );
200
193
final TableItem secondCompletionProposalItem = completionProposalList .getItem (1 );
201
194
String firstCompletionProposalText = ((ICompletionProposal )firstCompletionProposalItem .getData ()).getDisplayString ();
@@ -211,25 +204,27 @@ private static boolean isComputingInfoEntry(TableItem item) {
211
204
}
212
205
213
206
public static Shell findNewShell (Set <Shell > beforeShells , Display display , boolean expectShell ) {
214
- Shell [] afterShells = Arrays .stream (display .getShells ())
207
+ List < Shell > afterShells = Arrays .stream (display .getShells ())
215
208
.filter (Shell ::isVisible )
216
209
.filter (shell -> !beforeShells .contains (shell ))
217
- .toArray ( Shell []:: new );
210
+ .toList ( );
218
211
if (expectShell ) {
219
- assertEquals (1 , afterShells .length , "No new shell found" );
212
+ assertEquals (1 , afterShells .size () , "No new shell found" );
220
213
}
221
- return afterShells .length > 0 ? afterShells [ 0 ] : null ;
214
+ return afterShells .isEmpty () ? null : afterShells . get ( 0 ) ;
222
215
}
223
216
224
217
@ Test
225
218
@ DisabledOnOs (value = OS .MAC , disabledReason = "test fails on Mac, see https://github.com/eclipse-platform/eclipse.platform.ui/issues/906" )
226
219
public void testCompletionFreeze_bug521484 () throws Exception {
227
220
editor .selectAndReveal (3 , 0 );
228
- this .completionShell =openConentAssist ( );
221
+ this .completionShell =openContentAssist ( true );
229
222
final Table completionProposalList = findCompletionSelectionControl (this .completionShell );
230
223
// should be instantaneous, but happens to go asynchronous on CI so let's allow a wait
231
- waitForProposalRelatedCondition ("Proposal list did not show two items" , completionProposalList ,
232
- () -> completionProposalList .getItemCount () == 2 , 200 );
224
+ assertTrue (DisplayHelper .waitForCondition (completionProposalList .getDisplay (), 200 , () -> {
225
+ assertFalse (completionProposalList .isDisposed (), "Completion proposal list was unexpectedly disposed" );
226
+ return completionProposalList .getItemCount () == 2 ;
227
+ }), "Proposal list did not show two items" );
233
228
assertTrue (isComputingInfoEntry (completionProposalList .getItem (0 )), "Missing computing info entry" );
234
229
// Some processors are long running, moving cursor can cause freeze (bug 521484)
235
230
// asynchronous
@@ -254,7 +249,7 @@ public void testMoveCaretBackUsesAllProcessors_bug522255() throws Exception {
254
249
255
250
private void emulatePressLeftArrowKey () {
256
251
editor .selectAndReveal (((ITextSelection )editor .getSelectionProvider ().getSelection ()).getOffset () - 1 , 0 );
257
- StyledText styledText = ( StyledText ) editor .getAdapter (Control .class );
252
+ Control styledText = editor .getAdapter (Control .class );
258
253
Event e = new Event ();
259
254
e .type = ST .VerifyKey ;
260
255
e .widget = styledText ;
0 commit comments