Associating and using javadoc comments with java elements.

S

sude

Hi!,
I need a way to associate a javadoc comment with the corresponding
Java Element. And access that programmatically in Java.
e.g. For the code below
/**
* This is my Class
*/
public class X {
…
}

I need something like
<sometype> myJavaElement = <something which gives class X>
myJavaElement.getComment();


One way which I was thinking of was using the AntLR and modifying the
lexer code generated by the AntLR. But was wondering that this problem
might (should ïŠ) have been faced by other people and if there exists
an open source tool which can be used for this purpose.
I looked at qdox but that I guess will not be able to handle package
level comments which is a basic requirement for me.

Any help is highly appreciated and highly awaited.

Thanks a lot,
Sudhanshu
 
R

Roedy Green

One way which I was thinking of was using the AntLR and modifying the
lexer code generated by the AntLR. But was wondering that this problem
might (should =EF=81=8A) have been faced by other people and if there exists
an open source tool which can be used for this purpose.
I looked at qdox but that I guess will not be able to handle package
level comments which is a basic requirement for me.

I don't follow why you are doing this or what precisely you are
tracking. However, there are two techniques in general for tackling
this sort of problem.

1. annotations:

2. custom Javadoc comments you handle with a custom Doclet to generate
the HTML or other summaries.

See http://mindprod.com/jgloss/annotations.html
http://mindprod.com/jgloss/javadoc.html
 
O

Owen Jacobson

Hi!,
I need a way to associate a javadoc comment with the corresponding
Java Element. And access that programmatically in Java.

Comments (including "javadoc comments") are not retained by the compiler.
End of story. If you need some descriptive information about a class at
runtime, either store it in an annotation with runtime retention or create
a lookup table mapping symbols (class names, packages, class member names,
et cetera) to the information you need and access that.
 
R

Richard Wheeldon

sude said:
I need a way to associate a javadoc comment with the corresponding
Java Element. And access that programmatically in Java.

Use a custom doclet, write <method,comment> pairs to some output file.
Read them back as required,

Richard
 
S

sude

Well this requires an assumption on my part that the comments that are
provided in the java code are given through a java doc tag. Right? But
I do not want to impose any such restriction to the user. In my opinion
JDT would need to solve this problem to show the javadoc comment
associated with any element.
Am not sure if they have any lean/minimal component to solve this.
Anybody has any idea?

sudhanshu
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top