11/*******************************************************************************
2- * Copyright (c) 2018, 2023 Red Hat Inc. and others.
2+ * Copyright (c) 2018, 2026 Red Hat Inc. and others.
33 *
44 * This program and the accompanying materials are made
55 * available under the terms of the Eclipse Public License 2.0
1212 *******************************************************************************/
1313package org .eclipse .wildwebdeveloper .tests ;
1414
15- import static org .junit .jupiter .api .Assertions .assertNotNull ;
1615import static org .junit .jupiter .api .Assertions .assertTrue ;
1716
1817import java .util .concurrent .TimeUnit ;
18+
1919import org .eclipse .core .commands .Command ;
2020import org .eclipse .core .commands .ExecutionEvent ;
2121import org .eclipse .core .resources .IFile ;
2222import org .eclipse .core .resources .IProject ;
2323import org .eclipse .core .resources .ResourcesPlugin ;
2424import org .eclipse .core .runtime .CoreException ;
2525import org .eclipse .jface .text .IDocument ;
26- import org .eclipse .jface .text .ITextViewer ;
27- import org .eclipse .jface .text .link .LinkedModeModel ;
28- import org .eclipse .jface .text .link .LinkedPosition ;
29- import org .eclipse .jface .text .link .LinkedPositionGroup ;
3026import org .eclipse .jface .text .TextSelection ;
31- import org .eclipse .swt . SWT ;
27+ import org .eclipse .jface . text . link . LinkedModeModel ;
3228import org .eclipse .swt .widgets .Control ;
3329import org .eclipse .swt .widgets .Display ;
3430import org .eclipse .swt .widgets .Event ;
@@ -89,9 +85,8 @@ private void internalTestRename(IFile file, String content, String oldName, Stri
8985 file .create (content .getBytes (), true , false , null );
9086
9187 AbstractTextEditor editor = (AbstractTextEditor ) IDE .openEditor (
92- PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getActivePage (), file ,
93- "org.eclipse.ui.genericeditor.GenericEditor"
94- );
88+ PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getActivePage (), file ,
89+ "org.eclipse.ui.genericeditor.GenericEditor" );
9590
9691 editor .getSelectionProvider ().setSelection (new TextSelection (offset , 0 ));
9792 editor .setFocus ();
@@ -116,63 +111,19 @@ private void internalTestRename(IFile file, String content, String oldName, Stri
116111 command .executeWithChecks (executionEvent );
117112
118113 assertTrue (
119- DisplayHelper .waitForCondition (display , 5000 , () -> LinkedModeModel .getModel (document , offset ) != null ),
120- "Linked rename mode did not start"
121- );
114+ DisplayHelper .waitForCondition (display , 5000 , () -> LinkedModeModel .getModel (document , offset ) != null ),
115+ "Linked rename mode did not start" );
122116
123- LinkedModeModel model = LinkedModeModel .getModel (document , offset );
124-
125- display .syncExec (() -> {
117+ display .asyncExec (() -> {
126118 try {
127- for (LinkedPositionGroup group : getLinkedPositionGroups (model )) {
128- for (LinkedPosition pos : group .getPositions ()) {
129- document .replace (pos .getOffset (), pos .getLength (), newName );
130- }
131- }
119+ document .replace (offset , oldName .length (), newName );
132120 } catch (Exception e ) {
133121 throw new RuntimeException (e );
134122 }
135123 });
136124
137- display .syncExec (() -> {
138- ITextViewer viewer = editor .getAdapter (ITextViewer .class );
139- Event enter = new Event ();
140- enter .type = SWT .KeyDown ;
141- enter .character = SWT .CR ;
142- enter .keyCode = SWT .CR ;
143- viewer .getTextWidget ().notifyListeners (SWT .KeyDown , enter );
144- });
145-
146125 assertTrue (DisplayHelper .waitForCondition (display , 5000 , () -> expectedContent .equals (document .get ())),
147- "Rename not applied to document"
148- );
126+ "Rename not applied to document" );
149127 }
150128
151- // LinkedModeModel has no public API to access position groups at this JFace Text level, so tests must use reflection.
152- @ SuppressWarnings ("unchecked" )
153- private static LinkedPositionGroup [] getLinkedPositionGroups (LinkedModeModel model ) {
154- try {
155- for (String fieldName : new String [] { "fGroups" , "fPositionGroups" }) {
156- try {
157- var field = LinkedModeModel .class .getDeclaredField (fieldName );
158- field .setAccessible (true );
159- Object value = field .get (model );
160-
161- if (value instanceof LinkedPositionGroup []) {
162- return (LinkedPositionGroup []) value ;
163- }
164- if (value instanceof java .util .List <?>) {
165- return ((java .util .List <LinkedPositionGroup >) value )
166- .toArray (new LinkedPositionGroup [0 ]);
167- }
168- } catch (NoSuchFieldException e ) {
169- // try next name
170- }
171- }
172- throw new IllegalStateException ("No linked position groups found in LinkedModeModel" );
173- } catch (Exception e ) {
174- throw new RuntimeException (e );
175- }
176- }
177129}
178-
0 commit comments