Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] point cut on:: Annotated field + new ArrayList()

hi,

its not working.

java class:

public class UserAttributes implements Interceptable {
    @LIST(3)
    private ArrayList<String> alias;

    public static void main(String[] argv) {
        UserAttributes u = new UserAttributes();
        u.alias = new ArrayList();// point 1
    }

}

point cut:
public aspect INAspect {

    pointcut annCut(LIST in) : set(@LIST* (*) * ) && @annotation(in) && target(java.util.List+);

    //this should return the new MYList(); I also want the annotation to be accessible here (i.e.. cutting :: point 1).
    after(LIST in) :annCut(in) && within(com.pg.interceptor.Interceptable+) {
        System.out.println("**annotation " + thisJoinPoint + " ann:"
                + in.value());
        // return new PGList();
    }

any ideas please? :(

ravi


On Tue, Jun 23, 2009 at 12:35 AM, Andrew Eisenberg <andrew@xxxxxxxxxxxx> wrote:
Hi Ravi,

I believe that your problem is that the return type for your around advice is ArrayList, whereas it should be Object.

The reason is that since you are not specifying that the field being set must be of type List+, the pointcut can theoretically be applied to any field of any type.  Hence, the incompatible return type error.

Hope this helps,
--a


On Mon, Jun 22, 2009 at 10:58 AM, Ravi Chandra <ravi.eze@xxxxxxxxx> wrote:
Issue:
1. I have a variable defined with annotation
2, This variable is being assigned to an ArrayList

Now, i want to intercept this call and execute a logic by AOP. In the interception
1. I should be able to access the annotated value
2. Return a new object called MYLIst

The below mail therad is abt the same,
1. If i use set(* *List) then i cant access the annotation
2. If i use the below its (in eclipse) is throwing compilation errors

    pointcut listCut(LIST in) : set(@LIST* (*) * ) && @annotation(in);

    ArrayList around( LIST in) :listCut(in){
        System.out.println("**annotation " + thisJoinPoint + " ann:"
                + in.value());
        return new MyList();
    }

The java class i want to intercept::

    public static void main(String[] argv) {
        UserAttributes u = new UserAttributes();
        u.alias = new ArrayList();
    }

Any ideas where i am going wrong? Please help.





Back to the top