Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 297752 - [ccp] Pasting copied method only pastes method name
Summary: [ccp] Pasting copied method only pastes method name
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.6 M6   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 297092 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-12-14 11:51 EST by John Arthorne CLA
Modified: 2010-01-28 10:25 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Arthorne CLA 2009-12-14 11:51:51 EST
Build: 3.6 M4

1) Select a method in the Outline view
2) Ctrl+X to cut the method
3) Select a new destination file in the Project Explorer view
4) Ctrl+V to paste

The entire method bodies are cut from the source file, but only the string from the outline view is pasted into the destination. I.e., in the source file I had this:

public void testGetValueForArgument() throws Exception {
	List args = new ArrayList();
	args.add("-foo");
	args.add("bar");
	assertEquals( "bar", ParserUtils.getValueForArgument("-foo", args));
	args.set(1, "-bar");
	assertEquals(null, ParserUtils.getValueForArgument("-foo", args));
}

And in the destination I got this:

testGetValueForArgument()

I would expect Cut/Paste to be symmetric and paste the same method body that was cut at the source location.
Comment 1 Dani Megert CLA 2010-01-08 04:38:24 EST
It works if you paste it into a valid parent. A CU can contain many classes and hence we only paste the full method if you paste it into a class.
Comment 2 John Arthorne CLA 2010-01-08 13:58:12 EST
(In reply to comment #1)
> It works if you paste it into a valid parent. A CU can contain many classes and
> hence we only paste the full method if you paste it into a class.

Shouldn't you just fail to paste then? The current behaviour is that the paste operation does select a class in that CU (the top-level public class), and selects a reasonable place to paste the new method at the end of the method list for that class. But, instead of pasting the method body it pastes the method declaration only. If it's not safe to select a destination class automatically then the paste of a method shouldn't be permitted with a CU target.
Comment 3 Dani Megert CLA 2010-01-11 04:28:48 EST
>selects a reasonable place to paste the new method at the end of the method
>list for that class. But, instead of pasting the method body it pastes the
>method declaration only. 
That's because of the feature to paste any text snippet into the Package Explorer.

I agree we could be smarter and in case of having the body we paste the full source.
Comment 4 Markus Keller CLA 2010-01-28 05:24:49 EST
I'll disable snippet paste if the clipboard only contains file names. Pasting to the CU will paste into the CU's main type.
Comment 5 Markus Keller CLA 2010-01-28 10:01:57 EST
Fixed in ReorgPolicyFactory and enabled CopyTest#test_method_yes_cu_with_main_type().
Comment 6 Markus Keller CLA 2010-01-28 10:05:57 EST
A problem is that the target CU does not get opened in the editor, but that's bug 274019.
Comment 7 Markus Keller CLA 2010-01-28 10:25:17 EST
*** Bug 297092 has been marked as a duplicate of this bug. ***