Organize imports in eclipse java - java

enter image description here
I'm working on a JUnit project on eclipse , please help me to organize imports ,because im using checkList plugin. I tried source +organize imports also , I tried Control+Shift +o , but both of them did not work . can you help .

To enable this, go to Windows -> Preferences -> Java -> Editor -> Save Actions and then enable Perform the selected action on save -> Organize imports. After this, whenever you save a java file, eclipse will remove the unused imports automatically.
Little googling might help

To fix this issue:
Go to Preferences -> General -> Keys Click on Filters... and de-select Filter uncategorized commands then Ok.
Then look for the command Go To Symbol in File and select it. Then click on Unbind and then Apply and Close
Ctrl+Shift+O. should now work.
Note:
Also unbind any other conflicting commands and leave only one command for Ctrl+Shift+O and set the When to Editing Java Source.

Related

How do I disable 'Convert Java to Kotlin upon paste' in IntelliJ IDEA?

When IntelliJ IDEA detects I'm pasting a piece of copied Java code into a Kotlin file, it offers me to convert the pasted Java to Kotlin. This dialog contains a 'Do not ask again next time checkbox'. I checked this box and selected 'Yes', but now I want to undo my default choice. How do I do this?
I've looked and searched in IntelliJ IDEA's preferences, but haven't found the respective checkbox. Is it actually in the settings, or can I somehow reset default checkbox selections?
Preferences -> Editor -> General -> Smart Keys and somewhere down below you should find your checkbox (took me a while to find this, phew)

Eclipse Organize Imports shortcut not working on Mac

I'm using Eclipse (STS version 3.9.0) on macOS Sierra. I have a fresh install of STS. Organize Imports (Cmd + Shift + O) is defined out of the box. I can get this function to work by going through the menu entry Source > Organize Imports, but the key combination does nothing.
Additionally, the shortcut combination is not shown next to the menu item, while other menu items do have shortcut combinations shown.
What can I do to get this functionality via keystroke?
I have seen this happen on two different machines.
I have checked there are no other conflicting keybindings by sorting by the binding:
In Preferences > General > Keys > Filter the keys for ⇧⌘O
By changing the When from In Windows to Editing Java Source, the shortcut key started to work for me.
I've seen the answer on the comments above but it wasn't easy to see, that's why I'm writing it right here for more clarity. Thanks Paul for the question & answer.
Try the following steps:
Go to Windows -> Preferences-> General -> Keys on STS Menu
Click "Filters..." on the Keys page and uncheck all.
Enter "⇧+⌘+O" to search the command list for ⇧+⌘+O.
You can see the command list, and then unbind commands other than "Organize Imports".
Click "Apply".

Stop spacebar keypress from triggering autocomplete in Eclipse

Update
This was fixed in Eclipse 2018-12. This behaviour is still default, but can be configured off - see the accepted answer for how
I'll leave the question as it was for posterity, and for those on earlier versions of Eclipse
In Eclipse, I've enabled intellisense-style suggestions for Java by going to
Window -> Preferences -> Java/Editor/Content Assist
and setting the following
Auto activation delay (ms) -> 0
Auto activation triggers for Java -> .(abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
source = Eclipse Intellisense?
This works brilliantly, apart from one annoying problem. When I hit spacebar, the token being typed is autocompleted with whatever is at the top of the suggestions list. Fair enough, except that sometimes I'll type a class/variable name with an exact legal match, but this won't appear as the top suggestion. So when I naturally hit spacebar Eclipse inserts something completely wrong.
E.G. after typing Cookie I'll hit spacebar and get CookieMonster.
This seems like a bug, and happens often enough to be annoying, but even despite this I don't want spacebar to trigger autocomplete in general. I may want to type a variable name which hasn't been declared yet, or something similar. I want to use autocomplete as a helper tool, but my natural typing should always take priority over it.
I'd like to stop spacebar triggering autocomplete, and either fall back to using enter, or better still trigger autocomplete with a custom key not used in ordinary typing. Is any of this possible?
I've played around with all the settings in Content Assist to no avail. Googling the question just returns a bunch of results about disabling the autocomplete feature.
This issue is fixed from Eclipse 2018-12 [4.10] see the accepted answer
It's present in all prior versions, i.e. 2018-09 [4.9], Photon [4.8], Oxygen [4.7], Neon [4.6], etc..
Eclipse 2018-12 was already patched for this!
A patch for Bug 348857 was recently merged to the Eclipse project and was released as part of Eclipse 2018-12. You can download that version here.
You now have a new option to disable all insertion triggers apart from enter, which will prevent spacebar from causing autocompletion.
Simply go to Preferences... -> Java -> Editor -> Content Assist (or Window -> Preferences -> Java -> Editor -> Content Assist on Windows) and select Disable insertion triggers except 'Enter', as shown in the screenshot below:
There is a solution on the issue tracker for this.
Copy the jar in the eclipse/dropins folder. With the next restart space is diabled as autocompletion trigger.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=348857
Eclipse 12-2018 and newer: This is working natively, check Pyves answer.
Use a SDK version of eclipse
1.open Plug-ins View and find org.eclipse.jface.text, right click, choose import as Source Project. After import, you find it in your workspace.
2.In src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java
char[] triggers = t.getTriggerCharacter();
if(contains(triggers,key))
change to
if(key!='='&&key!=0x20&&contains(triggers,key))
3.Export org.eclipse.jface.text
Right click the project folder of org.eclipse.jface.text, choose export-->Deployable plugins and fragments, next, destination choose archive file, finish. Replace the one in eclipse/plugins with the one you generate.
The spacebar has been a key to select the autocomplete even in Indigo. To my knowledge, this can't be configured.
In fact, that is probably why the delay exists.
I suggest setting the delay to some optimal value that allows you to type things like private void ... comfortably without triggering suggestions for private and void. Then in case you get a suggestion because you waited too long, press Escape to abort Content Assist.
Same configuration as davnicwil, same issue, still on eclipse 4.4.
Solution: Intercept (hook) SHIFT+SPACE (press and hold) on (editor-window) eclipse and replace it with ESC,SPACE (sequence). Now you my decide between
Autocomplete+SPACE: press SPACE when autosuggestion present
just SPACE: press predefined key combination or sequence (e.g. SHIFT+SPACE)
On windows you may use http://www.heise.de/download/activaid.html (you can also use AutoHotkey, java native hook, ...)
HowTo with ActivAid:
Open Ac'tivAid, select "UserHotkeys"
click on "+", set a description
click on "short cut", press e.g. SHIFT+SPACE
Command: "{ESC}{SPACE}" (without quotes)
click "+", select eclipse editor frame, press ENTER
click OK, OK in Ac'tivAid
My config file:activAid/settings/ac'tivAid.ini:[UserHotkeys]
Hotkey11=+Space
Path11=<Send>{ESC}{SPACE}
Description11=Eclipse Shift+Space -> Esc,Space
Category11=
Application11=ahk_class SWT_Window0
You may also remap keys on non-english keyboards with "HotStrings", e.g. ö->{,ä->} etc.
Finally worked it out.
Try download this org.eclipse.jface.text.jar and copy it to your plugin folder(Typically eclipse/plugin). Do not forget to backup your own one.
Works on Eclipse Juno.
If the link doesn't work, comment on this, thanks.
In Eclipse go to Window -> Preferences -> General -> Keys and remove the binding for the command Content Assist.
You could disable Auto activation via the check box in
Window -> Preferences -> Java/Editor/Content Assist
and activate the auto-complete feature on demand. The default hotkey for this is
CTRL+Space

Remove unused import from All projects in eclipse

Is there a way , a shortcut or any setting which removes unused import from all projects ? effectively from workspace?
I found following question which states about removing from single file. How to remove unused imports from Eclipse.
But I need from whole workspace?
P.S.: Let me know if there are in any case ,a plug ins available for performing same.
Key combination Ctrl+ Shift + O - will trigger the Organize Imports that will remove and add missing imports.
To apply it on whole workspace you just have to select the project in the view Package Explorer and then use the key combination
Right click your working set node, or all projects that you need and select Source->Organize Imports.
Shortcut is Ctrl+Shift+O, it is basically written in the menu so if you are using a different OS, you should be able to find it. It works on single files as well as project nodes in the Package Explorer
As said, Ctrl+ Shift + O to do it manually or Window -> Preferences -> Java -> Editor -> Save Actions -> Organize Imports to have it organized automatically whenever you save a class.
Eclipse Workspace -> Java Resources -> right click on (src/main/java) folder -> Select Sorce from the menu -> Now finally select Organize import & you are done.
For macOS , you can use -->control+option+O combination.

How to use Hotswap in Netbeans?

How to do that? I can't find any option for it in the IDE... Please help me, I'm clueless.
Run your app in "debug" mode
Modify your .java files and save them
Click on the "Apply Code Changes" button that appears on the toolbar (it looks like three linked green rectangles, or Tools -> Options -> Java -> Java Debugger -> General -> Appl code changes after save)

Categories