Bug 55347 Surround with try/catch QF corrupts code
I20040318 With this code: import java.io.*; public class EF { public static void foo() throws IOException { InputStream is= null; if (is != null) { is.close(); } } } - select the full line containing the "close" - press Command-1 for QF - select surround with try/catch Observe: corrupted code import java.io.*; public class EF { public static void foo() throws IOException { InputStream is= null; if (is != null) { try { is.close(); } } catch (Exception e) { // TODO: handle exception } } }
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickTemplateProcessor.java
private static final String $_LINE_SELECTION= "${" + GlobalVariables.LineSelection.NAME + "}"; 
		
	public QuickTemplateProcessor() {
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jdt.internal.ui.text.correction.IAssistProcessor#hasAssists(org.eclipse.jdt.internal.ui.text.correction.IAssistContext)
	 */
	public boolean hasAssists(IInvocationContext context) throws CoreException {
		ICompilationUnit cu= context.getCompilationUnit();
		IDocument document= getDocument(cu);
			
		int offset= context.getSelectionOffset();
		int length= context.getSelectionLength();
		try {
			int startLine= document.getLineOfOffset(offset);
			int endLine= document.getLineOfOffset(offset + length);
			IRegion region= document.getLineInformation(endLine);
			return ((startLine  < endLine) || (length > 0 && offset == region.getOffset() && length == region.getLength()));
		} catch (BadLocationException e) {
			return false;
		}
	}	
	
	/* (non-Javadoc)
	 * @see org.eclipse.jdt.internal.ui.text.correction.IAssistProcessor#getAssists(org.eclipse.jdt.internal.ui.text.correction.IAssistContext, org.eclipse.jdt.internal.ui.text.correction.IProblemLocation[])
	 */
	public IJavaCompletionProposal[] getAssists(IInvocationContext context, IProblemLocation[] locations) throws CoreException {
		if (locations != null && locations.length > 0) {