groovy

include example of observing and editing compilation phase during class loading

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.6-beta-2
  • Fix Version/s: 1.6-rc-1, 1.5.8, 1.7-beta-1
  • Component/s: None
  • Labels:
    None
  • Environment:
    I've attached an example which has been tested on Xandros Linux and Windows XP. Works fine with latest build of source.
  • Testcase included:
    yes
  • Patch Submitted:
    Yes
  • Number of attachments :
    1

Description

I've attached an example of observing the compilation process.
This came out of the discussion here: http://www.nabble.com/Groovy-as-arithmetic-expression-evaluator--to19459935.html

This example code is in /src/examples/groovyShell

The class is called ArithmeticShell. "The arithmetic shell is similar to a GroovyShell in that it can evaluate text as code and return a result. It is not a subclass of GroovyShell because it does not widen the contract of GroovyShell, instead it narrows it. Using one of these shells like a GroovyShell would result in many runtime errors." It should how to observe the compilation process and how to walk the AST.

I did not do a static import on java.lang.Math because it was a hassle to test. I did not extend CodeVisitorSupport for reasons stated in the Javadoc.

It includes a GroovyTestCase but does not include an Ant script to build it.

Perhaps this can help someone.

Activity

Hide
Guillaume Laforge added a comment -

Thanks a lot Hamlet for this great example!
Keep contributions coming

Show
Guillaume Laforge added a comment - Thanks a lot Hamlet for this great example! Keep contributions coming

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: