Skip to content

Commit 5897f0e

Browse files
committed
Fix Debug Hover not working on inner class constructors
This commit enables debug hovers on inner class constructor's params and variables Fixes : #928
1 parent e717a57 commit 5897f0e

4 files changed

Lines changed: 66 additions & 3 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
public class InnerClassBug {
15+
16+
public static void main(String[] args) {
17+
InnerClassBug a = new InnerClassBug();
18+
T t = a.new T(4);
19+
System.out.println(t.x);
20+
}
21+
22+
private class T {
23+
final int x;
24+
private T(int x1) {
25+
this.x = x1;
26+
}
27+
}
28+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ synchronized void assert18Project() {
551551
cfgs.add(createLaunchConfiguration(jp, "LambdaBreakpoints1"));
552552
cfgs.add(createLaunchConfiguration(jp, "GH275"));
553553
cfgs.add(createLaunchConfiguration(jp, "LambdaTest"));
554+
cfgs.add(createLaunchConfiguration(jp, "InnerClassBug"));
554555
loaded18 = true;
555556
waitForBuild();
556557
}

org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/DebugHoverTests.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017, 2024 Andrey Loskutov and others.
2+
* Copyright (c) 2017, 2026 Andrey Loskutov and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -1527,4 +1527,36 @@ public void testResolveIn2Lambdas() throws Exception {
15271527
}
15281528
}
15291529

1530+
public void testHoverOnInnerClassConstructorVariables() throws Exception {
1531+
sync(() -> TestUtil.waitForJobs(getName(), 1000, 10000, ProcessConsole.class));
1532+
final String typeName = "InnerClassBug";
1533+
final String expectedMethod = "<init>";
1534+
final int frameNumber = 3;
1535+
final int bpLine = 25;
1536+
IJavaBreakpoint bp = createLineBreakpoint(bpLine, "", typeName + ".java", typeName);
1537+
bp.setSuspendPolicy(IJavaBreakpoint.SUSPEND_THREAD);
1538+
IFile file = (IFile) bp.getMarker().getResource();
1539+
assertEquals(typeName + ".java", file.getName());
1540+
IJavaThread thread = null;
1541+
try {
1542+
thread = launchToBreakpoint(typeName);
1543+
CompilationUnitEditor part = openEditorAndValidateStack(expectedMethod, frameNumber, file, thread);
1544+
JavaDebugHover hover = new JavaDebugHover();
1545+
hover.setEditor(part);
1546+
String variableName = "x1";
1547+
int offset = part.getViewer().getDocument().get().indexOf("this.x = x1") + " this.x =".length();
1548+
IRegion region = new Region(offset, variableName.length());
1549+
String text = selectAndReveal(part, bpLine, region);
1550+
assertEquals(variableName, text);
1551+
IVariable info = (IVariable) sync(() -> hover.getHoverInfo2(part.getViewer(), region));
1552+
1553+
assertNotNull(info);
1554+
assertEquals(variableName, info.getName());
1555+
assertEquals("4", info.getValue().getValueString());
1556+
} finally {
1557+
terminateAndRemove(thread);
1558+
removeAllBreakpoints();
1559+
}
1560+
}
1561+
15301562
}

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JavaDebugHover.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2020 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
@@ -448,7 +448,9 @@ public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
448448
}
449449
else { // Finding variables in anonymous class
450450
int index = frame.getDeclaringTypeName().indexOf('$');
451-
if (index > 0) {
451+
if (method.isConstructor() && index > 0) {
452+
equal = true;
453+
} else if (index > 0) {
452454
String name = frame.getDeclaringTypeName().substring(index + 1);
453455
try {
454456
Integer.getInteger(name);

0 commit comments

Comments
 (0)