Eclipse template for comment not working (cursor positioning) - eclipse

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.

Related

How to fix Eclipse generating Empty Javadoc comments for Overriden methods

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.

What is the shortcut to insert multiple line comment with * in the beginning in VS Code?

I know the shortcut Ctrl+shift+A in VS Code Linux to insert the multiple lines comment, but it just insert like this:
/*
my comment
my code i want to hide
etc
*/
How to get a comment like this?
/**
* my comment
* my code i want to hide
* etc
*/
If I want to get comment like above, I need to insert manually like this
/**
*/
And every time I hit "Enter" inside that comment, VS Code automatically insert * like this
/**
*
*
*
*
*
*/
It looks like that kind of comment is supported in VS Code,
But I dont know the short cut to insert the new one without typing manually.
Anyone know the answer ? Thanks,
UPDATE : VS CODE has update about this, more info : https://code.visualstudio.com/docs/languages/javascript#_jsdoc-support
When you type /** VS code will know what you want and show like this
hit enter and move your code inside that comment block
Look like there is no shortcut key for this till now, and if we want to that kind of comment style, we need to do it manually by typing this:
/**
*/
and hit "Enter" inside that comment

How can I customise Eclipse function comment block parsing?

If I have a block of code like this:
/**
* function description text here
* with
* other
* stuff
* on
* multiple
* lines
*/
function somefunction() ...
The function description on hovering the function will show the lines with a space in between, eg:
function description here
with
other
...
How can I customise the Eclipse function comment block parser to make it so that there is no extra space? Of course, I'd also like to customise it to do other things, but this seems like a good place to start.
Try and change from the following menu:
Window>Preferences>Java>Code Style>Formatter>Edit >Comments Tab >General Settings

Adding java docs to a program in netbeans

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.

How can I make eclipse's autoformatter ignore a section of code?

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...