Skip to content

Commit 05ca613

Browse files
committed
Automatic cleanups in tests and in ui
1 parent 5b7b412 commit 05ca613

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+559
-823
lines changed

org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/AbstractDebugUiTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,7 @@ protected static void closeAllEditors() throws RuntimeException {
362362
* @return the handle to the {@link IDebugView} with the given id
363363
*/
364364
protected static IViewPart openView(final String viewId) throws RuntimeException {
365-
return sync(() -> {
366-
return getActivePage().showView(viewId);
367-
});
365+
return sync(() -> getActivePage().showView(viewId));
368366
}
369367

370368
private void assertBreakpointExists(IJavaLineBreakpoint bp, IBreakpoint[] bps) throws Exception {

org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/AbstractDebugViewTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ protected void waitForNonConsoleJobs() throws Exception {
208208
}
209209

210210
protected Object[] selectedText(TreeItem[] selected) throws Exception {
211-
Object[] selectedText = sync(() -> Arrays.stream(selected).map(x -> x.getText()).toArray());
211+
Object[] selectedText = sync(() -> Arrays.stream(selected).map(TreeItem::getText).toArray());
212212
return selectedText;
213213
}
214214

@@ -230,7 +230,7 @@ protected void terminateAndCleanUp(IJavaThread thread) throws Exception {
230230
}
231231

232232
protected String dumpFrames(Object[] childrenData) {
233-
return Arrays.toString(Arrays.stream(childrenData).map(x -> Objects.toString(x)).toArray());
233+
return Arrays.toString(Arrays.stream(childrenData).map(Objects::toString).toArray());
234234
}
235235

236236
protected TreeItem[] getSelectedItemsFromDebugView(boolean wait) throws Exception {
@@ -263,7 +263,7 @@ protected void setDebugViewSelection(IThread thread) throws Exception {
263263
IDebugTarget debugTarget = thread.getDebugTarget();
264264
ILaunch launch = debugTarget.getLaunch();
265265

266-
Object[] segments = new Object[] { launch, debugTarget, thread, frame };
266+
Object[] segments = { launch, debugTarget, thread, frame };
267267
TreePath newPath = new TreePath(segments);
268268
TreeSelection newSelection = new TreeSelection(newPath);
269269
debugView.getViewer().setSelection(newSelection);

org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/DebugViewTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void testLastStackElementShown() throws Exception {
8787
// Now we inspect the children of the stopped thread (parent element of selected method)
8888
TreeItem threadItem = sync(() -> selectedTreeItem.getParentItem());
8989
TreeItem[] children = sync(() -> threadItem.getItems());
90-
Object[] childrenText = sync(() -> Arrays.stream(children).map(x -> x.getText()).toArray());
90+
Object[] childrenText = sync(() -> Arrays.stream(children).map(TreeItem::getText).toArray());
9191

9292
// we expect to see one monitor + frames
9393
final int expectedChildrenCount = expectedFramesNumber + 1;

org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/InstructionPointerManagerTests.java

Lines changed: 127 additions & 168 deletions
Large diffs are not rendered by default.

org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/ViewManagementTests.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,8 @@ public ViewManagementTests(String name) {
7777
* Returns whether the specified view is open
7878
*/
7979
protected boolean isViewOpen(final IWorkbenchWindow window, final String id) throws Exception {
80-
final IViewReference[] refs = new IViewReference[1];
81-
sync(new Runnable() {
82-
@Override
83-
public void run() {
84-
refs[0] = window.getActivePage().findViewReference(id);
85-
}
86-
});
87-
return refs[0] != null;
80+
final IViewReference refs = sync(() -> window.getActivePage().findViewReference(id));
81+
return refs != null;
8882
}
8983

9084
@Override
@@ -275,8 +269,8 @@ private void partsMessage(String header, List<String> partIds, StringBuilder buf
275269
* Adds ids of views to 'expecting open' queue.
276270
*/
277271
protected void expectingViewOpenEvents(IWorkbenchWindow window, String[] viewIds) {
278-
for (int i = 0; i < viewIds.length; i++) {
279-
fExpectingOpenEvents.add(viewIds[i]);
272+
for (String viewId : viewIds) {
273+
fExpectingOpenEvents.add(viewId);
280274
}
281275
window.addPerspectiveListener(this);
282276
}
@@ -285,8 +279,8 @@ protected void expectingViewOpenEvents(IWorkbenchWindow window, String[] viewIds
285279
* Adds ids of views to 'expecting open' queue.
286280
*/
287281
protected void expectingViewCloseEvents(IWorkbenchWindow window, String[] viewIds) {
288-
for (int i = 0; i < viewIds.length; i++) {
289-
fExpectingCloseEvents.add(viewIds[i]);
282+
for (String viewId : viewIds) {
283+
fExpectingCloseEvents.add(viewId);
290284
}
291285
window.addPerspectiveListener(this);
292286
}
@@ -351,10 +345,7 @@ public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor persp
351345
* Check if all expected events have occurred.
352346
*/
353347
protected boolean checkComplete() {
354-
if (!fExpectingOpenEvents.isEmpty()) {
355-
return false;
356-
}
357-
if (!fExpectingCloseEvents.isEmpty()) {
348+
if (!fExpectingOpenEvents.isEmpty() || !fExpectingCloseEvents.isEmpty()) {
358349
return false;
359350
}
360351
// all expected events have occurred, notify

org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/VirtualThreadsDebugViewTests.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,24 +94,21 @@ public void testVirtualThreadDebugView() throws Exception {
9494
mainThread = launchToBreakpoint(typeName);
9595
assertNotNull("Launch unsuccessful", mainThread);
9696
openEditorInDebug(file);
97-
Display.getDefault().asyncExec(new Runnable() {
98-
@Override
99-
public void run() {
100-
IDebugView debugViewer = (IDebugView) getActivePage().findView(IDebugUIConstants.ID_DEBUG_VIEW);
101-
ISelection currentSelection = debugViewer.getViewer().getSelection();
102-
assertNotNull("Debug View is not available", debugViewer);
103-
if (currentSelection instanceof IStructuredSelection) {
104-
Object sel = ((IStructuredSelection) currentSelection).getFirstElement();
105-
if (sel instanceof IStackFrame stackFrame) {
106-
IThread thread = stackFrame.getThread();
107-
JDIThread vThread = (JDIThread) stackFrame.getThread();
108-
assertTrue("Not a Virtual thread", vThread.isVirtualThread());
109-
StructuredSelection select = new StructuredSelection(thread);
110-
debugViewer.getViewer().setSelection(select, true);
111-
IDebugModelPresentation md = DebugUITools.newDebugModelPresentation();
112-
String groupName = md.getText(thread);
113-
assertTrue("Not a Virtual thread grouping", groupName.contains("Virtual"));
114-
}
97+
Display.getDefault().asyncExec(() -> {
98+
IDebugView debugViewer = (IDebugView) getActivePage().findView(IDebugUIConstants.ID_DEBUG_VIEW);
99+
ISelection currentSelection = debugViewer.getViewer().getSelection();
100+
assertNotNull("Debug View is not available", debugViewer);
101+
if (currentSelection instanceof IStructuredSelection) {
102+
Object sel = ((IStructuredSelection) currentSelection).getFirstElement();
103+
if (sel instanceof IStackFrame stackFrame) {
104+
IThread thread = stackFrame.getThread();
105+
JDIThread vThread = (JDIThread) stackFrame.getThread();
106+
assertTrue("Not a Virtual thread", vThread.isVirtualThread());
107+
StructuredSelection select = new StructuredSelection(thread);
108+
debugViewer.getViewer().setSelection(select, true);
109+
IDebugModelPresentation md = DebugUITools.newDebugModelPresentation();
110+
String groupName = md.getText(thread);
111+
assertTrue("Not a Virtual thread grouping", groupName.contains("Virtual"));
115112
}
116113
}
117114
});

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/BreakpointMarkerUpdater.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,8 @@ public boolean updateMarker(IMarker marker, IDocument document, Position positio
129129
loc = new ValidBreakpointLocationLocator(unit, document.getLineOfOffset(position.getOffset()) + 1, true, true);
130130
}
131131
unit.accept(loc);
132-
if(loc.getLocationType() == ValidBreakpointLocationLocator.LOCATION_NOT_FOUND) {
133-
return false;
134-
}
135132
// Remove the watch point if it is not a valid watch point now
136-
if (loc.getLocationType() != ValidBreakpointLocationLocator.LOCATION_FIELD && breakpoint instanceof IJavaWatchpoint) {
133+
if ((loc.getLocationType() == ValidBreakpointLocationLocator.LOCATION_NOT_FOUND) || (loc.getLocationType() != ValidBreakpointLocationLocator.LOCATION_FIELD && breakpoint instanceof IJavaWatchpoint)) {
137134
return false;
138135
}
139136
int line = loc.getLineLocation();
@@ -203,10 +200,9 @@ private IJavaLineBreakpoint lineBreakpointExists(IResource resource, String type
203200
String markerType= JavaLineBreakpoint.getMarkerType();
204201
IBreakpointManager manager= DebugPlugin.getDefault().getBreakpointManager();
205202
for (IBreakpoint b : manager.getBreakpoints(modelId)) {
206-
if (!(b instanceof IJavaLineBreakpoint)) {
203+
if (!(b instanceof IJavaLineBreakpoint breakpoint)) {
207204
continue;
208205
}
209-
IJavaLineBreakpoint breakpoint = (IJavaLineBreakpoint) b;
210206
IMarker marker = breakpoint.getMarker();
211207
if (marker != null && marker.exists() && marker.getType().equals(markerType) && currentmarker.getId() != marker.getId()) {
212208
String breakpointTypeName = breakpoint.getTypeName();

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/BreakpointUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,7 @@ public static IBreakpoint getBreakpointFromEditor(ITextEditor editor, IVerticalR
345345
Iterator<Annotation> iterator = annotationModel.getAnnotationIterator();
346346
while (iterator.hasNext()) {
347347
Object object = iterator.next();
348-
if (object instanceof SimpleMarkerAnnotation) {
349-
SimpleMarkerAnnotation markerAnnotation = (SimpleMarkerAnnotation) object;
348+
if (object instanceof SimpleMarkerAnnotation markerAnnotation) {
350349
IMarker marker = markerAnnotation.getMarker();
351350
try {
352351
if (marker.isSubtypeOf(IBreakpoint.BREAKPOINT_MARKER)) {

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DetailFormatterDialog.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,11 @@
5353
import org.eclipse.jface.text.source.ISourceViewer;
5454
import org.eclipse.osgi.util.NLS;
5555
import org.eclipse.swt.SWT;
56-
import org.eclipse.swt.events.ModifyEvent;
57-
import org.eclipse.swt.events.ModifyListener;
5856
import org.eclipse.swt.graphics.Font;
5957
import org.eclipse.swt.layout.GridData;
6058
import org.eclipse.swt.widgets.Button;
6159
import org.eclipse.swt.widgets.Composite;
6260
import org.eclipse.swt.widgets.Control;
63-
import org.eclipse.swt.widgets.Event;
64-
import org.eclipse.swt.widgets.Listener;
6561
import org.eclipse.swt.widgets.Shell;
6662
import org.eclipse.swt.widgets.Text;
6763
import org.eclipse.ui.IWorkbench;
@@ -175,22 +171,14 @@ protected Control createDialogArea(Composite parent) {
175171
fTypeNameText = SWTFactory.createSingleText(innerContainer, 1);
176172
fTypeNameText.setEditable(fEditTypeName);
177173
fTypeNameText.setText(fDetailFormatter.getTypeName());
178-
fTypeNameText.addModifyListener(new ModifyListener() {
179-
@Override
180-
public void modifyText(ModifyEvent e) {
181-
fTypeSearched= false;
182-
checkValues();
183-
}
174+
fTypeNameText.addModifyListener(e -> {
175+
fTypeSearched= false;
176+
checkValues();
184177
});
185178

186179
Button typeSearchButton = SWTFactory.createPushButton(innerContainer, DebugUIMessages.DetailFormatterDialog_Select__type_4, null);
187180
typeSearchButton.setEnabled(fEditTypeName);
188-
typeSearchButton.addListener(SWT.Selection, new Listener() {
189-
@Override
190-
public void handleEvent(Event e) {
191-
selectType();
192-
}
193-
});
181+
typeSearchButton.addListener(SWT.Selection, e -> selectType());
194182

195183
String labelText = null;
196184
IBindingService bindingService = workbench.getAdapter(IBindingService.class);
@@ -373,7 +361,7 @@ public void acceptSearchMatch(SearchMatch match) throws CoreException {
373361
return;
374362
}
375363
IJavaSearchScope scope= SearchEngine.createWorkspaceScope();
376-
SearchParticipant[] participants = new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()};
364+
SearchParticipant[] participants = {SearchEngine.getDefaultSearchParticipant()};
377365
try {
378366
engine.search(searchPattern, participants, scope, collector, monitor);
379367
} catch (CoreException e) {

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EditLogicalStructureDialog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ public void handleEvent(Event event) {
428428

429429
// code for add attribute button
430430
private void addAttribute() {
431-
String[] newAttribute= new String[] {DebugUIMessages.EditLogicalStructureDialog_14, DebugUIMessages.EditLogicalStructureDialog_15}; //
431+
String[] newAttribute= {DebugUIMessages.EditLogicalStructureDialog_14, DebugUIMessages.EditLogicalStructureDialog_15}; //
432432
fAttributesContentProvider.add(newAttribute);
433433
fAttributeListViewer.refresh();
434434
fAttributeListViewer.setSelection(new StructuredSelection((Object)newAttribute));
@@ -744,7 +744,7 @@ public void acceptSearchMatch(SearchMatch match) throws CoreException {
744744
return;
745745
}
746746
IJavaSearchScope scope= SearchEngine.createWorkspaceScope();
747-
SearchParticipant[] participants = new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()};
747+
SearchParticipant[] participants = {SearchEngine.getDefaultSearchParticipant()};
748748
try {
749749
engine.search(searchPattern, participants, scope, collector, monitor);
750750
} catch (CoreException e) {

0 commit comments

Comments
 (0)