groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [2/2] groovy git commit: GROOVY-8635: Make some groovy class compile static (closes #734)
Date Mon, 25 Jun 2018 06:25:16 GMT
GROOVY-8635: Make some groovy class compile static (closes #734)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/50f62297
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/50f62297
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/50f62297

Branch: refs/heads/GROOVY_2_5_X
Commit: 50f6229748604d32927092fa9c9311263291f252
Parents: 9f367aa
Author: Daniel Sun <realbluesun@hotmail.com>
Authored: Tue May 29 19:10:02 2018 +0800
Committer: Paul King <paulk@asert.com.au>
Committed: Mon Jun 25 16:25:06 2018 +1000

----------------------------------------------------------------------
 .../main/groovy/groovy/inspect/TextNode.groovy    |  3 +++
 .../groovy/inspect/TextTreeNodeMaker.groovy       |  2 ++
 .../groovy/inspect/swingui/AstBrowser.groovy      |  8 +++++++-
 .../inspect/swingui/AstNodeToScriptAdapter.groovy | 18 ++++++++++++------
 .../swingui/ButtonOrDefaultRenderer.groovy        |  3 +++
 .../inspect/swingui/ButtonOrTextEditor.groovy     |  5 ++++-
 .../src/main/groovy/groovy/ui/Console.groovy      |  6 ++++--
 .../main/groovy/groovy/ui/ConsoleApplet.groovy    |  3 +++
 .../main/groovy/groovy/ui/HistoryRecord.groovy    |  2 ++
 .../main/groovy/groovy/ui/OutputTransforms.groovy | 11 ++++++-----
 .../groovy/groovy/ui/text/AutoIndentAction.groovy |  9 ++++++---
 11 files changed, 52 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/50f62297/subprojects/groovy-console/src/main/groovy/groovy/inspect/TextNode.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/inspect/TextNode.groovy b/subprojects/groovy-console/src/main/groovy/groovy/inspect/TextNode.groovy
index 8a05063..31b8a02 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/inspect/TextNode.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/inspect/TextNode.groovy
@@ -23,6 +23,9 @@
  */
 package groovy.inspect
 
+import groovy.transform.CompileStatic
+
+@CompileStatic
 class TextNode {
     Object userObject
     List<List<String>> properties

http://git-wip-us.apache.org/repos/asf/groovy/blob/50f62297/subprojects/groovy-console/src/main/groovy/groovy/inspect/TextTreeNodeMaker.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/inspect/TextTreeNodeMaker.groovy
b/subprojects/groovy-console/src/main/groovy/groovy/inspect/TextTreeNodeMaker.groovy
index d084e4c..29f893e 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/inspect/TextTreeNodeMaker.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/inspect/TextTreeNodeMaker.groovy
@@ -24,7 +24,9 @@
 package groovy.inspect
 
 import groovy.inspect.swingui.AstBrowserNodeMaker
+import groovy.transform.CompileStatic
 
+@CompileStatic
 class TextTreeNodeMaker implements AstBrowserNodeMaker<TextNode> {
     TextNode makeNode(Object userObject) {
         new TextNode(userObject)

http://git-wip-us.apache.org/repos/asf/groovy/blob/50f62297/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/AstBrowser.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/AstBrowser.groovy
b/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/AstBrowser.groovy
index 10607f0..c88ce5a 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/AstBrowser.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/AstBrowser.groovy
@@ -20,6 +20,7 @@ package groovy.inspect.swingui
 
 import groovy.lang.GroovyClassLoader.ClassCollector
 import groovy.swing.SwingBuilder
+import groovy.transform.CompileStatic
 import org.apache.groovy.io.StringBuilderWriter
 import org.codehaus.groovy.ast.ClassNode
 import org.codehaus.groovy.control.CompilationUnit
@@ -553,6 +554,7 @@ class AstBrowserUiPreferences {
 /**
  * An adapter for the CompilePhase enum that can be entered into a Swing combobox.
  */
+@CompileStatic
 enum CompilePhaseAdapter {
     INITIALIZATION(Phases.INITIALIZATION, 'Initialization'),
     PARSING(Phases.PARSING, 'Parsing'),
@@ -567,7 +569,7 @@ enum CompilePhaseAdapter {
     final int phaseId
     final String string
 
-    def CompilePhaseAdapter(phaseId, string) {
+    def CompilePhaseAdapter(int phaseId, String string) {
         this.phaseId = phaseId
         this.string = string
     }
@@ -580,6 +582,7 @@ enum CompilePhaseAdapter {
 /**
  * This class is a TreeNode and you can store additional properties on it.
  */
+@CompileStatic
 class TreeNodeWithProperties extends DefaultMutableTreeNode {
 
     List<List<String>> properties
@@ -611,6 +614,7 @@ class TreeNodeWithProperties extends DefaultMutableTreeNode {
 /**
  * This interface is used to create tree nodes of various types 
  */
+@CompileStatic
 interface AstBrowserNodeMaker<T> {
     T makeNode(Object userObject)
 
@@ -620,6 +624,7 @@ interface AstBrowserNodeMaker<T> {
 /**
  * Creates tree nodes for swing UI  
  */
+@CompileStatic
 class SwingTreeNodeMaker implements AstBrowserNodeMaker<DefaultMutableTreeNode> {
     DefaultMutableTreeNode makeNode(Object userObject) {
         new DefaultMutableTreeNode(userObject)
@@ -647,6 +652,7 @@ class BytecodeCollector extends ClassCollector {
 
 }
 
+@CompileStatic
 class GeneratedBytecodeAwareGroovyClassLoader extends GroovyClassLoader {
 
     private final Map<String, byte[]> bytecode = new HashMap<String, byte[]>()

http://git-wip-us.apache.org/repos/asf/groovy/blob/50f62297/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/AstNodeToScriptAdapter.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/AstNodeToScriptAdapter.groovy
b/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/AstNodeToScriptAdapter.groovy
index 28c7b17..a0d0259 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/AstNodeToScriptAdapter.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/AstNodeToScriptAdapter.groovy
@@ -18,7 +18,9 @@
  */
 package groovy.inspect.swingui
 
+import groovy.transform.CompileStatic
 import org.apache.groovy.io.StringBuilderWriter
+import org.codehaus.groovy.ast.ASTNode
 import org.codehaus.groovy.ast.AnnotationNode
 import org.codehaus.groovy.ast.ClassHelper
 import org.codehaus.groovy.ast.ClassNode
@@ -97,12 +99,14 @@ import org.codehaus.groovy.control.CompilerConfiguration
 import org.codehaus.groovy.control.SourceUnit
 
 import java.lang.reflect.Modifier
+import java.security.CodeSource
 
 /**
  * This class takes Groovy source code, compiles it to a specific compile phase, and then
decompiles it
  * back to the groovy source. It is used by GroovyConsole's AST Browser, but can also be
invoked from
  * the command line.
  */
+@CompileStatic
 class AstNodeToScriptAdapter {
 
     /**
@@ -110,7 +114,7 @@ class AstNodeToScriptAdapter {
      * @param args
      *      a filename to compile and a CompilePhase to run to
      */
-    static void main(args) {
+    static void main(String[] args) {
 
         if (!args || args.length < 2) {
             println '''
@@ -148,6 +152,7 @@ and [compilephase] is a valid Integer based org.codehaus.groovy.control.CompileP
      *    optional compiler configuration
      * @returns the source code from the AST state
      */
+
     String compileToScript(String script, int compilePhase, ClassLoader classLoader = null,
boolean showScriptFreeForm = true, boolean showScriptClass = true, CompilerConfiguration config
= null) {
 
         def writer = new StringBuilderWriter()
@@ -156,7 +161,7 @@ and [compilephase] is a valid Integer based org.codehaus.groovy.control.CompileP
 
         def scriptName = 'script' + System.currentTimeMillis() + '.groovy'
         GroovyCodeSource codeSource = new GroovyCodeSource(script, scriptName, '/groovy/script')
-        CompilationUnit cu = new CompilationUnit(config ?: CompilerConfiguration.DEFAULT,
codeSource.codeSource, classLoader)
+        CompilationUnit cu = new CompilationUnit((CompilerConfiguration) (config ?: CompilerConfiguration.DEFAULT),
(CodeSource) codeSource.codeSource, (GroovyClassLoader) classLoader)
         cu.addPhaseOperation(new AstNodeToScriptVisitor(writer, showScriptFreeForm, showScriptClass),
compilePhase)
         cu.addSource(codeSource.getName(), script)
         try {
@@ -180,6 +185,7 @@ and [compilephase] is a valid Integer based org.codehaus.groovy.control.CompileP
 /**
  * An adapter from ASTNode tree to source code.
  */
+@CompileStatic
 class AstNodeToScriptVisitor extends PrimaryClassNodeOperation implements GroovyCodeVisitor,
GroovyClassVisitor {
 
     private final Writer _out
@@ -793,7 +799,7 @@ class AstNodeToScriptVisitor extends PrimaryClassNodeOperation implements
Groovy
         }
         print '.'
         if (expression?.property instanceof ConstantExpression) {
-            visitConstantExpression(expression?.property, true)
+            visitConstantExpression((ConstantExpression) expression?.property, true)
         } else {
             expression?.property?.visit this
         }
@@ -838,7 +844,7 @@ class AstNodeToScriptVisitor extends PrimaryClassNodeOperation implements
Groovy
         // handle multiple assignment expressions
         if (expression?.leftExpression instanceof ArgumentListExpression) {
             print 'def '
-            visitArgumentlistExpression expression?.leftExpression, true
+            visitArgumentlistExpression((ArgumentListExpression) expression?.leftExpression,
true)
             print " $expression.operation.text "
             expression.rightExpression.visit this
 
@@ -942,7 +948,7 @@ class AstNodeToScriptVisitor extends PrimaryClassNodeOperation implements
Groovy
         if (expression?.mapEntryExpressions?.size() == 0) {
             print ':'
         } else {
-            visitExpressionsAndCommaSeparate(expression?.mapEntryExpressions)
+            visitExpressionsAndCommaSeparate((List) expression?.mapEntryExpressions)
         }
         print ']'
     }
@@ -1119,7 +1125,7 @@ class AstNodeToScriptVisitor extends PrimaryClassNodeOperation implements
Groovy
                 print ', '
             }
             first = false
-            it.visit this
+            ((ASTNode) it).visit this
         }
     }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/50f62297/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/ButtonOrDefaultRenderer.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/ButtonOrDefaultRenderer.groovy
b/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/ButtonOrDefaultRenderer.groovy
index c63129c..95348c8 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/ButtonOrDefaultRenderer.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/ButtonOrDefaultRenderer.groovy
@@ -19,6 +19,8 @@
  */
 package groovy.inspect.swingui
 
+import groovy.transform.CompileStatic
+
 import javax.swing.*
 import javax.swing.table.DefaultTableCellRenderer
 import java.awt.*
@@ -28,6 +30,7 @@ import java.awt.*
  * or call the default in the case of a non component object.
  * This hack allows to render a button shape in a table cell.
  */
+@CompileStatic
 class ButtonOrDefaultRenderer extends DefaultTableCellRenderer {
     Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
         if (value instanceof JComponent) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/50f62297/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/ButtonOrTextEditor.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/ButtonOrTextEditor.groovy
b/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/ButtonOrTextEditor.groovy
index 17e4fcc..1045b36 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/ButtonOrTextEditor.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/ButtonOrTextEditor.groovy
@@ -19,6 +19,8 @@
  */
 package groovy.inspect.swingui
 
+import groovy.transform.CompileStatic
+
 import javax.swing.*
 import javax.swing.table.TableCellEditor
 import java.awt.*
@@ -30,6 +32,7 @@ import java.awt.event.FocusListener
  * a text field if the value exists, or null otherwise (non editable cell).
  * This hack allows to interact with buttons in a cell.
  */
+@CompileStatic
 class ButtonOrTextEditor extends AbstractCellEditor implements TableCellEditor {
     /** The Swing component being edited. */
     protected JComponent editorComponent
@@ -38,7 +41,7 @@ class ButtonOrTextEditor extends AbstractCellEditor implements TableCellEditor
{
     Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
int row, int column) {
         if (value instanceof JButton) {
             editorComponent = value
-            editorComponent.addActionListener({ fireEditingStopped() } as ActionListener)
+            ((JButton) editorComponent).addActionListener({ fireEditingStopped() } as ActionListener)
         } else if (value instanceof JTextArea) {
             editorComponent = value
         } else if (value) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/50f62297/subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy b/subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy
index 8cde224..d119fbb 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy
@@ -23,6 +23,7 @@ import groovy.cli.picocli.OptionAccessor
 import groovy.inspect.swingui.AstBrowser
 import groovy.inspect.swingui.ObjectBrowser
 import groovy.swing.SwingBuilder
+import groovy.transform.CompileStatic
 import groovy.transform.ThreadInterrupt
 import groovy.ui.text.FindReplaceUtility
 import org.apache.groovy.io.StringBuilderWriter
@@ -1584,8 +1585,9 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener,
Fo
     }
 }
 
+@CompileStatic
 class GroovyFileFilter extends FileFilter {
-    private static final GROOVY_SOURCE_EXTENSIONS = ['*.groovy', '*.gvy', '*.gy', '*.gsh',
'*.story', '*.gpp', '*.grunit']
+    private static final java.util.List GROOVY_SOURCE_EXTENSIONS = ['*.groovy', '*.gvy',
'*.gy', '*.gsh', '*.story', '*.gpp', '*.grunit']
     private static final GROOVY_SOURCE_EXT_DESC = GROOVY_SOURCE_EXTENSIONS.join(',')
 
     public boolean accept(File f) {
@@ -1599,7 +1601,7 @@ class GroovyFileFilter extends FileFilter {
         "Groovy Source Files ($GROOVY_SOURCE_EXT_DESC)"
     }
     
-    static String getExtension(f) {
+    static String getExtension(File f) {
         def ext = null;
         def s = f.getName()
         def i = s.lastIndexOf('.')

http://git-wip-us.apache.org/repos/asf/groovy/blob/50f62297/subprojects/groovy-console/src/main/groovy/groovy/ui/ConsoleApplet.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/ui/ConsoleApplet.groovy b/subprojects/groovy-console/src/main/groovy/groovy/ui/ConsoleApplet.groovy
index f6a9f72..ac11820 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/ui/ConsoleApplet.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/ui/ConsoleApplet.groovy
@@ -18,11 +18,14 @@
  */
 package groovy.ui
 
+import groovy.transform.CompileStatic
+
 import javax.swing.*
 
 /**
  * ConsoleApplet
  */
+@CompileStatic
 class ConsoleApplet extends JApplet {
 
     Console console

http://git-wip-us.apache.org/repos/asf/groovy/blob/50f62297/subprojects/groovy-console/src/main/groovy/groovy/ui/HistoryRecord.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/ui/HistoryRecord.groovy b/subprojects/groovy-console/src/main/groovy/groovy/ui/HistoryRecord.groovy
index fd23be9..5d5f833 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/ui/HistoryRecord.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/ui/HistoryRecord.groovy
@@ -18,7 +18,9 @@
  */
 package groovy.ui
 
+import groovy.transform.CompileStatic
 
+@CompileStatic
 class HistoryRecord {
     String allText
     int selectionStart

http://git-wip-us.apache.org/repos/asf/groovy/blob/50f62297/subprojects/groovy-console/src/main/groovy/groovy/ui/OutputTransforms.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/ui/OutputTransforms.groovy
b/subprojects/groovy-console/src/main/groovy/groovy/ui/OutputTransforms.groovy
index 9f804dc..f3323b6 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/ui/OutputTransforms.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/ui/OutputTransforms.groovy
@@ -18,17 +18,19 @@
  */
 package groovy.ui
 
+import groovy.transform.CompileStatic
 import org.codehaus.groovy.runtime.InvokerHelper
 
 import javax.swing.*
 import java.awt.*
 import java.awt.image.BufferedImage
 
+@CompileStatic
 class OutputTransforms {
 
-    @Lazy static localTransforms = loadOutputTransforms()
+    @Lazy static java.util.List<Closure> localTransforms = loadOutputTransforms()
 
-    static loadOutputTransforms() {
+    static java.util.List<Closure> loadOutputTransforms() {
         def transforms = []
 
         //
@@ -82,10 +84,10 @@ class OutputTransforms {
         // final case, non-nulls just get inspected as strings
         transforms << { it -> if (it != null) "${InvokerHelper.inspect(it)}" }
 
-        return transforms
+        return (java.util.List<Closure>) transforms
     }
 
-    static transformResult(base, transforms = localTransforms) {
+    static transformResult(base, java.util.List<Closure> transforms = localTransforms)
{
         for (Closure c : transforms) {
             def result = c(base as Object)
             if (result != null)  {
@@ -94,5 +96,4 @@ class OutputTransforms {
         }
         return base
     }
-
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/50f62297/subprojects/groovy-console/src/main/groovy/groovy/ui/text/AutoIndentAction.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/ui/text/AutoIndentAction.groovy
b/subprojects/groovy-console/src/main/groovy/groovy/ui/text/AutoIndentAction.groovy
index 491e306..2054c06 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/ui/text/AutoIndentAction.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/ui/text/AutoIndentAction.groovy
@@ -18,16 +18,19 @@
  */
 package groovy.ui.text
 
+import groovy.transform.CompileStatic
+
 import javax.swing.*
 import javax.swing.text.AttributeSet
 import javax.swing.text.SimpleAttributeSet
 import java.awt.event.ActionEvent
 
+@CompileStatic
 class AutoIndentAction extends AbstractAction {
     AttributeSet simpleAttributeSet = new SimpleAttributeSet()
 
-    public void actionPerformed(ActionEvent evt) {
-        def inputArea = evt.source
+    void actionPerformed(ActionEvent evt) {
+        JTextPane inputArea = (JTextPane) evt.source
         def rootElement = inputArea.document.defaultRootElement
         def cursorPos = inputArea.getCaretPosition()
         int rowNum = rootElement.getElementIndex(cursorPos)
@@ -48,4 +51,4 @@ class AutoIndentAction extends AbstractAction {
 
         inputArea.document.insertString(cursorPos, '\n' + whitespaceStr, simpleAttributeSet)
     }
-}
\ No newline at end of file
+}


Mime
View raw message