Skip to content

Commit 6281898

Browse files
committed
Add tests
1 parent baac137 commit 6281898

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 IBM Corporation.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* IBM Corporation - initial API and implementation
13+
*******************************************************************************/
14+
15+
/**
16+
* WatchItemContext
17+
*/
18+
public class WatchItemContext {
19+
20+
private class X {
21+
private int x = 0;
22+
}
23+
24+
private class Y {
25+
private X x = new X();
26+
private int y = 0;
27+
}
28+
29+
private class Z {
30+
private Y y = new Y();
31+
private int z = 0;
32+
}
33+
34+
public static void main(String[] args) {
35+
new WatchItemContext().foo();
36+
}
37+
38+
public void foo() {
39+
X x = new X();
40+
Y y = new Y();
41+
Z z = new Z();
42+
System.out.println(x + " " + y + " " + z);
43+
}
44+
}

org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public abstract class AbstractDebugTest extends TestCase implements IEvaluation
219219
"OutSync", "OutSync2", "ConsoleOutputUmlaut", "ErrorRecurrence", "ModelPresentationTests", "Bug565982",
220220
"SuspendVMConditionalBreakpointsTestSnippet", "FileConditionSnippet2", "compare.CompareObjectsStringTest", "compare.CompareListObjects",
221221
"compare.CompareMapObjects", "compare.CompareSetObjects", "compare.CompareNormalObjects", "compare.CompareArrayObjects",
222-
"StatementStep", "StatementStepArgument", "StatementStepNested", "StatementStepWithOperations" };
222+
"StatementStep", "StatementStepArgument", "StatementStepNested", "StatementStepWithOperations", "WatchItemContext" };
223223

224224
/**
225225
* the default timeout

org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/WatchExpressionTests.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2015 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,10 +13,13 @@
1313
*******************************************************************************/
1414
package org.eclipse.jdt.debug.tests.core;
1515

16+
import java.util.List;
17+
1618
import org.eclipse.debug.core.DebugEvent;
1719
import org.eclipse.debug.core.DebugPlugin;
1820
import org.eclipse.debug.core.IExpressionManager;
1921
import org.eclipse.debug.core.model.IValue;
22+
import org.eclipse.debug.core.model.IVariable;
2023
import org.eclipse.debug.core.model.IWatchExpression;
2124
import org.eclipse.debug.internal.ui.DebugUIPlugin;
2225
import org.eclipse.debug.ui.IDebugUIConstants;
@@ -27,6 +30,7 @@
2730
import org.eclipse.jdt.debug.testplugin.DebugElementEventWaiter;
2831
import org.eclipse.jdt.debug.testplugin.ExpressionWaiter;
2932
import org.eclipse.jdt.debug.tests.AbstractDebugTest;
33+
import org.eclipse.jdt.internal.debug.ui.heapwalking.JavaNestedWatchExpressionFilter;
3034
import org.eclipse.swt.widgets.Display;
3135
import org.eclipse.ui.IWorkbench;
3236
import org.eclipse.ui.IWorkbenchPage;
@@ -165,6 +169,32 @@ public void DisabledtestStepping() throws Exception {
165169
}
166170
}
167171

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+
168198
/**
169199
* Dumps any error messages to the console.
170200
*/

0 commit comments

Comments
 (0)