You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by GitBox <gi...@apache.org> on 2020/03/14 17:11:58 UTC

[GitHub] [groovy] danielsun1106 opened a new pull request #1192: GROOVY-9468: Support running as Java code in the Groovy console

danielsun1106 opened a new pull request #1192: GROOVY-9468: Support running as Java code in the Groovy console
URL: https://github.com/apache/groovy/pull/1192
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [groovy] danielsun1106 commented on a change in pull request #1192: GROOVY-9468: Support running as Java code in the Groovy console

Posted by GitBox <gi...@apache.org>.
danielsun1106 commented on a change in pull request #1192: GROOVY-9468: Support running as Java code in the Groovy console
URL: https://github.com/apache/groovy/pull/1192#discussion_r392673653
 
 

 ##########
 File path: subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
 ##########
 @@ -1136,13 +1142,25 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
         return consoleControllers.find { it.consoleId == consoleId }
     }
 
+    private enum SourceType {
+        GROOVY, JAVA
+    }
+
+    void runJava(EventObject evt = null) {
+        doRun(evt, SourceType.JAVA)
+    }
+
     // actually run the script
     void runScript(EventObject evt = null) {
 
 Review comment:
   I am not sure whether swingbuilder knows such method signature or not...

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [groovy] paulk-asert commented on a change in pull request #1192: GROOVY-9468: Support running as Java code in the Groovy console

Posted by GitBox <gi...@apache.org>.
paulk-asert commented on a change in pull request #1192: GROOVY-9468: Support running as Java code in the Groovy console
URL: https://github.com/apache/groovy/pull/1192#discussion_r392651183
 
 

 ##########
 File path: subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
 ##########
 @@ -1136,13 +1142,25 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
         return consoleControllers.find { it.consoleId == consoleId }
     }
 
+    private enum SourceType {
+        GROOVY, JAVA
+    }
+
+    void runJava(EventObject evt = null) {
+        doRun(evt, SourceType.JAVA)
+    }
+
     // actually run the script
     void runScript(EventObject evt = null) {
 
 Review comment:
   Would it be better to use default params here?
   `void runScript(EventObject evt = null, SourceType st = SourceType.GROOVY) {`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [groovy] danielsun1106 commented on issue #1192: GROOVY-9468: Support running as Java code in the Groovy console

Posted by GitBox <gi...@apache.org>.
danielsun1106 commented on issue #1192: GROOVY-9468: Support running as Java code in the Groovy console
URL: https://github.com/apache/groovy/pull/1192#issuecomment-599249987
 
 
   Thanks for your reviewing ;-)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [groovy] paulk-asert commented on a change in pull request #1192: GROOVY-9468: Support running as Java code in the Groovy console

Posted by GitBox <gi...@apache.org>.
paulk-asert commented on a change in pull request #1192: GROOVY-9468: Support running as Java code in the Groovy console
URL: https://github.com/apache/groovy/pull/1192#discussion_r392652009
 
 

 ##########
 File path: subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
 ##########
 @@ -1329,6 +1356,47 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
         }
     }
 
+    @CompileStatic
+    private Object doRun(boolean selected, SourceType st, HistoryRecord record) {
+        def result
+        def src = record.getTextToRun(selected)
+        if (SourceType.JAVA === st) {
+            Optional<String> optionalPrimaryClassName = findPrimaryClassName(src)
+            if (optionalPrimaryClassName.isPresent()) {
+                def js = new JavaShell(Thread.currentThread().contextClassLoader)
+                js.run(optionalPrimaryClassName.get(), src)
+            }
 
 Review comment:
   Otherwise, change `public class` to `class` and it looks like it ran but with no output. Whereas, it passes parser but hasn't been compiled or run.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [groovy] paulk-asert commented on a change in pull request #1192: GROOVY-9468: Support running as Java code in the Groovy console

Posted by GitBox <gi...@apache.org>.
paulk-asert commented on a change in pull request #1192: GROOVY-9468: Support running as Java code in the Groovy console
URL: https://github.com/apache/groovy/pull/1192#discussion_r392720496
 
 

 ##########
 File path: subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
 ##########
 @@ -1136,13 +1142,25 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
         return consoleControllers.find { it.consoleId == consoleId }
     }
 
+    private enum SourceType {
+        GROOVY, JAVA
+    }
+
+    void runJava(EventObject evt = null) {
+        doRun(evt, SourceType.JAVA)
+    }
+
     // actually run the script
     void runScript(EventObject evt = null) {
 
 Review comment:
   Groovy will create all the in between signatures, so it should work - we can try later.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [groovy] paulk-asert commented on a change in pull request #1192: GROOVY-9468: Support running as Java code in the Groovy console

Posted by GitBox <gi...@apache.org>.
paulk-asert commented on a change in pull request #1192: GROOVY-9468: Support running as Java code in the Groovy console
URL: https://github.com/apache/groovy/pull/1192#discussion_r392651656
 
 

 ##########
 File path: subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
 ##########
 @@ -1329,6 +1356,47 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
         }
     }
 
+    @CompileStatic
+    private Object doRun(boolean selected, SourceType st, HistoryRecord record) {
+        def result
+        def src = record.getTextToRun(selected)
+        if (SourceType.JAVA === st) {
+            Optional<String> optionalPrimaryClassName = findPrimaryClassName(src)
+            if (optionalPrimaryClassName.isPresent()) {
+                def js = new JavaShell(Thread.currentThread().contextClassLoader)
+                js.run(optionalPrimaryClassName.get(), src)
+            }
 
 Review comment:
   I wonder if there should be an else here with a message/error to output area saying "No public class found, nothing to run." or similar.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [groovy] paulk-asert commented on a change in pull request #1192: GROOVY-9468: Support running as Java code in the Groovy console

Posted by GitBox <gi...@apache.org>.
paulk-asert commented on a change in pull request #1192: GROOVY-9468: Support running as Java code in the Groovy console
URL: https://github.com/apache/groovy/pull/1192#discussion_r392720605
 
 

 ##########
 File path: subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
 ##########
 @@ -1329,6 +1356,47 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
         }
     }
 
+    @CompileStatic
+    private Object doRun(boolean selected, SourceType st, HistoryRecord record) {
+        def result
+        def src = record.getTextToRun(selected)
+        if (SourceType.JAVA === st) {
+            Optional<String> optionalPrimaryClassName = findPrimaryClassName(src)
+            if (optionalPrimaryClassName.isPresent()) {
+                def js = new JavaShell(Thread.currentThread().contextClassLoader)
+                js.run(optionalPrimaryClassName.get(), src)
+            }
 
 Review comment:
   No, it fails silently. Not the most catastrophic behavior but not as intuitive as possible. We can change later.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [groovy] danielsun1106 merged pull request #1192: GROOVY-9468: Support running as Java code in the Groovy console

Posted by GitBox <gi...@apache.org>.
danielsun1106 merged pull request #1192: GROOVY-9468: Support running as Java code in the Groovy console
URL: https://github.com/apache/groovy/pull/1192
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [groovy] paulk-asert commented on a change in pull request #1192: GROOVY-9468: Support running as Java code in the Groovy console

Posted by GitBox <gi...@apache.org>.
paulk-asert commented on a change in pull request #1192: GROOVY-9468: Support running as Java code in the Groovy console
URL: https://github.com/apache/groovy/pull/1192#discussion_r392651239
 
 

 ##########
 File path: subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
 ##########
 @@ -1180,11 +1198,20 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
         cc.getOptimizationOptions().get(CompilerConfiguration.INVOKEDYNAMIC)
     }
 
+    void runSelectedJava(EventObject evt = null) {
+        doRunSelected(evt, SourceType.JAVA)
+    }
+
     void runSelectedScript(EventObject evt = null) {
 
 Review comment:
   ditto here?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [groovy] paulk-asert commented on issue #1192: GROOVY-9468: Support running as Java code in the Groovy console

Posted by GitBox <gi...@apache.org>.
paulk-asert commented on issue #1192: GROOVY-9468: Support running as Java code in the Groovy console
URL: https://github.com/apache/groovy/pull/1192#issuecomment-599181148
 
 
   +1, I'd also like to see "Compile to Java" added but that can be a separate issue.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [groovy] danielsun1106 commented on a change in pull request #1192: GROOVY-9468: Support running as Java code in the Groovy console

Posted by GitBox <gi...@apache.org>.
danielsun1106 commented on a change in pull request #1192: GROOVY-9468: Support running as Java code in the Groovy console
URL: https://github.com/apache/groovy/pull/1192#discussion_r392673851
 
 

 ##########
 File path: subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
 ##########
 @@ -1329,6 +1356,47 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
         }
     }
 
+    @CompileStatic
+    private Object doRun(boolean selected, SourceType st, HistoryRecord record) {
+        def result
+        def src = record.getTextToRun(selected)
+        if (SourceType.JAVA === st) {
+            Optional<String> optionalPrimaryClassName = findPrimaryClassName(src)
+            if (optionalPrimaryClassName.isPresent()) {
+                def js = new JavaShell(Thread.currentThread().contextClassLoader)
+                js.run(optionalPrimaryClassName.get(), src)
+            }
 
 Review comment:
   It's better to check, but Java compiler/javaparser will complain finally ;-)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services