Fixed #73 SneakyThrows without parameter did not default to Throwable.class

Added tests for SneakyThrows
This commit is contained in:
Roel Spilker
2009-12-02 01:51:50 +01:00
parent d2fc0df773
commit 1f4fb2fb48
3 changed files with 31 additions and 3 deletions
@@ -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<SneakyThrows>
@Override public boolean handle(AnnotationValues<SneakyThrows> annotation, JCAnnotation ast, JavacNode annotationNode) {
markAnnotationAsProcessed(annotationNode, SneakyThrows.class);
Collection<String> exceptionNames = annotation.getRawExpressions("value");
List<JCExpression> memberValuePairs = ast.getArguments();
if (memberValuePairs == null || memberValuePairs.size() == 0) return false;
if (exceptionNames.isEmpty()) {
exceptionNames = Collections.singleton("java.lang.Throwable");
}
java.util.List<String> exceptions = new ArrayList<String>();
for (String exception : exceptionNames) {
@@ -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);
}
}
}
@@ -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");
}
}