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

Automatic cleanups in tests and in ui #582

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -362,9 +362,7 @@ protected static void closeAllEditors() throws RuntimeException {
* @return the handle to the {@link IDebugView} with the given id
*/
protected static IViewPart openView(final String viewId) throws RuntimeException {
return sync(() -> {
return getActivePage().showView(viewId);
});
return sync(() -> getActivePage().showView(viewId));
}

private void assertBreakpointExists(IJavaLineBreakpoint bp, IBreakpoint[] bps) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ protected void waitForNonConsoleJobs() throws Exception {
}

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

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

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

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

Object[] segments = new Object[] { launch, debugTarget, thread, frame };
Object[] segments = { launch, debugTarget, thread, frame };
TreePath newPath = new TreePath(segments);
TreeSelection newSelection = new TreeSelection(newPath);
debugView.getViewer().setSelection(newSelection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void testLastStackElementShown() throws Exception {
// Now we inspect the children of the stopped thread (parent element of selected method)
TreeItem threadItem = sync(() -> selectedTreeItem.getParentItem());
TreeItem[] children = sync(() -> threadItem.getItems());
Object[] childrenText = sync(() -> Arrays.stream(children).map(x -> x.getText()).toArray());
Object[] childrenText = sync(() -> Arrays.stream(children).map(TreeItem::getText).toArray());

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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,8 @@ public ViewManagementTests(String name) {
* Returns whether the specified view is open
*/
protected boolean isViewOpen(final IWorkbenchWindow window, final String id) throws Exception {
final IViewReference[] refs = new IViewReference[1];
sync(new Runnable() {
@Override
public void run() {
refs[0] = window.getActivePage().findViewReference(id);
}
});
return refs[0] != null;
final IViewReference refs = sync(() -> window.getActivePage().findViewReference(id));
return refs != null;
}

@Override
Expand Down Expand Up @@ -275,8 +269,8 @@ private void partsMessage(String header, List<String> partIds, StringBuilder buf
* Adds ids of views to 'expecting open' queue.
*/
protected void expectingViewOpenEvents(IWorkbenchWindow window, String[] viewIds) {
for (int i = 0; i < viewIds.length; i++) {
fExpectingOpenEvents.add(viewIds[i]);
for (String viewId : viewIds) {
fExpectingOpenEvents.add(viewId);
}
window.addPerspectiveListener(this);
}
Expand All @@ -285,8 +279,8 @@ protected void expectingViewOpenEvents(IWorkbenchWindow window, String[] viewIds
* Adds ids of views to 'expecting open' queue.
*/
protected void expectingViewCloseEvents(IWorkbenchWindow window, String[] viewIds) {
for (int i = 0; i < viewIds.length; i++) {
fExpectingCloseEvents.add(viewIds[i]);
for (String viewId : viewIds) {
fExpectingCloseEvents.add(viewId);
}
window.addPerspectiveListener(this);
}
Expand Down Expand Up @@ -351,10 +345,7 @@ public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor persp
* Check if all expected events have occurred.
*/
protected boolean checkComplete() {
if (!fExpectingOpenEvents.isEmpty()) {
return false;
}
if (!fExpectingCloseEvents.isEmpty()) {
if (!fExpectingOpenEvents.isEmpty() || !fExpectingCloseEvents.isEmpty()) {
return false;
}
// all expected events have occurred, notify
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,21 @@ public void testVirtualThreadDebugView() throws Exception {
mainThread = launchToBreakpoint(typeName);
assertNotNull("Launch unsuccessful", mainThread);
openEditorInDebug(file);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
IDebugView debugViewer = (IDebugView) getActivePage().findView(IDebugUIConstants.ID_DEBUG_VIEW);
ISelection currentSelection = debugViewer.getViewer().getSelection();
assertNotNull("Debug View is not available", debugViewer);
if (currentSelection instanceof IStructuredSelection) {
Object sel = ((IStructuredSelection) currentSelection).getFirstElement();
if (sel instanceof IStackFrame stackFrame) {
IThread thread = stackFrame.getThread();
JDIThread vThread = (JDIThread) stackFrame.getThread();
assertTrue("Not a Virtual thread", vThread.isVirtualThread());
StructuredSelection select = new StructuredSelection(thread);
debugViewer.getViewer().setSelection(select, true);
IDebugModelPresentation md = DebugUITools.newDebugModelPresentation();
String groupName = md.getText(thread);
assertTrue("Not a Virtual thread grouping", groupName.contains("Virtual"));
}
Display.getDefault().asyncExec(() -> {
IDebugView debugViewer = (IDebugView) getActivePage().findView(IDebugUIConstants.ID_DEBUG_VIEW);
ISelection currentSelection = debugViewer.getViewer().getSelection();
assertNotNull("Debug View is not available", debugViewer);
if (currentSelection instanceof IStructuredSelection) {
Object sel = ((IStructuredSelection) currentSelection).getFirstElement();
if (sel instanceof IStackFrame stackFrame) {
IThread thread = stackFrame.getThread();
JDIThread vThread = (JDIThread) stackFrame.getThread();
assertTrue("Not a Virtual thread", vThread.isVirtualThread());
StructuredSelection select = new StructuredSelection(thread);
debugViewer.getViewer().setSelection(select, true);
IDebugModelPresentation md = DebugUITools.newDebugModelPresentation();
String groupName = md.getText(thread);
assertTrue("Not a Virtual thread grouping", groupName.contains("Virtual"));
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,8 @@ public boolean updateMarker(IMarker marker, IDocument document, Position positio
loc = new ValidBreakpointLocationLocator(unit, document.getLineOfOffset(position.getOffset()) + 1, true, true);
}
unit.accept(loc);
if(loc.getLocationType() == ValidBreakpointLocationLocator.LOCATION_NOT_FOUND) {
return false;
}
// Remove the watch point if it is not a valid watch point now
if (loc.getLocationType() != ValidBreakpointLocationLocator.LOCATION_FIELD && breakpoint instanceof IJavaWatchpoint) {
if ((loc.getLocationType() == ValidBreakpointLocationLocator.LOCATION_NOT_FOUND) || (loc.getLocationType() != ValidBreakpointLocationLocator.LOCATION_FIELD && breakpoint instanceof IJavaWatchpoint)) {
return false;
}
int line = loc.getLineLocation();
Expand Down Expand Up @@ -203,10 +200,9 @@ private IJavaLineBreakpoint lineBreakpointExists(IResource resource, String type
String markerType= JavaLineBreakpoint.getMarkerType();
IBreakpointManager manager= DebugPlugin.getDefault().getBreakpointManager();
for (IBreakpoint b : manager.getBreakpoints(modelId)) {
if (!(b instanceof IJavaLineBreakpoint)) {
if (!(b instanceof IJavaLineBreakpoint breakpoint)) {
continue;
}
IJavaLineBreakpoint breakpoint = (IJavaLineBreakpoint) b;
IMarker marker = breakpoint.getMarker();
if (marker != null && marker.exists() && marker.getType().equals(markerType) && currentmarker.getId() != marker.getId()) {
String breakpointTypeName = breakpoint.getTypeName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,7 @@ public static IBreakpoint getBreakpointFromEditor(ITextEditor editor, IVerticalR
Iterator<Annotation> iterator = annotationModel.getAnnotationIterator();
while (iterator.hasNext()) {
Object object = iterator.next();
if (object instanceof SimpleMarkerAnnotation) {
SimpleMarkerAnnotation markerAnnotation = (SimpleMarkerAnnotation) object;
if (object instanceof SimpleMarkerAnnotation markerAnnotation) {
IMarker marker = markerAnnotation.getMarker();
try {
if (marker.isSubtypeOf(IBreakpoint.BREAKPOINT_MARKER)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,11 @@
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
Expand Down Expand Up @@ -175,22 +171,14 @@ protected Control createDialogArea(Composite parent) {
fTypeNameText = SWTFactory.createSingleText(innerContainer, 1);
fTypeNameText.setEditable(fEditTypeName);
fTypeNameText.setText(fDetailFormatter.getTypeName());
fTypeNameText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
fTypeSearched= false;
checkValues();
}
fTypeNameText.addModifyListener(e -> {
fTypeSearched= false;
checkValues();
});

Button typeSearchButton = SWTFactory.createPushButton(innerContainer, DebugUIMessages.DetailFormatterDialog_Select__type_4, null);
typeSearchButton.setEnabled(fEditTypeName);
typeSearchButton.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
selectType();
}
});
typeSearchButton.addListener(SWT.Selection, e -> selectType());

String labelText = null;
IBindingService bindingService = workbench.getAdapter(IBindingService.class);
Expand Down Expand Up @@ -373,7 +361,7 @@ public void acceptSearchMatch(SearchMatch match) throws CoreException {
return;
}
IJavaSearchScope scope= SearchEngine.createWorkspaceScope();
SearchParticipant[] participants = new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()};
SearchParticipant[] participants = {SearchEngine.getDefaultSearchParticipant()};
try {
engine.search(searchPattern, participants, scope, collector, monitor);
} catch (CoreException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public void handleEvent(Event event) {

// code for add attribute button
private void addAttribute() {
String[] newAttribute= new String[] {DebugUIMessages.EditLogicalStructureDialog_14, DebugUIMessages.EditLogicalStructureDialog_15}; //
String[] newAttribute= {DebugUIMessages.EditLogicalStructureDialog_14, DebugUIMessages.EditLogicalStructureDialog_15}; //
fAttributesContentProvider.add(newAttribute);
fAttributeListViewer.refresh();
fAttributeListViewer.setSelection(new StructuredSelection((Object)newAttribute));
Expand Down Expand Up @@ -744,7 +744,7 @@ public void acceptSearchMatch(SearchMatch match) throws CoreException {
return;
}
IJavaSearchScope scope= SearchEngine.createWorkspaceScope();
SearchParticipant[] participants = new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()};
SearchParticipant[] participants = {SearchEngine.getDefaultSearchParticipant()};
try {
engine.search(searchPattern, participants, scope, collector, monitor);
} catch (CoreException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,15 @@ private EvaluationContextManager() {
}

public static void startup() {
Runnable r = new Runnable() {
@Override
public void run() {
if (fgManager == null) {
fgManager = new EvaluationContextManager();
IWorkbench workbench = PlatformUI.getWorkbench();
for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) {
fgManager.windowOpened(window);
}
workbench.addWindowListener(fgManager);
fgManager.fActiveWindow = workbench.getActiveWorkbenchWindow();
Runnable r = () -> {
if (fgManager == null) {
fgManager = new EvaluationContextManager();
IWorkbench workbench = PlatformUI.getWorkbench();
for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) {
fgManager.windowOpened(window);
}
workbench.addWindowListener(fgManager);
fgManager.fActiveWindow = workbench.getActiveWorkbenchWindow();
}
};
JDIDebugUIPlugin.getStandardDisplay().asyncExec(r);
Expand Down Expand Up @@ -255,8 +252,7 @@ public void debugContextChanged(DebugContextEvent event) {
if (part != null) {
IWorkbenchPage page = part.getSite().getPage();
ISelection selection = event.getContext();
if (selection instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection)selection;
if (selection instanceof IStructuredSelection ss) {
if (ss.size() == 1) {
Object element = ss.getFirstElement();
if (element instanceof IAdaptable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public class EvaluationContextStatusHandler implements IStatusHandler {
*/
@Override
public Object handleStatus(IStatus status, Object source) {
if (source instanceof IDebugElement) {
IDebugElement element = (IDebugElement) source;
if (source instanceof IDebugElement element) {
IJavaDebugTarget target = element.getDebugTarget().getAdapter(IJavaDebugTarget.class);
if (target != null) {
IJavaStackFrame frame = EvaluationContextManager.getEvaluationContext((IWorkbenchWindow)null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public class EvaluationStackFrameContextStatusHandler implements IStatusHandler
*/
@Override
public Object handleStatus(IStatus status, Object source) {
if (source instanceof IDebugElement) {
IDebugElement element = (IDebugElement) source;
if (source instanceof IDebugElement element) {
IJavaDebugTarget target = element.getDebugTarget().getAdapter(IJavaDebugTarget.class);
if (target != null) {
IJavaStackFrame frame = EvaluationContextManager.getEvaluationContext((IWorkbenchWindow)null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,7 @@ protected void createContent(Composite parent) {
// copy over properties
IPresentationContext copy = ((TreeModelViewer)view.getViewer()).getPresentationContext();
String[] properties = copy.getProperties();
for (int i = 0; i < properties.length; i++) {
String key = properties[i];
for (String key : properties) {
fContext.setProperty(key, copy.getProperty(key));
}
}
Expand All @@ -314,16 +313,15 @@ protected void createContent(Composite parent) {
StructuredViewer structuredViewer = (StructuredViewer) view.getViewer();
if (structuredViewer != null) {
ViewerFilter[] filters = structuredViewer.getFilters();
for (int i = 0; i < filters.length; i++) {
fViewer.addFilter(filters[i]);
for (ViewerFilter filter : filters) {
fViewer.addFilter(filter);
}
}
}

fDetailPaneComposite = SWTFactory.createComposite(fSashForm, 1, 1, GridData.FILL_BOTH);
Layout layout = fDetailPaneComposite.getLayout();
if (layout instanceof GridLayout) {
GridLayout gl = (GridLayout) layout;
if (layout instanceof GridLayout gl) {
gl.marginHeight = 0;
gl.marginWidth = 0;
}
Expand Down Expand Up @@ -402,7 +400,7 @@ protected void initSashWeights(){
if (tree > 0) {
int details = getIntSetting(settings, SASH_WEIGHT_DETAILS);
if (details > 0) {
fSashForm.setWeights(new int[]{tree, details});
fSashForm.setWeights(tree, details);
}
}
}
Expand Down
Loading
Loading