diff options
author | Maarten Mulders <m.th.mulders@xs4all.nl> | 2014-02-07 16:14:01 +0100 |
---|---|---|
committer | Maarten Mulders <m.th.mulders@xs4all.nl> | 2014-02-08 15:18:23 +0100 |
commit | c38a64a5564996b552d88448bfb00722403bf194 (patch) | |
tree | 77dce34a5c427f1341a7278e030bae03beccba14 /src/core/lombok/eclipse | |
parent | d269cdcaf1012c967b353e3984072bf42a6061da (diff) | |
download | lombok-c38a64a5564996b552d88448bfb00722403bf194.tar.gz lombok-c38a64a5564996b552d88448bfb00722403bf194.tar.bz2 lombok-c38a64a5564996b552d88448bfb00722403bf194.zip |
Handlers and testcases for @Slf4j
Diffstat (limited to 'src/core/lombok/eclipse')
-rw-r--r-- | src/core/lombok/eclipse/handlers/HandleLog.java | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleLog.java b/src/core/lombok/eclipse/handlers/HandleLog.java index 6b1e94be..ee9986b1 100644 --- a/src/core/lombok/eclipse/handlers/HandleLog.java +++ b/src/core/lombok/eclipse/handlers/HandleLog.java @@ -38,6 +38,7 @@ import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; import org.eclipse.jdt.internal.compiler.ast.MessageSend; import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference; import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference; +import org.eclipse.jdt.internal.compiler.ast.StringLiteral; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; @@ -48,7 +49,7 @@ public class HandleLog { throw new UnsupportedOperationException(); } - public static void processAnnotation(LoggingFramework framework, AnnotationValues<? extends java.lang.annotation.Annotation> annotation, Annotation source, EclipseNode annotationNode) { + public static void processAnnotation(LoggingFramework framework, AnnotationValues<? extends java.lang.annotation.Annotation> annotation, Annotation source, EclipseNode annotationNode, String loggerCategory) { EclipseNode owner = annotationNode.up(); switch (owner.getKind()) { case TYPE: @@ -71,7 +72,7 @@ public class HandleLog { ClassLiteralAccess loggingType = selfType(owner, source); - FieldDeclaration fieldDeclaration = createField(framework, source, loggingType); + FieldDeclaration fieldDeclaration = createField(framework, source, loggingType, loggerCategory); fieldDeclaration.traverse(new SetGeneratedByVisitor(source), typeDecl.staticInitializerScope); // TODO temporary workaround for issue 217. http://code.google.com/p/projectlombok/issues/detail?id=217 // injectFieldSuppressWarnings(owner, fieldDeclaration); @@ -97,7 +98,7 @@ public class HandleLog { return result; } - public static FieldDeclaration createField(LoggingFramework framework, Annotation source, ClassLiteralAccess loggingType) { + public static FieldDeclaration createField(LoggingFramework framework, Annotation source, ClassLiteralAccess loggingType, String loggerCategory) { int pS = source.sourceStart, pE = source.sourceEnd; long p = (long)pS << 32 | pE; @@ -116,7 +117,12 @@ public class HandleLog { factoryMethodCall.receiver = createNameReference(framework.getLoggerFactoryTypeName(), source); factoryMethodCall.selector = framework.getLoggerFactoryMethodName().toCharArray(); - Expression parameter = framework.createFactoryParameter(loggingType, source); + Expression parameter; + if (loggerCategory == null || loggerCategory.trim().length() == 0) { + parameter = framework.createFactoryParameter(loggingType, source); + } else { + parameter = new StringLiteral(loggerCategory.toCharArray(), pS, pE, 0); + } factoryMethodCall.arguments = new Expression[] { parameter }; factoryMethodCall.nameSourcePosition = p; @@ -155,7 +161,7 @@ public class HandleLog { @ProviderFor(EclipseAnnotationHandler.class) public static class HandleCommonsLog extends EclipseAnnotationHandler<lombok.extern.apachecommons.CommonsLog> { @Override public void handle(AnnotationValues<lombok.extern.apachecommons.CommonsLog> annotation, Annotation source, EclipseNode annotationNode) { - processAnnotation(LoggingFramework.COMMONS, annotation, source, annotationNode); + processAnnotation(LoggingFramework.COMMONS, annotation, source, annotationNode, ""); } } @@ -165,7 +171,7 @@ public class HandleLog { @ProviderFor(EclipseAnnotationHandler.class) public static class HandleJulLog extends EclipseAnnotationHandler<lombok.extern.java.Log> { @Override public void handle(AnnotationValues<lombok.extern.java.Log> annotation, Annotation source, EclipseNode annotationNode) { - processAnnotation(LoggingFramework.JUL, annotation, source, annotationNode); + processAnnotation(LoggingFramework.JUL, annotation, source, annotationNode, ""); } } @@ -175,7 +181,7 @@ public class HandleLog { @ProviderFor(EclipseAnnotationHandler.class) public static class HandleLog4jLog extends EclipseAnnotationHandler<lombok.extern.log4j.Log4j> { @Override public void handle(AnnotationValues<lombok.extern.log4j.Log4j> annotation, Annotation source, EclipseNode annotationNode) { - processAnnotation(LoggingFramework.LOG4J, annotation, source, annotationNode); + processAnnotation(LoggingFramework.LOG4J, annotation, source, annotationNode, ""); } } @@ -185,7 +191,7 @@ public class HandleLog { @ProviderFor(EclipseAnnotationHandler.class) public static class HandleLog4j2Log extends EclipseAnnotationHandler<lombok.extern.log4j.Log4j2> { @Override public void handle(AnnotationValues<lombok.extern.log4j.Log4j2> annotation, Annotation source, EclipseNode annotationNode) { - processAnnotation(LoggingFramework.LOG4J2, annotation, source, annotationNode); + processAnnotation(LoggingFramework.LOG4J2, annotation, source, annotationNode, ""); } } @@ -195,7 +201,7 @@ public class HandleLog { @ProviderFor(EclipseAnnotationHandler.class) public static class HandleSlf4jLog extends EclipseAnnotationHandler<lombok.extern.slf4j.Slf4j> { @Override public void handle(AnnotationValues<lombok.extern.slf4j.Slf4j> annotation, Annotation source, EclipseNode annotationNode) { - processAnnotation(LoggingFramework.SLF4J, annotation, source, annotationNode); + processAnnotation(LoggingFramework.SLF4J, annotation, source, annotationNode, annotation.getInstance().value()); } } @@ -205,7 +211,7 @@ public class HandleLog { @ProviderFor(EclipseAnnotationHandler.class) public static class HandleXSlf4jLog extends EclipseAnnotationHandler<lombok.extern.slf4j.XSlf4j> { @Override public void handle(AnnotationValues<lombok.extern.slf4j.XSlf4j> annotation, Annotation source, EclipseNode annotationNode) { - processAnnotation(LoggingFramework.XSLF4J, annotation, source, annotationNode); + processAnnotation(LoggingFramework.XSLF4J, annotation, source, annotationNode, ""); } } |