Skip to content

shils/groovy-exp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Experimental AST transformations featuring:

@AutoBreak

@AutoBreak
int test() {
    int result = 0
    switch(1) {
        case 1:
        case 2:
            result = 2
        default:
            result = 3
    }
    return result
}
assert test() == 2

@AutoBreak(includeEmptyCases = true)
int test() {
    int result = 0
    switch(1) {
        case 1:
        case 2:
            result = 2
        default:
            result = 3
    }
    return result
}
assert test() == 0

@LocalStatic

class Bar {
    static final String CONSTANT = 'def'
}

class Foo {
    List<String> test() {
        @LocalStatic final List<String> x = ['abc', Bar.CONSTANT]
        x
    }
}
def foo = new Foo()
assert foo.test() == ['abc', 'def']
assert foo.test().is(new Foo().test())

@Use

@CompileStatic
class A {
    @Use(IntCat.class)
    int multiply(int a, int b){
        a.times(b)
    }

    static class IntCat {
        static int times(int a, int b) {
            a*b
        }
    }
}

assert new A().multiply(3,4) == A.IntCat.times(3,4)

About

Experimental Groovy AST transformations

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published