string GetTextFinderMatchAsString(TextFinderMatch match)
		{
			return String.Format(
				"Position: {0}, Length: {1}, ResolvePosition: {2}",
				match.Position,
				match.Length,
				match.ResolvePosition);
		}
        public void Find_SearchingForSquareBracketCharacterAndInputTextHasSquareBracketAtPositionOne_ReturnsTextFinderMatchForPositionOne()
        {
            CreateIndexBeforeTextFinderWithSearchTextOf("[");
            TextFinderMatch match = textFinder.Find("a[0]", 0);

            TextFinderMatch expectedMatch =
                new TextFinderMatch(position: 1, length: 1, resolvePosition: 0);

            AssertTextFindMatchesAreEqual(expectedMatch, match);
        }
Exemplo n.º 3
0
		/// <summary>
		/// This method can be used in three modes (like RunFindReferences)
		/// </summary>
		static void AddReferences(List<Reference> list,
		                          IClass parentClass, IMember member,
		                          string fileName, string fileContent,
		                          CancellationToken cancellationToken)
		{
			TextFinder textFinder; // the class used to find the position to resolve
			if (member == null) {
				textFinder = parentClass.ProjectContent.Language.GetFindClassReferencesTextFinder(parentClass);
			} else {
				Debug.Assert(member.DeclaringType.GetCompoundClass() == parentClass.GetCompoundClass());
				textFinder = parentClass.ProjectContent.Language.GetFindMemberReferencesTextFinder(member);
			}
			
			// It is possible that a class or member does not have a name (when parsing incomplete class definitions)
			// - in that case, we cannot find references.
			if (textFinder == null) {
				return;
			}
			
			string fileContentForFinder = textFinder.PrepareInputText(fileContent);
			
			IExpressionFinder expressionFinder = null;
			TextFinderMatch match = new TextFinderMatch(-1, 0);
			
			while (true) {
				cancellationToken.ThrowIfCancellationRequested();
				match = textFinder.Find(fileContentForFinder, match.Position + 1);
				if (match.Position < 0)
					break;
				
				if (expressionFinder == null) {
					expressionFinder = ParserService.GetExpressionFinder(fileName);
					if (expressionFinder == null) {
						// ignore file if we cannot get an expression finder
						return;
					}
				}
				ExpressionResult expr = expressionFinder.FindFullExpression(fileContent, match.ResolvePosition);
				if (expr.Expression != null) {
					Point position = GetPosition(fileContent, match.ResolvePosition);
				repeatResolve:
					cancellationToken.ThrowIfCancellationRequested();
					// TODO: Optimize by re-using the same resolver if multiple expressions were
					// found in this file (the resolver should parse all methods at once)
					ResolveResult rr = ParserService.Resolve(expr, position.Y, position.X, fileName, fileContent);
					MemberResolveResult mrr = rr as MemberResolveResult;
					if (member != null) {
						// find reference to member
						if (rr != null && rr.IsReferenceTo(member)) {
							list.Add(new Reference(fileName, match.Position, match.Length, expr.Expression, rr));
						} else if (FixIndexerExpression(expressionFinder, ref expr, mrr)) {
							goto repeatResolve;
						}
					} else {
						// find reference to class
						if (rr != null && rr.IsReferenceTo(parentClass)) {
							list.Add(new Reference(fileName, match.Position, match.Length, expr.Expression, rr));
						}
					}
				}
			}
		}
 void AssertTextFindMatchesAreEqual(TextFinderMatch expectedMatch, TextFinderMatch actualMatch)
 {
     string expectedMatchAsString = GetTextFinderMatchAsString(expectedMatch);
     string actualMatchAsString = GetTextFinderMatchAsString(actualMatch);
     Assert.AreEqual(expectedMatchAsString, actualMatchAsString);
 }