protected ICSharpFile GetCodeFile(string fileName)
        {
            PsiManager   manager     = PsiManager.GetInstance(Solution);
            IProjectFile projectFile = Project.GetAllProjectFiles(file => file.Name.Equals(fileName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

            if (projectFile == null)
            {
                return(null);
            }

            IPsiSourceFile psiSourceFile = projectFile.ToSourceFile();

            if (psiSourceFile == null)
            {
                return(null);
            }

#if SDK70
            var cSharpFile = manager.GetPsiFile(psiSourceFile, CSharpLanguage.Instance,
                                                new DocumentRange(psiSourceFile.Document, psiSourceFile.Document.DocumentRange)) as ICSharpFile;
#else
            var cSharpFile = manager.GetPsiFile(psiSourceFile, CSharpLanguage.Instance) as ICSharpFile;
#endif
            if (cSharpFile == null || string.IsNullOrEmpty(cSharpFile.GetText()))
            {
                Assert.Fail("Unable to open the file '{0}', or the file is empty", fileName);
            }

            return(cSharpFile);
        }
        public static IPsiFile GetPsiFile(IPsiSourceFile sourceFile)
        {
            PsiManager manager = PsiManager.GetInstance(sourceFile.GetSolution());

            manager.AssertAllDocumentAreCommited();
            return(manager.GetPsiFile <PsiLanguage>(new DocumentRange(sourceFile.Document, 0)) as IPsiFile);
        }
示例#3
0
        private bool FileIsValid()
        {
            PsiManager manager = PsiManager.GetInstance(this.daemonProcess.Solution);

            if (this.daemonProcess.ProjectFile == null)
            {
                return(false);
            }

            if (!this.daemonProcess.ProjectFile.IsValid)
            {
                return(false);
            }

            IFile file = manager.GetPsiFile(this.daemonProcess.ProjectFile, PsiLanguageType.GetByProjectFile(this.daemonProcess.ProjectFile));

            if (file == null)
            {
                return(false);
            }

            bool hasErrorElements = new RecursiveElementCollector <ErrorElement>().ProcessElement(file).GetResults().Any();

            StyleCopTrace.Info("File has error elements = {0}", hasErrorElements);

            return(!hasErrorElements);
        }
示例#4
0
        public void Execute(Action <DaemonStageResult> commiter)
        {
            PsiManager  manager = PsiManager.GetInstance(myDaemonProcess.Solution);
            ICSharpFile file    = manager.GetPsiFile(myDaemonProcess.SourceFile, CSharpLanguage.Instance) as ICSharpFile;

            if (file == null)
            {
                return;
            }

            // Running visitor against the PSI
            var elementProcessor = new MakeEnumComparisonTypeSafeFinderElementProcessor(myDaemonProcess);

            file.ProcessDescendants(elementProcessor);

            // Checking if the daemon is interrupted by user activity
            if (myDaemonProcess.InterruptFlag)
            {
                throw new ProcessCancelledException();
            }

            // Fill in the result
            DaemonStageResult result = new DaemonStageResult(elementProcessor.Highlightings);

            commiter(result);
        }
        private ICSharpFile GetCodeFile(string fileName)
        {
            PsiManager   manager     = PsiManager.GetInstance(Solution);
            IProjectFile projectFile = Project.GetAllProjectFiles(file => file.Name.Equals(fileName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

            if (projectFile != null)
            {
                return(manager.GetPsiFile(projectFile.ToSourceFile(), CSharpLanguage.Instance) as ICSharpFile);
            }

            return(null);
        }
示例#6
0
        /// <summary>
        /// Executes the process.
        /// The process should check for <see cref="P:JetBrains.ReSharper.Daemon.IDaemonProcess.InterruptFlag"/> periodically (with intervals less than 100 ms)
        /// and throw <see cref="T:JetBrains.Application.Progress.ProcessCancelledException"/> if it is true.
        /// Failing to do so may cause the program to prevent user from typing while analysing the code.
        /// Stage results should be passed to <param name="commiter"/>. If DaemonStageResult is <c>null</c>, it means that no highlightings available
        /// </summary>
        public void Execute(Action <DaemonStageResult> commiter)
        {
            if (DaemonProcess.InterruptFlag)
            {
                return;
            }

            PsiManager manager    = PsiManager.GetInstance(DaemonProcess.Solution);
            var        sourceFile = manager.GetPsiFile(DaemonProcess.SourceFile, CSharpLanguage.Instance) as ICSharpFile;

            if (sourceFile != null)
            {
                List <INamingConsistencyChecker> list =
                    LanguageManager.Instance.GetServices <INamingConsistencyChecker>(sourceFile.Language).Where(x => x.IsApplicable(DaemonProcess.SourceFile)).ToList();

                list.ForEach(Console.WriteLine);

                var highlights = new List <HighlightingInfo>();

                // highlight field declarations
                var processor = new RecursiveElementProcessor <IFieldDeclaration>(
                    declaration =>
                {
                    DocumentRange docRange = declaration.GetNameDocumentRange();

                    highlights.Add(new HighlightingInfo(docRange, new NameInfoHighlighting(declaration)));
                });
                sourceFile.ProcessDescendants(processor);

                // highlight local var declarations
                var localVarsProcessor = new RecursiveElementProcessor <ILocalVariableDeclaration>(
                    declaration =>
                {
                    DocumentRange docRange = declaration.GetNameDocumentRange();

                    highlights.Add(new HighlightingInfo(docRange, new NameInfoHighlighting(declaration)));
                });
                sourceFile.ProcessDescendants(localVarsProcessor);

                commiter(new DaemonStageResult(highlights));
            }
        }