mirror of
https://github.com/tiennm99/lombok.git
synced 2026-09-02 12:20:23 +00:00
Fixed #73 SneakyThrows without parameter did not default to Throwable.class
Added tests for SneakyThrows
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user