|
1 | 1 | /******************************************************************************* |
2 | | - * Copyright (c) 2000, 2015 IBM Corporation and others. |
| 2 | + * Copyright (c) 2000, 2026 IBM Corporation and others. |
3 | 3 | * |
4 | 4 | * This program and the accompanying materials |
5 | 5 | * are made available under the terms of the Eclipse Public License 2.0 |
|
13 | 13 | *******************************************************************************/ |
14 | 14 | package org.eclipse.jdt.debug.tests.core; |
15 | 15 |
|
| 16 | +import java.util.List; |
| 17 | + |
16 | 18 | import org.eclipse.debug.core.DebugEvent; |
17 | 19 | import org.eclipse.debug.core.DebugPlugin; |
18 | 20 | import org.eclipse.debug.core.IExpressionManager; |
19 | 21 | import org.eclipse.debug.core.model.IValue; |
| 22 | +import org.eclipse.debug.core.model.IVariable; |
20 | 23 | import org.eclipse.debug.core.model.IWatchExpression; |
21 | 24 | import org.eclipse.debug.internal.ui.DebugUIPlugin; |
22 | 25 | import org.eclipse.debug.ui.IDebugUIConstants; |
|
27 | 30 | import org.eclipse.jdt.debug.testplugin.DebugElementEventWaiter; |
28 | 31 | import org.eclipse.jdt.debug.testplugin.ExpressionWaiter; |
29 | 32 | import org.eclipse.jdt.debug.tests.AbstractDebugTest; |
| 33 | +import org.eclipse.jdt.internal.debug.ui.heapwalking.JavaNestedWatchExpressionFilter; |
30 | 34 | import org.eclipse.swt.widgets.Display; |
31 | 35 | import org.eclipse.ui.IWorkbench; |
32 | 36 | import org.eclipse.ui.IWorkbenchPage; |
@@ -165,6 +169,32 @@ public void DisabledtestStepping() throws Exception { |
165 | 169 | } |
166 | 170 | } |
167 | 171 |
|
| 172 | + public void testExpressionContext() throws Exception { |
| 173 | + String typeName = "WatchItemContext"; |
| 174 | + createLineBreakpoint(42, typeName); |
| 175 | + IJavaThread thread = null; |
| 176 | + try { |
| 177 | + thread = launchToBreakpoint(typeName); |
| 178 | + assertNotNull("Breakpoint not hit within timeout period", thread); |
| 179 | + IJavaStackFrame stackFrame = (IJavaStackFrame) thread.getTopStackFrame(); |
| 180 | + IVariable v1 = stackFrame.findVariable("y"); |
| 181 | + IVariable v2 = v1.getValue().getVariables()[2]; |
| 182 | + JavaNestedWatchExpressionFilter javaFilter = new JavaNestedWatchExpressionFilter(); |
| 183 | + assertTrue(javaFilter.canCreateWatchExpression(List.of(v1, v2))); |
| 184 | + String exp = javaFilter.createWatchExpression(List.of(v1, v2)); |
| 185 | + assertEquals("Invalid Expression", "y.y", exp); |
| 186 | + IWatchExpression expression = getExpressionManager().newWatchExpression(exp); |
| 187 | + DebugElementEventWaiter waiter = new ExpressionWaiter(DebugEvent.CHANGE, expression); |
| 188 | + getExpressionManager().addExpression(expression); |
| 189 | + waiter.waitForEvent(); |
| 190 | + assertEquals("Wrong Value", "0", expression.getValue().toString()); |
| 191 | + } finally { |
| 192 | + terminateAndRemove(thread); |
| 193 | + removeAllBreakpoints(); |
| 194 | + removeAllExpressions(); |
| 195 | + } |
| 196 | + } |
| 197 | + |
168 | 198 | /** |
169 | 199 | * Dumps any error messages to the console. |
170 | 200 | */ |
|
0 commit comments