Bug 115513 [quick assist] Surround with template
Version: 3.2.0 Build id: I20051102-1600 Surround with template is an enhancement of surround with runnable. It adds logic to the 'surround with' templates. Users can define there own templates to surround code with (i.e. 'surround with ISafeRunnable').
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/SurroundWithRunnableProposal.java
fRewrite= ASTRewrite.create(ast);
			Block newBody= ast.newBlock();
			Statement insertedCode= generateCodeSkeleton(newBody, fRewrite);
			
			BodyDeclaration enclosingBodyDeclaration= (BodyDeclaration)ASTNodes.getParent(selectedNodes[0], BodyDeclaration.class);
			int maxVariableId= LocalVariableIndex.perform(enclosingBodyDeclaration) + 1;
			
			List accessedAfter= getVariableDeclarationsAccessedAfter(selectedNodes[selectedNodes.length - 1], maxVariableId);
			List readInside= getVariableDeclarationReadsInside(selectedNodes, maxVariableId);
			
			moveToBlock(selectedNodes, newBody, accessedAfter, readInside, fRewrite);
			
			if (selectedNodes.length == 1 && ASTNodes.isControlStatementBody(selectedNodes[0].getLocationInParent())) {
				Block wrap= ast.newBlock();
				fRewrite.replace(selectedNodes[0], wrap, null);
				fRewrite.getListRewrite(wrap, Block.STATEMENTS_PROPERTY).insertFirst(insertedCode, null);
			} else {
				getListRewrite(selectedNodes[0], fRewrite).insertAfter(insertedCode, selectedNodes[selectedNodes.length - 1], null);
			}
			
			setEndPosition(fRewrite.track(insertedCode));
		}
		return fRewrite;
	}
	
	/**
	 * Generate a new code skeleton.
	 * @param newBody The new body which will be filled with code.
	 * @param rewrite The rewrite to use to change the ast.