diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIDebugUIPlugin.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIDebugUIPlugin.java index ac2a0b79a2..1ee5661032 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIDebugUIPlugin.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIDebugUIPlugin.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2022 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -383,7 +383,7 @@ public void start(BundleContext context) throws Exception { manager.registerAdapters(monitorFactory, JavaOwningThread.class); manager.registerAdapters(monitorFactory, JavaWaitingThread.class); manager.registerAdapters(monitorFactory, IJavaStackFrame.class); - manager.registerAdapters(monitorFactory, GroupedStackFrame.class); + manager.registerAdapters(monitorFactory, GroupedStackFrame.class); IAdapterFactory targetFactory = new TargetAdapterFactory(); manager.registerAdapters(targetFactory, IJavaDebugTarget.class); @@ -393,7 +393,7 @@ public void start(BundleContext context) throws Exception { IAdapterFactory showInFactory = new JavaDebugShowInAdapterFactory(); manager.registerAdapters(showInFactory, IJavaStackFrame.class); - manager.registerAdapters(showInFactory, GroupedStackFrame.class); + manager.registerAdapters(showInFactory, GroupedStackFrame.class); IAdapterFactory columnFactory = new ColumnPresentationAdapterFactory(); manager.registerAdapters(columnFactory, IJavaVariable.class); diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIDebugUIPreferenceInitializer.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIDebugUIPreferenceInitializer.java index f400e017a2..2d379b99ec 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIDebugUIPreferenceInitializer.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIDebugUIPreferenceInitializer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2020 IBM Corporation and others. + * Copyright (c) 2004, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIModelPresentation.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIModelPresentation.java index c38e099215..5eac44b0fa 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIModelPresentation.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIModelPresentation.java @@ -249,8 +249,7 @@ public String getText(Object item) { return getJavaOwningTreadText((JavaOwningThread)item); } else if (item instanceof JavaWaitingThread) { return getJavaWaitingTreadText((JavaWaitingThread)item); - } else if (item instanceof GroupedStackFrame) { - var groupping = (GroupedStackFrame) item; + } else if (item instanceof GroupedStackFrame groupping) { return getFormattedString(DebugUIMessages.JDIModelPresentation_collapsed_frames, String.valueOf(groupping.getFrameCount())); } else if (item instanceof NoMonitorInformationElement) { return DebugUIMessages.JDIModelPresentation_5; diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/StackFramePresentationProvider.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/StackFramePresentationProvider.java index 8277e23aa3..33a5a2d459 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/StackFramePresentationProvider.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/StackFramePresentationProvider.java @@ -249,9 +249,8 @@ private Category categorizeSourceElement(IJavaStackFrame frame) { if (source == null) { return Category.UNKNOWN; } - if (source instanceof IFile) { + if (source instanceof IFile file) { if (isEnabled(Category.TEST)) { - var file = (IFile) source; var jproj = JavaCore.create(file.getProject()); var cp = jproj.findContainingClasspathEntry(file); if (cp != null && cp.isTest()) { diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/HighlightStackFrameAction.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/HighlightStackFrameAction.java index 97b67ae402..ebd4e2814a 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/HighlightStackFrameAction.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/HighlightStackFrameAction.java @@ -42,16 +42,15 @@ public void run(IAction action) { final var preferenceStore = JDIDebugUIPlugin.getDefault().getPreferenceStore(); final var filterManager = JavaStackFramePreferencePage.CUSTOM_STACK_FRAMES; for (Object selected : selection) { - if (selected instanceof IJavaStackFrame) { - IJavaStackFrame frame = (IJavaStackFrame) selected; + if (selected instanceof IJavaStackFrame frame) { try { addFilter(filterManager, preferenceStore, frame.getDeclaringTypeName()); // Reset all the stack frames, to be evaluated on the next step again. var thread = frame.getThread(); var frames = thread.getStackFrames(); for (var oneFrame : frames) { - if (oneFrame instanceof IJavaStackFrame) { - ((IJavaStackFrame) oneFrame).setCategory(null); + if (oneFrame instanceof IJavaStackFrame currentFrame) { + currentFrame.setCategory(null); } } } catch (DebugException e) { diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/JavaThreadContentProvider.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/JavaThreadContentProvider.java index ab5247da51..470ac94a89 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/JavaThreadContentProvider.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/JavaThreadContentProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2012 IBM Corporation and others. + * Copyright (c) 2006, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -49,8 +49,8 @@ public class JavaThreadContentProvider extends JavaElementContentProvider { */ @Override protected int getChildCount(Object element, IPresentationContext context, IViewerUpdate monitor) throws CoreException { - if (element instanceof GroupedStackFrame) { - return ((GroupedStackFrame) element).getFrameCount(); + if (element instanceof GroupedStackFrame groupedFrame) { + return groupedFrame.getFrameCount(); } IJavaThread thread = (IJavaThread)element; if (!thread.isSuspended()) { @@ -83,8 +83,8 @@ private int getFrameCount(IJavaThread thread) throws DebugException { */ @Override protected Object[] getChildren(Object parent, int index, int length, IPresentationContext context, IViewerUpdate monitor) throws CoreException { - if (parent instanceof GroupedStackFrame) { - return getChildren((GroupedStackFrame) parent, index, length); + if (parent instanceof GroupedStackFrame groupedFrame) { + return getChildren(groupedFrame, index, length); } IJavaThread thread = (IJavaThread)parent; if (!thread.isSuspended()) { @@ -146,8 +146,7 @@ private List getStackFrames(IJavaThread thread) throws DebugException { result.add(frame); first = false; } else { - if (frame instanceof JDIStackFrame) { - var javaFrame = (JDIStackFrame) frame; + if (frame instanceof JDIStackFrame javaFrame) { var category = stackFrameProvider.getCategory(javaFrame); if (category == null || category == Category.TEST || category == Category.PRODUCTION || category == Category.CUSTOM_FILTERED) { result.add(javaFrame); @@ -180,8 +179,8 @@ protected boolean hasChildren(Object element, IPresentationContext context, IVie } } } - if (element instanceof GroupedStackFrame) { - return ((GroupedStackFrame) element).getFrameCount() > 0; + if (element instanceof GroupedStackFrame groupedFrame) { + return groupedFrame.getFrameCount() > 0; } return ((IJavaThread)element).hasStackFrames() || (isDisplayMonitors() && ((IJavaThread)element).hasOwnedMonitors()); diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/sourcelookup/JavaDebugShowInAdapterFactory.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/sourcelookup/JavaDebugShowInAdapterFactory.java index 69c5fe7738..4c7f3855e3 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/sourcelookup/JavaDebugShowInAdapterFactory.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/sourcelookup/JavaDebugShowInAdapterFactory.java @@ -44,9 +44,9 @@ public T getAdapter(Object adaptableObject, Class adapterType) { } } if (adapterType == ISourceDisplay.class) { - if (adaptableObject instanceof GroupedStackFrame) { + if (adaptableObject instanceof GroupedStackFrame groupedFrames) { return (T) (ISourceDisplay) (element, page, forceSourceLookup) -> { - var frame = ((GroupedStackFrame) element).getTopMostFrame(); + var frame = groupedFrames.getTopMostFrame(); SourceLookupFacility.getDefault().displaySource(frame, page, forceSourceLookup); }; } diff --git a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/GroupedStackFrame.java b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/GroupedStackFrame.java index 04fe48c4d4..bb80f93bff 100644 --- a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/GroupedStackFrame.java +++ b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/GroupedStackFrame.java @@ -37,10 +37,6 @@ public int getFrameCount() { return stackFrames.size(); } - public Object[] getFramesAsArray() { - return stackFrames.toArray(); - } - public Object[] getFramesAsArray(int index, int length) { var subList = stackFrames.subList(index, Math.min(index + length, stackFrames.size())); return subList.isEmpty() ? null : subList.toArray();