How can I add java docs to my java program using netbeans?
You have a number of options:
Right-click on a source package and select Tools > Analyse Javadoc. This will add Javadoc to all methods
Type /** on the line before a class, method or field declaration, and then press Enter. Default Javadoc will be created for that method
Place the cursor within a class or method declaration. Press Alt + Enter, and then select "Create Javadoc"
On the line above any method or class, type /** and hit enter.
Enter your comments in between.
Also, use the
#param
tag to specify parameters in a Javadoc:
/**
*
* A method
*
* #param abc Used to do nothing
*/
public static void doNothing(int abc) {
System.out.println(abc);
}
You can also use the Alt+Enter combination in Netbeans to automatically insert the Javadoc with all parameters, however remember that this method/field can't be private.
Related
I have just realized that when trying to add an auto generated Javadoc (by typing /** and then enter on top of a method) on methods that have the #Override annotation on them Eclipse only adds an empty Javadoc.
/**
*
*/
Whereas if the method doesnt have the #Override annotation Eclipse adds the default comment which I have specified through the settings (Window - Preferences - Java - Code Style - Code Templates - Comments - Types - Edit)
/**
* #author
*
* ${tags}
*
*/
I havent added any new plug ins, and I get the same output even if I restore to default the Pattern of the Javadoc.
There is a separate "Overriding methods" template for overridden methods. "Methods" is used for normal methods ("Types" is for classes).
All in Preferences > Java > Code Style > Code Templates', 'Comments' section.
I have set the template for "Types" to be:
/** $$Id$$
* $$Author$$
* $$Revision$$
*
* ${cursor}
*/
However the ${cursor} isn't working as it ought to, you can see here ( http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Fconcepts%2Fconcept-template-variables.htm - top of the first table) how ${cursor} should work.
When I use this template (by typing /** and then pressing enter) I get the following (where | denotes the cursor position)
/**
* |$Id$
* $Author$
* $Revision$
*
*
*/
How can I fix this, or if I am at fault, how can I get the desired behaviour?
The help does not make it very clear but the variables list you reference only applies to the 'Java > Editor > Templates' templates and not to the 'Java > Code Style > Code Templates'.
There is a much more restricted list for variables for the Code Templates which does not include ${cursor}.
Only the variables shown by the 'Insert Variable...' button of the Edit Template dialog are available.
In my eclipse plugin I have the following code:
public class MyHandler extends AbstractHandler {
#Override
public Object execute( ExecutionEvent event ) throws ExecutionException {
ISelection sel = HandlerUtil
.getActiveWorkbenchWindowChecked( event )
.getSelectionService()
.getSelection();
if( sel instanceof TextSelection ) {
IEditorPart activeEditor = PlatformUI
.getWorkbench()
.getActiveWorkbenchWindow()
.getActivePage()
.getActiveEditor();
IEditorInput editorInput = activeEditor.getEditorInput();
if( editorInput instanceof CompareEditorInput ) {
// here are two possible sources of the text selection, the
// left or the right side of the compare editor.
// How can I find out, which side it is from?
}
}
return null;
}
}
Here I'm handling a text selection event coming from an CompareEditorInput, i.e. the result of comparing two remote revisions of a file with subclipse.
Now I want to handle the text selection properly. For that I have to know if it selects some text inside the left side editor or inside the right side editor.
How can I find that out?
EDIT 2010-04-10:
The concrete instance of CompareEditorInput is org.tigris.subversion.subclipse.ui.compare.SVNCompareEditorInput.
The issue is: org.eclipse.compare.CompareEditorInput (which have its java sources here) is an abstract class which has not always "left" or "right" pane:
/**
* The most important part of this implementation is the setup
* of the compare/merge UI.
* The UI uses a simple browser metaphor to present compare results.
* The top half of the layout shows the structural compare results
* (e.g. added, deleted, and changed files),
* The bottom half the content compare results
* (e.g. textual differences between two files).
* A selection in the top pane is fed to the bottom pane.
* If a content viewer is registered for the type of the selected object,
* this viewer is installed in the pane.
* In addition if a structure viewer is registered for the selection type,
* the top pane is split horizontally to make room for another pane
* and the structure viewer is installed in it.
* When comparing Java files this second structure viewer would show
* the structural differences within a Java file,
* e.g. added, deleted or changed methods and fields.
*/
The question is: do you know the exact implementation type of this CompareEditorInput object?
I.e: It is interesting to see how concrete classes deal with selection:
The org.eclipse.compare.internal.ResourceCompareInput for instance deals with org.eclipse.jface.viewers.IStructuredSelection, and comes with an utility function to get left and right IResource based on the selection.
Is there an option in Eclipse PDT to show every call of chosen function.
I now if you select some kind of function and hit F3 key you will see a definition of selected function.
Open the Search Menu, Choose 'Search...', and navigate to the PHP tab, then
Enter the method name in the search string text box;
Select Method in the Search for group;
Select References in the Limit to group.
Find method usages http://img217.imageshack.us/img217/83/eclipsepdtfindmethodusa.png
We have a plugin for that... nWire for PHP. It's a comprehensive PHP code analyzer which represents all your code associations, invocations included in one quick and easy to use view. It can also represent the associations graphically.
i remember there being a way of marking a section of code in eclipse (special comment or annotation?) which made the autoformatter ignore that section. Or I may have drempt this...
Used mainly when I have strings which wrap onto several lines and i don't want the autoformatter to rearrange this.
Since eclipse 3.5 (or 3.6) this is possible:
- Go to project properties -- Java Code Style -- Formatter -- Edit...
- choose the tab marked "Off/On Tags",
- include the tags in comments in your source code, like
/* #formatter:on */
You can wrap the code you don't want auto-formatted between these special comments:
normal code
/* #formatter:off */
strangely laid out code
/* #formatter:on */
normal code
Here's a basic usage example that makes a json string (slightly) more readable:
public class SomeTest {
#Test
public void can_deserialize_json() {
/* #formatter:off */
String json = "" +
"{" +
" \"id\" : 123," +
" \"address1\" : blah," +
" \"shippingInfo\" : {" +
" \"trackingUrl\" : null," +
" \"price\" : 350" +
" }," +
" \"errorMessage\" : null" +
"}";
/* #formatter:on */
MyClass.deserializeJson(json);
}
}
I only know the answer for comments:
Eclipse is smart enough to only re-format the comments where the generated JavaDoc wouldn't change (i.e. where whitespace doesn't matter):
/**
* foo <i>
* bar </i>
*
* <pre>
* foo
* bar
* </pre>
*/
will be reformatted into
/**
* foo <i> bar </i>
*
* <pre>
* foo
* bar
* </pre>
*/
Note how the content of the <pre> tags is not reformatted.
For long String literals, I'd suggest that they might be an indication that you should be externalizing some of them.
I am not sure about the exact feature you're referring to, but you can change the line wrap policy of expressions, which may help you with your strings problem. See:
Window->Preferences->Java->Code Style->Formatter
Click "Edit..." Button
Click "Line Wrapping" Tab
In the tree, choose Expressions->Assignments, then change the indent policy at the bottom of the window.
Of course there are myriad other options inside the formatter, you may find many of those useful as well for other rules, such as where to put your braces, or how to indent control blocks.
I just found this question because I'm also annoyed by the lack of this feature.
A small search showed this question and the following answer:
Stop eclipse from line wrapping?
Eclipse 3.5 supports this. (It hit release candidate a a few days ago, so could be worth checking out)
Good luck with this! :)
I stumbled upon this, 'cause I'd love to see section coloring in Eclipse. Imagine you could simply give some background color to sections within your code. Wouldn't it make it more accessible, especially when you're faded at 4 a.m.? :)
You can mark the code you want to format and selct format with right mouse click in this section. This is a "whitlist" solution, perhaps it helps...