Class Aspects

java.lang.Object
org.aspectj.lang.Aspects

public class Aspects extends Object
Handles generic aspectOf method when those are not available in the aspects but added later on thru load time weaving. Aspects.aspectOf(..) is doing reflective calls to the aspect aspectOf, so for better performance consider using ajc compilation of the aspects and using them as a binary dependencies in your project.
Author:
Alexandre Vasseur
  • Constructor Details

    • Aspects

      public Aspects()
  • Method Details

    • aspectOf

      public static <T> T aspectOf(Class<T> aspectClass) throws NoAspectBoundException
      Type Parameters:
      T - the expected class of the aspect
      Parameters:
      aspectClass - the aspect class
      Returns:
      the singleton aspect or the percflow / percflowbelow associated with the current thread
      Throws:
      NoAspectBoundException - if no such aspect
    • aspectOf

      public static <T> T aspectOf(Class<T> aspectClass, Object perObject) throws NoAspectBoundException
      Type Parameters:
      T - the expected class of the aspect
      Parameters:
      aspectClass - the aspect class
      perObject - the this/target object for which to look for an aspect instance
      Returns:
      the associated perthis / pertarget aspect instance
      Throws:
      NoAspectBoundException - if no such aspect, or no aspect bound
    • aspectOf

      public static <T> T aspectOf(Class<T> aspectClass, Class<?> perTypeWithin) throws NoAspectBoundException
      Type Parameters:
      T - the expected class of the aspect
      Parameters:
      aspectClass - the aspect class
      perTypeWithin - the class for which to search for an aspect instance
      Returns:
      the associated aspect instance
      Throws:
      NoAspectBoundException - if no such aspect, or no aspect bound
    • hasAspect

      public static boolean hasAspect(Class<?> aspectClass) throws NoAspectBoundException
      Parameters:
      aspectClass - the aspect class
      Returns:
      true if singleton aspect or percflow / percflowbelow aspect is bound
      Throws:
      NoAspectBoundException - if not bound
    • hasAspect

      public static boolean hasAspect(Class<?> aspectClass, Object perObject) throws NoAspectBoundException
      Parameters:
      aspectClass - the aspect class
      perObject - the this/target object for which to look for an aspect instance
      Returns:
      true if the perthis / pertarget aspect is bound
      Throws:
      NoAspectBoundException - if not bound
    • hasAspect

      public static boolean hasAspect(Class<?> aspectClass, Class<?> perTypeWithin) throws NoAspectBoundException
      Parameters:
      aspectClass - the aspect class
      perTypeWithin - class
      Returns:
      true if the pertypewithin aspect is bound
      Throws:
      NoAspectBoundException - if not bound