-
Notifications
You must be signed in to change notification settings - Fork 62
Honor Java Expression's context when creating Watches #926
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
org.eclipse.jdt.debug.tests/testprograms/WatchItemContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2026 IBM Corporation. | ||
| * | ||
| * This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License 2.0 | ||
| * which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Contributors: | ||
| * IBM Corporation - initial API and implementation | ||
| *******************************************************************************/ | ||
|
|
||
| /** | ||
| * WatchItemContext | ||
| */ | ||
| public class WatchItemContext { | ||
|
|
||
| private class X { | ||
| private int x = 0; | ||
| } | ||
|
|
||
| private class Y { | ||
| private X x = new X(); | ||
| private int y = 0; | ||
| } | ||
|
|
||
| private class Z { | ||
| private Y y = new Y(); | ||
| private int z = 0; | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| new WatchItemContext().foo(); | ||
| } | ||
|
|
||
| public void foo() { | ||
| X x = new X(); | ||
| Y y = new Y(); | ||
| Z z = new Z(); | ||
| System.out.println(x + " " + y + " " + z); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
....ui/ui/org/eclipse/jdt/internal/debug/ui/heapwalking/JavaNestedWatchExpressionFilter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2026 IBM Corporation. | ||
| * | ||
| * This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License 2.0 | ||
| * which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Contributors: | ||
| * IBM Corporation - initial API and implementation | ||
| *******************************************************************************/ | ||
| package org.eclipse.jdt.internal.debug.ui.heapwalking; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.eclipse.core.runtime.CoreException; | ||
| import org.eclipse.debug.core.DebugException; | ||
| import org.eclipse.debug.core.model.IVariable; | ||
| import org.eclipse.debug.internal.ui.views.variables.IndexedVariablePartition; | ||
| import org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapter2; | ||
| import org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapterExtension; | ||
| import org.eclipse.jdt.internal.debug.core.logicalstructures.JDIPlaceholderVariable; | ||
| import org.eclipse.jdt.internal.debug.core.model.JDIArrayEntryVariable; | ||
| import org.eclipse.jdt.internal.debug.core.model.JDIPlaceholderValue; | ||
| import org.eclipse.jdt.internal.debug.core.model.JDIReferenceListEntryVariable; | ||
| import org.eclipse.jdt.internal.debug.core.model.JDIReferenceListVariable; | ||
|
|
||
| /** | ||
| * Uses the {@link IWatchExpressionFactoryAdapterExtension} to filter when the watch expression action is available based on the variable selected. | ||
| * | ||
| * Currently removes the action from {@link JDIPlaceholderVariable}s and {@link JDIReferenceListVariable}s. | ||
| */ | ||
| public class JavaNestedWatchExpressionFilter implements IWatchExpressionFactoryAdapter2 { | ||
|
|
||
| @Override | ||
| public String createWatchExpression(Object element) throws CoreException { | ||
| if (element instanceof List<?> expVariablesList) { | ||
| StringBuilder expresion = new StringBuilder(); | ||
| for (Object ob : expVariablesList) { | ||
| if (ob instanceof IVariable variable) { | ||
| String current = variable.getName(); | ||
| expresion.append(current); | ||
| expresion.append('.'); | ||
| } | ||
| } | ||
| expresion.deleteCharAt(expresion.length() - 1); | ||
| return expresion.toString(); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean canCreateWatchExpression(Object variable) { | ||
| if (variable instanceof List<?> expVariablesList) { | ||
| for (Object ob : expVariablesList) { | ||
| if (ob instanceof IVariable variable2) { | ||
| return checkForValidVariable(variable2); | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Checks whether the given {@link IVariable} is suitable for creating a watch expression. | ||
| * <p> | ||
| * Filters out variables that represent internal or synthetic structures (such as reference lists, array entries, indexed partitions) or | ||
| * placeholder values that do not have a concrete value. | ||
| * </p> | ||
| * | ||
| * @param variable | ||
| * the variable to check | ||
| * @return {@code true} if the variable can be used to create a watch expression, {@code false} otherwise | ||
| */ | ||
| private boolean checkForValidVariable(IVariable variable) { | ||
| if (variable instanceof JDIReferenceListVariable || variable instanceof JDIReferenceListEntryVariable | ||
| || variable instanceof JDIArrayEntryVariable || variable instanceof IndexedVariablePartition) { | ||
| return false; | ||
| } | ||
| try { | ||
| if (variable.getValue() instanceof JDIPlaceholderValue) { | ||
| return false; | ||
| } | ||
| } catch (DebugException e) { | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.