use of org.eclipse.jdt.internal.compiler.ast.MemberValuePair in project lombok by rzwitserloot.
the class HandleSneakyThrows method handle.
@Override
public void handle(AnnotationValues<SneakyThrows> annotation, Annotation source, EclipseNode annotationNode) {
handleFlagUsage(annotationNode, ConfigurationKeys.SNEAKY_THROWS_FLAG_USAGE, "@SneakyThrows");
List<String> exceptionNames = annotation.getRawExpressions("value");
List<DeclaredException> exceptions = new ArrayList<DeclaredException>();
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++]));
}
}
EclipseNode owner = annotationNode.up();
switch(owner.getKind()) {
// return handleField(annotationNode, (FieldDeclaration)owner.get(), exceptions);
case METHOD:
handleMethod(annotationNode, (AbstractMethodDeclaration) owner.get(), exceptions);
break;
default:
annotationNode.addError("@SneakyThrows is legal only on methods and constructors.");
}
}
Aggregations