protected override Action<ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
{
Argument.IsNotNull(() => solution);
Argument.IsNotNull(() => progress);
#if R8X
IDocCommentBlockNode exceptionCommentBlock = null;
#else
IDocCommentBlock exceptionCommentBlock = null;
#endif
var xmlDoc = _methodDeclaration.GetXMLDoc(false);
if (xmlDoc == null || !IsArgumentCheckDocumented(xmlDoc, _parameterDeclaration))
{
// TODO: Move out the initialization of the exception block down (CreateExceptionXmlDoc).
exceptionCommentBlock =
Provider.ElementFactory.CreateDocCommentBlock(
CreateExceptionXmlDoc(_parameterDeclaration));
// TODO: Detect the right position to insert the document node.
#if R8X
if (_methodDeclaration.FirstChild is IDocCommentBlockNode)
#else
if (_methodDeclaration.FirstChild is IDocCommentBlock)
#endif
{
var lastChild = _methodDeclaration.FirstChild.LastChild;
if (lastChild != null)
{
exceptionCommentBlock = ModificationUtil.AddChildAfter(lastChild, exceptionCommentBlock);
}
}
else if (_methodDeclaration.Parent != null)
{
exceptionCommentBlock = ModificationUtil.AddChildBefore(_methodDeclaration.Parent, _methodDeclaration.FirstChild, exceptionCommentBlock);
}
}
// TODO: Detect the right position to insert the code.
var methodBodyFirstChild = _methodDeclaration.Body.FirstChild;
Dictionary<string, List<DocumentRange>> fields = null;
if (methodBodyFirstChild != null)
{
var checkStatement = ModificationUtil.AddChildAfter(methodBodyFirstChild, CreateArgumentCheckStatement(_parameterDeclaration));
fields = checkStatement.GetFields();
if (exceptionCommentBlock != null)
{
fields.Merge(exceptionCommentBlock.GetFields());
}
}
var hotspotInfos = fields != null ? fields.AsHotspotInfos() : new HotspotInfo[] { };
return hotspotInfos.Length == 0
? (Action<ITextControl>)null
: textControl =>
{
var hotspotSession =
Shell.Instance.GetComponent<LiveTemplatesManager>()
.CreateHotspotSessionAtopExistingText(
solution,
TextRange.InvalidRange,
textControl,
LiveTemplatesManager.EscapeAction.LeaveTextAndCaret,
hotspotInfos);
hotspotSession.Execute();
};
}