eclipse use available space line w - java

in our company we recently changed the used line width from like 80 to 150.
Now it is quite annoying that all code is - of course - wrapped after 100 characters, as this was the previous setting.
We use save actions to run the format settings and it all works wonderful in the one direction: wrap too large lines.
But what I need now: UNWRAP me all lines as I now got enough space available, USE it. Is there a possibility to do that in form of a format setting? I couldn't find any
I now got this line (extremly) wrapped as there were not enough space:
final List<SomeSuperDuperType>
mySuperDuperListOfSuperDuperTypes =
CrazyUtils.gimmeSomeCrazyStuffAsList(
parameter1, parameter2);
Now, with more space available, this code is still correctly formatted as it doesn't exceed the limit. Though I want to actually USE that extra space and make the line now like this (length=133):
final List<SomeSuperDuperType> mySuperDuperListOfSuperDuperTypes = CrazyUtils.gimmeSomeCrazyStuffAsList(parameter1, parameter2);

On Eclipse, go to Window>Preferences>Java>Code Style>Formatter, edit the active profile, and you'll find what you're looking for under the tab Line Wrapping.
Then, select all your code (CTRL+A) and use CTRL+Shift+F to format the text using these new setttings.

Related

When I use getRawSignature() to get the comment which has " in it, it is writing some improper string "“"

When I use getRawSignature() to get the comment which has " in it, it is writing some improper string "“". How to resolve this to get correct output? is there any alternate funtion WE have from IASTNode?
“ is mojibake - almost always the result of having the unicode symbol “ (U+201C, the left double quotation mark - that is not a normal quote! It is slanted), which you then convert into bytes by using UTF_8 encoding, and then you read those bytes back into a string but using some ISO-8859-X encoding. That's how you get mojibake: Take text, save in one encoding, read in another: Most non_ASCII has now turned into mojibake. You can't generally unbake this stuff, you have to get your encodings right, and read data in with the same encoding you wrote it with.
However, that is probably not the root cause here.
You've likely corrupted your source file and you pasted some source code into word, and then from word saved it, and then tried to read it with your parser. This borks your code, as word converts stuff. Such as converting "Hello" to “Hello”. Which you definitely do not want. You'll have to go in and undo all the damage done by hand, get a backup, or, if you're actually writing source code in MSWord, stop doing that right away - it is not a code editor and cannot be used to write code. Use notepad++, atom, eclipse, intellij, etc.
TL;DR:
Real fix: Stop using MSWord to edit source. It mangled it beyond suitable recognition.
If somehow you really wanted this (doubtful), find all places where you convert strings implicitly to bytes or vice versa and stop ever using those - you always want the explicit ones, where you specify charset. Then, specify StandardCharsets.UTF_8. There are many such methods and you have no code pasted here so I can't tell you where you call one of these. An example is new String(byteArr) - that method is forbidden and must never be called. Call new String(byteArr, StandardCharsets.UTF_8) instead. You've got something like this earlier in your code, and that made a ticking time bomb. It went off when you invoked .getRawSignature(), but you're just seeing the bomb go off, you need to fix it where you created it.

Eclipse doesn't split string at line width when formatting

I'm currently working on an application in Eclipse where I'm running a really huge SQL statement that spans about 20 lines when splitting it in notepad to fit on the screen. Thus I want the string for the query also to be formatted somewhat more readable than a single line. All the time autoformatting normally worked when I used Eclipse but somehow now neither Ctrl + Alt + F nor rightclicking and selecting the "Format" option from the menu doesn't work to get a line break after a certain amount of characters.
I already checked the preferences where I already tried running my own profile with 120 and 100 characters line width but that didn't fix anything so far. I really don't know why Eclipse won't let me format this anymore. Normally Eclipse would be splitting the string into several lines in this case but I don't really know why this doesn't work anymore.
However other formatting is being fixed when executing autoformatting (e.g. if(xyz){ still becomes if (xyz) {.
Thank you for your help in advance.
As far as I can tell, autoformat as you described was never supported (at least as far back as 2008). And I have been using Eclipse much longer than that
You can do one of several things.
Simply insert the cursor in the string and hit a return.
Toggle word wrap Alt-Shift-Y
Try writing a regex to do what you want(not certain if this will work).

unwrapping comments to undo faulty eclipse formatting

A colleague's Eclipse formatting rules cause extreme indentation, and wraps comments to look like this:
// this
// is
// indented
// several
// tabs
They're wrapped at every word boundary because they're indented all the way past the line wrap width. I can reformat them to look only slightly more sane:
// this
// is
// indented
// several
// tabs
but the wrapping remains. Is there any way I can automagically undo this wrapping so that I won't have to spend 30 minutes every time I commit to manually reformat these comments and make the comments readable again? I don't care if other line breaks are not preserved; that would be a reasonable trade. Target result:
// this is indented several tabs
You are not the first to be frustrated by this (me included) I have never found an answer on how to undo this kind of formatting in a great way.
To prevent it happening again, there is of course the option of fixing the formatting rules and then applying them to the project instead of to the workspace. That ensures that if your colleague does format it won't be ruined like this. I recommend setting (in Comments tab of formatter):
turn on Never indent line comments on first column --> this prevents commented out code from being indented and lost
turn off Enable line comment formatting --> this fixes the wrapping problem
Take those settings, followed by using block /* */ comments for actual block comments (instead of what I often see of using line // comments for block comments).
Some other SO users who have posted similar questions with no full resolution, but some suggestions that may help. Such as using a third party formatter (perhaps only once to recover your code state and then continuing as above?)
How to reformat multi-line comments in Eclipse PDT?
Join Lines in Eclipse
I don't think this will be possible with standard IDEs; whilst they're usually good at reflowing lines over the margin, most are reticent to reflow legitimate lines (for good reasons, generally).
That said, I know you do this semi-automatically in IntelliJ IDEA at (sorry haven't used Eclipse for a while but I think it's now possible):
Select the lines with comments and type Ctrl-Shift-J (or equivalent mapping to join lines). This immediately pulls them into one line. Ctrl-Alt-L to reformat that selection if you need to.
It's that or regex I guess.. but be warned...
Try going to Windows -> Preferences -> Java -> Code Style -> Formatter and then click the Edit... button towards the top right under the Active Profile header.
Mess around with the settings in there, specifically the Line Wrapping and Comments tab.

Apache Poi formula Strings

I have a strange behavious and hope that someone might know what is going on.
For a personal project in Java i'm using Apache poi (version 3.9) to read and write to excel files.
In these excel files there is a formula i wanted to change to another way writing it.
I have a loop that sets my Excelobject with the required formula string
excelobject.setDataFormula("SUM(L" + counter + "-6,75)"); // it will look like SUM(L2-6,75) and so on
However when i write these formula in a file and check it. it has mysteriously changed to something like SUM(L2-6;75). changing the , to a ; and thus the formula does not work like intended.
can someone explain to me why apache poi setFormula on a cell does this to a , ?
EDIT :
I changed my loop to use a double 6,75 instead of a string 6,75 and that seems to help when creating the formula. So this immediate question is fixed though I am still curious on why this behavious comes.
Go to Control panel -> Region and Language -> Additional settings and change the List Separator to something other than a comma. You should use a character that doesn't appear in your file. Be sure to pick something that won't be added to the file in future either.
It changes from , to ; because , is being used as a delimiter. Anywhere that a , is found indicates a new cell. When your string is read, it changes the comma so that 2 cells wont be created where there should only be one. If you change the List Separator as described, the comma should remain unchanged.

Overwriting text on terminal with Java, issue with Console.read*

I know there are hundreds of questions asking how to update already written text on console and I know I can do it printing the \r character.
My issue comes when I use Console.readPassword or Console.readLine which creates a new line and later I can't overwrite it.
I think that my issue isn't related to something special about the Console.read* methods but to new lines. \r goes to the start of the current line, I need to be able to go to the start of the previous N line and start overwriting from there. Or just clear the entire screen.
Any ideas how can I do this?
Thanks.
In principle, this is terminal dependent, and with simple Java means there is no way to do this for all consoles.
Many terminals (at least in unixoid systems) support ANSI-escape sequences, so you can there write something like "\u001B[1;5H" to move the cursor to line 1, columnn 5.

Categories