I must print on a standard output the comment write over a Java class. How can I do so?
eg.
/**
* Comment to write
* @version 1.1
*/
public class WriteMyComment {
//something...
}
I must print on a standard output the comment write over a Java class. How can I do so?
eg.
/**
* Comment to write
* @version 1.1
*/
public class WriteMyComment {
//something...
}
I'd rather use annotations for whatever you need to do. I'm not sure is it possible to has access to source comments on runtime.
MyAnnotation.java
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface MyAnnotation {
String value();
}
Test.java
@MyAnnotation("Some notes here")
public class Test {
public static void main(String[] args) {
System.out.println(Test.class.getAnnotation(MyAnnotation.class).value());
}
}
I used QDox for a similiar task and as far as I remember, I was able to handle the comments too.
Comments are not available in the java class files, so you can't use them if you don't have the source files. If the comments mean anything for you application, use annotations, they are meant to be used by applications.
Otherwise you'll have to reside to tools that scan the source code for comments, perhaps like javadoc or tools mentioned in other answers.