[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] How to add methods to java.lang.String

Hi MattOng,

How come it is not done the same way like in the case of the StringUtils?

 Based on the same discussion, you used an ITD (inter-type declaration of AspectJ). By doing that you need to expose the target type (String in this case) to the weaver since you do not control the source code. You're trying to and a method to the type String. Hence you need to do what Andy explained in previous email.

cheers,
Henrique 
 

On Sat, Jun 9, 2012 at 8:29 AM, MattOng <ongbp@xxxxxxxxx> wrote:
Hi Henrique,

In other words, you're not instrumenting the supplier code by changing a
method or trying to access a private field. Because of that you do not need
to weave the java classes.

In summary, you aspect below is intercepting only the call to the method
"System.currentTimeMillis()" made within the static method MillisUser().
------------------------------
Ok. That makes some sense. The weaving is done on the user class instead of
the internal rt.jar. I am an aspectj user and not a developer of aspectj.
The compilation or weaving mechanism is not known to me.

How come it is not done the same way like in the case of the StringUtils?

--------------------------------
public class StringRedefUser
{
   public static void main(String[] args)
   {
       String string="ABCDEFG";
       MyString mystring=new MyString();
       // This is allowed and has no compilation error.
       System.out.println("LTRIM:"+mystring.ltrim());  <<< The same weaving
can be done for non-existing method at the USER class level instead of the
rt.jar level.

       // This is NOT allowed because it is not expose to weaving.
       System.out.println("LTRIM:"+string.ltrim());
   }
}
--------------------------------------
Could not that be also less dangerous and does not need the user to change
any of the bootclasspath and also the rt.jar?

Yes. I am not incline to change the rt.jar and also bootclasspath for a
simple enhancement such as this.




--
View this message in context: http://aspectj.2085585.n4.nabble.com/How-to-add-methods-to-java-lang-String-tp4650376p4650385.html
Sent from the AspectJ - users mailing list archive at Nabble.com.
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



--
...............................................................................................................................
Henrique Rebelo
http://www.cin.ufpe.br/~hemr
Informatics Center, UFPE, Brazil