Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3707

I wish i could parse a class using eval function of JSR223

    XMLWordPrintableJSON

Details

    • Wish
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 1.6.4
    • None
    • JSR / TCK / GLS
    • None

    Description

      Verbose version of the test passes, but it is a little ugly.

          public static final String FOO_CLASS = "class Foo { int getResult() { return 1; } } ; Foo.class";
          public static final String FOO = "class Foo { int getResult() { return 1; } }";
      
          public void testClassEvalVerbose() throws ScriptException {
              ScriptEngineManager factory = new ScriptEngineManager();
              ScriptEngine engine = factory.getEngineByName("groovy");
              assertEquals("Foo", ((Class) engine.eval(FOO_CLASS)).getCanonicalName());
          }
      
          public void testClassEvalBrief() throws ScriptException {
              ScriptEngineManager factory = new ScriptEngineManager();
              ScriptEngine engine = factory.getEngineByName("groovy");
              assertEquals("Foo", ((Class) engine.eval(FOO)).getCanonicalName());
          }
      

      Brief version throws:
      javax.script.ScriptException: javax.script.ScriptException: org.codehaus.groovy.runtime.metaclass.MissingMethodExceptionNoStack: No signature of method: Foo.main() is applicable for argument types: ([Ljava.lang.String values: [[]]
      at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:119)
      at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:247)
      at com.jtstand.TestStepScriptTest.testClassEvalBrief(TestStepScriptTest.java:42)
      Caused by: javax.script.ScriptException: org.codehaus.groovy.runtime.metaclass.MissingMethodExceptionNoStack: No signature of method: Foo.main() is applicable for argument types: ([Ljava.lang.String values: [[]]
      at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:307)
      at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:113)
      ... 28 more
      Caused by: org.codehaus.groovy.runtime.metaclass.MissingMethodExceptionNoStack: No signature of method: Foo.main() is applicable for argument types: ([Ljava.lang.String values: [[]]

      Why?
      Is this what JSR223 specifies to do?
      To sad if yes!

      Attachments

        Issue Links

          Activity

            People

              guillaume Guillaume Sauthier
              ali65 Albert Kurucz
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: