From 5fe49cd7be7373b758959bae85045f19214a9e86 Mon Sep 17 00:00:00 2001 From: sougandhs Date: Mon, 6 Jan 2025 13:57:19 +0530 Subject: [PATCH] This commit provides support for Primitive types and Primitive arrays in Detail Formatter for variables view. Fixes : https://github.com/eclipse-jdt/eclipse.jdt.debug/issues/268 --- .../jdt/debug/tests/AbstractDebugTest.java | 1 + .../tests/variables/DetailFormatterTests.java | 136 ++++++++++++++ .../a/b/c/primitivesTest.java | 28 +++ org.eclipse.jdt.debug.ui/plugin.xml | 19 +- .../internal/debug/ui/DebugUIMessages.java | 2 + .../debug/ui/DebugUIMessages.properties | 2 + .../debug/ui/DetailFormatterDialog.java | 66 ++++++- .../debug/ui/JavaDetailFormattersManager.java | 166 +++++++++++++++++- .../debug/ui/JavaVarActionFilter.java | 5 + .../jdt/debug/eval/IAstEvaluationEngine.java | 37 ++++ .../eval/ast/engine/ASTEvaluationEngine.java | 20 +++ .../eval/ast/engine/IRuntimeContext.java | 5 + .../engine/JavaPrimitiveRuntimeContext.java | 92 ++++++++++ 13 files changed, 551 insertions(+), 28 deletions(-) create mode 100644 org.eclipse.jdt.debug.tests/testsource-j2se-1.5/a/b/c/primitivesTest.java create mode 100644 org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/JavaPrimitiveRuntimeContext.java diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java index 9e60b1c4f3..f32f2d2cd7 100644 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java @@ -404,6 +404,7 @@ void assert15Project() { cfgs.add(createLaunchConfiguration(jp, "a.b.c.bug329294WithGenerics")); cfgs.add(createLaunchConfiguration(jp, "a.b.c.bug403028")); cfgs.add(createLaunchConfiguration(jp, "a.b.c.bug484686")); + cfgs.add(createLaunchConfiguration(jp, "a.b.c.primitivesTest")); cfgs.add(createLaunchConfiguration(jp, "a.b.c.GenericMethodEntryTest")); cfgs.add(createLaunchConfiguration(jp, "org.eclipse.debug.tests.targets.HcrClass", true)); cfgs.add(createLaunchConfiguration(jp, "a.b.c.Bug570988")); diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/variables/DetailFormatterTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/variables/DetailFormatterTests.java index 0c685e5c07..1a09782dd1 100644 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/variables/DetailFormatterTests.java +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/variables/DetailFormatterTests.java @@ -340,4 +340,140 @@ public void testHoverWithNoTypeArguments() throws Exception { removeAllBreakpoints(); } } + + public void testFormatterForPrimitivesInt() throws Exception { + IJavaThread thread = null; + DetailFormatter formatter = null; + JavaDetailFormattersManager jdfm = JavaDetailFormattersManager.getDefault(); + try { + String typename = "a.b.c.primitivesTest"; + createLineBreakpoint(26, typename); + thread = launchToBreakpoint(typename); + assertNotNull("The program did not suspend", thread); + String snippet = "this + 12"; + formatter = new DetailFormatter("int", snippet, true); + jdfm.setAssociatedDetailFormatter(formatter); + IJavaVariable var = thread.findVariable("x"); + assertNotNull("the variable 'x' must exist in the frame", var); + jdfm.computeValueDetail((IJavaValue) var.getValue(), thread, fListener); + waitForListenerValue(); + assertNotNull("The IValue of the detailComputed callback cannot be null", fListener.value); + assertEquals("24", fListener.result.toString()); + + snippet = "new String(this)"; // for char arrays formatter = new DetailFormatter("char[]", snippet, true); + jdfm.setAssociatedDetailFormatter(formatter); + var = thread.findVariable("aCh"); + assertNotNull("the variable 'aCh' must exist in the frame", var); + jdfm.computeValueDetail((IJavaValue) var.getValue(), thread, fListener); + waitForListenerValue(); + assertNotNull("The IValue of the detailComputed callback cannot be null", fListener.value); + assertEquals("ab", fListener.result.toString()); + + } finally { + jdfm.removeAssociatedDetailFormatter(formatter); + terminateAndRemove(thread); + removeAllBreakpoints(); + } + } + + public void testFormatterForPrimitivesfloat() throws Exception { + IJavaThread thread = null; + DetailFormatter formatter = null; + JavaDetailFormattersManager jdfm = JavaDetailFormattersManager.getDefault(); + try { + String typename = "a.b.c.primitivesTest"; + createLineBreakpoint(26, typename); + thread = launchToBreakpoint(typename); + assertNotNull("The program did not suspend", thread); + String snippet = "this + 10"; + formatter = new DetailFormatter("float", snippet, true); + jdfm.setAssociatedDetailFormatter(formatter); + IJavaVariable var = thread.findVariable("f"); + assertNotNull("the variable 'f' must exist in the frame", var); + jdfm.computeValueDetail((IJavaValue) var.getValue(), thread, fListener); + waitForListenerValue(); + assertNotNull("The IValue of the detailComputed callback cannot be null", fListener.value); + assertEquals("20", fListener.result.toString()); + } finally { + jdfm.removeAssociatedDetailFormatter(formatter); + terminateAndRemove(thread); + removeAllBreakpoints(); + } + } + + public void testFormatterForPrimitivesIntArrays() throws Exception { + IJavaThread thread = null; + DetailFormatter formatter = null; + JavaDetailFormattersManager jdfm = JavaDetailFormattersManager.getDefault(); + try { + String typename = "a.b.c.primitivesTest"; + createLineBreakpoint(26, typename); + thread = launchToBreakpoint(typename); + assertNotNull("The program did not suspend", thread); + String snippet = "this[1]"; + formatter = new DetailFormatter("int[]", snippet, true); + jdfm.setAssociatedDetailFormatter(formatter); + IJavaVariable var = thread.findVariable("arInt"); + assertNotNull("the variable 'arInt' must exist in the frame", var); + jdfm.computeValueDetail((IJavaValue) var.getValue(), thread, fListener); + waitForListenerValue(); + assertNotNull("The IValue of the detailComputed callback cannot be null", fListener.value); + assertEquals("2", fListener.result.toString()); + } finally { + jdfm.removeAssociatedDetailFormatter(formatter); + terminateAndRemove(thread); + removeAllBreakpoints(); + } + } + + public void testFormatterForPrimitivesIntArraysMulti() throws Exception { + IJavaThread thread = null; + DetailFormatter formatter = null; + JavaDetailFormattersManager jdfm = JavaDetailFormattersManager.getDefault(); + try { + String typename = "a.b.c.primitivesTest"; + createLineBreakpoint(26, typename); + thread = launchToBreakpoint(typename); + assertNotNull("The program did not suspend", thread); + String snippet = "this[0][0]"; + formatter = new DetailFormatter("int[][]", snippet, true); + jdfm.setAssociatedDetailFormatter(formatter); + IJavaVariable var = thread.findVariable("mul"); + assertNotNull("the variable 'mul' must exist in the frame", var); + jdfm.computeValueDetail((IJavaValue) var.getValue(), thread, fListener); + waitForListenerValue(); + assertNotNull("The IValue of the detailComputed callback cannot be null", fListener.value); + assertEquals("[1]", fListener.result.toString()); + } finally { + jdfm.removeAssociatedDetailFormatter(formatter); + terminateAndRemove(thread); + removeAllBreakpoints(); + } + } + + public void testFormatterForPrimitivesCharArray() throws Exception { + IJavaThread thread = null; + DetailFormatter formatter = null; + JavaDetailFormattersManager jdfm = JavaDetailFormattersManager.getDefault(); + try { + String typename = "a.b.c.primitivesTest"; + createLineBreakpoint(26, typename); + thread = launchToBreakpoint(typename); + assertNotNull("The program did not suspend", thread); + String snippet = "new String(this)"; + formatter = new DetailFormatter("char[]", snippet, true); + jdfm.setAssociatedDetailFormatter(formatter); + IJavaVariable var = thread.findVariable("aCh"); + assertNotNull("the variable 'aCh' must exist in the frame", var); + jdfm.computeValueDetail((IJavaValue) var.getValue(), thread, fListener); + waitForListenerValue(); + assertNotNull("The IValue of the detailComputed callback cannot be null", fListener.value); + assertEquals("ab", fListener.result.toString()); + } finally { + jdfm.removeAssociatedDetailFormatter(formatter); + terminateAndRemove(thread); + removeAllBreakpoints(); + } + } + } diff --git a/org.eclipse.jdt.debug.tests/testsource-j2se-1.5/a/b/c/primitivesTest.java b/org.eclipse.jdt.debug.tests/testsource-j2se-1.5/a/b/c/primitivesTest.java new file mode 100644 index 0000000000..3e1a7a841d --- /dev/null +++ b/org.eclipse.jdt.debug.tests/testsource-j2se-1.5/a/b/c/primitivesTest.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2025 IBM Corporation and others. + * + * 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 a.b.c; + +public class primitivesTest { + public static void main(String[] args) { + Double xd = Double.valueOf(1); + int x = 12; + float f = 10; + int[] arInt = { 1, 2, 3 }; + char[] aCh = { 'a', 'b' }; + boolean b = false; + double[] d = { 1, 3, 4 }; + int[][] mul = { { 1, 3, 4 }, { 1, 3, 4 } }; + int p1 = 120; + } +} diff --git a/org.eclipse.jdt.debug.ui/plugin.xml b/org.eclipse.jdt.debug.ui/plugin.xml index 718a2c9a99..5adba5ecc5 100644 --- a/org.eclipse.jdt.debug.ui/plugin.xml +++ b/org.eclipse.jdt.debug.ui/plugin.xml @@ -1,7 +1,7 @@