aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac/handlers/HandleSneakyThrows.java
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2014-02-06 20:40:19 +0100
committerRoel Spilker <r.spilker@gmail.com>2014-02-06 20:40:19 +0100
commitc128331d4dd5c38f5f0218940632dfffb0b25f5c (patch)
tree34bf3d690afdeac8c37ef4e94b571d28cbb7c6b0 /src/core/lombok/javac/handlers/HandleSneakyThrows.java
parente1344ec4c99878e2e6b7a09ae604b37b92dbb7eb (diff)
parentd1182bbf45ffd392134cb2379b33913f744b69d0 (diff)
downloadlombok-c128331d4dd5c38f5f0218940632dfffb0b25f5c.tar.gz
lombok-c128331d4dd5c38f5f0218940632dfffb0b25f5c.tar.bz2
lombok-c128331d4dd5c38f5f0218940632dfffb0b25f5c.zip
Merge pull request #43 from jlahoda/471
#471: @SneakyThrows should work in NetBeans
Diffstat (limited to 'src/core/lombok/javac/handlers/HandleSneakyThrows.java')
-rw-r--r--src/core/lombok/javac/handlers/HandleSneakyThrows.java21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/core/lombok/javac/handlers/HandleSneakyThrows.java b/src/core/lombok/javac/handlers/HandleSneakyThrows.java
index 0b444801..aa0c3c7e 100644
--- a/src/core/lombok/javac/handlers/HandleSneakyThrows.java
+++ b/src/core/lombok/javac/handlers/HandleSneakyThrows.java
@@ -40,12 +40,15 @@ import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCBlock;
+import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCStatement;
+import com.sun.tools.javac.tree.JCTree.JCTry;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.List;
+import lombok.javac.Javac;
/**
* Handles the {@code lombok.SneakyThrows} annotation for javac.
@@ -120,15 +123,25 @@ public class HandleSneakyThrows extends JavacAnnotationHandler<SneakyThrows> {
Context context = node.getContext();
JCBlock tryBlock = setGeneratedBy(maker.Block(0, contents), source, context);
-
JCExpression varType = chainDots(node, exception.split("\\."));
- JCVariableDecl catchParam = maker.VarDef(maker.Modifiers(Flags.FINAL), node.toName("$ex"), varType, null);
+ JCVariableDecl catchParam = maker.VarDef(maker.Modifiers(Flags.FINAL | Flags.PARAMETER), node.toName("$ex"), varType, null);
JCExpression lombokLombokSneakyThrowNameRef = chainDots(node, "lombok", "Lombok", "sneakyThrow");
JCBlock catchBody = maker.Block(0, List.<JCStatement>of(maker.Throw(maker.Apply(
List.<JCExpression>nil(), lombokLombokSneakyThrowNameRef,
List.<JCExpression>of(maker.Ident(node.toName("$ex")))))));
-
- return setGeneratedBy(maker.Try(tryBlock, List.of(recursiveSetGeneratedBy(maker.Catch(catchParam, catchBody), source, context)), null), source, context);
+ JCTry tryStatement = maker.Try(tryBlock, List.of(recursiveSetGeneratedBy(maker.Catch(catchParam, catchBody), source, context)), null);
+ if (JavacHandlerUtil.inNetbeansEditor(node)) {
+ //set span (start and end position) of the try statement and the main block
+ //this allows NetBeans to dive into the statement correctly:
+ JCCompilationUnit top = (JCCompilationUnit) node.top().get();
+ int startPos = contents.head.pos;
+ int endPos = Javac.getEndPosition(contents.last().pos(), top);
+ tryBlock.pos = startPos;
+ tryStatement.pos = startPos;
+ Javac.storeEnd(tryBlock, endPos, top);
+ Javac.storeEnd(tryStatement, endPos, top);
+ }
+ return setGeneratedBy(tryStatement, source, context);
}
}