This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Xml { | |
boolean called = false | |
void bar() { called = true } | |
void foo(@DelegatesTo(Xml)Closure cl) { cl.delegate=this;cl() } | |
} | |
def mylist = [1] | |
def xml = new Xml() | |
xml.foo { | |
mylist.each { bar() } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo { | |
def foo() { println 'Called foo' } | |
} | |
@groovy.transform.CompileStatic | |
def with(Object target, @DelegatesTo(parameter='target') Closure arg) { | |
arg.delegate = target | |
arg() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@GrabResolver('http://www.emn.fr/z-info/choco-repo/mvn/repository/') | |
@Grab('choco:choco-solver:2.1.5') | |
import static choco.Choco.* | |
import choco.cp.model.CPModel | |
import choco.cp.solver.CPSolver | |
import choco.kernel.model.variables.integer.IntegerVariable | |
@groovy.transform.CompileStatic | |
def solve(Map<String,Integer> menu, int sum) { | |
def m = new CPModel() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parser = new groovy.json.JsonSlurper() | |
def contribs = parser.parseText(new URL('https://api.github.com/repos/groovy/groovy-core/contributors').text) | |
def stats = contribs.inject([sum:0,contribs:[:]]) { map, val -> | |
map.contribs[val.login] = val.contributions | |
map.sum += val.contributions | |
map | |
} | |
stats.contribs.each { | |
println "${it.key.padRight(16)} = $it.value (${(int)(100*it.value/stats.sum)}%)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.transform.CompileStatic | |
import groovyx.ast.bytecode.Bytecode | |
import java.lang.invoke.*; | |
import java.lang.invoke.MethodHandles.Lookup; | |
import static groovyjarjarasm.asm.Opcodes.* | |
import static java.lang.invoke.MethodHandles.* | |
public static MethodHandle findMethod(Lookup lookup, String name) { | |
lookup.findVirtual(Main, name, MethodType.methodType(int)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void greet(String name) { println "Hello, $name!" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
First, create: | |
foo/Echo.ceylon: | |
class Echo() { | |
shared void echo(Array<String> list) { print(list); } | |
} | |
foo/Echo2.ceylon | |
import foo {Echo} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab('com.googlecode.gbench:gbench:0.4.2-groovy-2.1') | |
class Person { | |
String name | |
int age | |
} | |
def p = new Person(name:'foo', age:10) | |
def pName = 'name' | |
def props = p.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2003-2012 the original author or authors. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.codehaus.groovy.control.CompilerConfiguration | |
import org.codehaus.groovy.syntax.SyntaxException | |
import org.codehaus.groovy.ast.ClassNode | |
import org.codehaus.groovy.control.SourceUnit | |
import org.codehaus.groovy.classgen.GeneratorContext | |
class SynchronizedRemover extends org.codehaus.groovy.control.customizers.CompilationCustomizer { | |
SynchronizedRemover() { | |
super(org.codehaus.groovy.control.CompilePhase.CONVERSION) | |
} |