Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 96004 - [typing] Incorrect indentation when pasting method body into method
Summary: [typing] Incorrect indentation when pasting method body into method
Status: RESOLVED DUPLICATE of bug 72247
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Tom Hofmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-19 15:01 EDT by Randy Hudson CLA
Modified: 2005-05-31 10:19 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Randy Hudson CLA 2005-05-19 15:01:13 EDT
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.
Comment 1 Dani Megert CLA 2005-05-20 04:49:41 EDT
We now consistently use the formatter for typing operations. You could file a
bug report against JDT Core for additional formatter preferences.
Comment 2 Dani Megert CLA 2005-05-20 04:49:53 EDT
We now consistently use the formatter for typing operations. You could file a
bug report against JDT Core for additional formatter preferences.
Comment 3 Randy Hudson CLA 2005-05-20 10:24:03 EDT
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.
Comment 4 Dani Megert CLA 2005-05-20 10:56:33 EDT
Tom, please comment the last point.
Comment 5 Tom Hofmann CLA 2005-05-20 11:21:59 EDT
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.
Comment 6 Randy Hudson CLA 2005-05-20 11:31:03 EDT
I am pasting the entire class declaration into a method body.  It is an inner 
class.

So, given:

void destinationMethod() {
<<PASTE HERE>>
}
Comment 7 Randy Hudson CLA 2005-05-20 11:32:29 EDT
Sorry for the confusion. The original description is correct is misleading. The 
class is the body of the method :-)
Comment 8 Randy Hudson CLA 2005-05-20 11:33:26 EDT
*IF* misleading (typo)
Comment 9 Tom Hofmann CLA 2005-05-20 11:52:32 EDT
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.
Comment 10 Randy Hudson CLA 2005-05-20 14:02:20 EDT
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.
Comment 11 Dani Megert CLA 2005-05-30 17:48:02 EDT
Tom, please find the dup and close.
Comment 12 Randy Hudson CLA 2005-05-30 22:53:33 EDT
This is a regression. The behavior was correct in 3.0, with "Pasting for 
correct indentation" enabled.
Comment 13 Tom Hofmann CLA 2005-05-31 10:19:41 EDT

*** This bug has been marked as a duplicate of 72247 ***