List of Groovy Annotations

Don’t know where i found this list but have always wondered what annotations can we use when coding groovy scripts ? This list may not include more recent annotations – sorry.

Yeah, know you always wanted to understand groovy annotations but were afraid to ask, so just to give you the scoop, yo can watch this Paul King video where he explains how it all works – enjoy 🙂


Groovy AST Transforms
Groovy AST Transforms by Paul King

For those who don’t know, annotations are metadata tags we provide to the groovy compiler. These annotations are not directly turned into byte code, but more typically generate a small set of add-on logic to support specific stuff.

One typical annotation i use a lot is

@ToString class Fred{}

which asks the groovy compiler to produce extra code to create a toString() method for my class rather than hand-code one myself – cos i’m a lazy bugger like that ;-}

The list so far is :

// Abstract Syntax Tree
- in memory transform of your groovy script before bytecode generation
- it's a macro-like compiler hook allowing further mods to post-xlate /  pre-generate stage
- Code generation
@ToString
@EqualsAndHashCode
@Canonical
@TupleConstructor
@InheritConstructors
@Category
@IndexedProperty
@Lazy
@Newify

- Class design
@Delegate
@Immutable
@Memoized
@Singleton
@Mixin

- Logging
@Log
@log4j
@Log4j2
@Slf4j

- Safe Scripting
@ConditionalInterrupt
@ThreadInterrupt
@TimedInterrupt

-CompilerDirective
@Field
@PackageScope
@AnnotationCollector
@DelegatesTo
@TypeChecked - throws error if typo in var.s ane method names, bad return types, wrong type assigns -- allows fine-grained type inferences for DSLs or dynamics
@CompileStatic - generates same bytecode as javac w/same performance whe used with @TypeChecked
@CompileDynamic

- Swing
@Bindable
@ListenerList
@Vetoable

- Dependencies
@Grab
@GrabConfig
@GrabExclude
@GrabResolver

- Testing
@NotYetImplemented
@ASTTest

More

Let me know if you find more annotations we can add to this list.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s