[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,

Please take a time to understand the semantics of call and execution pointcuts in AspectJ. The latter one instruments the supplier code. Hence, when you used the call pointcut, you interceped only the "calls" in your app code. 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().

cheers,
Henrique

On Fri, Jun 8, 2012 at 10:16 PM, MattOng <ongbp@xxxxxxxxx> wrote:
Hi Andy,

Apply that to the JVM classes:
ajc -inpath rt.jar StringUtils.java -outjar newrt.jar

Thanks very much, this shows that it is an eclipse AJDT only restriction and
not the AspectJ compiler.
------------------------------------------

The reason I am asking this sort of question is because JRuby(which also
supports this sort of Meta Programming in "open class" done it even at
script level to allow java class to access the new feature introduce to a
final class.)

------------------------------------------
Here is something that I do not understand. Why this is perfectly working
without error in eclipse plugin AJDT and NOT

public aspect JavaLangSystemAspect {
 /**
    * Selects calls to System.currentTimeMillis() occurring within tested
code.
    */
   pointcut currentTimeMillis() :
            call(public long System.currentTimeMillis());


   long around() : currentTimeMillis(){
       return 12345;
   }
}

-----------------------------------------------
public class SystemUser
{

   public static void MillisUser(){
       // will show only 12345
       System.out.println("The
currentTimeMilis:"+System.currentTimeMillis());
   }

   public static void main(String[] args)
   {
       MillisUser(); // will show only 12345
   }

}
--------------------------------------

I can't comment on  the legality of it, but I perhaps wouldn't advise
shipping a product that included a modified set of classes like this.
---------------------------------------
This is strange, because the above around point cut is more dangerous than
to introduce new methods to a immutable objects.



--
View this message in context: http://aspectj.2085585.n4.nabble.com/How-to-add-methods-to-java-lang-String-tp4650376p4650382.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