IntelliJ has some such facilities and options. For example, I want it to format like:
#Override public
void foo()
{ ... }
Better yet would be the ability to indent the annotations and visibility like so
#Override public
void foo()
{ ... }
but I don't want to be greedy.
Do such formatting options exist in Eclipse?
Java -> Code Style -> Formatter -> Edit --> New Lines --> Annotation:
Unclick Insert new line after annotations on methods
Don't think you can do your second option.
In case you still have Annotation formatting problems in Eclipse 2018 (Oxygen.3a, 4.7.3a) try this:
In Preferences go to: Java -> Code Style -> Formatter -> Edit --> New Lines --> Annotations:
You have to select Annotations and then set "line wrapping policy" to a "Wrap ..." setting. Without this setting any complex set of Annotations was formatted to very long lines in Eclipse
Go to settings-> Editor-> Code Style -> Java
Choose your code formatter and choose tab Wrapping and Braces (Try to find tab Wrapping if using different Intellij Version).
Look for option Class Annotation and Method Annotation and select option "Wrap Always"
Open the preferences dialog. Go to "Java" -> "Code Style" -> "Formatter".
Check the many options :-)
Related
Smalle question.
Is there a way to append automatically generate comments/trigger notification/popup window at the end of new code.
Example:
int i = 0; //my comment
Whenever I start writing "int i = 0;", "//my comment" is appended automatically.
Or if u have any suggestion regarding something like this.
Kind regards,
Gregory
There are code templates
Goto Window -> Preferences -> Java -> Code Style -> Code Templates
Under Code there are different options, maybe yours is Method Body
Click on Edit, remove the comment and Save
Is it possible autocomplete in Eclipse Java project. Something like I type:
public static void clr()
then press something and get:
public static void clr()
{
}
Alt+/ not working in this case.
In your situation, I don't think you will get any shorter than just typing { and Enter.
Alternatively, you could use the template for public_static_method, i.e. start typing pub..., hit Ctrl+Space, select the template (just press down once and then Enter), type in the method's return type and name and then Enter again to get straight to the body.
You can also go to Preferences -> Java -> Editor -> Templates to adapt that template to your own needs (give it a shorter name, or move the { to a separate line) or define your own ones.
For example, if I type sysout and then ctrl + space, it'll automaticlly fill System.out.println();.
How can I add a custom shortcut? Thanks in advance!
access the menu, window>preference, type the name of your language, at threeview select editor>template click at new put your template and OK
Window -> Preferences -> New -> Java -> Editor -> Templates
Name: MainProgram (which is like sysout)
Pattern:
public static void main(String args[]){
}
And then ok.
Now If you type MainProgram and Ctrl+space which gives you the full program..
window-preferences-General-key
then set you custom key on "content assistant" item
In standard Java code I have comment:
/** Called when the activity is first created. */
Where can I change this comment in the template for the Eclipse IDE?
You Project -> Properties -> Java Code Style -> Code Templates -> Comments -> Types -> Edit
Then customize comments for your own choices.
There is a nice feature in Visual Studio: you can create special code areas which can be minimized just as class methods in Eclipse are minimized. Like:
#region
//some code
#endregion
Is there a way do make such pleasant feature in Eclipse?
It's called "collapse all", click on the editor view that you want to collapse all your methods in go to
help>
key assist...>
double click "collapse all">, everything is collapsed
Click on ' - (minus)' symbol on the side of the editor, Right click on minus symbol , Go to folding / Collapse All
Keyboard shortcut : Ctrl+Shift+NumbPad_Divide
First check Folding is enable or disable if enabled then you can minimize or collapse code and expand code. You can check Folding through
Folding is configured under Window -> Preferences -> Java -> Editor ->Folding
Please check Enable Folding if its unchecked
Now you can minimize your code
Collapse All (all functions on page) : Ctrl+Shift+NumbPad_Divide
Expand All (all function on page) : Ctrl+Shift+NumbPad_Mulitply
Collapse One function : Ctrl+NumbPad_Minus
Expand One Function : Ctrl+NumbPad_Plus
If you mean by minimizing folding, then I don't think Eclipse has the folding option you want. When I look at the eclipse folding options it tells me that it can fold
Comments
Header Comments
Inner Types
Members
Imports
If you don't mean folding, then I'm sorry for the confusion.
There are some plugins for this, like "Coffee Bytes Java Folding" for Eclipse.
Other IDE like Netbeans as an native equivalent.
It's really IDE dependent in Java, not implemented in the language like in C# for example.
Java Equivalent to #region in c#
Check the second answer
//region MY REGION
code here
//endregion
Heres how I do it:
Create an empty class called Blank
Use this outline for your code:
Blank b = new Blank()
{
public void myCode()
{
/Insert code here/
}
};
b.myCode();