/// <summary> /// Checks if the current token represents the beginning of a code block, if yes, parse every code block after the token. /// </summary> /// <param name="tokenNodeType">The current token type.</param> /// <param name="parentElement">The parent element where the potential code block will be appended as a child.</param> /// <returns><c>true</c> is a code block has been parsed, <c>false</c> otherwise.</returns> private bool TryParseCodeBlock([CanBeNull] T4TokenNodeType tokenNodeType, [NotNull] CompositeElement parentElement) { if (tokenNodeType != null) { T4CodeBlock codeBlock; if (tokenNodeType == T4TokenNodeTypes.StatementStart) { codeBlock = new T4StatementBlock(); } else if (tokenNodeType == T4TokenNodeTypes.ExpressionStart) { codeBlock = new T4ExpressionBlock(); } else if (tokenNodeType == T4TokenNodeTypes.FeatureStart) { codeBlock = new T4FeatureBlock(); } else { codeBlock = null; } if (codeBlock != null) { AppendNewChild(parentElement, ParseCodeBlock(tokenNodeType, codeBlock)); return(true); } } return(false); }
protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress) { T4StatementBlock statementBlock = _highlighting.AssociatedNode; var file = statementBlock.GetContainingFile() as IT4File; Assertion.AssertNotNull(file, "file != null"); T4FeatureBlock feature = file.GetFeatureBlocks().First(); ITreeNode featureBlock; using (file.CreateWriteLock()) { // clone the statement block and add it before the feature block ITreeNode featurePrevSibling = feature.PrevSibling; featureBlock = ModificationUtil.CloneNode(statementBlock, node => { }); featureBlock = ModificationUtil.AddChildBefore(feature, featureBlock); // add a new line before the new statement block if needed if (featurePrevSibling != null && featurePrevSibling.GetTokenType() == T4TokenNodeTypes.NewLine) { ModificationUtil.AddChildAfter(featureBlock, T4TokenNodeTypes.NewLine.CreateLeafElement()); } ModificationUtil.DeleteChild(statementBlock); } return(textControl => { TextRange range = featureBlock.GetDocumentRange().TextRange; textControl.Caret.MoveTo(range.EndOffset, CaretVisualPlacement.Generic); }); }