Eclipse Version:2018-09 (4.9.0)
Plugin "Code Recommenders for Java Developers": 2.5.4.v20180909-1131
My Eclipse autocompletion does a little more than I like when it completes generic classes.
Example:
when(component.method(param)).thenReturn(Opt... [Press Strg+Enter])
Current Behavior
when(component.method(param)).thenReturn(Optional<Type>)
Wanted Behavior
when(component.method(param)).thenReturn(Optional)
I only want to complete the class name in order to call a static method (Optional.of(...)), but now I first have to delete the type and the diamond brackets.
What I found so far
This is old but partly similar: Eclipse Auto Complete: Java 1.7 Generics Diamond
The wanted behavior in this case is an empty diamond operator when creating a new instance. This issue seems to be fixed since 2014.
The plugin Code recommenders is mentioned there and that you can specify what eclipse will offer as autocompletion at
Eclipse -> Window -> Preferences
-> Java -> Editor -> Content Assist -> Advanced
Turning of the options "Java Proposals" and/or "Java Proposals (Code Recommenders)" will stop this behavior... because it turns of absolutely all Java Code recomendations.
May the force be with you!
Related
I've started working with Intellij (used Eclipse before), and I can't seem to mimic the eclipse formatting
the Eclipse Code Formatter plugin did most of the work, but there are still some differences.
for example:
Original line:
object.add(new ClassForSomething(param1, param2, paramObj.method()));
with IntelliJ formatting:
object.add(new ClassForSomething(param1, param2, paramObj
.method()));
with Eclipse formatting:
object.add(new ClassForSomething(param1, param2,
paramObj.method()));
where do I find the configuration to adjust my intelliJ formatter to what I used to have on the eclipse?
EDIT 1:
I've uploaded my code style --> wrapping and braces configuration
In Preferences > Editor > Code Style > Java > Wrapping and Braces
Method call arguments - Do not wrap
Take priority over call chain wrapping - True
Here's a screenshot:
I reproduced the method splitting behaviour you described and then 'fixed' it with the settings I propose here. However, there are so many formatter configurations, some of which impact each other, that it's possible I haven't reproduced exactly what you are seeing. If so, then I'd suggest trying the following:
Save your Java Code Style to a project specific version then start changing its configuration one item at a time until you find the right one.
Export your Eclipse codestyle (from Eclipse’s Preferences > Java > Code Style > Formatter and export the settings to an XML file via the Export All button) and then import that into IntelliJ (see screenshot below) ... perhaps IntelliJ can work out the correct configuration from the Eclipse formatter.
Check File -> Settings -> Code Style -> Java -> Wrapping and Braces. Make sure "Chained method calls" is set to "Do not wrap" and two squares are unchecked.
I just upgraded to Luna (from Kepler) and I noticed some little (yet annoying) problem:
The auto completion lacks the possibility to generate diamonds "<>" for already specified generics in variable initialisation. For Example, when I type:
Set<String> mySet = new HashSet
I would expect, that it gets auto-completed to
Set<String> mySet = new HashSet<>();
rather than
Set<String> mySet = new HashSet<String>();
I am using JDK 1.7 and the compliance level is set to 1.7 also.
Its also very strange that when I hit STRG+Space multiple times during auto-completing till it reaches java-autocompletion again and then hit Enter it delivers the expected diamonds.
This looks very much like a bug to me.
Is this bug "known" and is there any workaround for this issue? Could not find anything related to this topic.
You have most likely installed the Code Recommenders plug-in. Unfortunately this plug-in is affected by bug #435597 which breaks this functionality.
This bug appears to occur only if you have certain proposal kinds enabled in the “'default' content assist list” (Eclipse Preferences > Java > Editor > Content Assist > Advanced). For example I could get back the correct behavior by disabling the following proposal kinds:
Basic Proposals
JPA Proposals
Template Proposals
(the last one is likely the most annoying if you are using code templates…)
When you are cycling with ctrl+space, you are actually reaching the “Java Proposals” (instead of the “Intelligent Java Proposals (Code Recommenders)”), which is not affected by this bug.
This bug is scheduled for release 2.2.0 in June 2015. The best you can do for the moment is:
Play with the proposals to check which ones trigger the bug for you (maybe take a screenshot of your current setup before doing that);
Vote for bug #435597 and bug #435660 to get them fixed;
Propose patches for fixing those bugs :-)
For anyone still experiencing this with the latest Eclipse version:
Open "Window" > "Preferences" > "Java" > "Editor" > "Content Assist" > "Advanced". In the opened dialog under "Default Proposal Kinds":
Check "Java Proposals"
Uncheck "Java Proposals (Task-Focused)"
Set is an interface rather than an implementation so the IDE can only assume that you want an anonymous inner type which always requires the generic type parameter. You could do
Set<String> mySet = new HashSet + CTRL + SPACE
This diamond feature is introduced in jdk 1.8 it does not work with jdk 1.7.
So it is the new feature introduced by oracle .
Thus this will only depend on the jdk version on your computer not the ide version..
Eclipse seems to be generating a lot of these unnecessary warnings about JavaDoc in my code, and I can't seem to be able to get rid of the warnings.
First of all, the warnings don't make sense. These appear in links, like:
/**
* {#link Foo#bar}
*/
Where Foo.bar definitely exists. Eclipse can find it via right click > open declaration. The field is protected.
At first, I thought it was because Foo inherits from another class, which is where bar actually belongs, but changing the link to the super class doesn't remove the warning.
All the warnings are for the same field. I've tried accessing it in different ways (including Foo#bar, SuperClass#bar, #bar, and the fully qualified name).
I used to have enabled JavaDoc warnings in Java > Compiler > Javadoc, but have since disabled them. The project settings are also disabled.
The code base is using Java 8, which changed how Javadoc warnings and errors work, so it may be related to this (the JavaDoc can't be created by Eclipse because of errors in the Javadoc, presumably caused by Java 8, but we only use Eclipse's JavaDoc on hover, anyway).
I have two pieces of additional software installed in Eclipse: m2e v1.5 and CodePro v7.1.
mvn compile has no warnings, so I'm pretty sure that this is an Eclipse issue. Using Eclipse 4.4. I've tried restarting and rebuilding the project several times.
The warnings only show up in the problems view if I choose Show > Show all. Ticking all the individual "show options" does not display these warnings. They're still displayed in the editor, though.
It turns out this was a problem with the AJDT, which I had recently removed. The AJDT (at least the dev version for Eclipse 4.4 as of 2014-07-19) does not uninstall cleanly. As a result, the program wasn't building correctly (and in fact, errors could not be detected).
The fix is here. The issue was that the AJDT left a buildCommand and nature in the .project file, which should have been changed back to org.eclipse.jdt.core.javabuilder and org.eclipse.jdt.core.javanature, respectfully.
I'm using the Kleper version of Eclipse. Days ago the IDE was working fine but I made some configurations in Window -> Preferences and my Eclipse doesn't show anymore which classes were changed.
When I say "classes were changed" I mean the symbol '>' beside the class name is gone. Example: > Teste.java
What can I do to fix that?
Probably you accidently changed a setting in General->Appearance->Label Decorations? There you can enable/disable annotations ... e.g. CVS anntotations.
It depends of your versioning system, but in general this is set in :
Window -> Preference -> Team -> your_version_system -> Label Decoration
in the Text Decorations tab.
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