From f6bbebfbd200fab85a637e3b7939a9c1444332a3 Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Sat, 6 Nov 2010 14:17:22 +0100 Subject: Use an annotation instead of implementations of interfaces --- src/core/lombok/javac/handlers/HandleLog.java | 135 ++++++++++---------------- 1 file changed, 49 insertions(+), 86 deletions(-) diff --git a/src/core/lombok/javac/handlers/HandleLog.java b/src/core/lombok/javac/handlers/HandleLog.java index abeca18e..652fbae0 100644 --- a/src/core/lombok/javac/handlers/HandleLog.java +++ b/src/core/lombok/javac/handlers/HandleLog.java @@ -111,126 +111,89 @@ public class HandleLog { return true; } - static interface LoggingFramework { - Class getAnnotationClass(); - String getLoggerTypeName(); - String getLoggerFactoryMethodName(); - JCExpression createFactoryParameter(JavacNode typeNode, String typeName); - } - - // private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(TargetType.class); - private static LoggingFramework COMMONS = new LoggingFramework() { - @Override public Class getAnnotationClass() { - return lombok.jul.Log.class; - } - - @Override public String getLoggerTypeName() { - return "org.apache.commons.logging.Log"; - } - - @Override public String getLoggerFactoryMethodName() { - return "org.apache.commons.logging.LogFactory.getLog"; - } - - @Override public JCExpression createFactoryParameter(JavacNode typeNode, String typeName) { - return chainDotsString(typeNode.getTreeMaker(), typeNode, typeName + ".class"); - } - }; - /** * Handles the {@link lombok.commons.Log} annotation for javac. */ @ProviderFor(JavacAnnotationHandler.class) public static class HandleCommonsLog implements JavacAnnotationHandler { @Override public boolean handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { - return processAnnotation(COMMONS, annotation, annotationNode); + return processAnnotation(LoggingFramework.COMMONS, annotation, annotationNode); } } - // private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger("TargetType"); - private static LoggingFramework JUL = new LoggingFramework() { - @Override public Class getAnnotationClass() { - return lombok.jul.Log.class; - } - - @Override public String getLoggerTypeName() { - return "java.util.logging.Logger"; - } - - @Override public String getLoggerFactoryMethodName() { - return "java.util.logging.Logger.getLogger"; - } - - @Override public JCExpression createFactoryParameter(JavacNode typeNode, String typeName) { - return typeNode.getTreeMaker().Literal(typeName); - } - }; - /** * Handles the {@link lombok.jul.Log} annotation for javac. */ @ProviderFor(JavacAnnotationHandler.class) public static class HandleJulLog implements JavacAnnotationHandler { @Override public boolean handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { - return processAnnotation(JUL, annotation, annotationNode); + return processAnnotation(LoggingFramework.JUL, annotation, annotationNode); } } - // private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(TargetType.class); - private static LoggingFramework LOG4J = new LoggingFramework() { - @Override public Class getAnnotationClass() { - return lombok.jul.Log.class; - } - - @Override public String getLoggerTypeName() { - return "org.apache.log4j.Logger"; - } - - @Override public String getLoggerFactoryMethodName() { - return "org.apache.log4j.Logger.getLogger"; - } - - @Override public JCExpression createFactoryParameter(JavacNode typeNode, String typeName) { - return chainDotsString(typeNode.getTreeMaker(), typeNode, typeName + ".class"); - } - }; - /** * Handles the {@link lombok.log4j.Log} annotation for javac. */ @ProviderFor(JavacAnnotationHandler.class) public static class HandleLog4jLog implements JavacAnnotationHandler { @Override public boolean handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { - return processAnnotation(LOG4J, annotation, annotationNode); + return processAnnotation(LoggingFramework.LOG4J, annotation, annotationNode); } } - // private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(TargetType.class); - private static LoggingFramework SLF4J = new LoggingFramework() { - @Override public Class getAnnotationClass() { - return lombok.slf4j.Log.class; + /** + * Handles the {@link lombok.slf4j.Log} annotation for javac. + */ + @ProviderFor(JavacAnnotationHandler.class) + public static class HandleSlf4jLog implements JavacAnnotationHandler { + @Override public boolean handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { + return processAnnotation(LoggingFramework.SLF4J, annotation, annotationNode); + } + } + + enum LoggingFramework { + // private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(TargetType.class); + COMMONS(lombok.jul.Log.class, "org.apache.commons.logging.Log", "org.apache.commons.logging.LogFactory.getLog"), + + // private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger("TargetType"); + JUL(lombok.jul.Log.class, "java.util.logging.Logger", "java.util.logging.Logger.getLogger") { + @Override public JCExpression createFactoryParameter(JavacNode typeNode, String typeName) { + return typeNode.getTreeMaker().Literal(typeName); + } + }, + + // private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(TargetType.class); + LOG4J(lombok.jul.Log.class, "org.apache.log4j.Logger", "org.apache.log4j.Logger.getLogger"), + + // private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(TargetType.class); + SLF4J(lombok.slf4j.Log.class, "org.slf4j.Logger", "org.slf4j.LoggerFactory.getLogger"), + + ; + + private final Class annotationClass; + private final String loggerTypeName; + private final String loggerFactoryName; + + LoggingFramework(Class annotationClass, String loggerTypeName, String loggerFactoryName) { + this.annotationClass = annotationClass; + this.loggerTypeName = loggerTypeName; + this.loggerFactoryName = loggerFactoryName; } - @Override public String getLoggerTypeName() { - return "org.slf4j.Logger"; + final Class getAnnotationClass() { + return annotationClass; } - @Override public String getLoggerFactoryMethodName() { - return "org.slf4j.LoggerFactory.getLogger"; + final String getLoggerTypeName() { + return loggerTypeName; } - @Override public JCExpression createFactoryParameter(JavacNode typeNode, String typeName) { - return chainDotsString(typeNode.getTreeMaker(), typeNode, typeName + ".class"); + final String getLoggerFactoryMethodName() { + return loggerFactoryName; } - }; - - /** - * Handles the {@link lombok.slf4j.Log} annotation for javac. - */ - @ProviderFor(JavacAnnotationHandler.class) - public static class HandleSlf4jLog implements JavacAnnotationHandler { - @Override public boolean handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { - return processAnnotation(SLF4J, annotation, annotationNode); + + JCExpression createFactoryParameter(JavacNode typeNode, String typeName) { + return chainDotsString(typeNode.getTreeMaker(), typeNode, typeName + ".class"); } } } -- cgit