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
IFile file= (IFile) cu.getResource();
		IDocument document= JavaUI.getDocumentProvider().getDocument(new FileEditorInput(file));
		if (document == null) {
			return new Document(cu.getSource()); 
		}
		return document;
	}
	
	private void collectSurroundTemplates(IDocument document, ICompilationUnit cu, int offset, int length, Collection result) throws BadLocationException {
		CompilationUnitContextType contextType= (CompilationUnitContextType) JavaPlugin.getTemplateContextRegistry().getContextType(JavaContextType.NAME);
		CompilationUnitContext context= contextType.createContext(document, offset, length, cu);
		context.setVariable("selection", document.get(offset, length)); 
		context.setForceEvaluation(true);
		int start= context.getStart();
		int end= context.getEnd();
		IRegion region= new Region(start, end - start);
		Template[] templates= Templates.getInstance().getTemplates();
		for (int i= 0; i != templates.length; i++) {
			Template curr= templates[i];
			if (context.canEvaluate(curr) && curr.getContextTypeId().equals(JavaContextType.NAME) && curr.getPattern().indexOf($_LINE_SELECTION) != -1) {
				
				TemplateProposal proposal= new TemplateProposal(curr, context, region, JavaPluginImages.get(JavaPluginImages.IMG_OBJS_TEMPLATE));
				String[] arg= new String[] { curr.getName(), curr.getDescription() };
				proposal.setDisplayString(CorrectionMessages.getFormattedString("QuickTemplateProcessor.surround.label", arg)); 
				result.add(proposal);
			}
		}
	}
}