Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 367222

Summary: [formatting][typing] Formatted/smart paste for Java
Product: [Eclipse Project] JDT Reporter: Nathan Reynolds <numeralnathan>
Component: TextAssignee: JDT-Text-Inbox <jdt-text-inbox>
Status: RESOLVED WONTFIX QA Contact:
Severity: enhancement    
Priority: P3 CC: daniel_megert, deepakazad
Version: 3.8   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Nathan Reynolds CLA 2011-12-20 12:10:56 EST
Build Identifier: 20110916-0149

When pasting Java code, the formatter should kick in and format the code.  An option to turn this on/off should be added to Preferences | Java | Editor | Typing | When pasting.  If the user hits undo, the formatting should be undone.  If the user hits undo a 2ⁿᵈ time, the block of code should be removed.

Reproducible: Always

Steps to Reproduce:
1.  Change some Java code to *not* be formatted according to your Java formatter settings.
2.  Copy the block of code.
3.  Paste the block of code into another location.
4.  Notice that the pasted block of code is not formatted according to your Java formatter settings.
Comment 1 Deepak Azad CLA 2011-12-20 13:30:46 EST
Are you aware of 'Preferences > Java > Editor > Save Actions'? You can use Save actions to auto-format edited code on every save.
Hence, after pasting unformatted code, press Ctrl+S => Code is formatted.

With the save action available, do you really need Format on paste?
Comment 2 Nathan Reynolds CLA 2011-12-20 14:02:46 EST
This would require that I hit Ctrl+V and Ctrl+S every time I want to paste.  Also, I don't turn on auto-format with every save because the format rules can't format my code exactly how I like to read it.  So, yes, format on paste is very important because the formatting is only applied to the block I am pasting and then I can fix any thing that the formatter didn't.
Comment 3 Dani Megert CLA 2011-12-21 02:36:15 EST
We already do the auto-indenting. Besides that format on save can be narrowed to changed lines only.