I have to follow a particular coding standard, and I am having issues with netbeans formatting to one of the standards.
Here is how netbeans is formatting the code:
}else
{
Here is how I need it to format the code:
}
else
{
It does it for both else and elseif. Under Formatting in the Editor options, in the Braces category I have them all set to New Line, so why is it formatting the else and elseif on the same line as the closing brace?
That's indeed a bit misleading.
Under the category "Alignment" there is a group of checkboxes for "New Lines". You need to check there the "else" checkbox.
Related
I use default toggle comment line (editor.action.commentLine) to add/remove line comment (PHP).
My comments look like
// $someVar = null;
I want to change comment line format from // to // ~. Is there any way to change the default line comment format?
I have made an extension, Custom Language Properties, to do this. Demo:
The setting is as simple as :
"custom-language-properties": {
"php.comments.lineComment": "// ~"
}
Modifying blockComments and brackets (as well as lineComments) are supported for many languages - with the ability for the user to add additional language support pretty easily.
I am using NetBeans for my C++ development.
Previously there was nice formatting of code but it has changed.
This is the format that I want
This is the format that I am getting
Note the two closing braces in one line after connection line and also the closing braces after semicolon in else statement.
if you press crtl + a then right click, you will find a "format" option. I hope this helped!
I want to know if there is a way to highlight the full content in an expression like if, while, etc.
I have to work in a code that is bad indented where expressions can cover over 1000 lines and I can't format it.
for exemple :
if ($somethingTrue) {
while ($somethingHappen) {
// 500 lines...
} }
if ($someCondition) {
}
look, it's very hard to see the end of the first if and what it cover...
Does someone know if there is a native feature or plugin on netbeans that do this job ?
Thanks !
You don't need any plugin/external jar file for achieving the same. Whichever expression you want to check the body of, just click on the opening brace after that expression and NetBeans will automatically show you the closing brace for that expression.
Basically, Netbeans shows the ending brace for a corresponding starting brace entry---for each of if-statements,loop-statements,method declarations,etc.
In the shown figure, see my if-statement starting with yellow brace(cursor blinking there), and the corresponding ending brace for the if-statement.
EDIT :-
You also can also have a brand new-code fold,just by typing fcom, and hitting (Tab) button on KeyBoard. And, then put whatever block you want inside it and done. Expand whenever you wish and collapse whenever you want.
Check the position of my mouse-pointer which shows the current block of if-statement. You can expand and collapse as per your wish. And, also you can have several of them for each of your expression-tree.
I have the Eclipse formatter configured to allow me to do one liners as much as possible. However sometimes I want related commands on the same line such as
temp.add; temp.flush(); ⇦Problem
Also I configured the formatter to allow my if statements to look like this
if(true) return;
But if I have multiple commands it will push it down to the next line but I want it to format like this
if(true) {n++; return;} ⇦Problem
It formats like this
if(true) {
n++;
return;
}
Is there a setting to retain these multi line commands but still format the spacing and everything? It gets to the point that I purposely use ternary operators as much as possible because I hate doing one logical step on multiple lines. If there is no way to configure this or a plugin to fix this I think I am going to just turn the formatter off. I know I can just use ctrl+shift+f but I enjoy it formatting every time I run my program.
You can use off/on tags to avoid formatting in certain regions of editor. if you are using eclipse version 3.6 onwards.
This post explains how to do this How to turn off the Eclipse code formatter for certain sections of Java code?
In my java code formatter, in my profile I have (actually it's the eclipse's default) all choices in the "braces" tab set to "same line". Nevertheless when I have a piece of code like this:
interface TestI
{
}
and I invoke the formatter (key binding, context menu, whatever) all I get is
interface TestI
{
}
it doesn't move the opening braces to the same line, the same applies to methods, control statements etc. then when I manually change it to
interface TestI {
}
it then formats it to:
interface TestI {
}
So it generally respects the format I did manually but only formats the spaces between the braces and other elements.
Other formatting options in my formatter work as as specified. I'm using the latest Eclipse Indigo release 3.7.1, I had the same with 3.7, and my friend tried it with a 3.5 release, so it makes me think that this is on purpose, but then again why is there this "braces" tab at all if I can't reformat the code using this rule ...
I hope I'm missing something and that you will make me fell stupid in a moment and the problem will go away, because I have a gazillion of classes to cleanup and I don't want to do it by hand .. :)
UPDATE: when I set the rule not to "same line" but "next line" then formatting works as expected, it forces the rule regardless of how I've written the code, as soon as I change it back to "same line" the the formatter doesn't force this rule.
Found it... it was caused by:
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="false"/>
which in the Formatter setting GUI is under "Line Wrapping/Never join already wrapped lines"
yes now I remember setting it, but I never thought that this would override the braces setting ...
a nice-to-have feature of the formatter would be to have warnings if you set options that are no-ops because of other options that you've set override them.
For those wondering how to make this apply to array initializers, the settings are
New Lines > After opening brace of array initializer
New Lines > Before closing brace of array initializer