aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/eclipse/TransformEclipseAST.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-06-14 23:55:39 +0200
committerReinier Zwitserloot <reinier@tipit.to>2009-06-14 23:55:39 +0200
commit65de2407ae2b5fac6244d2ca670ea5b458992221 (patch)
tree1fd1f00b7fc8715cdae7d389dcd0b889f129dafe /src/lombok/eclipse/TransformEclipseAST.java
parent65cd03b6c592f825b037a6647888f4eafbaf3388 (diff)
downloadlombok-65de2407ae2b5fac6244d2ca670ea5b458992221.tar.gz
lombok-65de2407ae2b5fac6244d2ca670ea5b458992221.tar.bz2
lombok-65de2407ae2b5fac6244d2ca670ea5b458992221.zip
Made lombok more robust by catching exceptions near the top level and turning them into eclipse-wide errors in the worst case, but usually in an error in the problems dialog.
Diffstat (limited to 'src/lombok/eclipse/TransformEclipseAST.java')
-rw-r--r--src/lombok/eclipse/TransformEclipseAST.java39
1 files changed, 27 insertions, 12 deletions
diff --git a/src/lombok/eclipse/TransformEclipseAST.java b/src/lombok/eclipse/TransformEclipseAST.java
index 34350597..c9690953 100644
--- a/src/lombok/eclipse/TransformEclipseAST.java
+++ b/src/lombok/eclipse/TransformEclipseAST.java
@@ -31,18 +31,17 @@ public class TransformEclipseAST {
private static final Field astCacheField;
private static final HandlerLibrary handlers;
+ private static boolean disableLombok = false;
+
static {
Field f = null;
HandlerLibrary l = null;
try {
l = HandlerLibrary.load();
- } catch ( Exception e ) {
- e.printStackTrace();
- }
- try {
f = CompilationUnitDeclaration.class.getDeclaredField("$lombokAST");
- } catch ( NoSuchFieldException ignore ) {
- ignore.printStackTrace();
+ } catch ( Throwable t ) {
+ Eclipse.error("Problem initializing lombok", t);
+ disableLombok = true;
}
astCacheField = f;
handlers = l;
@@ -60,12 +59,28 @@ public class TransformEclipseAST {
* @param ast The AST node belonging to the compilation unit (java speak for a single source file).
*/
public static void transform(Parser parser, CompilationUnitDeclaration ast) {
- EclipseAST existing = getCache(ast);
- if ( existing == null ) {
- existing = new EclipseAST(ast);
- setCache(ast, existing);
- } else existing.reparse();
- new TransformEclipseAST(existing).go();
+ if ( disableLombok ) return;
+ try {
+ EclipseAST existing = getCache(ast);
+ if ( existing == null ) {
+ existing = new EclipseAST(ast);
+ setCache(ast, existing);
+ } else existing.reparse();
+ new TransformEclipseAST(existing).go();
+ } catch ( Throwable t ) {
+ try {
+ String fileName = "(unknown)";
+ if ( ast.compilationResult != null && ast.compilationResult.fileName != null ) {
+ fileName = new String(ast.compilationResult.fileName);
+ }
+
+ String message = "Lombok can't parse this source: " + t.toString();
+
+ EclipseAST.addProblemToCompilationResult(fileName, ast, false, message, ast, 0, 0);
+ } catch ( Throwable t2 ) {
+ Eclipse.error("Can't create an error in the problems dialog while adding: " + t.toString(), t2);
+ }
+ }
}
private static EclipseAST getCache(CompilationUnitDeclaration ast) {