Skip to main content

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

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

Back to the top