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
package transformacoes; | |
import org.codehaus.groovy.ast.ASTNode; | |
import org.codehaus.groovy.control.CompilePhase; | |
import org.codehaus.groovy.control.SourceUnit; | |
import org.codehaus.groovy.transform.ASTTransformation; | |
import org.codehaus.groovy.transform.GroovyASTTransformation; | |
@GroovyASTTransformation(phase=CompilePhase.SEMANTIC_ANALYSIS) | |
public class LoggerTransformation implements ASTTransformation { |
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
@Override | |
public void visit(ASTNode[] nodes, SourceUnit sourceUnit) { | |
AnnotationNode logAnnotation = (AnnotationNode) nodes[0]; | |
ClassNode targetClass = (ClassNode) nodes[1]; | |
final ClassNode LOGGER_CLASSNODE = ClassHelper.make( | |
java.util.logging.Logger.class); | |
classNode.addField("log", |
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
@Logger | |
class Controller { | |
} |
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
AnnotatedNode targetClass = (AnnotatedNode) nodes[1]; | |
if (!(targetClass instanceof ClassNode)) | |
sourceUnit.addError( | |
new SyntaxException("@Logger anotado fora de uma Classe", | |
logAnnotation.getLineNumber(), | |
logAnnotation.getLastColumnNumber())); | |
final ClassNode classNode = (ClassNode) targetClass; |
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 methodMissing(String methodName, Object args) { | |
FinderMethod method = gormDynamicFinders.find { | |
FinderMethod f -> f.isMethodMatch(methodName) | |
} | |
if (!method) { | |
throw new MissingMethodException(methodName, persistentClass, args) | |
} | |
def mc = persistentClass.getMetaClass() | |
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
@Grapes( | |
@Grab(group='log4j', module='log4j', version='1.2.16') | |
) | |
import org.apache.commons.logging.LogFactory; | |
import org.apache.commons.logging.Log; | |
trait Loggable { | |
private Log logger | |
Log getLog() { | |
if( !logger ) | |
logger = LogFactory.getLog( this.getClass() ) |
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
trait A { | |
String exec() { 'A' } | |
} | |
trait B { | |
String exec() { 'B' } | |
} | |
class C implements A,B {} | |
def c = new C() | |
println c.exec() |
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 C implements A,B { | |
String exec() { A.super.exec() } | |
} |
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
trait Controller implements ResponseRenderer, | |
ResponseRedirector, | |
RequestForwarder, | |
DataBinder, | |
WebAttributes, | |
ServletAttributes { | |
//... | |
} |
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 ComponenteCustomizado implements WebAttributes { | |
def meuMetodo() { | |
println "params: " + params | |
} | |
} |