private void AddGetterSetterPreview(List <ReferenceInfo> refInfos, ASResult target, string prefix, string name, bool supportInsideComment, bool supportInsideString)
        {
            target = RenamingHelper.FindGetterSetter(target, prefix + name);
            if (target == null)
            {
                return;
            }

            var results = new FRRunner().SearchSync(GetConfig(prefix + name))[currentDoc.FileName];
            int offset  = prefix.Length;

            foreach (var match in results)
            {
                int    index         = match.Index + offset;
                int    length        = match.Length - offset;
                string value         = match.Value.Substring(offset);
                int    style         = sci.BaseStyleAt(index);
                bool   insideComment = supportInsideComment && RefactoringHelper.IsCommentStyle(style);
                bool   insideString  = supportInsideString && RefactoringHelper.IsStringStyle(style);

                if (RefactoringHelper.DoesMatchPointToTarget(sci, match, target, null) || insideComment || insideString)
                {
                    var @ref = new ReferenceInfo()
                    {
                        Index = index, Length = length, Value = value
                    };
                    refInfos.Add(@ref);

                    if (previewChanges && (!insideComment || includeComments) && (!insideString || includeStrings))
                    {
                        Highlight(index, value.Length);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Finds the given target in all project files.
        /// If the target is a local variable or function parameter, it will only search the associated file.
        /// Note: if running asynchronously, you must supply a listener to "findFinishedHandler" to retrieve the results.
        /// If running synchronously, do not set listeners and instead use the return value.
        /// </summary>
        /// <param name="target">the source member to find references to</param>
        /// <param name="progressReportHandler">event to fire as search results are compiled</param>
        /// <param name="findFinishedHandler">event to fire once searching is finished</param>
        /// <param name="asynchronous">executes in asynchronous mode</param>
        /// <param name="onlySourceFiles">searches only on defined classpaths</param>
        /// <returns>If "asynchronous" is false, will return the search results, otherwise returns null on bad input or if running in asynchronous mode.</returns>
        public static FRResults FindTargetInFiles(ASResult target, FRProgressReportHandler progressReportHandler, FRFinishedHandler findFinishedHandler, Boolean asynchronous, Boolean onlySourceFiles, Boolean ignoreSdkFiles, bool includeComments, bool includeStrings)
        {
            if (target == null)
            {
                return(null);
            }
            var member = target.Member;
            var type   = target.Type;

            if ((member == null || string.IsNullOrEmpty(member.Name)) && (type == null || (type.Flags & (FlagType.Class | FlagType.Enum)) == 0))
            {
                return(null);
            }
            FRConfiguration config;
            IProject        project = PluginBase.CurrentProject;
            String          file    = PluginBase.MainForm.CurrentDocument.FileName;

            // This is out of the project, just look for this file...
            if (IsPrivateTarget(target) || !IsProjectRelatedFile(project, file))
            {
                String mask = Path.GetFileName(file);
                if (mask.Contains("[model]"))
                {
                    findFinishedHandler?.Invoke(new FRResults());
                    return(null);
                }
                String path = Path.GetDirectoryName(file);
                config = new FRConfiguration(path, mask, false, GetFRSearch(member != null ? member.Name : type.Name, includeComments, includeStrings));
            }
            else if (member != null && !CheckFlag(member.Flags, FlagType.Constructor))
            {
                config = new FRConfiguration(GetAllProjectRelatedFiles(project, onlySourceFiles, ignoreSdkFiles), GetFRSearch(member.Name, includeComments, includeStrings));
            }
            else
            {
                target.Member = null;
                config        = new FRConfiguration(GetAllProjectRelatedFiles(project, onlySourceFiles, ignoreSdkFiles), GetFRSearch(type.Name, includeComments, includeStrings));
            }
            config.CacheDocuments = true;
            FRRunner runner = new FRRunner();

            if (progressReportHandler != null)
            {
                runner.ProgressReport += progressReportHandler;
            }
            if (findFinishedHandler != null)
            {
                runner.Finished += findFinishedHandler;
            }
            if (asynchronous)
            {
                runner.SearchAsync(config);
            }
            else
            {
                return(runner.SearchSync(config));
            }
            return(null);
        }
Exemple #3
0
        /// <summary>
        /// Finds the given target in all project files.
        /// If the target is a local variable or function parameter, it will only search the associated file.
        /// Note: if running asynchronously, you must supply a listener to "findFinishedHandler" to retrieve the results.
        /// If running synchronously, do not set listeners and instead use the return value.
        /// </summary>
        /// <param name="target">the source member to find references to</param>
        /// <param name="progressReportHandler">event to fire as search results are compiled</param>
        /// <param name="findFinishedHandler">event to fire once searching is finished</param>
        /// <param name="asynchronous">executes in asynchronous mode</param>
        /// <returns>If "asynchronous" is false, will return the search results, otherwise returns null on bad input or if running in asynchronous mode.</returns>
        public static FRResults FindTargetInFiles(ASResult target, FRProgressReportHandler progressReportHandler, FRFinishedHandler findFinishedHandler, Boolean asynchronous)
        {
            Boolean currentFileOnly = false;

            // checks target is a member
            if (target == null || ((target.Member == null || target.Member.Name == null || target.Member.Name == String.Empty) && (target.Type == null || CheckFlag(FlagType.Class, target.Type.Flags))))
            {
                return(null);
            }
            else
            {
                // if the target we are trying to rename exists as a local variable or a function parameter we only need to search the current file
                if (target.Member != null && (RefactoringHelpera.CheckFlag(target.Member.Flags, FlagType.LocalVar) || RefactoringHelpera.CheckFlag(target.Member.Flags, FlagType.ParameterVar)))
                {
                    currentFileOnly = true;
                }
            }
            // sets the FindInFiles settings to the project root, *.as files, and recursive
            String path = Path.GetDirectoryName(PluginBase.CurrentProject.ProjectPath);

            if (!PluginBase.MainForm.CurrentDocument.FileName.StartsWith(path))
            {
                // This is out of the project, just look for this file...
                currentFileOnly = true;
            }
            String  mask      = "*.as;*.hx";
            Boolean recursive = true;

            // but if it's only the current file, let's just search that!
            if (currentFileOnly)
            {
                path      = Path.GetDirectoryName(PluginBase.MainForm.CurrentDocument.FileName);
                mask      = Path.GetFileName(PluginBase.MainForm.CurrentDocument.FileName);
                recursive = false;
            }
            FRConfiguration config = new FRConfiguration(path, mask, recursive, GetFRSearch(target.Member.Name));

            config.CacheDocuments = true;
            FRRunner runner = new FRRunner();

            if (progressReportHandler != null)
            {
                runner.ProgressReport += progressReportHandler;
            }
            if (findFinishedHandler != null)
            {
                runner.Finished += findFinishedHandler;
            }
            if (asynchronous)
            {
                runner.SearchAsync(config);
            }
            else
            {
                return(runner.SearchSync(config));
            }
            return(null);
        }
        /// <summary>
        /// Set up required variables for live preview features.
        /// </summary>
        /// <param name="supportInsideComment">Whether searching inside comments are enabled.</param>
        /// <param name="supportInsideString">Whether searching inside strings are enabled.</param>
        /// <param name="supportPreviewChanges">Whether live preview is enabled.</param>
        /// <param name="target">Current target to rename.</param>
        private void SetupLivePreview(bool supportInsideComment, bool supportInsideString, bool supportPreviewChanges, ASResult target)
        {
            if (!supportPreviewChanges)
            {
                return;
            }

            var results  = new FRRunner().SearchSync(GetConfig(oldName))[currentDoc.FileName];
            var tempRefs = new List <ReferenceInfo>();

            foreach (var match in results)
            {
                int    index         = match.Index;
                int    length        = match.Length;
                string value         = match.Value;
                int    style         = sci.BaseStyleAt(index);
                bool   insideComment = supportInsideComment && RefactoringHelper.IsCommentStyle(style);
                bool   insideString  = supportInsideString && RefactoringHelper.IsStringStyle(style);

                if (RefactoringHelper.DoesMatchPointToTarget(sci, match, target, null) || insideComment || insideString)
                {
                    var @ref = new ReferenceInfo()
                    {
                        Index = index, Length = length, Value = value
                    };
                    tempRefs.Add(@ref);

                    if (currentRef == null && match.Index == start)
                    {
                        currentRef = @ref;
                    }
                    else if (previewChanges && (!insideComment || includeComments) && (!insideString || includeStrings))
                    {
                        Highlight(index, length);
                    }
                }
            }

            if (RenamingHelper.HasGetterSetter(target))
            {
                var list = target.Member.Parameters;
                if (list[0].Name == RenamingHelper.ParamGetter)
                {
                    AddGetterSetterPreview(tempRefs, target, RenamingHelper.PrefixGetter, oldName, supportInsideComment, supportInsideString);
                }
                if (list[1].Name == RenamingHelper.ParamSetter)
                {
                    AddGetterSetterPreview(tempRefs, target, RenamingHelper.PrefixSetter, oldName, supportInsideComment, supportInsideString);
                }
                tempRefs.Sort();
            }

            refs = tempRefs.ToArray();
        }
 /// <summary>
 /// Finds the given target in all project files.
 /// If the target is a local variable or function parameter, it will only search the associated file.
 /// Note: if running asynchronously, you must supply a listener to "findFinishedHandler" to retrieve the results.
 /// If running synchronously, do not set listeners and instead use the return value.
 /// </summary>
 /// <param name="target">the source member to find references to</param>
 /// <param name="progressReportHandler">event to fire as search results are compiled</param>
 /// <param name="findFinishedHandler">event to fire once searching is finished</param>
 /// <param name="asynchronous">executes in asynchronous mode</param>
 /// <returns>If "asynchronous" is false, will return the search results, otherwise returns null on bad input or if running in asynchronous mode.</returns>
 public static FRResults FindTargetInFiles(ASResult target, FRProgressReportHandler progressReportHandler, FRFinishedHandler findFinishedHandler, Boolean asynchronous)
 {
     Boolean currentFileOnly = false;
     // checks target is a member
     if (target == null || ((target.Member == null || String.IsNullOrEmpty(target.Member.Name))
         && (target.Type == null || !CheckFlag(target.Type.Flags, FlagType.Class) && !target.Type.IsEnum())))
     {
         return null;
     }
     else
     {
         // if the target we are trying to rename exists as a local variable or a function parameter we only need to search the current file
         if (target.Member != null && (
                 target.Member.Access == Visibility.Private
                 || RefactoringHelper.CheckFlag(target.Member.Flags, FlagType.LocalVar)
                 || RefactoringHelper.CheckFlag(target.Member.Flags, FlagType.ParameterVar))
             )
         {
             currentFileOnly = true;
         }
     }
     FRConfiguration config;
     IProject project = PluginBase.CurrentProject;
     String file = PluginBase.MainForm.CurrentDocument.FileName;
     // This is out of the project, just look for this file...
     if (currentFileOnly || !IsProjectRelatedFile(project, file))
     {
         String mask = Path.GetFileName(file);
         String path = Path.GetDirectoryName(file);
         if (mask.Contains("[model]"))
         {
             if (findFinishedHandler != null)
             {
                 findFinishedHandler(new FRResults());
             }
             return null;
         }
         config = new FRConfiguration(path, mask, false, GetFRSearch(target.Member != null ? target.Member.Name : target.Type.Name));
     }
     else if (target.Member != null && !CheckFlag(target.Member.Flags, FlagType.Constructor))
     {
         config = new FRConfiguration(GetAllProjectRelatedFiles(project), GetFRSearch(target.Member.Name));
     }
     else
     {
         target.Member = null;
         config = new FRConfiguration(GetAllProjectRelatedFiles(project), GetFRSearch(target.Type.Name));
     }
     config.CacheDocuments = true;
     FRRunner runner = new FRRunner();
     if (progressReportHandler != null)
     {
         runner.ProgressReport += progressReportHandler;
     }
     if (findFinishedHandler != null)
     {
         runner.Finished += findFinishedHandler;
     }
     if (asynchronous) runner.SearchAsync(config);
     else return runner.SearchSync(config);
     return null;
 }
Exemple #6
0
        /// <summary>
        /// Finds the given target in all project files.
        /// If the target is a local variable or function parameter, it will only search the associated file.
        /// Note: if running asynchronously, you must supply a listener to "findFinishedHandler" to retrieve the results.
        /// If running synchronously, do not set listeners and instead use the return value.
        /// </summary>
        /// <param name="target">the source member to find references to</param>
        /// <param name="progressReportHandler">event to fire as search results are compiled</param>
        /// <param name="findFinishedHandler">event to fire once searching is finished</param>
        /// <param name="asynchronous">executes in asynchronous mode</param>
        /// <param name="onlySourceFiles">searches only on defined classpaths</param>
        /// <returns>If "asynchronous" is false, will return the search results, otherwise returns null on bad input or if running in asynchronous mode.</returns>
        public static FRResults FindTargetInFiles(ASResult target, FRProgressReportHandler progressReportHandler, FRFinishedHandler findFinishedHandler, Boolean asynchronous, Boolean onlySourceFiles, Boolean ignoreSdkFiles)
        {
            Boolean currentFileOnly = false;

            // checks target is a member
            if (target == null || ((target.Member == null || String.IsNullOrEmpty(target.Member.Name)) &&
                                   (target.Type == null || !CheckFlag(target.Type.Flags, FlagType.Class) && !target.Type.IsEnum())))
            {
                return(null);
            }
            else
            {
                // if the target we are trying to rename exists as a local variable or a function parameter we only need to search the current file
                if (target.Member != null && (
                        target.Member.Access == Visibility.Private ||
                        CheckFlag(target.Member.Flags, FlagType.LocalVar) ||
                        CheckFlag(target.Member.Flags, FlagType.ParameterVar))
                    )
                {
                    currentFileOnly = true;
                }
            }
            FRConfiguration config;
            IProject        project = PluginBase.CurrentProject;
            String          file    = PluginBase.MainForm.CurrentDocument.FileName;

            // This is out of the project, just look for this file...
            if (currentFileOnly || !IsProjectRelatedFile(project, file))
            {
                String mask = Path.GetFileName(file);
                String path = Path.GetDirectoryName(file);
                if (mask.Contains("[model]"))
                {
                    if (findFinishedHandler != null)
                    {
                        findFinishedHandler(new FRResults());
                    }
                    return(null);
                }
                config = new FRConfiguration(path, mask, false, GetFRSearch(target.Member != null ? target.Member.Name : target.Type.Name));
            }
            else if (target.Member != null && !CheckFlag(target.Member.Flags, FlagType.Constructor))
            {
                config = new FRConfiguration(GetAllProjectRelatedFiles(project, onlySourceFiles, ignoreSdkFiles), GetFRSearch(target.Member.Name));
            }
            else
            {
                target.Member = null;
                config        = new FRConfiguration(GetAllProjectRelatedFiles(project, onlySourceFiles, ignoreSdkFiles), GetFRSearch(target.Type.Name));
            }
            config.CacheDocuments = true;
            FRRunner runner = new FRRunner();

            if (progressReportHandler != null)
            {
                runner.ProgressReport += progressReportHandler;
            }
            if (findFinishedHandler != null)
            {
                runner.Finished += findFinishedHandler;
            }
            if (asynchronous)
            {
                runner.SearchAsync(config);
            }
            else
            {
                return(runner.SearchSync(config));
            }
            return(null);
        }
 /// <summary>
 /// Finds the given target in all project files.
 /// If the target is a local variable or function parameter, it will only search the associated file.
 /// Note: if running asynchronously, you must supply a listener to "findFinishedHandler" to retrieve the results.
 /// If running synchronously, do not set listeners and instead use the return value.
 /// </summary>
 /// <param name="target">the source member to find references to</param>
 /// <param name="progressReportHandler">event to fire as search results are compiled</param>
 /// <param name="findFinishedHandler">event to fire once searching is finished</param>
 /// <param name="asynchronous">executes in asynchronous mode</param>
 /// <returns>If "asynchronous" is false, will return the search results, otherwise returns null on bad input or if running in asynchronous mode.</returns>
 public static FRResults FindTargetInFiles(ASResult target, FRProgressReportHandler progressReportHandler, FRFinishedHandler findFinishedHandler, Boolean asynchronous)
 {
     Boolean currentFileOnly = false;
     // checks target is a member
     if (target == null || ((target.Member == null || target.Member.Name == null || target.Member.Name == String.Empty) && (target.Type == null || CheckFlag(FlagType.Class, target.Type.Flags))))
     {
         return null;
     }
     else
     {
         // if the target we are trying to rename exists as a local variable or a function parameter we only need to search the current file
         if (target.Member != null && (RefactoringHelpera.CheckFlag(target.Member.Flags, FlagType.LocalVar) || RefactoringHelpera.CheckFlag(target.Member.Flags, FlagType.ParameterVar)))
         {
             currentFileOnly = true;
         }
     }
     // sets the FindInFiles settings to the project root, *.as files, and recursive
     String path = Path.GetDirectoryName(PluginBase.CurrentProject.ProjectPath);
     if (!PluginBase.MainForm.CurrentDocument.FileName.StartsWith(path))
     {
         // This is out of the project, just look for this file...
         currentFileOnly = true;
     }
     String mask = "*.as;*.hx";
     Boolean recursive = true;
     // but if it's only the current file, let's just search that!
     if (currentFileOnly)
     {
         path = Path.GetDirectoryName(PluginBase.MainForm.CurrentDocument.FileName);
         mask = Path.GetFileName(PluginBase.MainForm.CurrentDocument.FileName);
         recursive = false;
     }
     FRConfiguration config = new FRConfiguration(path, mask, recursive, GetFRSearch(target.Member.Name));
     config.CacheDocuments = true;
     FRRunner runner = new FRRunner();
     if (progressReportHandler != null)
     {
         runner.ProgressReport += progressReportHandler;
     }
     if (findFinishedHandler != null)
     {
         runner.Finished += findFinishedHandler;
     }
     if (asynchronous) runner.SearchAsync(config);
     else return runner.SearchSync(config);
     return null;
 }