Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to intelligently fix documentation in Eclipse?

Back in my C# days, I loved using a Visual Studio extension called "GhostDoc". Now that I'm a being used as a Java developer I'm using Eclipse. I can live without being able to have inferred documentation, but something that I'd like to do is to intelligently "fix" my documentation. For example, let's assume I have the following method:

/**
 * Gets a collection of {@link Foo} objects
 * @param bar The bar level
 * @param baz The bazziness
 */
public Collection<Foo> getFoos(int bar, int baz)
{
    // Do something cool
}

Later on in development I realize that it would be useful to allow the consumers of my method to pass in a qux value. Not only that, but it makes the most sense to have it as the first parameter. Also I'm going to have the method throw my super useful FooBarException. So now my method looks like this:

/**
 * Gets a collection of {@link Foo} objects
 * @param bar The bar level
 * @param baz The bazziness
 */
public Collection<Foo> getFoos(String qux, int bar, int baz) throws FooBarException
{
    // Do something cool
}

Being a good developer, I want my changes reflected in my JavaDoc. In GhostDoc I could hit my document shortcut key and it would add in the new stuff without disturbing the old stuff. In Eclipse, it renders a whole new set of JavaDoc and I have to do a bunch of copy pasta-ing. How can I automatically put in the new @param, @exception, and the missing @returns parameter into my JavaDoc without losing the JavaDoc that I currently have?

like image 262
Jason Thompson Avatar asked Oct 17 '12 15:10

Jason Thompson


People also ask

How do you document in eclipse?

Step 1 − Open eclipse, select the option Project →Generate Javadoc. Step 2 − Select the javadoc.exe file from the bin folder of java installation directory, select the destination folder for the generated java doc and select Next. finish button.

How do I get javadoc in Eclipse?

To see the javadoc of a class having attached source in eclipse: select Window -> show view -> javadoc (or alt + shift + q, j). then in the javadoc view, right click -> open attached javadoc (or shift + F2), this will display the javadoc of the class in the internal browser of eclipse.


3 Answers

Not sure if the following is what you ment, but since eclipse has its own JavaDoc Validator, you can configure compile Warnings/Errors under

Window -> Preferences -> Java -> Compiler -> JavaDoc.

With activating missing javadoc tags on your own needs and setting warning level to "warning", the compiler will notice your changes and give you a warning, as soon as your javadoc differs from your methods signature. To fix it, it offers a quickfix (STRG+1) and you can choose add all missing tags. This operation will add the missing tags even in the right place without messing with your old comment.

enter image description here

like image 96
crusam Avatar answered Oct 25 '22 15:10

crusam


Eclipse support "code"-completion for JavaDoc too. You do not have to type the hole statement. You only have to type "@p" and CTRL+Space will print the rest for you. Or even better, just write the name of the parmeter, code-completion will add the rest.

It is not directly a shortcut, but you can faster ehhance the javadoc than to write everything from scratch.

same for @t (@throw) @r (@return) and so on.

Edit to your comment:

You can configure Checkstyle, for checking your classes automatically. Checkstyle will report when your method has a non documented parameter or some other missing parameters. Checkstyle can also check, whether your first sentence ends with a '.' or not. You can a lot of such rules by hand.

Checkstyle will add problem markers in your java code editor and your problems view. So you can find easily code lines, with javadoc problems.

like image 29
Markus Lausberg Avatar answered Oct 25 '22 17:10

Markus Lausberg


http://jautodoc.sourceforge.net/ works well with Luna as well please check in the market placeenter image description here

like image 32
Ram Ghadiyaram Avatar answered Oct 25 '22 17:10

Ram Ghadiyaram