From 35691e83edffdadd5ef438793eec9c968e8bfd35 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 23 Sep 2009 07:44:53 +0200 Subject: Massive change to the eclipse handlers: They now set the 'generatedBy' flag which we can use to patch eclipse in specific places to ignore generated nodes. --- .../eclipse/handlers/HandleSneakyThrows.java | 58 +++++++++++++--------- 1 file changed, 35 insertions(+), 23 deletions(-) (limited to 'src/lombok/eclipse/handlers/HandleSneakyThrows.java') diff --git a/src/lombok/eclipse/handlers/HandleSneakyThrows.java b/src/lombok/eclipse/handlers/HandleSneakyThrows.java index f0ff53db..75dad780 100644 --- a/src/lombok/eclipse/handlers/HandleSneakyThrows.java +++ b/src/lombok/eclipse/handlers/HandleSneakyThrows.java @@ -27,6 +27,7 @@ import java.util.List; import lombok.SneakyThrows; import lombok.core.AnnotationValues; +import lombok.eclipse.Eclipse; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseAST.Node; @@ -68,29 +69,32 @@ public class HandleSneakyThrows implements EclipseAnnotationHandler annotation, Annotation ast, Node annotationNode) { + @Override public boolean handle(AnnotationValues annotation, Annotation source, Node annotationNode) { List exceptionNames = annotation.getRawExpressions("value"); + List exceptions = new ArrayList(); - MemberValuePair[] memberValuePairs = ast.memberValuePairs(); - if ( memberValuePairs == null || memberValuePairs.length == 0 ) return false; - - Expression arrayOrSingle = memberValuePairs[0].value; - final Expression[] exceptionNameNodes; - if ( arrayOrSingle instanceof ArrayInitializer ) { - exceptionNameNodes = ((ArrayInitializer)arrayOrSingle).expressions; - } else exceptionNameNodes = new Expression[] { arrayOrSingle }; - - if ( exceptionNames.size() != exceptionNameNodes.length ) { - annotationNode.addError( - "LOMBOK BUG: The number of exception classes in the annotation isn't the same pre- and post- guessing."); + MemberValuePair[] memberValuePairs = source.memberValuePairs(); + if ( memberValuePairs == null || memberValuePairs.length == 0 ) { + exceptions.add(new DeclaredException("java.lang.Throwable", source)); + } else { + Expression arrayOrSingle = memberValuePairs[0].value; + final Expression[] exceptionNameNodes; + if ( arrayOrSingle instanceof ArrayInitializer ) { + exceptionNameNodes = ((ArrayInitializer)arrayOrSingle).expressions; + } else exceptionNameNodes = new Expression[] { arrayOrSingle }; + + if ( exceptionNames.size() != exceptionNameNodes.length ) { + annotationNode.addError( + "LOMBOK BUG: The number of exception classes in the annotation isn't the same pre- and post- guessing."); + } + + int idx = 0; + for ( String exceptionName : exceptionNames ) { + if ( exceptionName.endsWith(".class") ) exceptionName = exceptionName.substring(0, exceptionName.length() - 6); + exceptions.add(new DeclaredException(exceptionName, exceptionNameNodes[idx++])); + } } - List exceptions = new ArrayList(); - int idx = 0; - for ( String exceptionName : exceptionNames ) { - if ( exceptionName.endsWith(".class") ) exceptionName = exceptionName.substring(0, exceptionName.length() - 6); - exceptions.add(new DeclaredException(exceptionName, exceptionNameNodes[idx++])); - } Node owner = annotationNode.up(); switch ( owner.getKind() ) { @@ -147,7 +151,7 @@ public class HandleSneakyThrows implements EclipseAnnotationHandler> 32), pE = (int)p; TryStatement tryStatement = new TryStatement(); + Eclipse.setGeneratedBy(tryStatement, source); tryStatement.tryBlock = new Block(0); - tryStatement.tryBlock.sourceStart = pS; - tryStatement.tryBlock.sourceEnd = pE; + tryStatement.tryBlock.sourceStart = pS; tryStatement.tryBlock.sourceEnd = pE; + Eclipse.setGeneratedBy(tryStatement.tryBlock, source); tryStatement.tryBlock.statements = contents; TypeReference typeReference; if ( exception.exceptionName.indexOf('.') == -1 ) { @@ -182,27 +187,34 @@ public class HandleSneakyThrows implements EclipseAnnotationHandler