title: @AspectJ Class level Annotation Advice with Annotation as method argument
body: <p>How can I get the annotation to be passed as the argument for the Advice defined for 
  class-level annotation? Is it possible?</p>
  
  <p>From the post <a href="https://stackoverflow.com/questions/2011089/aspectj-pointcut-for-all-methods-of-a-class-with-specific-annotation/2522821">here</a> I am able to get the point cut that identifies all the public method in the class which is marked by a specific Annotation. I am able to get the advice applied as well. However, I don’t know how to get the annotation variable passed as argument in above case.</p>
  
  <p>For a method-level annotation, I am able to get the pointcut and advice in which I can get the annotation passed as argument, but I don’t know how to achieve the same for class-level annotation.</p>
  
  <p>The below code works, but I need to get the annotation as the argument for the advice “<strong>LogExecutionTimeByClass</strong>” in below program and I couldn’t able to get appropriate advice or pointcut for the same.</p>
  
  <p>Annotation:   </p>
  
  <pre><code>import java.lang.annotation.ElementType;
  import java.lang.annotation.Retention;
  import java.lang.annotation.RetentionPolicy;
  import java.lang.annotation.Target;
  
  @Target({ElementType.TYPE, ElementType.METHOD})
  @Retention(RetentionPolicy.RUNTIME)
  public @interface LogExecutionTime {
  String level();
  }
  </code></pre>
  
  <p>Aspect:  </p>
  
  <pre><code>import org.aspectj.lang.ProceedingJoinPoint;
  import org.aspectj.lang.annotation.Around;
  import org.aspectj.lang.annotation.Aspect;
  import org.aspectj.lang.annotation.Pointcut;
  
  @Aspect
  public class LogTimeAspect {
  
      /*
       * Pointcut to match all the public methods.
      */
      @Pointcut("execution(public * *(..))")
      public void publicMethod() {}
  
      /*
       * Advice for the public methods that are marked with Annotation "LogExecutionTime" and it works as expected no issue.
      */ 
      @Around("publicMethod() &amp;&amp; @annotation(annotation) ")
      public Object LogExecutionTimeByMethod(final ProceedingJoinPoint joinPoint,final LogExecutionTime annotation) throws Throwable 
      {
          System.out.println("Invoking the method " +joinPoint.getSignature() +" by LogExecutionTimeByMethod Advice");
          return joinPoint.proceed();
      }
  
  
      /*
       * Pointcut to match all the public methods that are defined under the Class marked with Annotation LogExecutionTime.
      */
      @Pointcut("within(@LogExecutionTime *)")
      public void beanAnnotatedWithMonitor() {}
  
      @Pointcut("publicMethod() &amp;&amp; beanAnnotatedWithMonitor()")
      public void publicMethodInsideAClassMarkedWithAtMonitor() {}
  
      /*
       * Below Advice works but I need the LogExecutionTime annotation as an argument to below method. (similar to the advice "LogExecutionTimeByMethod" 
       * defined above)
      */
      @Around("publicMethodInsideAClassMarkedWithAtMonitor()")
      public Object LogExecutionTimeByClass(final ProceedingJoinPoint joinPoint) throws Throwable 
      {
          System.out.println("Invoking the method " +joinPoint.getSignature() +" by  LogExecutionTimeByClass Advice");
          //System.out.println("Invoked by " + annotation.value()); //Need the Annotation Variable here as well...
          return joinPoint.proceed();
      }
  
  /*
      */
  }
  </code></pre>
  
  <p>Annotated Class:  </p>
  
  <pre><code>@LogExecutionTime(level="Class_Level_Invocation")
  public class Operator {
  
      @LogExecutionTime(level="Method_Level_Invocation")
      public void operate()  throws InterruptedException {
          Thread.sleep(1000);
      }
  
      public void operate1() throws InterruptedException {
          Thread.sleep(1000);
      }
  }
  </code></pre>
  
  <p>Main Program:  </p>
  
  <pre><code>public class AspectJMain {
       public static void main(String[] args) throws InterruptedException {
              Operator op = new Operator();
              op.operate();
              op.operate1();
          }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Invoking the method void Operator.operate() by LogExecutionTimeByMethod Advice
  Invoking the method void Operator.operate() by  LogExecutionTimeByClass Advice
  Invoking the method void Operator.operate1() by  LogExecutionTimeByClass Advice
  </code></pre>
  
  <p>Please note that using Spring is is not an option. I have to use AspectJ compiler.
  I compiled my classes and packaged them as jar and use ApsectJ compiler to woven the aspect using below command.</p>
  
  <p>ajc -inpath core.jar -outjar ..\lib\core_woven.jar -1.5</p>
  
  <p>Any pointer would be helpful.</p>