当前位置: 首页>>代码示例>>C#>>正文


C# TreeOffset类代码示例

本文整理汇总了C#中TreeOffset的典型用法代码示例。如果您正苦于以下问题:C# TreeOffset类的具体用法?C# TreeOffset怎么用?C# TreeOffset使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TreeOffset类属于命名空间,在下文中一共展示了TreeOffset类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindIncludeAtOffset

		private IncludeWithOffset FindIncludeAtOffset(TreeOffset offset, bool preferRoot) {
			// no includes, tree and document are matching
			if (_includes.Count == 0)
				return new IncludeWithOffset(offset.Offset);

			int includesLength = 0;
			int count = _includes.Count;
			for (int i = 0; i < count; i++) {
				IT4Include include = _includes[i];
				TreeTextRange includeRange = include.GetTreeTextRange();

				// the offset is before the include, in the root file
				if (offset < includeRange.StartOffset)
					return new IncludeWithOffset((offset - includesLength).Offset);
				
				// the offset is inside the include
				if (offset < includeRange.EndOffset) {
					// we're on an edge position: we can be just after the end of the root file,
					// or just at the beginning of an include; we make the choice using the preferRoot parameter
					if (offset == includeRange.StartOffset && preferRoot)
						return new IncludeWithOffset((offset - includesLength).Offset);
					return new IncludeWithOffset(offset - includeRange.StartOffset, include);
				}

				includesLength += includeRange.Length;
			}

			// the offset is after the include, in the root file
			return new IncludeWithOffset((offset - includesLength).Offset);
		}
开发者ID:mnaoumov,项目名称:ForTea,代码行数:30,代码来源:T4DocumentRangeTranslator.cs

示例2: AppendMapped

		/// <summary>
		/// Appends a mapped node.
		/// </summary>
		/// <param name="treeNode">The tree node to add.</param>
		internal void AppendMapped([CanBeNull] ITreeNode treeNode) {
			if (treeNode == null)
				return;

			var startOffset = new TreeOffset(_builder.Length);
			treeNode.GetText(_builder);
			var endOffset = new TreeOffset(_builder.Length);
			_generatedRangeMap.Add(
				new TreeTextRange<Generated>(startOffset, endOffset),
				new TreeTextRange<Original>(treeNode.GetTreeTextRange()));
		}
开发者ID:mnaoumov,项目名称:ForTea,代码行数:15,代码来源:GenerationResult.cs

示例3: Create

 public override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset)
 {
     return new VariableIdentifier(buffer.GetText(new TextRange(startOffset.Offset, endOffset.Offset)));
 }
开发者ID:xsburg,项目名称:ReSharper.NTriples,代码行数:4,代码来源:NTriplesTokenType.cs

示例4: TryHighlightToRight

        // We have left brace. We'll find all right braces.
        // '[caret]LBRACE'
        protected override void TryHighlightToRight(MatchingHighlightingsConsumer consumer, ITokenNode selectedToken, TreeOffset treeOffset)
        {
            if (selectedToken.GetTokenType() != CSharpTokenType.STRING_LITERAL)
                return;

            if (ExistingTreeNodes.ExistingTrees.Count == 0)
                return;

            DocumentRange lBraceRange = myProvider.DocumentCaret.ExtendRight(1);
            ITreeNode node = GetNodeFromRange(lBraceRange);
            string lang = GetLanguageFromNode(node);

            if (String.IsNullOrEmpty(lang))
                return;

            string lBrother = node.UserData.GetData(Constants.YcTokenName);

            string rBrother = LanguageHelper.GetBrother(lang, lBrother, Brother.Right);
            if (String.IsNullOrEmpty(rBrother))
                return;

            int leftNumber = Int32.Parse(node.UserData.GetData(Constants.YcTokNumber));
            int rightNumber = LanguageHelper.GetNumberFromYcName(lang, rBrother);

            var helper = Helper.ReSharperHelper<DocumentRange, ITreeNode>.Instance;

            IEnumerable<DocumentRange> ranges = helper.GetPairedRanges(lang, leftNumber, rightNumber, lBraceRange, true);
            
            foreach (DocumentRange range in ranges)
            {
                MatchingBracesContextHighlightersUtil.ConsumeMatchingBracesHighlighting(consumer, lBraceRange, range);
            }
            /*
             * need for measurement
            Console.WriteLine();
            Stopwatch timer = new Stopwatch();
            timer.Start();
            List<ITreeNode> forest = Helper.ReSharperHelper<DocumentRange, ITreeNode>.Instance.GetForestWithToken(lang, lBraceRange);

            var lBraceTextRange = new TreeTextRange(treeOffset, 1);

            var rightRanges = new List<DocumentRange>();

            foreach (ITreeNode tree in forest)
            {
                var lbraceNode = tree.FindNodeAt(lBraceTextRange);
                //if (lbraceNode == null)
                ////in general, this should not be. But while such a situation occurs
                //    continue;
                var rBraceNode = lbraceNode.NextSibling;
                while (rBraceNode != null
                    && rBraceNode.UserData.GetData(Constants.YcTokenName) != rBrother)
                {
                    var text = rBraceNode.UserData.GetData(Constants.YcTokenName);
                    if (string.IsNullOrEmpty(text))
                        Console.WriteLine();
                    rBraceNode = rBraceNode.NextSibling;
                }
                if (rBraceNode != null)
                    rightRanges.Add(rBraceNode.GetNavigationRange());
            }
            timer.Stop();
            measure.Add(timer.Elapsed);
            if (measure.Count == 10)
            {
                using (var str = new StreamWriter(String.Format(newName, measure.Count)))
                {
                    foreach (TimeSpan span in measure)
                    {
                        str.WriteLine(span);
                    }
                }
            }
            
            foreach (DocumentRange range in rightRanges)
            {
                MatchingBracesContextHighlightersUtil.ConsumeMatchingBracesHighlighting(consumer, lBraceRange, range);
            }
            */
        }
开发者ID:mtashkinov,项目名称:YaccConstructor,代码行数:82,代码来源:MatchingBraceContextHighlighter.cs

示例5: Translate

		private TreeOffset Translate(int documentOffset) {
			int offset = 0;

			foreach (IT4Include include in _includes) {
				TreeTextRange includeRange = include.GetTreeTextRange();

				var finalOffset = new TreeOffset(documentOffset + offset);

				// the matching file offset starts before the include, we got it
				if (finalOffset < includeRange.StartOffset)
					return finalOffset;

				offset += includeRange.Length;
			}

			// the offset is in the file, after the last include
			return new TreeOffset(documentOffset + offset);
		}
开发者ID:mnaoumov,项目名称:ForTea,代码行数:18,代码来源:T4DocumentRangeTranslator.cs

示例6: NitraToken

 public NitraToken(NodeType nodeType, [NotNull] IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) : base(nodeType, buffer, startOffset, endOffset) { }
开发者ID:derigel23,项目名称:Nitra,代码行数:1,代码来源:NitraContentTypeDefinition.cs

示例7: Create

 public override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset)
 {
     return new NamespaceSeparatorTokenElement(this);
 }
开发者ID:xsburg,项目名称:ReSharper.NTriples,代码行数:4,代码来源:TokenTypeGenerated.cs

示例8: Create

 public override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset)
 {
     throw new System.NotImplementedException();
 }
开发者ID:lhsail,项目名称:Nitra,代码行数:4,代码来源:NitraIdentifierNodeType.cs

示例9: T4Token

 /// <summary>
 /// Initializes a new instance of the <see cref="T4Token"/> class.
 /// </summary>
 /// <param name="nodeType">The token type.</param>
 /// <param name="buffer">The buffer holding the token text.</param>
 /// <param name="startOffset">The token starting offset in <paramref name="buffer"/>.</param>
 /// <param name="endOffset">The token ending offset in <paramref name="buffer"/>.</param>
 public T4Token(T4TokenNodeType nodeType, IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset)
     : base(nodeType, buffer, startOffset, endOffset)
 {
 }
开发者ID:ThatShawGuy,项目名称:ForTea,代码行数:11,代码来源:T4Token.cs

示例10: TryHighlightToRight

        protected override void TryHighlightToRight(MatchingHighlightingsConsumer consumer, ITokenNode selectedToken, TreeOffset treeOffset)
        {
            TokenNodeType tokenType = selectedToken.GetTokenType();
            if (this.IsLeftBracket(tokenType))
            {
                ITokenNode matchedToken;
                if (this.FindMatchingRightBracket(selectedToken, out matchedToken))
                {
                    consumer.ConsumeMatchingBracesHighlighting(selectedToken.GetDocumentRange(), matchedToken.GetDocumentRange());
                }
                else
                {
                    consumer.ConsumeHighlighting(
                        "ReSharper Unmatched Brace", selectedToken.GetDocumentRange().StartOffsetRange().ExtendRight(1));
                    if (matchedToken == null)
                    {
                        return;
                    }
                    consumer.ConsumeHighlighting(
                        "ReSharper Unmatched Brace", matchedToken.GetDocumentRange().EndOffsetRange().ExtendLeft(1));
                }
            }
            else
            {
                if (tokenType != NTriplesTokenType.STRING_LITERAL)
                {
                    return;
                }
                if (selectedToken.GetText()[0] == 64)
                {
                    if (treeOffset != selectedToken.GetTreeTextRange().StartOffset.Shift(1))
                    {
                        return;
                    }

                    consumer.ConsumeMatchingBracesHighlighting(
                        selectedToken.GetDocumentRange().StartOffsetRange().ExtendRight(1).Shift(1),
                        selectedToken.GetDocumentRange().EndOffsetRange().ExtendLeft(1));
                }
                else
                {
                    if (treeOffset != selectedToken.GetTreeTextRange().StartOffset)
                    {
                        return;
                    }

                    consumer.ConsumeMatchingBracesHighlighting(
                        selectedToken.GetDocumentRange().StartOffsetRange().ExtendRight(1),
                        selectedToken.GetDocumentRange().EndOffsetRange().ExtendLeft(1));
                }
            }
        }
开发者ID:xsburg,项目名称:ReSharper.NTriples,代码行数:52,代码来源:NTriplesMatchingBraceContextHighlighter.cs

示例11: Create

		/// <summary>
		/// Creates a new token having this token type.
		/// </summary>
		/// <param name="buffer">The buffer holding the token text.</param>
		/// <param name="startOffset">The token starting offset in <paramref name="buffer"/>.</param>
		/// <param name="endOffset">The token ending offset in <paramref name="buffer"/>.</param>
		/// <returns>A new instance of <see cref="T4Token"/>.</returns>
		public override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) {
			return new T4Token(this, buffer, startOffset, endOffset);
		}
开发者ID:ThatShawGuy,项目名称:ForTea,代码行数:10,代码来源:T4TokenNodeType.cs

示例12: Create

 public override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset)
 {
   return new NitraToken(NitraFakeTokenNodeType.Instance, buffer, startOffset, endOffset);
 }
开发者ID:derigel23,项目名称:Nitra,代码行数:4,代码来源:NitraContentTypeDefinition.cs

示例13: TryHighlightToLeft

        // We have right brace. We'll find all left braces.
        // 'RBRACE[caret]'
        protected override void TryHighlightToLeft(MatchingHighlightingsConsumer consumer, ITokenNode selectedToken, TreeOffset treeOffset)
        {
            if (selectedToken.GetTokenType() != CSharpTokenType.STRING_LITERAL)
                return;

            if (ExistingTreeNodes.ExistingTrees.Count == 0)
                return;

            DocumentRange rBraceRange = myProvider.DocumentCaret.ExtendLeft(1);

            ITreeNode node = GetNodeFromRange(rBraceRange);
            string lang = GetLanguageFromNode(node);

            if (String.IsNullOrEmpty(lang))
                return;

            string rBrother = node.UserData.GetData(Constants.YcTokenName);

            string lbrother = LanguageHelper.GetBrother(lang, rBrother, Brother.Left);

            if (String.IsNullOrEmpty(lbrother))
                return;

            int leftNumber = LanguageHelper.GetNumberFromYcName(lang, lbrother);
            int rightNumber = Int32.Parse(node.UserData.GetData(Constants.YcTokNumber));

            var helper = Helper.ReSharperHelper<DocumentRange, ITreeNode>.Instance;

            IEnumerable<DocumentRange> ranges = helper.GetPairedRanges(lang, leftNumber, rightNumber, rBraceRange, false);
            foreach (DocumentRange range in ranges)
            {
                MatchingBracesContextHighlightersUtil.ConsumeMatchingBracesHighlighting(consumer, range, rBraceRange);
            }

            /*
             * need for measurement
            List<ITreeNode> forest = Helper.ReSharperHelper<DocumentRange, ITreeNode>.Instance.GetForestWithToken(lang, rBraceRange);

            var lBraceTextRange = new TreeTextRange(treeOffset.Shift(-1), 1);

            var leftRanges = new List<DocumentRange>();

            foreach (ITreeNode tree in forest)
            {
                var rBraceNode = tree.FindNodeAt(lBraceTextRange);
                //if (rBraceNode == null)
                //    //in general, this should not be. But while such a situation occurs
                //    continue;

                var lbraceNode = rBraceNode.PrevSibling;
                while (lbraceNode != null
                    && lbraceNode.UserData.GetData(Constants.YcTokenName) != lbrother)
                {
                    lbraceNode = lbraceNode.PrevSibling;
                }
                if (lbraceNode != null)
                    leftRanges.Add(lbraceNode.GetNavigationRange());
            }

            foreach (DocumentRange range in leftRanges)
            {
                MatchingBracesContextHighlightersUtil.ConsumeMatchingBracesHighlighting(consumer, range, rBraceRange);
            }
            */
        }
开发者ID:mtashkinov,项目名称:YaccConstructor,代码行数:67,代码来源:MatchingBraceContextHighlighter.cs


注:本文中的TreeOffset类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。