You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2022/07/12 01:36:15 UTC

[groovy] branch master updated (e21b5d41a3 -> 46111a29c8)

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


    from e21b5d41a3 GROOVY-9854: STC: propagate `switch` type to `case` closure parameter
     new 8ce727449c GROOVY-10686: Add tooltips for Object/AST browser to display contents for narrow columns (ObjectBrowser)
     new 118deb2770 GROOVY-10686: Add tooltips for Object/AST browser to display contents for narrow columns (AstBrowser)
     new 46111a29c8 GROOVY-10686: Add tooltips for Object/AST browser to display contents for narrow columns (column size tweaking and allow (meta)method browsing)

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/main/java/groovy/inspect/Inspector.java        | 34 ++++++++++
 .../groovy/groovy/console/ui/AstBrowser.groovy     |  2 +-
 .../console/ui/CellValueToolTipJTable.groovy       | 15 ++++
 .../groovy/groovy/console/ui/ObjectBrowser.groovy  | 79 +++++++++++++++-------
 4 files changed, 103 insertions(+), 27 deletions(-)
 create mode 100644 subprojects/groovy-console/src/main/groovy/groovy/console/ui/CellValueToolTipJTable.groovy


[groovy] 02/03: GROOVY-10686: Add tooltips for Object/AST browser to display contents for narrow columns (AstBrowser)

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 118deb2770f164176e5d666aa8e74ba54b7aa374
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Jul 12 10:28:57 2022 +1000

    GROOVY-10686: Add tooltips for Object/AST browser to display contents for narrow columns (AstBrowser)
---
 .../groovy-console/src/main/groovy/groovy/console/ui/AstBrowser.groovy  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/AstBrowser.groovy b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/AstBrowser.groovy
index 685ddb026a..4bca92e09f 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/AstBrowser.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/AstBrowser.groovy
@@ -194,7 +194,7 @@ class AstBrowser {
                                     model: new DefaultTreeModel(new DefaultMutableTreeNode('Loading...'))) {}
                         },
                         rightComponent: scrollPane {
-                            propertyTable = table(selectionMode: SINGLE_SELECTION) {
+                            propertyTable = table(new CellValueToolTipJTable(), selectionMode: SINGLE_SELECTION) {
                                 tableModel(list: [[:]]) {
                                     propertyColumn(header: 'Name', propertyName: 'name')
                                     propertyColumn(header: 'Value  (double-click to browse)', propertyName: 'value')


[groovy] 03/03: GROOVY-10686: Add tooltips for Object/AST browser to display contents for narrow columns (column size tweaking and allow (meta)method browsing)

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 46111a29c8e73465d56a07785117c4b0e3665b5b
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Jul 12 11:36:04 2022 +1000

    GROOVY-10686: Add tooltips for Object/AST browser to display contents for narrow columns (column size tweaking and allow (meta)method browsing)
---
 src/main/java/groovy/inspect/Inspector.java        | 34 +++++++++++
 .../groovy/groovy/console/ui/ObjectBrowser.groovy  | 69 +++++++++++++++-------
 2 files changed, 81 insertions(+), 22 deletions(-)

diff --git a/src/main/java/groovy/inspect/Inspector.java b/src/main/java/groovy/inspect/Inspector.java
index b435c25a37..9e1d02b39d 100644
--- a/src/main/java/groovy/inspect/Inspector.java
+++ b/src/main/java/groovy/inspect/Inspector.java
@@ -133,6 +133,25 @@ public class Inspector {
         return result;
     }
 
+    /**
+     * Get info about usual Java instance and class Methods as well as Constructors.
+     */
+    public Tuple2[] getMethodsWithInfo() {
+        Method[] methods = getClassUnderInspection().getMethods();
+        Constructor[] ctors = getClassUnderInspection().getConstructors();
+        Tuple2[] result = new Tuple2[methods.length + ctors.length];
+        int resultIndex = 0;
+        for (; resultIndex < methods.length; resultIndex++) {
+            Method method = methods[resultIndex];
+            result[resultIndex] = Tuple2.tuple(method, methodInfo(method));
+        }
+        for (int i = 0; i < ctors.length; i++, resultIndex++) {
+            Constructor ctor = ctors[i];
+            result[resultIndex] = Tuple2.tuple(ctor, methodInfo(ctor));
+        }
+        return result;
+    }
+
     /**
      * Get info about instance and class Methods that are dynamically added through Groovy.
      *
@@ -150,6 +169,21 @@ public class Inspector {
         return result;
     }
 
+    /**
+     * Get info about instance and class Methods that are dynamically added through Groovy.
+     */
+    public Tuple2[] getMetaMethodsWithInfo() {
+        MetaClass metaClass = InvokerHelper.getMetaClass(objectUnderInspection);
+        List<MetaMethod> metaMethods = metaClass.getMetaMethods();
+        Tuple2[] result = new Tuple2[metaMethods.size()];
+        int i = 0;
+        for (Iterator<MetaMethod> iter = metaMethods.iterator(); iter.hasNext(); i++) {
+            MetaMethod metaMethod = (MetaMethod) iter.next();
+            result[i] = Tuple2.tuple(metaMethod, methodInfo(metaMethod));
+        }
+        return result;
+    }
+
     /**
      * Get info about usual Java public fields incl. constants.
      *
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ObjectBrowser.groovy b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ObjectBrowser.groovy
index df3d210d33..116ba15de6 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ObjectBrowser.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ObjectBrowser.groovy
@@ -100,10 +100,15 @@ class ObjectBrowser {
                                     closureColumn(header: 'Raw Value', read: { it[0] })
                                 }
                             }
-                            arrayTable.columnModel.getColumn(2).with {
-                                minWidth = 0
-                                maxWidth = 0
-                                width = 0
+                            arrayTable.columnModel.with {
+                                getColumn(2).with {
+                                    minWidth = 0
+                                    maxWidth = 0
+                                    width = 0
+                                    preferredWidth = 0
+                                }
+                                getColumn(0).preferredWidth = 50
+                                getColumn(1).preferredWidth = 400
                             }
                             arrayTable.addMouseListener(makeClickAdapter(arrayTable, 2) { row ->
                                 path + "[${arrayTable.model.getValueAt(row, 0)}]"
@@ -118,10 +123,15 @@ class ObjectBrowser {
                                     closureColumn(header: 'Raw Value', read: { it[0] })
                                 }
                             }
-                            collectionTable.columnModel.getColumn(2).with {
-                                minWidth = 0
-                                maxWidth = 0
-                                width = 0
+                            collectionTable.columnModel.with {
+                                getColumn(2).with {
+                                    minWidth = 0
+                                    maxWidth = 0
+                                    width = 0
+                                    preferredWidth = 0
+                                }
+                                getColumn(0).preferredWidth = 50
+                                getColumn(1).preferredWidth = 400
                             }
                             collectionTable.addMouseListener(makeClickAdapter(collectionTable, 2) { row ->
                                 path + "[${collectionTable.model.getValueAt(row, 0)}]"
@@ -138,10 +148,16 @@ class ObjectBrowser {
                                 }
                             }
                             ToolTipManager.sharedInstance().registerComponent(mapTable)
-                            mapTable.columnModel.getColumn(3).with {
-                                minWidth = 0
-                                maxWidth = 0
-                                width = 0
+                            mapTable.columnModel.with {
+                                getColumn(3).with {
+                                    minWidth = 0
+                                    maxWidth = 0
+                                    width = 0
+                                    preferredWidth = 0
+                                }
+                                getColumn(0).preferredWidth = 50
+                                getColumn(1).preferredWidth = 200
+                                getColumn(2).preferredWidth = 400
                             }
                             mapTable.addMouseListener(makeClickAdapter(mapTable, 2) { row ->
                                 path + "[${mapTable.model.getValueAt(row, 1)}]"
@@ -171,19 +187,28 @@ class ObjectBrowser {
                         })
                     }
                     scrollPane(name: ' (Meta) Methods ') {
-                        methodTable = table(selectionMode: SINGLE_SELECTION) {
-                            def data = Inspector.sort(inspector.methods.toList())
-                            data.addAll(Inspector.sort(inspector.metaMethods.toList()))
+                        methodTable = table(new CellValueToolTipJTable(), selectionMode: SINGLE_SELECTION) {
+                            def data = Inspector.sort(inspector.methodsWithInfo.toList(), comparator)
+                            data.addAll(Inspector.sort(inspector.metaMethodsWithInfo.toList(), comparator))
                             tableModel(list: data) {
-                                closureColumn(header: 'Name', read: { it[MEMBER_NAME_IDX] })
-                                closureColumn(header: 'Params', read: { it[MEMBER_PARAMS_IDX] })
-                                closureColumn(header: 'Type', read: { it[MEMBER_TYPE_IDX] })
-                                closureColumn(header: 'Origin', read: { it[MEMBER_ORIGIN_IDX] })
-                                closureColumn(header: 'Modifier', read: { it[MEMBER_MODIFIER_IDX] })
-                                closureColumn(header: 'Declarer', read: { it[MEMBER_DECLARER_IDX] })
-                                closureColumn(header: 'Exceptions', read: { it[MEMBER_EXCEPTIONS_IDX] })
+                                closureColumn(header: 'Name', read: { it.v2[MEMBER_NAME_IDX] })
+                                closureColumn(header: 'Params', read: { it.v2[MEMBER_PARAMS_IDX] })
+                                closureColumn(header: 'Type', read: { it.v2[MEMBER_TYPE_IDX] })
+                                closureColumn(header: 'Origin', read: { it.v2[MEMBER_ORIGIN_IDX] })
+                                closureColumn(header: 'Modifier', read: { it.v2[MEMBER_MODIFIER_IDX] })
+                                closureColumn(header: 'Declarer', read: { it.v2[MEMBER_DECLARER_IDX] })
+                                closureColumn(header: 'Exceptions', read: { it.v2[MEMBER_EXCEPTIONS_IDX] })
+                                closureColumn(header: 'Raw Value', read: { it.v1 })
                             }
                         }
+                        methodTable.columnModel.getColumn(7).with {
+                            minWidth = 0
+                            maxWidth = 0
+                            width = 0
+                        }
+                        methodTable.addMouseListener(makeClickAdapter(methodTable, 7) { row ->
+                            path + (path.size() == 0 ? '' : ".method['") + "${methodTable.model.getValueAt(row, 0)}']"
+                        })
                     }
                 }
                 panel(name: 'Path',


[groovy] 01/03: GROOVY-10686: Add tooltips for Object/AST browser to display contents for narrow columns (ObjectBrowser)

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 8ce727449c02cc066dc31674c51e5d2e6acc1a07
Author: Sandip Chitale <sa...@gmail.com>
AuthorDate: Sun Jul 10 02:04:02 2022 -0700

    GROOVY-10686: Add tooltips for Object/AST browser to display contents for narrow columns (ObjectBrowser)
---
 .../groovy/console/ui/CellValueToolTipJTable.groovy       | 15 +++++++++++++++
 .../main/groovy/groovy/console/ui/ObjectBrowser.groovy    | 10 ++++++----
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/CellValueToolTipJTable.groovy b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/CellValueToolTipJTable.groovy
new file mode 100644
index 0000000000..23960d0452
--- /dev/null
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/CellValueToolTipJTable.groovy
@@ -0,0 +1,15 @@
+package groovy.console.ui
+
+import javax.swing.JTable
+import java.awt.event.MouseEvent
+
+class CellValueToolTipJTable extends JTable {
+    public String getToolTipText(MouseEvent me) {
+        int viewRowIndex = rowAtPoint(me.point)
+        int viewColumnIndex = columnAtPoint(me.point)
+
+        def value = getValueAt(viewRowIndex, viewColumnIndex)
+
+        return (value != null ? String.valueOf(value) : null)
+    }
+}
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ObjectBrowser.groovy b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ObjectBrowser.groovy
index 315c3c5be1..df3d210d33 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ObjectBrowser.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ObjectBrowser.groovy
@@ -26,6 +26,7 @@ import javax.swing.WindowConstants
 import java.awt.FlowLayout
 import java.awt.event.MouseAdapter
 import java.awt.event.MouseEvent
+import javax.swing.ToolTipManager
 
 import static javax.swing.ListSelectionModel.SINGLE_SELECTION
 
@@ -92,7 +93,7 @@ class ObjectBrowser {
                 tabbedPane(constraints: CENTER) {
                     if (inspector.object?.class?.array) {
                         scrollPane(name: ' Array data ') {
-                            arrayTable = table(selectionMode: SINGLE_SELECTION) {
+                            arrayTable = table(new CellValueToolTipJTable(), selectionMode: SINGLE_SELECTION) {
                                 tableModel(list: inspector.object.toList().withIndex()) {
                                     closureColumn(header: 'Index', read: { it[1] })
                                     closureColumn(header: 'Value', read: { it[0] })
@@ -110,7 +111,7 @@ class ObjectBrowser {
                         }
                     } else if (inspector.object instanceof Collection) {
                         scrollPane(name: ' Collection data ') {
-                            collectionTable = table(selectionMode: SINGLE_SELECTION) {
+                            collectionTable = table(new CellValueToolTipJTable(), selectionMode: SINGLE_SELECTION) {
                                 tableModel(list: inspector.object.withIndex()) {
                                     closureColumn(header: 'Index', read: { it[1] })
                                     closureColumn(header: 'Value', read: { it[0] })
@@ -128,7 +129,7 @@ class ObjectBrowser {
                         }
                     } else if (inspector.object instanceof Map) {
                         scrollPane(name: ' Map data ') {
-                            mapTable = table(selectionMode: SINGLE_SELECTION) {
+                            mapTable = table(new CellValueToolTipJTable(), selectionMode: SINGLE_SELECTION) {
                                 tableModel(list: inspector.object.entrySet().withIndex()) {
                                     closureColumn(header: 'Index', read: { it[1] })
                                     closureColumn(header: 'Key', read: { it[0].key })
@@ -136,6 +137,7 @@ class ObjectBrowser {
                                     closureColumn(header: 'Raw Value', read: { it[0].value })
                                 }
                             }
+                            ToolTipManager.sharedInstance().registerComponent(mapTable)
                             mapTable.columnModel.getColumn(3).with {
                                 minWidth = 0
                                 maxWidth = 0
@@ -148,7 +150,7 @@ class ObjectBrowser {
                     }
                     scrollPane(name: ' Properties (includes public fields) ') {
                         def data = Inspector.sort(inspector.propertiesWithInfo.toList(), comparator)
-                        fieldTable = table(selectionMode: SINGLE_SELECTION) {
+                        fieldTable = table(new CellValueToolTipJTable(), selectionMode: SINGLE_SELECTION) {
                             tableModel(list: data) {
                                 closureColumn(header: 'Name', read: { it.v2[MEMBER_NAME_IDX] })
                                 closureColumn(header: 'Value', read: { it.v2[MEMBER_VALUE_IDX] })