You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2022/08/06 18:48:56 UTC

[groovy] branch GROOVY_4_0_X updated (d10ec42d40 -> cb1e55f82d)

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

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


    from d10ec42d40 Update README: update the link to github status icon
     new 891bb39d62 Highlight class info in object browser
     new cb1e55f82d Tweak highlighting class info in object browser

The 2 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:
 .../groovy/groovy/console/ui/ObjectBrowser.groovy  | 30 ++++++++++++++++++----
 .../console/ui/text/SmartDocumentFilter.java       | 13 +++++-----
 2 files changed, 32 insertions(+), 11 deletions(-)


[groovy] 02/02: Tweak highlighting class info in object browser

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

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

commit cb1e55f82d8ce0c65b2621b017fe19d2479f3520
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Aug 7 02:39:49 2022 +0800

    Tweak highlighting class info in object browser
    
    (cherry picked from commit 116cf18355d263bd804f00f5dd2b92fbd7fa4f83)
---
 .../src/main/groovy/groovy/console/ui/ObjectBrowser.groovy           | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

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 b0d2b7d30c..094ab6c3ac 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
@@ -156,10 +156,9 @@ class ObjectBrowser {
                                     VOCABULARY.getLiteralName(it)?.replace("'", '')
                                 }.grep { it } + ['module', 'true', 'false'])) {
                     content = content.replaceAll(/\b(${ln})\b/, '<b>$1</b>')
-                                        .replace(',', '<b>,</b>')
-                                        .replace(':', '<b>:</b>')
                 }
-                def classLabel = "<html>${content.replace('\n', '<br/>')}</html>"
+                content = content.replace('\n', '<br/>').replace(',', '<b>,</b>').replace(':', '<b>:</b>')
+                def classLabel = "<html>${content}</html>"
                 label(classLabel)
             }
             tabbedPane(constraints: CENTER) {


[groovy] 01/02: Highlight class info in object browser

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

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

commit 891bb39d62b0514da1a5eb7b203d92ed0c2a7b3f
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Aug 7 02:25:11 2022 +0800

    Highlight class info in object browser
    
    (cherry picked from commit b76b2e6034703caf85620cf14dca864a298f3131)
---
 .../groovy/groovy/console/ui/ObjectBrowser.groovy  | 31 ++++++++++++++++++----
 .../console/ui/text/SmartDocumentFilter.java       | 13 ++++-----
 2 files changed, 33 insertions(+), 11 deletions(-)

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 3c436b0b9f..b0d2b7d30c 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
@@ -32,6 +32,7 @@ import java.awt.datatransfer.StringSelection
 import java.awt.event.MouseAdapter
 import java.awt.event.MouseEvent
 
+import static groovy.console.ui.text.SmartDocumentFilter.HIGHLIGHTED_TOKEN_TYPE_LIST
 import static groovy.inspect.Inspector.MEMBER_DECLARER_IDX
 import static groovy.inspect.Inspector.MEMBER_EXCEPTIONS_IDX
 import static groovy.inspect.Inspector.MEMBER_MODIFIER_IDX
@@ -41,7 +42,7 @@ import static groovy.inspect.Inspector.MEMBER_PARAMS_IDX
 import static groovy.inspect.Inspector.MEMBER_TYPE_IDX
 import static groovy.inspect.Inspector.MEMBER_VALUE_IDX
 import static javax.swing.ListSelectionModel.SINGLE_SELECTION
-
+import static org.apache.groovy.parser.antlr4.GroovyLexer.VOCABULARY
 /**
  * A little GUI to show some of the Inspector capabilities.
  * Starting this script opens the ObjectBrowser on "some String".
@@ -130,15 +131,35 @@ class ObjectBrowser {
         builder.panel {
             borderLayout()
             panel(name: 'Class Info',
-                    border: emptyBorder([5, 10, 5, 10]),
+                    border: titledBorder('Class Info'),
                     constraints: NORTH) {
                 flowLayout(alignment: FlowLayout.LEFT)
-                def props = inspector.classProps.findAll{ it != 'implements ' }
+                def props = inspector.classProps.findAll { it != 'implements ' }
                 try {
                     def module = inspector.object.class.module.name
-                    if (module) props.add(0, 'module ' + module)
+                    if (module) props.add(0, "module ${module}")
                 } catch(Exception ignore) {}
-                def classLabel = '<html>' + props.join('<br>')
+
+                final implementsPrefix = 'implements '
+                def content = props.collect {
+                    String p = it.trim()
+                    if (p.startsWith(implementsPrefix)) {
+                        return "${implementsPrefix}${p.substring(implementsPrefix.length()).replace(' ', ', ')}"
+                    }
+                    if (p.startsWith('is ')) {
+                        return "(${p})"
+                    }
+                    return p
+                }.join('\n').trim()
+
+                for (def ln in (HIGHLIGHTED_TOKEN_TYPE_LIST.collect {
+                                    VOCABULARY.getLiteralName(it)?.replace("'", '')
+                                }.grep { it } + ['module', 'true', 'false'])) {
+                    content = content.replaceAll(/\b(${ln})\b/, '<b>$1</b>')
+                                        .replace(',', '<b>,</b>')
+                                        .replace(':', '<b>:</b>')
+                }
+                def classLabel = "<html>${content.replace('\n', '<br/>')}</html>"
                 label(classLabel)
             }
             tabbedPane(constraints: CENTER) {
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/text/SmartDocumentFilter.java b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/text/SmartDocumentFilter.java
index 26ef0dae0c..31a22c99f1 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/text/SmartDocumentFilter.java
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/text/SmartDocumentFilter.java
@@ -123,6 +123,12 @@ import static org.apache.groovy.parser.antlr4.GroovyLexer.YIELD;
  * @since 3.0.0
  */
 public class SmartDocumentFilter extends DocumentFilter {
+    public static final List<Integer> HIGHLIGHTED_TOKEN_TYPE_LIST = Arrays.asList(AS, DEF, IN, TRAIT, THREADSAFE,
+            VAR, BuiltInPrimitiveType, ABSTRACT, ASSERT, BREAK, CASE, CATCH, CLASS, CONST, CONTINUE, DEFAULT, DO,
+            ELSE, ENUM, EXTENDS, FINAL, FINALLY, FOR, IF, GOTO, IMPLEMENTS, IMPORT, INSTANCEOF, INTERFACE,
+            NATIVE, NEW, NON_SEALED, NOT_IN, NOT_INSTANCEOF, PACKAGE, PERMITS, PRIVATE, PROTECTED, PUBLIC,
+            RECORD, RETURN, SEALED, STATIC, STRICTFP, SUPER, SWITCH, SYNCHRONIZED,
+            THIS, THROW, THROWS, TRANSIENT, TRY, VOID, VOLATILE, WHILE, YIELD, NullLiteral, BooleanLiteral);
     private static final String MONOSPACED = "Monospaced";
     private final DefaultStyledDocument styledDocument;
     private final StyleContext styleContext;
@@ -381,12 +387,7 @@ public class SmartDocumentFilter extends DocumentFilter {
         }
 
         // reserved keywords, null literals, boolean literals
-        for (int t : Arrays.asList(AS, DEF, IN, TRAIT, THREADSAFE,
-                VAR, BuiltInPrimitiveType, ABSTRACT, ASSERT, BREAK, CASE, CATCH, CLASS, CONST, CONTINUE, DEFAULT, DO,
-                ELSE, ENUM, EXTENDS, FINAL, FINALLY, FOR, IF, GOTO, IMPLEMENTS, IMPORT, INSTANCEOF, INTERFACE,
-                NATIVE, NEW, NON_SEALED, NOT_IN, NOT_INSTANCEOF, PACKAGE, PERMITS, PRIVATE, PROTECTED, PUBLIC,
-                RECORD, RETURN, SEALED, STATIC, STRICTFP, SUPER, SWITCH, SYNCHRONIZED,
-                THIS, THROW, THROWS, TRANSIENT, TRY, VOID, VOLATILE, WHILE, YIELD, NullLiteral, BooleanLiteral)) {
+        for (int t : HIGHLIGHTED_TOKEN_TYPE_LIST) {
             Style style = createDefaultStyleByTokenType(t);
             StyleConstants.setBold(style, true);
             StyleConstants.setForeground(style, Color.BLUE.darker().darker());