Blank line when inserting code template in Eclipse - java

I have been working with customizing the formatter in Eclipse to suit my style and I finally feel like it seems to do it exactly as I want it to except when inserting templates.
Whenever I use any Eclipse template (for example "Add unimplemented methods") it inserts a blank line before the code, even though the "Blank Lines" settings is set to 0 for "Before method declarations".
Anyone who knows how to disable this blank line or do I have to remove it manually every time?

I have the same issue with Eclipse too, and it's been a pet peeve of mine for some time. I believe it's a bug, because it has nothing to do with the formatting settings at all - turning off all 'new line' features and setting all 'blank line' parameters to 0 still doesn't fix the issue. You might want to report it as a bug.

Related

Is there a way to update comments when saving an Eclipse file?

This isn't exactly a programming question, but my goal is to add a comment at the top of the class that shows when you last edited the file, updating when it saves. I know Eclipse can access the date and time, since adding a "Date Created:" comment was easy, but that's just editing the new file code templates so I would imagine it's not in the same area. I've been learning Java and Eclipse for about a year now, and this would be super helpful to keep track of files.
Here's a picture in case I wasn't clear
No, not out of the box. Someone could write a plug-in to do it, but as the comments have mentioned, once you're past a trivial example, this is usually the job for a source control system.

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.

How to force the Eclipse Mars 4.5 formatter not to join already wrapped lines?

I've just moved from eclipse Kepler to eclipse Mars and my Java formatter seems not to behave the same way anymore.
I used to be able to do the following:
object
.method1()
.method2()
.method3();
The formatter would keep my code like that. However since I changed to eclipse mars, everything is wrapped to one line.
I've verified the formatter and I still have the option "Never join already wrapped lines" checked. My project doesn't use specific settings regarding the eclipse formatter. I tried recreating a formatter from scratch and the result is the same.
How can I force eclipse not to join those lines ?
Thanks
I found solution: I selected all specific elements (Annotations, Class Declarations, ...) and defined Wrap where necessary instead of my usual Do not wrap. I then set the maximum line width to a high value so that Wrap when necessary never actually wraps anything. That seems to be sufficient for my already wrapped lines not to be joined and keep the default behavior of the formatter to "do not wrap".
EDIT: Even though that's a solution for the problem at hand, I've faced many more problems with Eclipse Mars's formatter that made me got back to Kepler. I tried Luna and it seems not to have the same problems. I'll probably be switching to Luna.
EDIT: I switched to Luna and everything works fine
EDIT: I tried the new Mars.1 and even though I do not have the exact same formatting, a lot of bugs have been fixed and it was enough for me to start using it for some projects. I'll probably be switching all my projects there in due time.
Add this line to your profile.xml or set the property to false if it already exists.
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="false"/>
Sample xml could be found here.

Getting better syntax highlighting with ctags and vim

I'm trying to set up vim to work nicely with Java. I've set up eclim, which seems to work great for letting me know when something is wrong, but I'd really like to get vim to do two things to make my code easier to read.
Have brackets and braces show up with a different colour from the main font.
Get classes to highlight as a different colour.
I haven't come up with anything good for the first point, but it seems like the second should be doable with ctags. I found a plugin called TagHilight that should do this but I can't seem to get it to work.
I also found a file called javaid.vim that is supposed to do this, but again I've had no luck with that.
For your first requirement of highlighting braces and brackets, there is no default highlight group for braces. You need to create one for yourself. Here is how you do it!
For your second requirement of how to highlight classes, you should be using this TagHighlight plugin. And this page explains in detail about the plugin and how to get it working. It also shows you snapshots where your exact requirement is met! :)

Eclipse console doesn't show the whole output

In Java I tried to write a String as an output to the console. The length of the String is 20166 characters. After printing the string to the console only second half of the String appears.
The whole string is one long line:
What it looks like:
From the beginning there is a lot of whitespaces (which are supposed to be alphanumeric characters) and after that there is the rest of the string displayed properly.
I tried to change console encoding from default to UTF-16 and UTF-8, but it didn't help.
The String I am trying to output is text content crawled from a specific webpage (http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery). If I crawl a different webpage there is no problem.
How I process the string:
I use a webservice to get the text content from the webpage. The returned String (text contet) is printed properly (whole). I need to process this string so I change all characters to lowercase and replace all multiple whitespaces with the single one.
textContent.toLowerCase().replaceAll("\\s+", " ");
After lowercasing the characters I am still able to print whole string properly, but after replacing the multiple whitespaces with one, the beginning of string is not visible.
Do you have any idea what the problem is?
Thakns in advance for any help.
This is no bug. It is 1 of the changeable settings that Eclipse includes to make the output more readable.
It can be changed by going to Windows --> Preferences --> Run/Debug --> Console and then unchecking "Limit Console Output" which is ON by default.
For more information and details about these settings visit:
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fpreferences%2Frun-debug%2Fref-console.htm
This works on STS any version too. This would help printing complete console output.
What are the preferences for the console? Especially check the settings "Fixed width console" plus "Limit console output". Maybe your console simply can't hold that many characters in one line.
In Eclipse if you go to preference and in the drop-down, you can see RUN/DEBUG option if you click on that RUN/DEBUG drop-down you can see the console button and there you can adjust the "Fixed width console" plus "Limit console output"
[EDIT] Now Eclipse eventually has to cut the data in the console since it doesn't have infinite amounts of memory. If the console is still cut off, you can use this trick: Open the "Run Configurations" dialog (Found in the drop down menu for the green "run" button).
The tab "Common" tab has options in the "Standard Input and Output" group at the bottom to save a copy of all output in a file. You can then use your OSs tools to examine this file.
Also note that very long lines can make Eclipse slow (i.e. it can hang for a couple of seconds). This is due to a bug in the regexp matching patterns for Exception stack traces. If that happens, limit the line length to 1000 characters or less.
This is especially a problem with Spring which sometimes creates exceptions that have 50'000 characters in the message.
If you have a similar problem with the CDT Global Build Console, see here: Eclipse CDT Build Console output not displaying entire compiler output
Check whether the console buffer size is enough for your case, in Preference. Usually it's 80000 characters, just in case it's been changed.
Check this bug: Long Lines not printed to console, which is a duplicate of Bug 23406, opened in 2002 and not fixed yet! I just discovered it in Eclipse 2020-06, then I tried also the very old Ecipse Mars and it works. They says that the problem affects not only the console but also editors. A comment says "This bug has too many dups for a WONTFIX".

Categories

Resources