private InlineRenameLocation ConvertLocation(RenameLocation location)
 {
     return(new InlineRenameLocation(
                _renameLocationSet.Solution.GetDocument(location.DocumentId),
                location.Location.SourceSpan
                ));
 }
        private static bool IsWrittenToOutsideOfConstructorOrProperty(
            RenameLocation location, TPropertyDeclaration propertyDeclaration, ISet <TConstructorDeclaration> constructorNodes, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (!location.IsWrittenTo)
            {
                // We don't need a setter if we're not writing to this field.
                return(false);
            }

            var node = location.Location.FindToken(cancellationToken).Parent;

            while (node != null)
            {
                if (node == propertyDeclaration)
                {
                    // Not a write outside the property declaration.
                    return(false);
                }

                if (constructorNodes.Contains(node))
                {
                    // Not a write outside a constructor of the field's class
                    return(false);
                }

                node = node.Parent;
            }

            // We do need a setter
            return(true);
        }
예제 #3
0
        public static string CreateNeededFolder(string currentFolder, RenameLocation location)
        {
            currentFolder = (currentFolder.EndsWith("\\") || currentFolder.EndsWith("/")) ? currentFolder : currentFolder + "\\";
            var ret = "";

            switch (location)
            {
            case RenameLocation.Fin:
                ret = CreateFolder(currentFolder + @"fin\");
                break;

            case RenameLocation.Notfound:
                ret = CreateFolder(currentFolder + @"未找到\");
                break;

            case RenameLocation.Uncensor:
                ret = CreateFolder(currentFolder + @"无码\");
                break;

            case RenameLocation.US:
                ret = CreateFolder(currentFolder + @"欧美\");
                break;

            case RenameLocation.VR:
                ret = CreateFolder(currentFolder + @"VR\");
                break;
            }

            return(ret);
        }
예제 #4
0
            /// We try to rewrite all locations that are invalid candidate locations. If there is only
            /// one location it must be the correct one (the symbol is ambiguous to something else)
            /// and we always try to rewrite it.  If there are multiple locations, we only allow it
            /// if the candidate reason allows for it).
            private bool ShouldIncludeLocation(ISet <RenameLocation> renameLocations, RenameLocation location)
            {
                if (location.IsRenameInStringOrComment)
                {
                    return(false);
                }

                if (renameLocations.Count == 1)
                {
                    return(true);
                }

                return(RenameLocation.ShouldRename(location));
            }
        private static bool IsWrittenToOutsideOfConstructorOrProperty(
            Solution solution,
            RenameLocation location,
            TPropertyDeclaration propertyDeclaration,
            ISet <TConstructorDeclaration> constructorNodes,
            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (!location.IsWrittenTo)
            {
                // We don't need a setter if we're not writing to this field.
                return(false);
            }

            var syntaxFacts = solution.GetDocument(location.DocumentId).GetLanguageService <ISyntaxFactsService>();
            var node        = location.Location.FindToken(cancellationToken).Parent;

            while (node != null && !syntaxFacts.IsAnonymousOrLocalFunction(node))
            {
                if (node == propertyDeclaration)
                {
                    // Not a write outside the property declaration.
                    return(false);
                }

                if (constructorNodes.Contains(node))
                {
                    // Not a write outside a constructor of the field's class
                    return(false);
                }

                node = node.Parent;
            }

            // We do need a setter
            return(true);
        }
            private static void AddLocationsToRenameInStringsAndComments(
                Document document,
                SyntaxTree tree,
                string renameText,
                IEnumerable<Tuple<string, int, TextSpan>> renameStringsAndPositions,
                List<RenameLocation> renameLocations,
                bool isRenameInStrings,
                bool isRenameInComments)
            {
                var regex = GetRegexForMatch(renameText);
                foreach (var renameStringAndPosition in renameStringsAndPositions)
                {
                    string renameString = renameStringAndPosition.Item1;
                    int renameStringPosition = renameStringAndPosition.Item2;
                    var containingSpan = renameStringAndPosition.Item3;

                    MatchCollection matches = regex.Matches(renameString);

                    foreach (Match match in matches)
                    {
                        int start = renameStringPosition + match.Index;
                        Debug.Assert(renameText.Length == match.Length);
                        var matchTextSpan = new TextSpan(start, renameText.Length);
                        var matchLocation = tree.GetLocation(matchTextSpan);
                        var renameLocation = new RenameLocation(matchLocation, document.Id, containingLocationForStringOrComment: containingSpan);
                        renameLocations.Add(renameLocation);
                    }
                }
            }
예제 #7
0
 public static SerializableRenameLocation Dehydrate(RenameLocation location) =>
예제 #8
0
            /// We try to rewrite all locations that are invalid candidate locations. If there is only
            /// one location it must be the correct one (the symbol is ambiguous to something else)
            /// and we always try to rewrite it.  If there are multiple locations, we only allow it
            /// if the candidate reason allows for it).
            private bool ShouldIncludeLocation(ISet<RenameLocation> renameLocations, RenameLocation location)
            {
                if (location.IsRenameInStringOrComment)
                {
                    return false;
                }

                if (renameLocations.Count == 1)
                {
                    return true;
                }

                return RenameLocation.ShouldRename(location);
            }
예제 #9
0
 public static SerializableRenameLocation Dehydrate(RenameLocation location)
 => new(location.Location.SourceSpan,
 private InlineRenameLocation ConvertLocation(RenameLocation location)
 {
     return new InlineRenameLocation(
         _renameLocationSet.Solution.GetDocument(location.DocumentId), location.Location.SourceSpan);
 }