Where can I change comment in Java class (template) in Eclipse - eclipse

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.

Related

Eclipse Neon 2.0 Append automatically comments

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

How to add eclipse String shortcuts?

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

Eclipse RCP: programmatically associate file type with Editor?

How programmatically associate file type with Editor?
That is what Eclipse-RCP Java code can do what is archived with the following UI interaction:
Window -> Preferences
General -> Editors -> File Associations
Add... > File type: *.json
Select *.json file type
Add... (Associated editors) > JavaScript Editor
Make it default
Ralated to Q
https://stackoverflow.com/questions/12429221/eclipse-file-associations-determine-which-editor-in-list-of-associated-editors
Eclipse: associate an editor with a content type
Get associated file extensions for an Eclipse editor
Opening a default editor, on a treeviewer selection eclipse rcp(eg: as eclipse knows that j.java files must be opened in text editor)
eclipse rcp change icon for xml configuration file
I know your questions says "programmatically" but I'll give a complete run down of the methods.
If you are writing the plugin that provides the editor, then you should simply declare the extension in your plugin.xml.
<extension
point="org.eclipse.ui.editors">
<editor
...
extensions="json"
...
If you are distributing a complete RPC application, you can edit the plugin.xml for the plugin that provides the editor or add a plugin that just refers to that editor.
But, if you have to do it programmatically, you are manipulating the internals of an RPC instance. Eclipse does not provide a public API for that but this code will do it:
// error handling is omitted for brevity
String extension = "json";
String editorId = "theplugin.editors.TheEditor";
EditorRegistry editorReg = (EditorRegistry)PlatformUI.getWorkbench().getEditorRegistry();
EditorDescriptor editor = (EditorDescriptor) editorReg.findEditor(editorId);
FileEditorMapping mapping = new FileEditorMapping(extension);
mapping.addEditor(editor);
mapping.setDefaultEditor(editor);
IFileEditorMapping[] mappings = editorReg.getFileEditorMappings();
FileEditorMapping[] newMappings = new FileEditorMapping[mappings.length+1];
for (int i = 0; i < mappings.length; i++) {
newMappings[i] = (FileEditorMapping) mappings[i];
}
newMappings[mappings.length] = mapping;
editorReg.setFileEditorMappings(newMappings);
Associating file type means associating content of ur editor with a predefined one.
This can be easily achieved via plugin.xml..
Just follow the following link:-
Eclipse help Documentation
http://help.eclipse.org/indigo/index.jsp
and search for org.eclipse.core.contenttype.contentTypes.

Eclipse formatter: New line after annotations/public?

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 :-)

How to specify the order of class members when formatting in Eclipse

In Eclipse IDE how do you customize the Java code style formatter to have it sort the class members with a specified order, for example to group all instance methods by visibility?
If the question is, "how do you customize the 'Source -> Format' command to re-order members?", I don't think it can be done. To change the order used for the 'Source -> Sort Members' command, change the "Members Sort Order" preference: "Window -> Preferences -> Java -> Appearance -> Members Sort Order"
I'm not sure when they added this functionality, but it seems to be there in 3.5:
Window -> Preferences
Java -> Editor -> Save Actions
Additional actions -> Configure ...
Code Organizing -> Members -> Sort Members
Another way to do this is to perform a code Clean Up:
Setting sorting order:
1 - Window -> Preferences -> Java -> Appearance -> Members Sort Order - Check "Sort members in same category by visibility
2 - Window -> Preferences ... Java -> Code Style -> Clean up ... On code Organizing, select Sort Members
Clean up:
3 - On your java source, right click -> Source -> Clean up.