content assist does not work in Eclipse - java

When I am typing Ctrl-Space in Java file in Eclipse June, I am getting "no proposals". Meanwhile, if I do Edit->Content Assist->Java Proposals I have normal proposals list.
I.e. default proposals are not Java by some reason.
What it can be and how to setup?

This happened to me at some point when I upgraded to Eclipse Kepler. Go to your Preferences. The appropriate page should be Java -> Editor -> Content Assist -> Advanced.
There are two lists of proposal types. Checking a type in the first list allows that proposal to appear automatically when it detects you pressing the trigger key. If it can't find any assist options in any of the checked proposal types, the Content Assist box will not appear.
Checking a type in the second list allows that proposal type to appear in the Content Assist box when it is already on screen, accessed by pressing the command to cycle the current proposal type. You can even change the order of appearance.
To solve your problem, at the very least, make sure Java Proposals checked in the first list (Technically, you can have it checked in only the second, but that means you'd need to manually bring up Content Assist and cycle to Java each time). Once checked, it should be automatically chosen as the default Content Assist for .java files.

Related

How to remove unused code in IntelliJ IDEA? [duplicate]

This question already has answers here:
Remove unused variable declarations automatically - Android Studio/Inteiij
(2 answers)
Closed 3 years ago.
In IntelliJ, in a .java file, some unused code is greyed out indicating that the declared variable or function is never used. Unused imports are removed using Ctrl+Alt+O. Is there any shortcut to remove those unused declarations?
As #Magnilex pointed out, hover over the unused variable / method and hit alt + enter to open the intentions menu (if that's how its called).
But in addition to this, don't just remove / safe delete this on variable, but choose "Fix all 'Unused declaration' problems in this file" which will not only get rid of this one, but of all.
See here:
An alternative approach might be to us the "Run inspections by name" and run the "Unused declaration" inspection for your whole project / module / Package, whatever.
This can be achieved by either right clicking on the editor, and chosing >Analyze >Run Inspection by Name from the context menu (or the keyboard short cut, which is ctrl+alt+shift+i by default). Then type "Unused declaration":
This will inspect your code for unused declarations and display them in an overview:
See also https://stackoverflow.com/a/56593832/2987273
Check the Code-Cleanup documentation, see if any of those solutions fit your needs. Creating a profile for that task might be a decent idea, as you can trigger it from anywhere, and hit all relevant occurrences.
Just be aware that his approach might "eat up" some new / uncompleted code, or even raise false-positives, e.g. due to a child project which is not in scope. So: handle with care.
There is not shortcut to remove unused code in a file. Just to make that sure: IntelliJ IDEA is only able to check if the code is currently used in your project.
If the declaration is used by another consumer, that is not part of your project, you may break the consumer when removing that piece of code.
Due to that fact, it's not possible to implement a general automatic remove unused declaration.
There may be cases where this is more safe like an unused private method, but there is no save automatic way to do that.
Therefore, there is no shortcut.
What you can do in order to check your code base and decide whether or not to remove code marked as unused is to run a Inspect Code analysis.
Just right click on you file or source code folder, got to Analyze and Inspect Code. Choose the scope, like a folder or a specific file and press Ok.
After that you can scroll through the warnings aso.

Eclipse Content Assist ignoring spelling errors

I recently bought a new keyboard and keep making spelling errors, closing the Content Assist midway. Is there any option within Eclipse preferences that let it stay open if at least some of the members have been found and spelled correctly?
For example if it suggests "myMethod()" and I write "myMb", Content Assist closes.
Eclipse does not feature a spelling error correcting content assist. I am also not aware of any plugins that do this.
What comes somewhat close is Eclipse Code Recommenders’ Subwords completion, which allows you to put in substrings of the method name, e.g. myMd would complete to myMethod(). However, when there are characters not part of the method’s name in your search string, the method won’t be found.

Feature or keyboard shortcut in eclipse Kepler for copying type hierarchy

As per Joshua Goldberg's comment I interpret that you can copy the entire type hierarchy to clipboard. However I am unable to find the keyboard shortcut to do this, tried searching on bug page.
Right now I select the classes one by one from type hierarchy that implement interface or extend a class, and copy them to text file, but I would guess there is a keyboard shortcut or feature to copy the entire hierarchy or even export it in some format. I just want to minimize the human error while listing all the classes.
Can somebody please point me to the right place. I am working on eclipse Kepler release build 20130614-0229, on Windows 7 64 bit.
Thanks.
EDIT: As per comment from PopoFibo below, there does not seem a way to do this.
I would be under impression, that since the type hierarchy is shown as a tree, and someone parses and fills those data slots. It would be just another extension to export them as XML or text file. Too much wishful thinking.

Eclipse - is it possible to jump to a particular package?

Say i'm looking at some file, and i'd like to see if there are similar files in a different package. I don't really know what the different files might be called - they were coded by different people, so could well be named differently.
I do know they're probably in a package of roughly the same name - for example, if i'm looking at a file in the com.sandwiches.ham.artisan package, and i think there should be a similar (although, in this case, sadly unrelated) file in the com.sandwiches.avocado.artisan package, what is the fastest way to jump to said package and check it out?
I'm fed up of scrolling through reams of artisan sanwiches, its making me hungry.
Well, no matter what, you are going to have to do some typing. There is a Go-to navigation item for packages, its just not bound to any quick keys. To bind it to a key combination of your choice, do the following:
Eclipse->Preferences, and type in Keys as your filter.
Search for the Go To Package command, click on the Binding entry field, and type whatever keys you want to use for the keybindings (in my screenshot I have it set to Command-Shift-0). Then click OK to save and close the preferences dialog.
After that, typing your chosen key bindings will bring up a package explorer that lets you type in whatever package you want and navigate to it.
From the Breadcrumb (press Alt+Shift+B to open it) it is quite quick to navigate your way through the sandwich menu ehm I meant packages structure...
Ctrl + Shift + R its a good shortcut to find files in every package in your proyects, i use it everytime... hope it help...

Eclipse recent files

Is there any list of recently opened files in eclipse?
If yes then is there also any shortcut for it?
Frequently I close classes in editor because there are too many of them opened. But in a few minutes I need them again. Maybe you solve this problem differently?
Thanks!
Probably your best option is to use "Quick Switch Editor" (Ctrl+E) but it displays the opened files only. There you have quick list along with filtering by starting to type first chars of file name. To make it useful, you may increase the size of opened files/windows before closing - Window->Preferences->General->Editors->Number of opened editors before closing. After you reach this threshold the oldest file open is closed in order to make room for newly open one.
The list of the files recently opened is displayed in File menu, just before the Exit menu option.
There you'll find the already open and last closed files.
If you want to use it extensively then you should probably increase the size of the items - Window->Preferences->General->Editors->Size of recently opened files list. You can quickly invoke one of last 9 filed with Alt+F,[Digit].
A drawback of third option "Open Resource" (Ctrl+Shift+R) is that the default list looks sorted, so it is not based on the most recent date of use. Also "Open Type" (Ctrl+Shift+T) has a long listing over time and you should enter part of the name to get a shorter match.
My initial comment is based on Eclipse 4.3 Kepler and is applicable to current latest Eclipse (4.5 Mars) too.
If you click on the File menu, you would see the list of recently used files. By default there are four of them. To increase the no, goto Window-> Preferences-> General -> Editors. You can set to as many as 15
If you know the class name you can use Ctrl+Shift+T (for classes) or Ctrl+Shift+R fo any other resource file. You don't have to type full name just the uppercase letters. Eclipse shows recently opened file in topmost section and other files in the lower section.
You can also use Ctrl+Q to goto last edit location.
For a complete list of shortcuts goto Help>KeyAssist. Also checkout Tips and Tricks under the same menu.
I'm using CTRL + F6.
Unfortunately it is not possible to use "regular expressions" as for CTRL + O, but I think this is what are you looking for.
You can either use the "last edit location" shortcuts on the toolbar (the yellow arrows, alt+left) if you wish to reopen a recently edited file, or use the short list of recently opened under the "File" menu (right above "exit")
I created a plugin called "RecentEditors" that shows a list of recently closed files, sorted by close time (so the last closed editor is at the top). There is also a command (and keyboard shortcut) to directly re-open the last closed editor.
You find the plugin on the Eclipse Marketplace, and GitHub.

Categories

Resources