[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
Re: [aspectj-users] Accessing protected methods of parent class from within an aspect in another package
|
- From: Andy Clement <andrew.clement@xxxxxxxxx>
- Date: Tue, 22 May 2012 09:18:08 -0700
- Delivered-to: aspectj-users@eclipse.org
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=kcXJZbwNMCK+e5/IcGM5b4xkfAb/M++YimeVVJGqt4g=; b=RliPOuePRuAx+7PoRn51y7KC0sGlIjNCeuPgGJK3nsgwdJQ5wY0uaM7hMev8UHC4K+ WEfzqD2PBIYmZ9JhcRwzsiFmcE/JhmG/nM30EY8NjLjJGfqIrCpalrsJUMjORDDOibXj aHE4QvHO9r7NcQMr36CIFXjIcZncA96xlHzbQCIkvALzG1V8WRlzpEQWTx08cm6fKPO2 Uzk51ZANs4kCaniB1QSce2XxIYzcBhSwcZAKchX7/pPcSNa9R1QWy+/9Nz+Fnv7w3y1g HQ4sw4XpZCaCJYzhJCHZuW0i4Kg6NKRcQYB89SQyweOvwjq1xEl+cAe2DXrz+r0ZK8xH 581w==
Hi Sina,
That should work, the use of 'privileged' should cause generation of
an accessor method that can then be used by the aspect.
here is my sample:
==== 8< ==== Parent.java
package com.somewhereelse;
public class Parent {
protected void foo() {
System.out.println("foo!");
}
}
===== 8< ====
===== 8< ==== Child.java
package com;
import com.somewhereelse.Parent;
public class Child extends Parent {
public static void main(String[] args) {
new Child().m();
}
public void m() {
}
}
===== 8< ==== Overthere.aj
package xxx;
import com.Child;
privileged aspect Overthere {
before(Child c): execution(* Child.m(..)) && this(c) {
c.foo();
}
}
===== 8< ====
> ajc -1.5 com/Child.java com/somewhereelse/Parent.java xxx/Overthere.aj -showWeaveInfo -d output
Join point 'method-execution(void com.Child.m())' in Type 'com.Child'
(Child.java:11) advised by before advice from 'xxx.Overthere'
(Overthere.aj:6)
> cd output
> java com.Child
foo!
Here is the accessor in the Parent class:
> javap com.somewhereelse.Parent
Compiled from "Parent.java"
public class com.somewhereelse.Parent extends java.lang.Object{
public com.somewhereelse.Parent();
protected void foo();
public void ajc$privMethod$xxx_Overthere$com_somewhereelse_Parent$foo();
}
So what is different about your configuration from mine?
cheers,
Andy
On 21 May 2012 09:25, Sina <my.linked.account@xxxxxxxxxxxxxx> wrote:
> Hi there.
>
> I have Parent class and a child one. The parent class has
> some protected methods.
> My pointcut works on methods of the child class. The problem is that I want
> to access protected methods of the parent in my Aspect, but they are not
> visible from within my Aspect.
>
> All these 3 classes (Parent, Child, Aspect) are in different packages.
>
> I read here http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg03270.html
> that using privileged modifier will solve the problem but it does not work
> for me.
> Any idea??
>
> Sina
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>