Bug 30468 enhanced smart pasting
consider the following file: public class Test { public void method() { String x = "hello"; } public class C { } } ------------------- if you select the method starting the 'p' in "public void method()" and paste it just below with smart pasting enabled you get the following: public class Test { public void method() { String x = "hello"; } public void method() { String x = "hello"; } public class C { } } If you then paste it as part of class C you get the following: public class Test { public void method() { String x = "hello"; } public void method() { String x = "hello"; } public class C { public void method() { String x = "hello"; } } } It would be nice if the brackets line up with the method. This can probably be achieved if you treat the first line of the pasted text as different to the other lines because you cannot guarentee that text selection will always start from the beginning of the line with the correct ammount of tabs/spaces in the first line of a selection.
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaAutoIndentStrategy.java
buf.append('}');
			}
			c.text= buf.toString();
		} catch (BadLocationException e) {
			JavaPlugin.log(e);
		}
	}
	/**
	 * Computes an insert position for an opening brace if <code>offset</code> maps to a position in
	 * <code>document</code> with a expression in parenthesis that will take a block after the closing parenthesis.
	 * 
	 * @param document the document being modified
	 * @param offset the offset of the caret position, relative to the line start.
	 * @param partitioning the document partitioning
	 * @param max the max position
	 * @return an insert position relative to the line start if <code>line</code> contains a parenthesized expression that can be followed by a block, -1 otherwise
	 */
	private static int computeAnonymousPosition(IDocument document, int offset, String partitioning,  int max) {
		
		
		
		
		JavaHeuristicScanner scanner= new JavaHeuristicScanner(document);
		int pos= offset;
		int length= max;
		int scanTo= scanner.scanForward(pos, length, '}');
		if (scanTo == -1)
			scanTo= length;
			
		int closingParen= findClosingParenToLeft(scanner, pos) - 1;