Reputation: 2026
For a programming course, I'm required to put comments within each class and method describing the following five things: Methods, fields, methods on fields, parameters, and methods on parameters. The first three are to be put directly under the class heading, and the last two are specific to each method.
Below is an example of what these comments should look like.
class ConsLoString implements ILoString {
/*
* Methods:
* - String convertToString();
* - String formatString();
* Fields:
* - String first;
* - ILoString rest
* Methods on fields:
* - All String methods
* - All ILoString methods
*/
String first;
ILoString rest;
...
Naturally, it is tedious and redundant to type all these out for every single class and method in a large file. Is there a way to generate these automatically, in Eclipse or otherwise?
I've looked into Eclipse's Java Editor Template Variables but there doesn't seem to be a way to iterate over every method/field in a class within Eclipse's template editor.
Any help is much appreciated!
Upvotes: 3
Views: 7813
Reputation: 14228
In Eclipse, go to Window ->Preferences -> Java -> Code style -> Code Templates On the right hand side, click on Code Style to expand, click on Methods - and in the bottom , check the check box that says : Automatically add comments for new methods and types. You can do the same for Fields also.
I haven't seen anywhere the way you are trying to document java classes. But if it is what you want : See this, and search for java ClassSpy ClassMember FIELD METHOD
. You can directly take the ClassSpy.java class from that link , compile it and execute the ClassSpy.class like : java ClassSpy ConsLoString FIELD METHOD
- It will print the fields, methods as output. Copy the output and use it whatever way you want.
Upvotes: 3
Reputation: 925
When you type /**
right before a class or method definition and then hit return, Eclipse generates some (templated) comments for classes and methods. You can define the content of the generated comments by going to Window>Preferences>Java>Code Style>Code Templates>Comments.
Upvotes: 1