Skip to content

Commit 79f0f53

Browse files
committed
Improve o.e.text.tests.Accessor usages
* Make it varargs to reduce needless code * Use adapters instead of reflection where possible
1 parent 805b5b9 commit 79f0f53

File tree

12 files changed

+36
-48
lines changed

12 files changed

+36
-48
lines changed

tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/ContextInformationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017, 2020 Stephan Wahlbrink and others.
2+
* Copyright (c) 2017, 2025 Stephan Wahlbrink and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -87,7 +87,7 @@ public void testContextInfo_hide_Bug512251() throws Exception {
8787
// ITextEditorActionConstants.DELETE_LINE
8888
getDocument().set("");
8989

90-
new Accessor(getContentAssistant(), ContentAssistant.class).invoke("hide", new Object[0]);
90+
new Accessor(getContentAssistant(), ContentAssistant.class).invoke("hide");
9191
}
9292

9393
@Test

tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/reconciler/AbstractReconcilerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2011 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -403,17 +403,17 @@ void pollUntilInactive() throws InterruptedException {
403403
}
404404

405405
boolean isActive() {
406-
Object bool= fAccessor.invoke("isActive", null);
406+
Object bool= fAccessor.invoke("isActive");
407407
return ((Boolean) bool).booleanValue();
408408
}
409409

410410
boolean isCanceled() {
411-
Object bool= fAccessor.invoke("isCanceled", null);
411+
Object bool= fAccessor.invoke("isCanceled");
412412
return ((Boolean)bool).booleanValue();
413413
}
414414

415415
boolean isDirty() {
416-
Object bool= fAccessor.invoke("isDirty", null);
416+
Object bool= fAccessor.invoke("isDirty");
417417
return ((Boolean) bool).booleanValue();
418418
}
419419

tests/org.eclipse.text.tests/src/org/eclipse/text/tests/Accessor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2016 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -146,7 +146,7 @@ public Accessor(String className, ClassLoader classLoader) {
146146
* @param arguments the method arguments which must all be instance of Object
147147
* @return the method return value
148148
*/
149-
public Object invoke(String methodName, Object[] arguments) {
149+
public Object invoke(String methodName, Object... arguments) {
150150
return invoke(methodName, getTypes(arguments), arguments);
151151
}
152152

@@ -158,7 +158,7 @@ public Object invoke(String methodName, Object[] arguments) {
158158
* @param arguments the method arguments
159159
* @return the method return value
160160
*/
161-
public Object invoke(String methodName, Class<?>[] types, Object[] arguments) {
161+
public Object invoke(String methodName, Class<?>[] types, Object... arguments) {
162162
Method method= null;
163163
try {
164164
method = fClass.getDeclaredMethod(methodName, types);
@@ -281,7 +281,7 @@ public Field getField(String fieldName) {
281281
}
282282
}
283283

284-
private static Class<?>[] getTypes(Object[] objects) {
284+
private static Class<?>[] getTypes(Object... objects) {
285285
if (objects == null)
286286
return null;
287287

tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/GotoLineTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2008 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -101,7 +101,7 @@ private void goToLine(int line, int expectedResult) {
101101
ITextEditor editor= (ITextEditor) part;
102102
IAction action= editor.getAction(ITextEditorActionConstants.GOTO_LINE);
103103
Accessor accessor= new Accessor(action, GotoLineAction.class);
104-
accessor.invoke("gotoLine", new Class[] {int.class}, new Integer[] {Integer.valueOf(line)});
104+
accessor.invoke("gotoLine", new Class[] { int.class }, Integer.valueOf(line));
105105
Control control= part.getAdapter(Control.class);
106106
if (control instanceof StyledText) {
107107
int caretLine= -1;

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AbstratGenericEditorTest.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016 Red Hat Inc. and others
2+
* Copyright (c) 2016, 2025 Red Hat Inc. and others
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -26,10 +26,6 @@
2626
import org.eclipse.core.resources.IProject;
2727
import org.eclipse.core.resources.ResourcesPlugin;
2828

29-
import org.eclipse.text.tests.Accessor;
30-
31-
import org.eclipse.jface.text.source.SourceViewer;
32-
3329
import org.eclipse.ui.IEditorInput;
3430
import org.eclipse.ui.IWorkbenchWindow;
3531
import org.eclipse.ui.PlatformUI;
@@ -38,8 +34,6 @@
3834
import org.eclipse.ui.part.FileEditorInput;
3935
import org.eclipse.ui.tests.harness.util.UITestCase;
4036

41-
import org.eclipse.ui.texteditor.AbstractTextEditor;
42-
4337
/**
4438
* Closes intro, create {@link #project}, create {@link #file} and open {@link #editor}; and clean up.
4539
* Also contains additional utility methods
@@ -117,11 +111,6 @@ protected void cleanFileAndEditor() throws Exception {
117111
}
118112
}
119113

120-
protected SourceViewer getSourceViewer() {
121-
SourceViewer sourceViewer= (SourceViewer) new Accessor(editor, AbstractTextEditor.class).invoke("getSourceViewer", new Object[0]);
122-
return sourceViewer;
123-
}
124-
125114
@After
126115
public void tearDown() throws Exception {
127116
cleanFileAndEditor();

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/BasicEditionTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2020 Red Hat Inc. and others
2+
* Copyright (c) 2020, 2025 Red Hat Inc. and others
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -15,6 +15,7 @@
1515
import org.junit.Test;
1616

1717
import org.eclipse.jface.text.IDocument;
18+
import org.eclipse.jface.text.ITextViewer;
1819

1920
public class BasicEditionTest extends AbstratGenericEditorTest{
2021

@@ -25,16 +26,17 @@ protected void createAndOpenFile() throws Exception {
2526

2627
@Test
2728
public void testNewLineHasIndent() {
28-
IDocument doc = getSourceViewer().getDocument();
29+
ITextViewer sourceViewer = editor.getAdapter(ITextViewer.class);
30+
IDocument doc = sourceViewer.getDocument();
2931
// Tab only
3032
doc.set("\t");
31-
getSourceViewer().setSelectedRange(doc.getLength(), 1);
32-
getSourceViewer().getTextWidget().insert("\n");
33+
sourceViewer.setSelectedRange(doc.getLength(), 1);
34+
sourceViewer.getTextWidget().insert("\n");
3335
assertEquals("\t\n\t", doc.get());
3436
// Space only
3537
doc.set(" ");
36-
getSourceViewer().setSelectedRange(doc.getLength(), 1);
37-
getSourceViewer().getTextWidget().insert("\n");
38+
sourceViewer.setSelectedRange(doc.getLength(), 1);
39+
sourceViewer.getTextWidget().insert("\n");
3840
assertEquals(" \n ", doc.get());
3941
}
4042
}

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/ContextInfoTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017 Stephan Wahlbrink and others.
2+
* Copyright (c) 2017, 2025 Stephan Wahlbrink and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -31,6 +31,7 @@
3131

3232
import org.eclipse.text.tests.Accessor;
3333

34+
import org.eclipse.jface.text.ITextViewer;
3435
import org.eclipse.jface.text.contentassist.ContentAssistant;
3536
import org.eclipse.jface.text.source.SourceViewer;
3637

@@ -95,9 +96,9 @@ public void testContextInfo_hide_Bug512251() throws Exception {
9596

9697
editor.getAction(ITextEditorActionConstants.DELETE_LINE).run();
9798

98-
SourceViewer sourceViewer= getSourceViewer();
99+
ITextViewer sourceViewer= editor.getAdapter(ITextViewer.class);
99100
ContentAssistant assist= (ContentAssistant) new Accessor(sourceViewer, SourceViewer.class).get("fContentAssistant");
100-
new Accessor(assist, ContentAssistant.class).invoke("hide", new Object[0]);
101+
new Accessor(assist, ContentAssistant.class).invoke("hide");
101102
}
102103

103104

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2017 Red Hat Inc. and others
2+
* Copyright (c) 2016, 2025 Red Hat Inc. and others
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -58,8 +58,6 @@
5858

5959
import org.eclipse.ui.workbench.texteditor.tests.ScreenshotTest;
6060

61-
import org.eclipse.ui.texteditor.AbstractTextEditor;
62-
6361
/**
6462
* @since 1.0
6563
*/
@@ -232,7 +230,7 @@ private AbstractInformationControlManager triggerCompletionAndRetrieveInformatio
232230
boolean foundHoverData = false;
233231
int attemptNumber = 0;
234232

235-
ITextViewer viewer= (ITextViewer) new Accessor(editor, AbstractTextEditor.class).invoke("getSourceViewer", new Object[0]);
233+
ITextViewer viewer= editor.getAdapter(ITextViewer.class);
236234
AbstractInformationControlManager textHoverManager= (AbstractInformationControlManager) new Accessor(viewer, TextViewer.class).get("fTextHoverManager");
237235

238236
while (!foundHoverData && attemptNumber++ < MAXIMUM_HOVER_RETRY_COUNT) {

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/ShowInformationTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2021 Red Hat Inc. and others
2+
* Copyright (c) 2021, 2025 Red Hat Inc. and others
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -47,8 +47,6 @@
4747

4848
import org.eclipse.ui.workbench.texteditor.tests.ScreenshotTest;
4949

50-
import org.eclipse.ui.texteditor.AbstractTextEditor;
51-
5250
/**
5351
* @since 1.2
5452
*/
@@ -151,7 +149,7 @@ protected boolean condition() {
151149
editorTextWidget.getShell().setFocus();
152150
editorTextWidget.getShell().getDisplay().wake();
153151

154-
ITextViewer viewer= (ITextViewer) new Accessor(editor, AbstractTextEditor.class).invoke("getSourceViewer", new Object[0]);
152+
ITextViewer viewer= editor.getAdapter(ITextViewer.class);
155153

156154
ITextOperationTarget textOperationTarget = (ITextOperationTarget)viewer;
157155
assertTrue(textOperationTarget.canDoOperation(ISourceViewer.INFORMATION));

tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlayTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2024 Vector Informatik GmbH and others.
2+
* Copyright (c) 2024, 2025 Vector Informatik GmbH and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -45,7 +45,7 @@ public class FindReplaceOverlayTest extends FindReplaceUITest<OverlayAccess> {
4545
@Override
4646
public OverlayAccess openUIFromTextViewer(TextViewer viewer) {
4747
Accessor actionAccessor= new Accessor(getFindReplaceAction(), FindReplaceAction.class);
48-
actionAccessor.invoke("showOverlayInEditor", null);
48+
actionAccessor.invoke("showOverlayInEditor");
4949
FindReplaceOverlay overlay= (FindReplaceOverlay) actionAccessor.get("overlay");
5050
OverlayAccess uiAccess= new OverlayAccess(getFindReplaceTarget(), overlay);
5151
waitForFocus(uiAccess::hasFocus, testName.getMethodName());

0 commit comments

Comments
 (0)