Skip to content

Commit a00ba18

Browse files
committed
Fix Debug Hover showing SuperClass Field's value in Subclass Field
This commit adds an additional computation for finding the subclass class field if superclass has same field as of subclass Fixes : #924
1 parent e717a57 commit a00ba18

5 files changed

Lines changed: 95 additions & 2 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 SubClass extends SuperClass {
15+
private boolean fInitialized;
16+
17+
public SubClass() {
18+
fInitialized = false;
19+
System.out.println("SubClass constructor");
20+
}
21+
22+
public static void main(String[] args) {
23+
new SubClass();
24+
}
25+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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 SuperClass {
15+
private boolean fInitialized = true;
16+
17+
public SuperClass() {
18+
19+
}
20+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,8 @@ 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, "SuperClass"));
555+
cfgs.add(createLaunchConfiguration(jp, "SubClass"));
554556
loaded18 = true;
555557
waitForBuild();
556558
}

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

Lines changed: 36 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,39 @@ public void testResolveIn2Lambdas() throws Exception {
15271527
}
15281528
}
15291529

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

org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIObjectValue.java

Lines changed: 12 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
@@ -277,6 +277,17 @@ public IJavaFieldVariable getField(final String name, final String declaringType
277277
field = fieldTmp;
278278
break;
279279
}
280+
List<Field> fieldList = ref.allFields(); // Possible sub class fields with same name as of super class
281+
fieldList.remove(fieldTmp);
282+
for (Field fieldCurrentTmp : fieldList) {
283+
if (name.equals(fieldCurrentTmp.name())) {
284+
String signatureCurrent = fieldCurrentTmp.declaringType().signature();
285+
if (declaringTypeSignature.equals(signatureCurrent)) {
286+
field = fieldCurrentTmp;
287+
break main;
288+
}
289+
}
290+
}
280291
// check if we are inside local type - Signature.createTypeSignature
281292
// can't create proper type name out of source field in JavaDebugHover
282293
// we get LDebugHoverTest$InnerClass2; instead of LDebugHoverTest$1InnerClass2;

0 commit comments

Comments
 (0)