public void Find_SearchingForSquareBracketCharacterAndInputTextHasNoSquareBracketCharacter_ReturnsEmptyTextFinderMatch()
        {
            CreateIndexBeforeTextFinderWithSearchTextOf("[");
            TextFinderMatch match = textFinder.Find("abc", 0);

            AssertTextFindMatchesAreEqual(TextFinderMatch.Empty, match);
        }
        public void Find_SearchingForSquareBracketCharacterAndInputTextHasSquareBracketCharacterAtPositionZero_ReturnsEmptyTextFinderMatch()
        {
            CreateIndexBeforeTextFinderWithSearchTextOf("[");
            TextFinderMatch match = textFinder.Find("[assembly: AssemblyCulture(\"\")]", 0);

            AssertTextFindMatchesAreEqual(TextFinderMatch.Empty, match);
        }
        void AssertTextFindMatchesAreEqual(TextFinderMatch expectedMatch, TextFinderMatch actualMatch)
        {
            string expectedMatchAsString = GetTextFinderMatchAsString(expectedMatch);
            string actualMatchAsString   = GetTextFinderMatchAsString(actualMatch);

            Assert.AreEqual(expectedMatchAsString, actualMatchAsString);
        }
 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);
        }
            public override TextFinderMatch Find(string inputText, int startPosition)
            {
                TextFinderMatch best = TextFinderMatch.Empty;

                foreach (TextFinder f in finders)
                {
                    TextFinderMatch r = f.Find(inputText, startPosition);
                    if (r.Position >= 0 && (best.Position < 0 || r.Position < best.Position))
                    {
                        best = r;
                    }
                }
                return(best);
            }
Beispiel #7
0
        /// <summary>
        /// This method can be used in three modes (like RunFindReferences)
        /// </summary>
        static void AddReferences(List <Reference> list,
                                  IClass parentClass, IMember member,
                                  bool isLocal,
                                  string fileName, string fileContent)
        {
            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)
            {
                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:
                    // 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));
                        }
                    }
                }
            }
        }