Repository: incubator-groovy
Updated Branches:
  refs/heads/master e4fc41022 -> 54e56856c


GROOVY-7423: Added access to Method parameter names at runtime.


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

Branch: refs/heads/master
Commit: 7c735bfc1807df4e8fa44f02958c7a000634b6de
Parents: e4fc410
Author: Nick Grealy <nickgre...@gmail.com>
Authored: Thu Jun 11 00:34:22 2015 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Thu Jun 11 12:44:35 2015 +1000

----------------------------------------------------------------------
 src/main/groovy/ui/GroovyMain.java              |  2 +
 .../groovy/classgen/AsmClassGenerator.java      |  8 +++
 .../groovy/control/CompilerConfiguration.java   | 66 ++++++++++++++++++++
 .../groovy/tools/FileSystemCompiler.java        | 19 ++++--
 src/spec/doc/tools-groovy.adoc                  |  1 +
 src/spec/doc/tools-groovyc.adoc                 |  3 +
 .../java/org/codehaus/groovy/ant/Groovy.java    | 16 +++++
 .../java/org/codehaus/groovy/ant/Groovyc.java   | 33 ++++++++++
 .../src/spec/doc/groovy-ant-task.adoc           |  1 +
 .../src/main/groovy/groovy/ui/Console.groovy    | 49 ++++++++++++---
 .../main/resources/groovy/ui/Console.properties | 38 +++++++++++
 .../src/spec/doc/groovy-console.adoc            | 18 ++++++
 .../codehaus/groovy/tools/shell/Groovysh.groovy | 17 +++++
 .../groovy/tools/shell/Interpreter.groovy       |  8 +++
 .../org/codehaus/groovy/tools/shell/Main.groovy | 14 ++++-
 .../codehaus/groovy/tools/shell/Main.properties |  2 +
 .../groovy-groovysh/src/spec/doc/groovysh.adoc  |  2 +
 17 files changed, 283 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/7c735bfc/src/main/groovy/ui/GroovyMain.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/ui/GroovyMain.java 
b/src/main/groovy/ui/GroovyMain.java
index 14269cd..4fc921b 100644
--- a/src/main/groovy/ui/GroovyMain.java
+++ b/src/main/groovy/ui/GroovyMain.java
@@ -194,6 +194,7 @@ public class GroovyMain {
                 
.addOption(builder("i").argName("extension").optionalArg(true).desc("modify 
files in place; create backup if extension is given (e.g. \'.bak\')").build())
                 .addOption(builder("n").hasArg(false).desc("process files line 
by line using implicit 'line' variable").build())
                 .addOption(builder("p").hasArg(false).desc("process files line 
by line and print result (see also -n)").build())
+                .addOption(builder("pa").hasArg(false).desc("Generate metadata 
for reflection on method parameter names (jdk8+ 
only)").longOpt("parameters").build())
                 
.addOption(builder("l").argName("port").optionalArg(true).desc("listen on a 
port and process inbound lines (default: 1960)").build())
                 
.addOption(builder("a").argName("splitPattern").optionalArg(true).desc("split 
lines using splitPattern (default '\\s') using implicit 'split' 
variable").longOpt("autosplit").build())
                 .addOption(builder().longOpt("indy").desc("enables compilation 
using invokedynamic").build())
@@ -245,6 +246,7 @@ public class GroovyMain {
         main.isScriptFile = !line.hasOption('e');
         main.debug = line.hasOption('d');
         main.conf.setDebug(main.debug);
+        main.conf.setParameters(line.hasOption("pa"));
         main.processFiles = line.hasOption('p') || line.hasOption('n');
         main.autoOutput = line.hasOption('p');
         main.editFiles = line.hasOption('i');

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/7c735bfc/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java 
b/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
index 563a052..3104e81 100644
--- a/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -374,6 +374,14 @@ public class AsmClassGenerator extends ClassGenerator {
             visitParameterAnnotations(parameters[i], i, mv);
         }
 
+        // Add parameter names to the MethodVisitor (jdk8+ only)
+        if (getCompileUnit().getConfig().getParameters()) {
+            for (int i = 0; i < parameters.length; i++) {
+                // TODO handle ACC_SYNTHETIC for enum method parameters?
+                mv.visitParameter(parameters[i].getName(), 0);
+            }
+        }
+
         if (controller.getClassNode().isAnnotationDefinition() && 
!node.isStaticConstructor()) {
             visitAnnotationDefault(node, mv);
         } else if (!node.isAbstract()) {

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/7c735bfc/src/main/org/codehaus/groovy/control/CompilerConfiguration.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/control/CompilerConfiguration.java 
b/src/main/org/codehaus/groovy/control/CompilerConfiguration.java
index a08a09b..de3efa8 100644
--- a/src/main/org/codehaus/groovy/control/CompilerConfiguration.java
+++ b/src/main/org/codehaus/groovy/control/CompilerConfiguration.java
@@ -109,6 +109,11 @@ public class CompilerConfiguration {
     private boolean debug;
 
     /**
+     * If true, generates metadata for reflection on method parameters
+     */
+    private boolean parameters = false;
+
+    /**
      * The number of non-fatal errors to allow before bailing
      */
     private int tolerance;
@@ -179,10 +184,12 @@ public class CompilerConfiguration {
         setClasspath("");
         setVerbose(false);
         setDebug(false);
+        setParameters(safeGetSystemProperty("groovy.parameters") != null);
         setTolerance(10);
         setScriptBaseClass(null);
         setRecompileGroovySource(false);
         setMinimumRecompilationInterval(100);
+        // TODO change following try/catches to use 
#safeGetSystemProperty(...) ??
         // Target bytecode
         String targetByteCode = null;
         try {
@@ -254,6 +261,45 @@ public class CompilerConfiguration {
     }
 
     /**
+     * Retrieves a System property, or null if any of the following exceptions 
occur.
+     * <ul>
+     *     <li>SecurityException - if a security manager exists and its 
checkPropertyAccess method doesn't allow access to the specified system 
property.</li>
+     *     <li>NullPointerException - if key is null.</li>
+     *     <li>IllegalArgumentException - if key is empty.</li>
+     * </ul>
+     * @param key the name of the system property.
+     * @return
+     */
+    private String safeGetSystemProperty(String key){
+        return safeGetSystemProperty(key, null);
+    }
+
+    /**
+     * Retrieves a System property, or null if any of the following exceptions 
occur (Warning: Exception messages are
+     * suppressed).
+     * <ul>
+     *     <li>SecurityException - if a security manager exists and its 
checkPropertyAccess method doesn't allow access to the specified system 
property.</li>
+     *     <li>NullPointerException - if key is null.</li>
+     *     <li>IllegalArgumentException - if key is empty.</li>
+     * </ul>
+     * @param key the name of the system property.
+     * @param def a default value.
+     * @return
+     */
+    private String safeGetSystemProperty(String key, String def){
+        try {
+            return System.getProperty(key, def);
+        } catch (SecurityException t){
+            // suppress exception
+        } catch (NullPointerException t){
+            // suppress exception
+        } catch (IllegalArgumentException t){
+            // suppress exception
+        }
+        return def;
+    }
+
+    /**
      * Copy constructor.  Use this if you have a mostly correct configuration
      * for your compilation but you want to make a some changes 
programatically.
      * An important reason to prefer this approach is that your code will most
@@ -276,6 +322,7 @@ public class CompilerConfiguration {
         setClasspathList(new LinkedList<String>(configuration.getClasspath()));
         setVerbose(configuration.getVerbose());
         setDebug(configuration.getDebug());
+        setParameters(configuration.getParameters());
         setTolerance(configuration.getTolerance());
         setScriptBaseClass(configuration.getScriptBaseClass());
         setRecompileGroovySource(configuration.getRecompileGroovySource());
@@ -451,6 +498,11 @@ public class CompilerConfiguration {
         if (text != null && text.equalsIgnoreCase("true")) setDebug(true);
 
         //
+        // Parameters
+        //
+        setParameters(configuration.getProperty("groovy.parameters") != null);
+
+        //
         // Tolerance
         // 
         numeric = 10;
@@ -626,6 +678,13 @@ public class CompilerConfiguration {
     }
 
     /**
+     * Returns true if parameter metadata generation has been enabled.
+     */
+    public boolean getParameters() {
+        return this.parameters;
+    }
+
+    /**
      * Turns debugging operation on or off.
      */
     public void setDebug(boolean debug) {
@@ -633,6 +692,13 @@ public class CompilerConfiguration {
     }
 
     /**
+     * Turns parameter metadata generation on or off.
+     */
+    public void setParameters(boolean parameters) {
+        this.parameters = parameters;
+    }
+
+    /**
      * Returns the requested error tolerance.
      */
     public int getTolerance() {

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/7c735bfc/src/main/org/codehaus/groovy/tools/FileSystemCompiler.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/tools/FileSystemCompiler.java 
b/src/main/org/codehaus/groovy/tools/FileSystemCompiler.java
index 47761cc..253e48f 100644
--- a/src/main/org/codehaus/groovy/tools/FileSystemCompiler.java
+++ b/src/main/org/codehaus/groovy/tools/FileSystemCompiler.java
@@ -45,6 +45,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Arrays;
 
 /**
  * Command-line compiler (aka. <tt>groovyc</tt>).
@@ -275,6 +276,8 @@ public class FileSystemCompiler {
             configuration.setTargetDirectory(cli.getOptionValue('d'));
         }
 
+        configuration.setParameters(cli.hasOption("pa"));
+
         if (cli.hasOption("encoding")) {
             configuration.setSourceEncoding(cli.getOptionValue("encoding"));
         }
@@ -287,11 +290,18 @@ public class FileSystemCompiler {
         if (cli.hasOption('j')) {
             Map<String, Object> compilerOptions = new HashMap<String, 
Object>();
 
-            String[] opts = cli.getOptionValues("J");
-            compilerOptions.put("namedValues", opts);
+            String[] namedValues = cli.getOptionValues("J");
+            compilerOptions.put("namedValues", namedValues);
 
-            opts = cli.getOptionValues("F");
-            compilerOptions.put("flags", opts);
+            String[] flags = cli.getOptionValues("F");
+            if (flags != null && cli.hasOption("pa")){
+                // convert to a list, so we can add a parameter...
+                List<String> tmp = new ArrayList<String>(Arrays.asList(flags));
+                tmp.add("parameters");
+                // convert back to an array...
+                flags = tmp.toArray(new String[tmp.size()]);
+            }
+            compilerOptions.put("flags", flags);
 
             configuration.setJointCompilationOptions(compilerOptions);
         }
@@ -336,6 +346,7 @@ public class FileSystemCompiler {
         options.addOption(Option.builder("h").longOpt("help").desc("Print a 
synopsis of standard options").build());
         options.addOption(Option.builder("v").longOpt("version").desc("Print 
the version").build());
         options.addOption(Option.builder("e").longOpt("exception").desc("Print 
stack trace on error").build());
+        
options.addOption(Option.builder("pa").longOpt("parameters").desc("Generate 
metadata for reflection on method parameter names (jdk8+ only)").build());
         
options.addOption(Option.builder("j").longOpt("jointCompilation").desc("Attach 
javac compiler to compile .java files").build());
         
options.addOption(Option.builder("b").longOpt("basescript").hasArg().argName("class").desc("Base
 class name for scripts (must derive from Script)").build());
 

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/7c735bfc/src/spec/doc/tools-groovy.adoc
----------------------------------------------------------------------
diff --git a/src/spec/doc/tools-groovy.adoc b/src/spec/doc/tools-groovy.adoc
index e14d23a..c30fa79 100644
--- a/src/spec/doc/tools-groovy.adoc
+++ b/src/spec/doc/tools-groovy.adoc
@@ -46,4 +46,5 @@ int (disable any int based optimizations) |
 | -n | | process files line by line using implicit 'line' variable |
 | -p | | process files line by line and print result (see also -n) |
 | -v | --version | display the Groovy and JVM versions | groovy -v
+| -pa | --parameters | Generates metadata for reflection on method parameter 
names on JDK 8 and above. Defaults to false. | groovy --parameters Person.groovy
 |=======================================================================

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/7c735bfc/src/spec/doc/tools-groovyc.adoc
----------------------------------------------------------------------
diff --git a/src/spec/doc/tools-groovyc.adoc b/src/spec/doc/tools-groovyc.adoc
index 153131f..138aa62 100644
--- a/src/spec/doc/tools-groovyc.adoc
+++ b/src/spec/doc/tools-groovyc.adoc
@@ -38,6 +38,7 @@ argument. | groovyc -cp lib/dep.jar MyClass.groovy
 | | --configscript | Advanced compiler configuration script | groovyc 
--configscript config/config.groovy src/Person.groovy
 | -Jproperty=value | | Properties to be passed to `javac` if joint compilation 
is enabled | groovyc -j -Jtarget=1.5 -Jsource=1.5 A.groovy B.java
 | -Fflag | | Flags to be passed to `javac` if joint compilation is enabled | 
groovyc -j -Fnowarn A.groovy B.java
+| -pa | --parameters | Generates metadata for reflection on method parameter 
names on JDK 8 and above. Defaults to false. | groovyc --parameters 
Person.groovy
 |=======================================================================
 
 *Notes:*
@@ -144,6 +145,8 @@ you need to set this flag to true. Defaults to false. |No
 
 |configscript |Set the configuration file used to customize the compilation 
configuration. |No
 
+|parameters |Generates metadata for reflection on method parameter names on 
JDK 8 and above. Defaults to false. |No
+
 |=======================================================================
 
 *Example:*

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/7c735bfc/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java
----------------------------------------------------------------------
diff --git 
a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java 
b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java
index c32e40d..f2cc4d4 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java
@@ -268,6 +268,22 @@ public class Groovy extends Java {
     }
 
     /**
+     * If true, generates metadata for reflection on method parameter names 
(jdk8+ only).  Defaults to false.
+     *
+     * @param parameters set to true to generate metadata.
+     */
+    public void setParameters(boolean parameters) {
+        configuration.setParameters(parameters);
+    }
+
+    /**
+     * Returns true if parameter metadata generation has been enabled.
+     */
+    public boolean getParameters() {
+        return configuration.getParameters();
+    }
+
+    /**
      * Load the file and then execute it
      */
     public void execute() throws BuildException {

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/7c735bfc/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
----------------------------------------------------------------------
diff --git 
a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java 
b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
index e956c90..e77dfc5 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
@@ -117,6 +117,7 @@ import 
org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit;
  * <li>keepStubs</li>
  * <li>forceLookupUnnamedFiles</li>
  * <li>configscript</li>
+ * <li>parameters</li>
  * </ul>
  * And these nested tasks:
  * <ul>
@@ -215,6 +216,12 @@ public class Groovyc extends MatchingTask {
 
     private Set<String> scriptExtensions = new LinkedHashSet<String>();
 
+
+    /**
+     * If true, generates metadata for reflection on method parameter names 
(jdk8+ only).  Defaults to false.
+     */
+    private boolean parameters = false;
+
     /**
      * Adds a path for source compilation.
      *
@@ -804,6 +811,22 @@ public class Groovyc extends MatchingTask {
     }
 
     /**
+     * If true, generates metadata for reflection on method parameter names 
(jdk8+ only).  Defaults to false.
+     *
+     * @param parameters set to true to generate metadata.
+     */
+    public void setParameters(boolean parameters) {
+        this.parameters = parameters;
+    }
+
+    /**
+     * Returns true if parameter metadata generation has been enabled.
+     */
+    public boolean getParameters() {
+        return this.parameters;
+    }
+
+    /**
      * Executes the task.
      *
      * @throws BuildException if an error occurs
@@ -1034,6 +1057,13 @@ public class Groovyc extends MatchingTask {
         }
     }
 
+    /**
+     * Add "groovyc" parameters to the commandLineList, based on the ant 
configuration.
+     *
+     * @param commandLineList
+     * @param jointOptions
+     * @param classpath
+     */
     private void doNormalCommandLineList(List<String> commandLineList, 
List<String> jointOptions, Path classpath) {
         commandLineList.add("--classpath");
         commandLineList.add(classpath.toString());
@@ -1052,6 +1082,9 @@ public class Groovyc extends MatchingTask {
         if (stacktrace) {
             commandLineList.add("-e");
         }
+        if (parameters) {
+            commandLineList.add("--parameters");
+        }
         if (useIndy) {
             commandLineList.add("--indy");
         }

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/7c735bfc/subprojects/groovy-ant/src/spec/doc/groovy-ant-task.adoc
----------------------------------------------------------------------
diff --git a/subprojects/groovy-ant/src/spec/doc/groovy-ant-task.adoc 
b/subprojects/groovy-ant/src/spec/doc/groovy-ant-task.adoc
index 0dc4f18..8f7d905 100644
--- a/subprojects/groovy-ant/src/spec/doc/groovy-ant-task.adoc
+++ b/subprojects/groovy-ant/src/spec/doc/groovy-ant-task.adoc
@@ -35,6 +35,7 @@ Assuming `groovy-all-VERSION.jar` is in `my.classpath` you 
will need to declare
 |fork|If enabled the script will be executed in another JVM (disabled by 
default).|No
 |scriptBaseClass|The name of the base class for scripts.|No
 |indy|If enabled the script will be executed with `invokedynamic` (disabled by 
default).|No
+|parameters |Generates metadata for reflection on method parameter names on 
JDK 8 and above. Defaults to false. |No
 |============================================
 
 == Parameters specified as nested elements

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/7c735bfc/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 ad9c0b8..7dbba16 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.inspect.swingui.AstBrowser
 import groovy.swing.SwingBuilder
 import groovy.ui.text.FindReplaceUtility
 import org.codehaus.groovy.control.messages.SimpleMessage
+import org.codehaus.groovy.tools.shell.util.MessageSource
 
 import java.awt.Component
 import java.awt.EventQueue
@@ -174,6 +175,7 @@ class Console implements CaretListener, HyperlinkListener, 
ComponentListener, Fo
     File currentClasspathDir = new 
File(Preferences.userNodeForPackage(Console).get('currentClasspathDir', '.'))
 
     // Running scripts
+    CompilerConfiguration baseConfig
     CompilerConfiguration config
     GroovyShell shell
     int scriptNameCounter = 0
@@ -192,12 +194,30 @@ class Console implements CaretListener, 
HyperlinkListener, ComponentListener, Fo
     Action interruptAction
     
     static void main(args) {
-        if (args.length == 1 && args[0] == '--help') {
-            println '''usage: groovyConsole [options] [filename]
-options:
-  --help                               This Help message
-  -cp,-classpath,--classpath <path>    Specify classpath'''
-            return
+        CliBuilder cli = new CliBuilder(usage: 'groovyConsole [options] 
[filename]', stopAtNonOption: false)
+        MessageSource messages = new MessageSource(Console)
+        cli.with {
+            classpath(messages['cli.option.classpath.description'])
+            cp(longOpt: 'classpath', messages['cli.option.cp.description'])
+            h(longOpt: 'help', messages['cli.option.help.description'])
+            V(longOpt: 'version', messages['cli.option.version.description'])
+            pa(longOpt: 'parameters', 
messages['cli.option.parameters.description'])
+        }
+        OptionAccessor options = cli.parse(args)
+
+        if (options == null) {
+            // CliBuilder prints error, but does not exit
+            System.exit(22) // Invalid Args
+        }
+
+        if (options.h) {
+            cli.usage()
+            System.exit(0)
+        }
+
+        if (options.V) {
+            System.out.println(messages.format('cli.info.version', 
GroovySystem.version))
+            System.exit(0)
         }
 
         // full stack trace should not be logged to the output window - 
GROOVY-4663
@@ -206,10 +226,16 @@ options:
         //when starting via main set the look and feel to system
         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
 
-        def console = new Console(Console.class.classLoader?.getRootLoader())
+        def baseConfig = new CompilerConfiguration()
+        baseConfig.setParameters((boolean) options.hasOption("pa"))
+
+        def console = new Console(Console.class.classLoader?.getRootLoader(), 
new Binding(), baseConfig)
         console.useScriptClassLoaderForScriptExecution = true
         console.run()
-        if (args.length == 1) console.loadScriptFile(args[0] as File)
+        if (args.length > 0 && !args[-1].toString().startsWith("-")) {
+            console.loadScriptFile(args[-1] as File)
+        }
+
     }
 
     Console() {
@@ -225,6 +251,11 @@ options:
     }
 
     Console(ClassLoader parent, Binding binding) {
+        this(parent, binding, new CompilerConfiguration())
+    }
+
+    Console(ClassLoader parent, Binding binding, CompilerConfiguration 
baseConfig) {
+        this.baseConfig = baseConfig
         newScript(parent, binding);
         try {
             System.setProperty('groovy.full.stacktrace', 
System.getProperty('groovy.full.stacktrace',
@@ -247,7 +278,7 @@ options:
     }
 
     void newScript(ClassLoader parent, Binding binding) {
-        config = new CompilerConfiguration()
+        config = new CompilerConfiguration(baseConfig)
         if (threadInterrupt) config.addCompilationCustomizers(new 
ASTTransformationCustomizer(ThreadInterrupt))
 
         shell = new GroovyShell(parent, binding, config)

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/7c735bfc/subprojects/groovy-console/src/main/resources/groovy/ui/Console.properties
----------------------------------------------------------------------
diff --git 
a/subprojects/groovy-console/src/main/resources/groovy/ui/Console.properties 
b/subprojects/groovy-console/src/main/resources/groovy/ui/Console.properties
new file mode 100644
index 0000000..5884355
--- /dev/null
+++ b/subprojects/groovy-console/src/main/resources/groovy/ui/Console.properties
@@ -0,0 +1,38 @@
+#
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+#
+
+#
+# $Id$
+#
+
+#
+# CLI messages
+#
+
+cli.option.help.description=Display this help message
+
+cli.option.version.description=Display the version
+
+cli.option.cp.description=Aliases for '-classpath'
+
+cli.option.classpath.description=Specify where to find the class files - must 
be first argument
+
+cli.option.parameters.description=Generate metadata for reflection on method 
parameter names (jdk8+ only)
+
+cli.info.version=GroovyConsole {0}

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/7c735bfc/subprojects/groovy-console/src/spec/doc/groovy-console.adoc
----------------------------------------------------------------------
diff --git a/subprojects/groovy-console/src/spec/doc/groovy-console.adoc 
b/subprojects/groovy-console/src/spec/doc/groovy-console.adoc
index 64ac62a..f1e7955 100644
--- a/subprojects/groovy-console/src/spec/doc/groovy-console.adoc
+++ b/subprojects/groovy-console/src/spec/doc/groovy-console.adoc
@@ -32,6 +32,24 @@ the output area.
 [[GroovyConsole-Features]]
 == Features
 
+[[GroovyConsole-Command-lineOptionsandArguments]]
+=== Command-line Options and Arguments
+
+The Groovy Console supports several options to control classpath and other 
features.
+
+[source,groovy]
+-----------------------------------------------------------------
+./bin/groovyConsole --help
+usage: groovyConsole [options] [filename]
+ -classpath         Specify where to find the class files - must be first
+                    argument
+ -cp,--classpath    Aliases for '-classpath'
+ -h,--help          Display this help message
+ -pa,--parameters   Generate metadata for reflection on method parameter
+                    names (jdk8+ only)
+ -V,--version       Display the version
+-----------------------------------------------------------------
+
 [[GroovyConsole-RunningScripts]]
 === Running Scripts
 

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/7c735bfc/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Groovysh.groovy
----------------------------------------------------------------------
diff --git 
a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Groovysh.groovy
 
b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Groovysh.groovy
index fc92cc2..c27f8e6 100644
--- 
a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Groovysh.groovy
+++ 
b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Groovysh.groovy
@@ -24,6 +24,7 @@ import jline.Terminal
 import jline.WindowsTerminal
 import jline.console.history.FileHistory
 import org.codehaus.groovy.control.CompilationFailedException
+import org.codehaus.groovy.control.CompilerConfiguration
 import org.codehaus.groovy.control.ErrorCollector
 import org.codehaus.groovy.control.MultipleCompilationErrorsException
 import org.codehaus.groovy.control.messages.Message
@@ -101,6 +102,17 @@ class Groovysh extends Shell {
         this.packageHelper = new PackageHelperImpl(classLoader)
     }
 
+    Groovysh(final ClassLoader classLoader, final Binding binding, final IO 
io, final Closure registrar, CompilerConfiguration configuration) {
+        super(io)
+        assert classLoader
+        assert binding
+        assert registrar
+        parser = new Parser()
+        interp = new Interpreter(classLoader, binding, configuration)
+        registrar.call(this)
+        this.packageHelper = new PackageHelperImpl(classLoader)
+    }
+
     private static Closure createDefaultRegistrar(final ClassLoader 
classLoader) {
 
         return {Groovysh shell ->
@@ -126,6 +138,11 @@ class Groovysh extends Shell {
         this(new Binding(), io)
     }
 
+    Groovysh(final IO io, CompilerConfiguration configuration) {
+        this(Thread.currentThread().contextClassLoader, new Binding(), io,
+                
createDefaultRegistrar(Thread.currentThread().contextClassLoader), 
configuration)
+    }
+
     Groovysh() {
         this(new IO())
     }

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/7c735bfc/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Interpreter.groovy
----------------------------------------------------------------------
diff --git 
a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Interpreter.groovy
 
b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Interpreter.groovy
index 81a9b7a..1eb28e2 100644
--- 
a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Interpreter.groovy
+++ 
b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Interpreter.groovy
@@ -18,6 +18,7 @@
  */
 package org.codehaus.groovy.tools.shell
 
+import org.codehaus.groovy.control.CompilerConfiguration
 import org.codehaus.groovy.runtime.InvokerHelper
 import org.codehaus.groovy.tools.shell.util.Logger
 import org.codehaus.groovy.runtime.MethodClosure
@@ -44,6 +45,13 @@ class Interpreter implements Evaluator
         shell = new GroovyShell(classLoader, binding)
     }
 
+    Interpreter(final ClassLoader classLoader, final Binding binding, 
CompilerConfiguration configuration) {
+        assert classLoader
+        assert binding
+
+        shell = new GroovyShell(classLoader, binding, configuration)
+    }
+
     Binding getContext() {
         return shell.context
     }

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/7c735bfc/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Main.groovy
----------------------------------------------------------------------
diff --git 
a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Main.groovy
 
b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Main.groovy
index 8fbc6d5..e3c2230 100644
--- 
a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Main.groovy
+++ 
b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Main.groovy
@@ -22,6 +22,7 @@ import jline.TerminalFactory
 import jline.UnixTerminal
 import jline.UnsupportedTerminal
 import jline.WindowsTerminal
+import org.codehaus.groovy.control.CompilerConfiguration
 import org.codehaus.groovy.tools.shell.util.HelpFormatter
 import org.codehaus.groovy.tools.shell.util.Logger
 import org.codehaus.groovy.tools.shell.util.MessageSource
@@ -58,6 +59,14 @@ class Main
         groovysh = new Groovysh(io)
     }
 
+    /**
+     * @param io: may just be new IO(), which is the default
+     */
+    Main(IO io, CompilerConfiguration configuration) {
+        Logger.io = io
+        groovysh = new Groovysh(io, configuration)
+    }
+
     Groovysh getGroovysh() {
         return groovysh
     }
@@ -81,6 +90,7 @@ class Main
             C(longOpt: 'color', args: 1, argName: 'FLAG', optionalArg: true, 
messages['cli.option.color.description'])
             D(longOpt: 'define', args: 1, argName: 'NAME=VALUE', 
messages['cli.option.define.description'])
             T(longOpt: 'terminal', args: 1, argName: 'TYPE', 
messages['cli.option.terminal.description'])
+            pa(longOpt: 'parameters', 
messages['cli.option.parameters.description'])
         }
         OptionAccessor options = cli.parse(args)
 
@@ -147,9 +157,11 @@ class Main
         if (options.e) {
             evalString = options.getOptionValue('e')
         }
+        def configuration = new CompilerConfiguration()
+        configuration.setParameters((boolean) options.hasOption("pa"))
 
         List<String> filenames = options.arguments()
-        Main main = new Main(io)
+        Main main = new Main(io, configuration)
         main.startGroovysh(evalString, filenames)
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/7c735bfc/subprojects/groovy-groovysh/src/main/resources/org/codehaus/groovy/tools/shell/Main.properties
----------------------------------------------------------------------
diff --git 
a/subprojects/groovy-groovysh/src/main/resources/org/codehaus/groovy/tools/shell/Main.properties
 
b/subprojects/groovy-groovysh/src/main/resources/org/codehaus/groovy/tools/shell/Main.properties
index 902ee16..ddbf5e3 100644
--- 
a/subprojects/groovy-groovysh/src/main/resources/org/codehaus/groovy/tools/shell/Main.properties
+++ 
b/subprojects/groovy-groovysh/src/main/resources/org/codehaus/groovy/tools/shell/Main.properties
@@ -47,4 +47,6 @@ cli.option.define.description=Define a system property
 
 cli.option.terminal.description=Specify the terminal TYPE to use
 
+cli.option.parameters.description=Generate metadata for reflection on method 
parameter names (jdk8+ only)
+
 cli.info.version=@|green Groovy Shell|@ {0}

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/7c735bfc/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc 
b/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc
index fafc6fd..a8eb306 100644
--- a/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc
+++ b/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc
@@ -46,6 +46,8 @@ usage: groovysh [options] [...]
   -e, --evaluate=arg         Evaluate option fist when starting
                              interactive session
   -h, --help                 Display this help message
+  -pa, --parameters          Generate metadata for reflection on method
+                             parameter names (jdk8+ only)
   -q, --quiet                Suppress superfluous output
   -v, --verbose              Enable verbose output
 -----------------------------------------------------------------

Reply via email to