Skip to content

Instantly share code, notes, and snippets.

View melix's full-sized avatar

Cédric Champeau melix

View GitHub Profile
@melix
melix / ProxyGeneratorAdapter.java
Created February 1, 2012 15:01
Proxy generator
/*
* Copyright 2003-2009 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
@melix
melix / unary.patch
Created February 7, 2012 12:32
UnaryExpressionHelper patch
diff --git a/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java b/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
index 925ffd7..4555783 100644
--- a/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -71,10 +71,6 @@ public class AsmClassGenerator extends ClassGenerator {
static final MethodCaller despreadList = MethodCaller.newStatic(ScriptBytecodeAdapter.class, "despreadList");
// Closure
static final MethodCaller getMethodPointer = MethodCaller.newStatic(ScriptBytecodeAdapter.class, "getMethodPointer");
- // unary plus, unary minus, bitwise negation
- static final MethodCaller unaryPlus = MethodCaller.newStatic(ScriptBytecodeAdapter.class, "unaryPlus");
@melix
melix / add_local_ast.groovy
Created March 1, 2012 16:42
Add local AST transformation to a method
import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.control.customizers.CompilationCustomizer
import org.codehaus.groovy.control.CompilePhase
import groovy.transform.CompileStatic
import org.codehaus.groovy.ast.AnnotationNode
import org.codehaus.groovy.ast.ClassHelper
import org.codehaus.groovy.ast.ClassNode
import org.codehaus.groovy.transform.sc.StaticCompileTransformation
def config = new CompilerConfiguration()
@melix
melix / nasty.groovy
Created March 28, 2012 11:35
Never change the generics types of a cached class node!
// This is very WRONG because it changes the generics type of the primary class node.
// It means that future instances of ArrayList without generic types specified would be ArrayList<Foo>
def listenerListType = ClassHelper.make(ArrayList)
listenerListType.setGenericsTypes(types)
// Instead, you MUST acquire a class node for which the redirect class node is the primary node
// This can be easily done using the getPlainNodeReference() method
def listenerListType = ClassHelper.make(ArrayList).plainNodeReference
diff --git a/build.gradle b/build.gradle
index 9102228..f774cfd 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,15 +5,17 @@ defaultTasks 'clean', 'test'
repositories {
mavenCentral()
mavenRepo name:"codehaus", url:"http://repository.codehaus.org/"
- mavenRepo name:"groovypp", url:"http://groovypp.artifactoryonline.com/groovypp/libs-releases-local"
+ //mavenRepo name:"groovypp", url:"http://groovypp.artifactoryonline.com/groovypp/libs-releases-local"
@melix
melix / factchecking.groovy
Created May 2, 2012 20:59
Factchecking #LeDebat !
import groovy.json.JsonSlurper
def candidats = ['#Sarkozy', '#Hollande']
def flavors = ['INCORRECT', 'CORRECT', 'IMPRECIS']
def factchecking = [:].withDefault { [:].withDefault { 0 } }
15.times { page ->
def jsonText = new URL("http://otter.topsy.com/search.json?type=tweet&q=factchecking+from:LeVeritometre&window=1d&offset=${10 * page}").text
def answers = new JsonSlurper().parseText(jsonText)
answers.response.list.title.each { content ->
candidats.each { c ->
@melix
melix / Transformer.groovy
Created July 18, 2012 12:08
Transformer.groovy
package moo
import org.codehaus.groovy.ast.ASTNode
import org.codehaus.groovy.ast.ClassNode
import org.codehaus.groovy.ast.MethodNode
import org.codehaus.groovy.ast.expr.ArgumentListExpression
import org.codehaus.groovy.ast.expr.ConstantExpression
import org.codehaus.groovy.ast.expr.MethodCallExpression
import org.codehaus.groovy.ast.expr.VariableExpression
import org.codehaus.groovy.ast.stmt.ExpressionStatement
@melix
melix / osgi.patch
Created July 24, 2012 17:16
Patch for bnd
diff --git a/subprojects/osgi/osgi.gradle b/subprojects/osgi/osgi.gradle
index 57d7c1f..ccef5a0 100644
--- a/subprojects/osgi/osgi.gradle
+++ b/subprojects/osgi/osgi.gradle
@@ -21,7 +21,8 @@ dependencies {
compile project(':plugins')
compile libraries.slf4j_api
- compile module('biz.aQute:bndlib:1.50.0')
+// compile module('biz.aQute:bndlib:1.50.0')
@melix
melix / antlr.patch
Created August 30, 2012 17:36
Patch for enclosing method
diff --git a/src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java b/src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java
index 790c763..d53cb4d 100644
--- a/src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java
+++ b/src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java
@@ -95,6 +95,7 @@ public class AntlrParserPlugin extends ASTHelper implements ParserPlugin, Groovy
protected AST ast;
private ClassNode classNode;
+ private MethodNode methodNode;
private String[] tokenNames;
@melix
melix / delegate.groovy
Created September 12, 2012 10:30
Groovy dynamic delegate
class Foo {}
class Bar { void baz() { println 'baz' } }
def delegate = new Bar()
// attention, toutes les instances de Foo seront redirigées vers le même delegate. Sinon, utiliser foo.metaClass par instance
Foo.metaClass.invokeMethod = { name, args -> delegate."$name"(*args) }
new Foo().baz()
// Autre solution, plus propre, avec @Delegate
class Foo {