How can I customise Eclipse function comment block parsing? - eclipse

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

Related

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

jsdoc how break/close a tag

I would like insert a description between two example
/**
*#method ChangeItem
*#example
*oMenu.ChangeItem("menu.enable_all",{enable:true});
*oMenu.ChangeItem("menu",label:"",icon:align:"after",text:ICO.arrow_down}});
*
*If I write description here, it appear into the first example
*
*#example
*oMenu.ChangeItem("menu.enable_all",{enable:true});
*oMenu.ChangeItem("menu",{label:"",icon:{align:"after",text:ICO.arrow_down}});
*/
How can I close the first tag?
I tried to use the tag description but it go on the top of the first example
Sorry for my english and for the stupid question
I don't think it can be done like that, I have not tried but you could put #description in front of your description (but this might not put your description in the right place).
I think the cleaner approach would be to have one #example block where you put code comments like
oMenu.ChangeItem("menu.enable_all",{enable:true});
oMenu.ChangeItem("menu",label:"",icon:align:"after",text:ICO.arrow_down}});
// Example 2
oMenu.ChangeItem("menu.enable_all",{enable:true});
oMenu.ChangeItem("menu",{label:"",icon:{align:"after",text:ICO.arrow_down}});

Eclipse template for comment not working (cursor positioning)

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.

Multi-line TODO: Comments in Eclipse

Fairly straight forward question here. Has anyone figured out how to do a TODO: comment in Eclipse that spans multiple lines? I cannot for the life of me get it to work.
I assign a short title/explanation to the TODO.
This title will be picked up by your IDE and put in the task list for reference.
Then underneath I describe my TODO at length.
The first line will be nicely highlighted in your code, so you can easily recognize your to-do's inline too.
/**
* TODO: Short explanatory title
* Here I start a more lengthy description.
* This can consist of as many lines as you want.
*/
Please try with below lines,
/**
* <pre>
* TODO : You can write very long line here, which will not truncate in task desc.
* </pre>
*/
I don't know if this might help you, but you can also add you own custom task tags under Preferences>Java>Compiler>Task tags. That way you can seperate the default(auto-generated) tags from your own tags which you might find more important to fix then the standard TODO tags.
You can then also configure the Tasks view to only display your own custom tags for instance...
You can create multi line TODO comments like this:
/**
*
* TODO This is the first line
* This is the second line of todo comment
*/
*
* #TODO this is the first line<br>this is the second line
*
Will display with 2 Lines in the tooltips since i've used <br> ;)
Go to preferences → Java → Code style → Formatter → New → give any name → uncheck block commenting.
It seem Eclipse does not mark TODO as comment, it looks for the word "TODO".
So it seem like you have to something like (for now at least):
// TODO:
// TODO:
// TODO:
or
/* TODO:
* TODO:
* TODO:
*/
for multi-line TODOs

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