Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2011, The Staccato-Commons Team This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; version 3 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 
 
 package net.sf.staccatocommons.instrument.internal;
 
 
 

Author(s):
flbulgarelli
 
 public class InstrumenterImpl implements InstrumenterConfigurationInstrumenter {
 
   private final Logger logger = LoggerFactory.getLogger("Processor-Logger");
 
   private final ClassPool classPool;
   private int handlersCount;

  
Creates a new InstrumenterImpl

Parameters:
classPool
processors
 
   public InstrumenterImpl(ClassPool classPool) {
     this. = new AnnotationProcessor();
     this. = new AnnotationProcessor();
     this. = new AnnotationProcessor();
     this. = new AnnotationProcessor();
     this. = classPool;
   }

  

Parameters:
instrumentationMark the instrumentationMark to set
Returns:
this
 
     this. = instrumentationMark;
     return this;
   }
 
     if (handler instanceof ClassAnnotationHandler)
 
     if (handler instanceof ArgumentAnnotationHandler)
 
     if (handler instanceof ConstructorAnnotationHandler)
 
     if (handler instanceof MethodAnnotationHandler)
 
     ++;
     return this;
   }

  
Ensures that at least a handler has being registered, and the instrumentation mark was set
  public void ensureConfigured() {
    Validate.throwing(IllegalStateException.class//
      .isNotNull("instrumentarionMark")
      .isGreaterThan("handlers.count", 0);
  }

  
  public void instrumentClass(final CtClass clazzthrows CannotCompileExceptionClassNotFoundException {
    if (clazz.isInterface())
      return;
    if (alreadyProcessed(clazz)) {
      .debug("Class {} was already processed. Ignoring"clazz);
      return;
    }
    final ClassAnnotationContext context = //
      protected void softExec(Object annotationClassAnnotationHandler handlerthrows Exception {
        handler.preProcessAnnotatedClass((Annotationannotationcontext);
      }
    });
    for (CtMethod method : clazz.getDeclaredMethods())
      if (!Modifier.isAbstract(method.getModifiers()))
        instrumentMethod(method);
    for (CtConstructor constructor : clazz.getDeclaredConstructors())
      instrumentConstructor(constructor);
      protected void softExec(Object annotationClassAnnotationHandler handlerthrows Exception {
        handler.postProcessAnnotatedClass((Annotationannotationcontext);
      }
    });
    markAsProcessed(clazz);
  }
  private void markAsProcessed(CtClass clazz) {
  }
  private boolean alreadyProcessed(CtClass clazz) {
    return clazz.getAttribute(.getMarkAttributeName()) != null;
  }
    methodContext.setMethod(method);
    Object[] availableAnnotations = method.getAvailableAnnotations();
    .processUsing(availableAnnotationsnew Block2<ObjectMethodAnnotationHandler>() {
      protected void softExec(Object annotationMethodAnnotationHandler handlerthrows Exception {
        handler.preProcessAnnotatedMethod((AnnotationannotationmethodContext);
      }
    });
    instrumentArguments(method);
    .processUsing(availableAnnotationsnew Block2<ObjectMethodAnnotationHandler>() {
      protected void softExec(Object annotationMethodAnnotationHandler handlerthrows Exception {
        handler.postProcessAnnotatedMethod((AnnotationannotationmethodContext);
      }
    });
  }

  
    context.setConstructor(constructor);
    Object[] availableAnnotations = constructor.getAvailableAnnotations();
      protected void softExec(Object annotationConstructorAnnotationHandler handlerthrows Exception {
        handler.preProcessAnnotatedConstructor((Annotationannotationcontext);
      }
    });
    instrumentArguments(constructor);
      protected void softExec(Object annotationConstructorAnnotationHandler handlerthrows Exception {
        handler.postProcessAnnotatedConstructor((Annotationannotationcontext);
      }
    });
  }
  private void instrumentArguments(CtBehavior behaviourthrows CannotCompileException {
    Object[][] parameterAnnotations = behaviour.getAvailableParameterAnnotations();
    argumentContext.setBehavior(behaviour);
    for (int i = 0; i < parameterAnnotations.lengthi++) {
      argumentContext.setParameterNumber(i);
      .processUsing(parameterAnnotations[i], new Block2<ObjectArgumentAnnotationHandler>() {
        protected void softExec(Object annotationArgumentAnnotationHandler handlerthrows Exception {
          handler.processAnnotatedArgument((AnnotationannotationargumentContext);
        }
      });
    }
  }
New to GrepCode? Check out our FAQ X