Search in sources :

Example 6 with ArrayInitializer

use of org.eclipse.jdt.internal.compiler.ast.ArrayInitializer 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.");
    }
}
Also used : MemberValuePair(org.eclipse.jdt.internal.compiler.ast.MemberValuePair) Expression(org.eclipse.jdt.internal.compiler.ast.Expression) ArrayList(java.util.ArrayList) EclipseNode(lombok.eclipse.EclipseNode) ArrayInitializer(org.eclipse.jdt.internal.compiler.ast.ArrayInitializer)

Aggregations

ArrayInitializer (org.eclipse.jdt.internal.compiler.ast.ArrayInitializer)6 ArrayList (java.util.ArrayList)3 Annotation (org.eclipse.jdt.internal.compiler.ast.Annotation)3 Expression (org.eclipse.jdt.internal.compiler.ast.Expression)3 MemberValuePair (org.eclipse.jdt.internal.compiler.ast.MemberValuePair)3 SingleMemberAnnotation (org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation)3 EclipseNode (lombok.eclipse.EclipseNode)2 AllocationExpression (org.eclipse.jdt.internal.compiler.ast.AllocationExpression)2 CastExpression (org.eclipse.jdt.internal.compiler.ast.CastExpression)2 EqualExpression (org.eclipse.jdt.internal.compiler.ast.EqualExpression)2 MarkerAnnotation (org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation)2 NormalAnnotation (org.eclipse.jdt.internal.compiler.ast.NormalAnnotation)2 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 List (java.util.List)1 AnnotationValues (lombok.core.AnnotationValues)1 AnnotationValue (lombok.core.AnnotationValues.AnnotationValue)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 FieldDeclaration (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration)1 ForStatement (org.eclipse.jdt.internal.compiler.ast.ForStatement)1