Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Usage of pointcut

First make the aspect abstract:

public abstract aspect X {
  pointcut p(): within(Foo);
  before(): execution(* *(..)) && p() {
    System.out.println(thisJoinPoint);
  }
}

But notice the point cut is not abstract, it has a value, that can be overridden in the concrete aspect. So this is the default value.

If I declare an aop.xml that concretizes the aspect but does not provide a point cut:

<aspectj>
<aspects>
<concrete-aspect name="Y" extends ="X">
</concrete-aspect>
</aspects>
<weaver options="-debug -showWeaveInfo"/>
</aspectj>

Then p() will be within(Foo) for application of my concrete aspect.

If I instead fill in a new value for p():

<aspectj>
<aspects>
<concrete-aspect name="Y" extends ="X">
  <pointcut name="p" _expression_="within(Bar)"/>
</concrete-aspect>
</aspects>
<weaver options="-debug -showWeaveInfo"/>
</aspectj>

Then that will be used instead of within(Foo). But you must at least concretize the aspect - a purely abstract aspect will not be applied even if referenced via <aspect…/>

Cheers,
Andy

On Nov 22, 2018, at 6:29 AM, Mikael Petterson <mikaelpetterson@xxxxxxxxxxx> wrote:

Hi,

I have the following aspect:

public aspect DeprecatedMethodsAspect  {
        
    private  Collector collector = new DeprecatedMethodsListener();
    
    //Only allow a default constructor with no args.

    //Pointcuts to match joinpoint.
    pointcut deprecated() :
        !within(com.mylibrary.aspects.*) && @annotation(java.lang.Deprecated) && (call(public * *(..)) || call(*.new(..)));

    pointcut beta() :
        @annotation(com.google.common.annotations.Beta);

    pointcut deprecatedMethods() :
        deprecated() && !beta();
        

    before() : deprecatedMethods() {
        collector.collect(thisJoinPoint);
    }

}

I want to be able to select only packages in the application running with this aspect. So I want to have a default pointcut that is used by most users but with the possibility to override it.

I was thinking of defining abstract pointcuts ( then aspect needs to be abstract as well) like:

protected abstract pointcut excludedPackages();
protected abstract pointcut includedPackages();
Then I can define them in the aop.xml

But what is the best way to provide a default value/values ( if multiple packages).

br,

//mikael
 
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/aspectj-users


Back to the top