From 1f4fb2fb4885ad9c808a080fbbf63353042e08d1 Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Wed, 2 Dec 2009 01:51:50 +0100 Subject: Fixed #73 SneakyThrows without parameter did not default to Throwable.class Added tests for SneakyThrows --- src/core/lombok/javac/handlers/HandleSneakyThrows.java | 7 ++++--- test/delombok/resource/after/SneakyThrowsPlain.java | 17 +++++++++++++++++ test/delombok/resource/before/SneakyThrowsPlain.java | 10 ++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 test/delombok/resource/after/SneakyThrowsPlain.java create mode 100644 test/delombok/resource/before/SneakyThrowsPlain.java diff --git a/src/core/lombok/javac/handlers/HandleSneakyThrows.java b/src/core/lombok/javac/handlers/HandleSneakyThrows.java index 8a185e87..fda8805c 100644 --- a/src/core/lombok/javac/handlers/HandleSneakyThrows.java +++ b/src/core/lombok/javac/handlers/HandleSneakyThrows.java @@ -26,6 +26,7 @@ import static lombok.javac.handlers.JavacHandlerUtil.markAnnotationAsProcessed; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import lombok.SneakyThrows; import lombok.core.AnnotationValues; @@ -52,9 +53,9 @@ public class HandleSneakyThrows implements JavacAnnotationHandler @Override public boolean handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { markAnnotationAsProcessed(annotationNode, SneakyThrows.class); Collection exceptionNames = annotation.getRawExpressions("value"); - - List memberValuePairs = ast.getArguments(); - if (memberValuePairs == null || memberValuePairs.size() == 0) return false; + if (exceptionNames.isEmpty()) { + exceptionNames = Collections.singleton("java.lang.Throwable"); + } java.util.List exceptions = new ArrayList(); for (String exception : exceptionNames) { diff --git a/test/delombok/resource/after/SneakyThrowsPlain.java b/test/delombok/resource/after/SneakyThrowsPlain.java new file mode 100644 index 00000000..d5abc478 --- /dev/null +++ b/test/delombok/resource/after/SneakyThrowsPlain.java @@ -0,0 +1,17 @@ +class SneakyThrowsPlain { + public void test() { + try { + System.out.println("test1"); + } catch (java.lang.Throwable $ex) { + throw lombok.Lombok.sneakyThrow($ex); + } + } + + public void test2() { + try { + System.out.println("test2"); + } catch (java.lang.Throwable $ex) { + throw lombok.Lombok.sneakyThrow($ex); + } + } +} \ No newline at end of file diff --git a/test/delombok/resource/before/SneakyThrowsPlain.java b/test/delombok/resource/before/SneakyThrowsPlain.java new file mode 100644 index 00000000..97fecf8f --- /dev/null +++ b/test/delombok/resource/before/SneakyThrowsPlain.java @@ -0,0 +1,10 @@ +import lombok.SneakyThrows; +class SneakyThrowsPlain { + @lombok.SneakyThrows public void test() { + System.out.println("test1"); + } + + @SneakyThrows public void test2() { + System.out.println("test2"); + } +} \ No newline at end of file -- cgit