public bool MoveNext()
        {
            ProjectItem item = nextItem;

            nextItem = (++index < projectItems.Count) ? projectItems[index] : null;
            if (item == null)
            {
                return(false);
            }

            if (ParserService.GetParser(item.FileName) == null)
            {
                return(MoveNext());
            }

            string fileContent;

            try {
                fileContent = GetFileContent(item);
            } catch (FileNotFoundException ex) {
                LoggingService.Warn("ParseableFileContentEnumerator: " + ex.Message);
                return(MoveNext());                // skip files that were not found
            } catch (IOException ex) {
                LoggingService.Warn("ParseableFileContentEnumerator: " + ex.Message);
                return(MoveNext());                // skip invalid files
            }
            current = new KeyValuePair <string, string>(item.FileName, fileContent);
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the files of files that could have a reference to the <paramref name="member"/>
        /// int the <paramref name="ownerClass"/>.
        /// </summary>
        static List <ProjectItem> GetPossibleFiles(IClass ownerClass, IEntity member)
        {
            List <ProjectItem> resultList = new List <ProjectItem>();

            if (ProjectService.OpenSolution == null)
            {
                foreach (IViewContent vc in WorkbenchSingleton.Workbench.ViewContentCollection)
                {
                    string name = vc.PrimaryFileName;
                    if (!string.IsNullOrEmpty(name) && ParserService.GetParser(name) != null)
                    {
                        FileProjectItem tempItem = new FileProjectItem(null, ItemType.Compile);
                        tempItem.Include = name;
                        resultList.Add(tempItem);
                    }
                }
                return(resultList);
            }

            if (member == null)
            {
                // get files possibly referencing ownerClass
                while (ownerClass.DeclaringType != null)
                {
                    // for nested classes, treat class as member
                    member     = ownerClass;
                    ownerClass = ownerClass.DeclaringType;
                }
                if (member == null)
                {
                    GetPossibleFilesInternal(resultList, ownerClass.ProjectContent, ownerClass.IsInternal);
                    return(resultList);
                }
            }
            if (member.IsPrivate)
            {
                List <string> fileNames = GetFileNames(ownerClass);
                foreach (string fileName in fileNames)
                {
                    ProjectItem item = FindItem(fileName);
                    if (item != null)
                    {
                        resultList.Add(item);
                    }
                }
                return(resultList);
            }

            if (member.IsProtected)
            {
                // TODO: Optimize when member is protected
            }

            GetPossibleFilesInternal(resultList, ownerClass.ProjectContent, ownerClass.IsInternal || member.IsInternal && !member.IsProtected);
            return(resultList);
        }
        public static IParser GetParser(string fileName)
        {
            IParser p;

            if (presetParsersUnitTestOnly == null)
            {
                p = ParserService.GetParser(fileName);
            }
            else
            {
                presetParsersUnitTestOnly.TryGetValue(System.IO.Path.GetExtension(fileName), out p);
            }
            return(p);
        }
        public void ActivateQuickClassBrowserOnDemand()
        {
            SharpDevelopTextEditorProperties sdtep = base.TextEditorProperties as SharpDevelopTextEditorProperties;

            if (sdtep != null && sdtep.ShowQuickClassBrowserPanel && FileName != null)
            {
                bool quickClassPanelActive = ParserService.GetParser(FileName) != null;
                if (quickClassPanelActive)
                {
                    ShowQuickClassBrowserPanel();
                }
                else
                {
                    RemoveQuickClassBrowserPanel();
                }
            }
        }
Exemplo n.º 5
0
        static void GenerateWebProxy(string proxyNamespace, string fileName, ServiceDescriptionCollection serviceDescriptions, XmlSchemas schemas)
        {
            ServiceDescriptionImporter importer = new ServiceDescriptionImporter();

            foreach (ServiceDescription description in serviceDescriptions)
            {
                importer.AddServiceDescription(description, null, null);
            }

            foreach (XmlSchema schema in schemas)
            {
                importer.Schemas.Add(schema);
            }

            CodeNamespace   codeNamespace = new CodeNamespace(proxyNamespace);
            CodeCompileUnit codeUnit      = new CodeCompileUnit();

            codeUnit.Namespaces.Add(codeNamespace);
            ServiceDescriptionImportWarnings warnings = importer.Import(codeNamespace, codeUnit);

            CodeDomProvider provider = null;

            ICSharpCode.SharpDevelop.Dom.IParser parser = ParserService.GetParser(fileName);
            if (parser != null)
            {
                provider = parser.Language.CodeDomProvider;
            }

            if (provider != null)
            {
                StreamWriter         sw      = new StreamWriter(fileName);
                CodeGeneratorOptions options = new CodeGeneratorOptions();
                options.BracingStyle = "C";
                provider.GenerateCodeFromCompileUnit(codeUnit, sw, options);
                sw.Close();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// This method can be used in three modes:
        /// 1. Find references to classes (parentClass = targetClass, member = null, fileName = null)
        /// 2. Find references to members (parentClass = parent, member = member, fileName = null)
        /// 3. Find references to local variables (parentClass = parent, member = local var as field, fileName = parent.CompilationUnit.FileName)
        /// </summary>
        static List <Reference> RunFindReferences(IClass ownerClass, IMember member,
                                                  string fileName,
                                                  IProgressMonitor progressMonitor)
        {
            if (ParserService.LoadSolutionProjectsThreadRunning)
            {
                if (progressMonitor != null)
                {
                    progressMonitor.ShowingDialog = true;
                }
                MessageService.ShowMessage("${res:SharpDevelop.Refactoring.LoadSolutionProjectsThreadRunning}");
                if (progressMonitor != null)
                {
                    progressMonitor.ShowingDialog = false;
                }
                return(null);
            }

            CancellationToken ct = progressMonitor != null ? progressMonitor.CancellationToken : CancellationToken.None;

            List <ProjectItem> files;

            if (!string.IsNullOrEmpty(fileName))
            {
                // search just in given file
                files = new List <ProjectItem>();
                files.Add(FindItem(fileName));
            }
            else
            {
                // search in all possible files
                ownerClass = ownerClass.GetCompoundClass();
                files      = GetPossibleFiles(ownerClass, member);
            }
            ParseableFileContentFinder finder     = new ParseableFileContentFinder();
            List <Reference>           references = new List <Reference>();

            if (progressMonitor != null)
            {
                progressMonitor.TaskName = StringParser.Parse("${res:SharpDevelop.Refactoring.FindingReferences}");
            }

            foreach (ProjectItem item in files)
            {
                FileName itemFileName = FileName.Create(item.FileName);

                if (progressMonitor != null)
                {
                    progressMonitor.Progress += 1.0 / files.Count;
                    if (ct.IsCancellationRequested)
                    {
                        return(null);
                    }
                }
                // Don't read files we don't have a parser for.
                // This avoids loading huge files (e.g. sdps) when we have no intention of parsing them.
                if (ParserService.GetParser(itemFileName) != null)
                {
                    ITextBuffer content = finder.Create(itemFileName);
                    if (content != null)
                    {
                        try {
                            AddReferences(references, ownerClass, member, itemFileName, content.Text, ct);
                        } catch (OperationCanceledException ex) {
                            if (ex.CancellationToken == ct)
                            {
                                return(null);
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                }
            }

            return(references);
        }