Skip to main content

[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

Hi Andy,

That worked. 
An I can now call those protected methods from the parent class and it gets compiled and the code runs.
But I still get that warning from Eclipse. 
Dont' know what's wrong with Eclipse...

cheers,
Sina
 

On May 25, 2012, at 1:07 AM, Andy Clement wrote:

> Hi,
> 
> This does characterise exactly what you are hitting:
> 
>> As it seems "ajc" can not weave the code into the parent class since it is in another project.
> 
> The accessor needs to be added to the parent and we can't do that
> because we haven't been given access to it.  And that, indeed, is what
> the message is telling us:
> 
> "This affected type is not exposed to the weaver: com.somewhere
> (needed for privileged access [Xlint:typeNotExposedToWeaver])"
> 
> I can imagine a modification to the weaver that attempted to add the
> accessor solely at the point in the hierarchy that needed it (so into
> 'Child' in my example).
> 
> But to get you going now, really, you have to provide the weaver
> access to make that change to Parent.  This would involve putting the
> library containing the parent on the inpath rather than the classpath.
> I think in maven terms this gets called 'weaveDependencies' in your
> pom setup.  If you put the library on there that contains Parent it
> will get woven into the same output folder as the current
> compile/weave step and have the accessor added.
> 
> cheers,
> Andy
> 
> On 24 May 2012 11:17, Sina <my.linked.account@xxxxxxxxxxxxxx> wrote:
>> Hi Andy,
>> 
>> First of all: the autocomplete function in my IDE (Eclipse 3.7.1) does not list the protected method as child's methods. (Is this the normal behavior?)
>> Second : when I write c.foo() in my aspect I get this warning from eclipse:
>> 
>> "This affected type is not exposed to the weaver: com.somewhere (needed for privileged access [Xlint:typeNotExposedToWeaver])"
>> there are some differences between your config and mine.
>> 
>> 1- Instead of exposing the Child class I'm exposing the parent class.
>> I don't think that should be problem, since I tried exposing both of classes in a dummy project and that has worked.
>> 
>> 2-I'm using maven and I have different modules. My aspect and the child class are in the same maven module, but the Parent is in another module.
>> The output of the parent module will be provided as a jar file to the module in which the child exists. (using dependencies in pom.xml)
>> 
>> As it seems "ajc" can not weave the code into the parent class since it is in another project.
>> If this is true, do you suggest any solution? (can I weave it into the jar file ? somehow?)
>> 
>> 
>> Cheers,
>> Sina
>> 
>> 
>> 
>> 
>> 
>> On May 22, 2012, at 8:48 PM, Andy Clement wrote:
>> 
>>> 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
>>>> 
>>> _______________________________________________
>>> aspectj-users mailing list
>>> aspectj-users@xxxxxxxxxxx
>>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>> 
>> _______________________________________________
>> aspectj-users mailing list
>> aspectj-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top