示例#1
0
        /// <summary>
        /// Creates a new feature block with new type members.
        /// </summary>
        /// <param name="originalFile">The original T4 file where the feature block must be created.</param>
        /// <param name="text">The code representing new C# type members.</param>
        /// <param name="first">The first node.</param>
        /// <param name="last">The last node.</param>
        /// <returns>A <see cref="TreeTextRange"/> representing the code range in the newly created feature block.</returns>
        protected override TreeTextRange CreateTypeMemberNode(IFile originalFile, string text, ITreeNode first, ITreeNode last)
        {
            T4FeatureBlock featureBlock = T4ElementFactory.Instance.CreateFeatureBlock(text);

            featureBlock = ((IT4File)originalFile).AddFeatureBlock(featureBlock);
            return(featureBlock.GetCodeToken().GetTreeTextRange());
        }
示例#2
0
        /// <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);
        }
示例#3
0
        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);
            });
        }
        private static void ProcessT4FeatureBlock([NotNull] T4FeatureBlock featureBlock, [NotNull] CodeStructureElement parentElement,
                                                  [NotNull] ICSharpFile cSharpFile, [NotNull] ISecondaryRangeTranslator secondaryRangeTranslator, [NotNull] CSharpCodeStructureProcessingState state)
        {
            TreeTextRange t4Range     = featureBlock.GetCodeToken().GetTreeTextRange();
            TreeTextRange cSharpRange = secondaryRangeTranslator.OriginalToGenerated(t4Range);

            if (!cSharpRange.IsValid())
            {
                return;
            }

            TreeOffset cSharpStart = cSharpRange.StartOffset;
            TreeOffset cSharpEnd   = cSharpRange.EndOffset;

            ITreeNode containingNode = cSharpFile.FindNodeAt(cSharpRange);

            if (containingNode == null)
            {
                return;
            }

            for (ITreeNode node = containingNode.FirstChild; node != null; node = node.NextSibling)
            {
                TreeOffset nodeStart = node.GetTreeStartOffset();
                if (nodeStart >= cSharpStart && nodeStart < cSharpEnd)
                {
                    ProcessCSharpNode(node, parentElement, state);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Gets an existing feature block that can contains type members.
        /// </summary>
        /// <param name="originalFile">The original T4 file.</param>
        /// <returns>A valid <see cref="TreeTextRange"/> if a feature block existed, <see cref="TreeTextRange.InvalidRange"/> otherwise.</returns>
        protected override TreeTextRange GetExistingTypeMembersRange(IFile originalFile)
        {
            T4FeatureBlock lastFeatureBlock = ((IT4File)originalFile).GetFeatureBlocks().LastOrDefault();

            return(lastFeatureBlock == null
                                ? TreeTextRange.InvalidRange
                                : lastFeatureBlock.GetCodeToken().GetTreeTextRange());
        }
示例#6
0
 /// <summary>
 /// Executes the process.
 /// </summary>
 public override void Execute(Action <DaemonStageResult> commiter)
 {
     _lastFeature = File.GetFeatureBlocks().LastOrDefault();
     base.Execute(commiter);
 }