Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Defining a pointcut selecting no joinpoints.

Daniel,

In the aTrack project (https://atrack.dev.java.net/), we have defined a library of common aspects and standard pointcuts that are commonly needed in AspectJ (as well as others for J2EE and extension libraries). This syntax for matching an empty pointcut is somewhat debatable (although the compiler supports it); you might consider using !within(*) instead...

/**
 * Defines commonly used pointcuts. This will be a natural to use with
 * Java 1.5's static import. 
 * 
 * @author Ron Bodkin
 *
 */
public class StandardPointcuts {
    /**
     * always false: matches no join puts 
     */
    public pointcut never();
    
    /**
     * always true: matches all join puts 
     */
    public pointcut always() : within(*);

    /** 
     * definition of the public join points that constitute entry to a package
     * i.e., it excludes field access 
     * limitation: we get initialization of all types, since we can't (yet) restrict to publics
     */ 
    public pointcut entryPoints() :  
        execution(public * *(..)) || execution(public new(..)) || initialization(public new(..)) || //adviceexecution() || 
        staticinitialization(/*public*/ *);

    /** 
     * definition of all public join points
     */ 
    public pointcut publicPoints() : 
        entryPoints() || get(public * *.*) || set(public * *.*);

    /**
     * all "execution" join points: method execution, constructor execution, or advice execution 
     */        
    public pointcut anyExecs():
        execution(* *(..)) || execution(new(..)) /*|| adviceexecution()*/;

    /**
     * call join points to methods with a signature that throws a checked exception
     */
    public pointcut callsThrowingChecked() : 
        (call(* *(..) throws (Throwable || Exception+ && !RuntimeException+)) ||
         call(new(..) throws (Throwable || Exception+ && !RuntimeException+)));

    /**
     * method execution join points for methods with a signature that throws a checked exception
     */
    public pointcut execsThrowingChecked() : 
        (execution(* *(..) throws (Throwable || Exception+ && !RuntimeException+)) ||
        execution(new(..) throws (Throwable || Exception+ && !RuntimeException+)));     
}

Ron
Ron Bodkin
Chief Technology Officer
New Aspects of Software
m: (415) 509-2895

> ------------Original Message------------
> From: Daniel McAllansmith <daniel@xxxxxxxxxxxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Thu, Feb-12-2004 1:40 PM
> Subject: [aspectj-users] Defining a pointcut selecting no joinpoints.
> 
> Hi,
> 
> is there a special pointcut syntax which is defined to select no joinpoints at
> all?
> 
> I'm writing a concrete extension of an abstract aspect and want to ensure that
> an inherited abstract pointcut will not match any joinpoints.
> 
> I used 'if (false)' but that's a bit ugly, and it seems that the current
> compiler (1.1.1) doesn't appear to optimise it out.
> I could use something like cflowbelow && !cflow but that's even uglier.
> 
> Thanks
> Daniel
> 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 
> 


Back to the top