Community
Participate
Working Groups
I have the following method body: class MyClass { MyClass() { //do nothing } } I select the entire method, cut it, and paste it back in, and I get: class MyClass { MyClass() { //do nothing } } Formatter is setup to not indent class members, which is what I want for outer classes, but I like nested classes to have indentation. I believe this worked in 3.0.
We now consistently use the formatter for typing operations. You could file a bug report against JDT Core for additional formatter preferences.
So, if I never use the formatter function, or it doesn't support my formatting needs, I am screwed when copying and pasting? This was not the case in previous releases and is a little agressive IMO. I'm reopening because the indendation shown above is not correct, even considering my formatter setting. The class' closing brace should be at the same indentation level as the class.
Tom, please comment the last point.
Cannot reproduce with the steps given. Randy, you talk about a method body, but your example is a class - can you specify what your file contents look like. I tried the following, the selection I cut out is marked with []: ----MyClass.java------- class MyClass { [MyClass() { //do nothing }] } ----------------------- I also tried this: ----MyClass.java------- class MyClass { [ MyClass() { //do nothing } ] } ----------------------- Both ways, and with various formatter settings, I was not able to reproduce the wrong indentation of the trailing brace. More general, paste is not supposed to ever change any code outside the selection. Please reopen with more details.
I am pasting the entire class declaration into a method body. It is an inner class. So, given: void destinationMethod() { <<PASTE HERE>> }
Sorry for the confusion. The original description is correct is misleading. The class is the body of the method :-)
*IF* misleading (typo)
ok, reproducable - here's what happens: - we always use the second line of the pasted text to determine the amount of indentation we have to shift the entire thing - the first line is indented separately, since it may not be completely copied - in your case, since the code you copied does not correspond to your formatter prefs, the lines [2-*] are shifted one unit to the left. This is a dup of XXX grr can't find it - basically there is no way we can know how to do this. In order to solve, we'd need to know the context of the source of the pasted text. Leaving open until I find the dup.
You could create your own Transfer type which copies the context along with the text. Maybe there are certain situations where it makes sense to determine indentation based on the first line and not the second. Perhaps when pasting into a line which contains just whitespace before the paste location. Another interesting note. The project is configured to use workspace formatter preferences. But, the project's preview differs from the active workbench formatting preferences. So, even though I have "Declarations within class body" off, it is not respecting that setting. That's why the last } is indented less.
Tom, please find the dup and close.
This is a regression. The behavior was correct in 3.0, with "Pasting for correct indentation" enabled.
*** This bug has been marked as a duplicate of 72247 ***