can annotations add code?

T

Timasmith

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
 
A

andrewmcdonagh

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
 
W

Wesley Hall

Timasmith said:
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.
 
D

Daniel Dyer

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.
 
H

hiwa

Do annotations come close to providing that?
Yes. You must be an apt expert to do that.
 
T

Thomas Hawtin

hiwa said:
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
 
T

Timasmith

Thomas said:
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.
 
R

Robert Klemme

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top