Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] help required in introducing new method

Hi Ravi,
you don't specify which error is blocking you, so I'll assume two possibilities.

The first one is that fields you are trying to access are private, so not visible from the aspect that is declaring the method. This can be solved using "public privileged aspect". The "privileged" keyword gives the aspect rights to access private members.

The second one is that you are declaring the toString on "SomeInterface" and then using field1, field2 etc.. Make sure those fields are declared on the class, AspectJ is subject to the same checks a normal class is, so if you declare a method on an interface, that method will be able to access other methods/fields in that interface or super interfaces.

Hope this helps,
Simone

Ravi Chandra wrote:
hi,

My problem is equivalent to implementing toString mehtod of a class. *The output should be like: fieldVariable1= val1 | fieldVariable2= val2 |... etc. I could introduce the toString method but am unable to read the field variables and print them. *Below is the approach i used.

public aspect INAspect *{*
    // INTRODUCTION
    public String SomeInterface.toString(byte[] bytes) {
       String s="";
       *// s = 'field1='+ this.field1 + 'field2=' + this.field2 | ... etc*
        return s;
    }

    // SYNTHETIC IMPLEMENTS
    declare parents: com.comp.attributes.* implements SomeInterface;
*}*

---

package com.comp.attributes;
public class UserAttributes *{*
    private String field1 = "abc";
    private int field2 = 100;
    ... getters and setters...

*   //here toString() should be introduced that is like
   // "field1="+  this.field1+ "field2="+ this.field2 etc.
}*

------

when i decompile the code of user attibutes it is showing hte toString implemented. except for reflections (which is not prefered to be used) i want to know if there is a way to get this achieved. I tried with AJType; but no luck.

Any ideas/ pointers please.
ravi
------------------------------------------------------------------------

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


--
Simone Gianni            CEO Semeru s.r.l.           Apache Committer
http://www.simonegianni.it/



Back to the top