Skip to content

Commit

Permalink
Couple of code cleanups around the GroupedStackFrames and other classes
Browse files Browse the repository at this point in the history
  • Loading branch information
gzsombor committed Dec 11, 2024
1 parent 873702d commit 86af524
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -146,8 +146,7 @@ private List<Object> 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);
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public <T> T getAdapter(Object adaptableObject, Class<T> 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);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 86af524

Please sign in to comment.