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/JavaIndenter.java
/*******************************************************************************
 * Copyright (c) 2000, 2003 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.internal.ui.text;
import org.eclipse.jface.text.Assert;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil;
import org.eclipse.jdt.internal.ui.JavaPlugin;
/**
 * Uses the {@link org.eclipse.jdt.internal.ui.text.JavaHeuristicScanner} to get the indentation
 * level for a certain position in a document.
 * 
 * <p>An instance holds some internal position in the document and is therefore not threadsafe.</p>
 * 
 * @since 3.0
 */
public class JavaIndenter {