Search in sources :

Example 6 with MemberValuePair

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.");
    }
}
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

MemberValuePair (org.eclipse.jdt.internal.compiler.ast.MemberValuePair)6 Annotation (org.eclipse.jdt.internal.compiler.ast.Annotation)4 EqualExpression (org.eclipse.jdt.internal.compiler.ast.EqualExpression)4 Expression (org.eclipse.jdt.internal.compiler.ast.Expression)4 MarkerAnnotation (org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation)4 NormalAnnotation (org.eclipse.jdt.internal.compiler.ast.NormalAnnotation)4 SingleMemberAnnotation (org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation)4 ArrayList (java.util.ArrayList)3 AllocationExpression (org.eclipse.jdt.internal.compiler.ast.AllocationExpression)3 ArrayInitializer (org.eclipse.jdt.internal.compiler.ast.ArrayInitializer)3 CastExpression (org.eclipse.jdt.internal.compiler.ast.CastExpression)3 EclipseNode (lombok.eclipse.EclipseNode)2 ParameterizedSingleTypeReference (org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference)2 SingleTypeReference (org.eclipse.jdt.internal.compiler.ast.SingleTypeReference)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 ASTNode (org.eclipse.jdt.internal.compiler.ast.ASTNode)1