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
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
@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
@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
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
package transformacoes; | |
import ... | |
@Retention(RetentionPolicy.SOURCE) | |
@Target({ElementType.TYPE}) | |
@GroovyASTTransformationClass("transformacoes.LoggerTransformation") | |
public @interface Logger { | |
} |
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
@Test | |
public void testarTransformacaoQueIncluiAtributoLog() { | |
def existeCampo = Controller.declaredFields.any { it.name == 'log' } | |
assert existeCampo | |
} |
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 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
public class Controller { | |
private static final Logger log = Logger.getLogger(‘Controller’) | |
public java.lang.Object index() { | |
if (log.isLoggable(Level.INFO)) { | |
log.info 'Entrando no Index...' | |
} | |
return null | |
} | |
} |
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
@groovy.util.logging.Log | |
class Controller { | |
def index(){ | |
log.info "Entrando no Index..." | |
} | |
} |