Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > can annotations add code?

Reply
Thread Tools

can annotations add code?

 
 
Timasmith
Guest
Posts: n/a
 
      11-29-2006
Hi,

One thing that would be wonderful is if I could add an annotation say

@logthis
public void doSomething() {
int i=0;
i=10;
}

which inserted code into the beginning and end of the method such as

public void doSomething() {
startLogging("doSomething");
int i=0;
i=10;
stopLoggin("doSomething";
}

Do annotations come close to providing that?

thanks

 
Reply With Quote
 
 
 
 
andrewmcdonagh
Guest
Posts: n/a
 
      11-29-2006


On Nov 29, 7:09 pm, "Timasmith" <timasm...@hotmail.com> wrote:
> Hi,
>
> One thing that would be wonderful is if I could add an annotation say
>
> @logthis
> public void doSomething() {
> int i=0;
> i=10;
>
> }which inserted code into the beginning and end of the method such as
>
> public void doSomething() {
> startLogging("doSomething");
> int i=0;
> i=10;
> stopLoggin("doSomething";
>
> }Do annotations come close to providing that?
>
> thanks


No

 
Reply With Quote
 
 
 
 
Wesley Hall
Guest
Posts: n/a
 
      11-29-2006
Timasmith wrote:
> Hi,
>
> One thing that would be wonderful is if I could add an annotation say
>
> @logthis
> public void doSomething() {
> int i=0;
> i=10;
> }
>
> which inserted code into the beginning and end of the method such as
>
> public void doSomething() {
> startLogging("doSomething");
> int i=0;
> i=10;
> stopLoggin("doSomething";
> }
>
> Do annotations come close to providing that?


No, but AOP does.
 
Reply With Quote
 
Daniel Dyer
Guest
Posts: n/a
 
      11-29-2006
On Wed, 29 Nov 2006 19:09:35 -0000, Timasmith <>
wrote:

> Hi,
>
> One thing that would be wonderful is if I could add an annotation say
>
> @logthis
> public void doSomething() {
> int i=0;
> i=10;
> }
>
> which inserted code into the beginning and end of the method such as
>
> public void doSomething() {
> startLogging("doSomething");
> int i=0;
> i=10;
> stopLoggin("doSomething";
> }
>
> Do annotations come close to providing that?


You might want to look into Aspect Oriented Programming (AOP).

Dan.

--
Daniel Dyer
http://www.uncommons.org
 
Reply With Quote
 
hiwa
Guest
Posts: n/a
 
      11-29-2006
> Do annotations come close to providing that?
Yes. You must be an apt expert to do that.

 
Reply With Quote
 
Thomas Hawtin
Guest
Posts: n/a
 
      11-30-2006
hiwa wrote:
>> Do annotations come close to providing that?

> Yes. You must be an apt expert to do that.


APT can be used to generate new code. It does not alter existing code.

I'm sure there are plenty of AOP-style tools that will help, either
modifying the byte code of the .class files, modifying classes in a
custom class loader or using instrumentation APIs on loading the code.

Tom Hawtin
 
Reply With Quote
 
Timasmith
Guest
Posts: n/a
 
      11-30-2006

Thomas Hawtin wrote:
> hiwa wrote:
> >> Do annotations come close to providing that?

> > Yes. You must be an apt expert to do that.

>
> APT can be used to generate new code. It does not alter existing code.
>
> I'm sure there are plenty of AOP-style tools that will help, either
> modifying the byte code of the .class files, modifying classes in a
> custom class loader or using instrumentation APIs on loading the code.
>
> Tom Hawtin



Ok, I guess ideally the annotation would drive the AOP- tool, I'll look
into that.

 
Reply With Quote
 
hiwa
Guest
Posts: n/a
 
      11-30-2006

Timasmith wrote:
> Thomas Hawtin wrote:
> > hiwa wrote:
> > >> Do annotations come close to providing that?
> > > Yes. You must be an apt expert to do that.

> >
> > APT can be used to generate new code. It does not alter existing code.
> >
> > I'm sure there are plenty of AOP-style tools that will help, either
> > modifying the byte code of the .class files, modifying classes in a
> > custom class loader or using instrumentation APIs on loading the code.
> >
> > Tom Hawtin

>
>
> Ok, I guess ideally the annotation would drive the AOP- tool, I'll look
> into that.

Some 'experts' on Java annotation are talking about ....
http://forum.java.sun.com/thread.jsp...rt=0&tstart=20
http://forum.java.sun.com/thread.jsp...227834#4227834

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      11-30-2006
On 29.11.2006 20:09, Timasmith wrote:
> Hi,
>
> One thing that would be wonderful is if I could add an annotation say
>
> @logthis
> public void doSomething() {
> int i=0;
> i=10;
> }
>
> which inserted code into the beginning and end of the method such as
>
> public void doSomething() {
> startLogging("doSomething");
> int i=0;
> i=10;
> stopLoggin("doSomething";
> }
>
> Do annotations come close to providing that?


Others have answered that already. However, if you just want to trace
execution then there are plenty tools out there. These work either on
VM level or inside (limpy log or so).

robert
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Partial Bookmarks and Annotations in Mozilla? mtodorov_69@yahoo.com Firefox 4 10-06-2005 02:27 PM
Annotations and Retention Vidar S. Ramdal Java 2 08-19-2005 07:27 AM
[annotations][reflection] getting the annotation of the "super.method" Ingo R. Homann Java 0 07-26-2005 12:59 PM
Java Annotations not working ??? chvid@acm.org Java 3 01-25-2005 10:25 AM
codegen:nullValue, Using Annotations with a Typed DataSet, Not resolved never! Efy. ASP .Net 1 09-22-2003 02:50 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57