Skip to the content.

Infinite Technology ∞ Supplies 📦

Misc commons/utilities/tools

Release info:

Attribute\Release type Latest Stable
Version 2.0.0-SNAPSHOT 1.1.x
Branch master SUPPLIES_1_1_X
CI Build status Build Status Build Status
Test coverage codecov codecov
Library (Maven) oss.jfrog.org snapshot Download

@CacheFieldInit

Caches the initialization of annotated field.
Cache is on class level (cache is static and shared across all instances).
Setting cached field reference to different object does not affect other users of this cached field.
Field should not be static. This is an eager cache. Polymorphism is not supported - cache is global per class hierarchy.
Example usage:

       @Cache
       File fileField = new File("./readme.txt")

Is transformed to:

       static ClosureCacheMap closureCacheMap = new ClosureCacheMap()
       File fileField = closureCacheMap.passThrough('fileField', {
           new File("./readme.txt")
       }, this)

Marker

❗ Since 1.1.0

Constructor call:

       new Marker()

Is automatically transformed (by global AST Transformation “MarkerTransformation”) to:

       new Marker([lineNumber], [lastLineNumber], [columnNumber], [lastColumnNumber], [className], [sourceUnitName])

Try it now!

Just run in the Groovy Console (requires Groovy 2.5.4):

@Grab('io.infinite:supplies:1.1.3')
import io.infinite.supplies.ast.marker.Marker
import io.infinite.supplies.ast.cache.CacheFieldInit
import java.util.UUID

class TryMe {

    @CacheFieldInit
    final String cachedField = UUID.randomUUID().toString()
    
    void tryMe() {
        println(toString() + ":" + cachedField + ":" + new Marker())
    }

}

new TryMe().tryMe()
new TryMe().tryMe()

Output:

TryMe@a294eb:ba2a0eb9-1210-467e-9c03-1199e69f4e30:Marker: className=TryMe, lineNumber=12, columnNumber=56, sourceUnitName=ConsoleScript5
TryMe@554d0f4:ba2a0eb9-1210-467e-9c03-1199e69f4e30:Marker: className=TryMe, lineNumber=12, columnNumber=56, sourceUnitName=ConsoleScript5