Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package net.sf.alchim.codeplus.spoonprocessor;
 
public class CheckBeforeProcessor extends AbstractProcessor<CtMethod<?>> {
    public void process(CtMethod<?> m) {
        try {
            CtAnnotation<?> annotation = null;
            for (CtAnnotation<?> a : m.getAnnotations()) {
                if (CheckBefore.class.equals(a.getActualAnnotation().annotationType())) {
                    annotation = a;
                    break;
                }
            }
            if (annotation == null) {
                return;
            }
            for (String check : ((CheckBeforeannotation.getActualAnnotation()).value()) {
                CtExpression<BooleancheckExpr = getFactory().Code().createCodeSnippetExpression(check);
                CtBlock<?> checkBlock = Substitution.substituteMethodBody((CtClass<?>) m.getDeclaringType(), new CheckBeforeTemplate(checkcheckExpr), "check");
                ProcessorHelper.forcePositionOfEveryStmt(checkBlockannotation.getPosition());
                m.getBody().insertBegin(checkBlock);
            }
            ProcessorHelper.removeAnnotation(mCheckBefore.class);
        } catch (Exception exc) {
            throw new ProcessingException(thismexc);
        }
    }
New to GrepCode? Check out our FAQ X