Exemple #1
0
        private HighlightingInfo[] GetHighlightings()
        {
#if RESHARPER_60_OR_NEWER
            var projectFile = DaemonProcess.SourceFile.ToProjectFile();
            if (projectFile == null || !projectFile.IsValid())
#else
            IProjectFile projectFile = DaemonProcess.ProjectFile;
            if (!projectFile.IsValid)
#endif
            { return(EmptyArray <HighlightingInfo> .Instance); }

            var state = ProjectFileState.GetFileState(projectFile);
            if (state == null)
            {
                return(EmptyArray <HighlightingInfo> .Instance);
            }

            var highlightings = new List <HighlightingInfo>();

            foreach (AnnotationState annotation in state.Annotations)
            {
                IDeclaredElement declaredElement = annotation.GetDeclaredElement();
                if (declaredElement != null && declaredElement.IsValid())
                {
#if RESHARPER_60_OR_NEWER
                    foreach (IDeclaration declaration in declaredElement.GetDeclarationsIn(DaemonProcess.SourceFile))
#else
                    foreach (IDeclaration declaration in declaredElement.GetDeclarationsIn(projectFile))
#endif
                    {
                        if (declaration.IsValid())
                        {
                            ReSharperDocumentRange range = declaration.GetNameDocumentRange();
#if RESHARPER_31 || RESHARPER_40 || RESHARPER_41
                            if (range.IsValid)
#else
                            if (range.IsValid())
#endif
                            {
                                var annotationHighlighting = AnnotationHighlighting.CreateHighlighting(annotation);
#if RESHARPER_60_OR_NEWER
                                var highlightingInfo = new HighlightingInfo(range, annotationHighlighting, null, null);
#else
                                var highlightingInfo = new HighlightingInfo(range, annotationHighlighting);
#endif
                                highlightings.Add(highlightingInfo);
                            }
                        }
                    }
                }
            }

            return(highlightings.ToArray());
        }
            private void HandleInvokedMethod(IDeclaredElement declaredElement, HotMethodAnalyzerContext context)
            {
                // find all declarations in current file
                var declarations = declaredElement.GetDeclarationsIn(mySourceFile);

                // update current declared element in context and then restore it
                var originDeclaredElement = context.CurrentDeclaredElement;
                var originDeclaration     = context.CurrentDeclaration;

                foreach (var declaration in declarations)
                {
                    context.CurrentDeclaredElement = declaredElement;
                    context.CurrentDeclaration     = declaration;

                    // Do not visit methods twice
                    if (!context.IsCurrentElementVisited())
                    {
                        myCheckForInterrupt();
                        declaration.ProcessThisAndDescendants(this, context);
                    }
                }


                context.CurrentDeclaration     = originDeclaration;
                context.CurrentDeclaredElement = originDeclaredElement;

                // propagate costly reachable methods back
                // Note : on this step there is methods that can be marked as costly reachable later (e.g. recursion)
                // so we will propagate costly reachable mark later
                if (context.IsDeclaredElementCostly(declaredElement))
                {
                    context.MarkCurrentAsCostly();
                }
            }
Exemple #3
0
 private void HighlightDeclarationsInFile(IDeclaredElement declaredElement, IPsiView psiView,
                                          HighlightingsConsumer consumer)
 {
     foreach (var psiSourceFile in psiView.SortedSourceFiles)
     {
         foreach (var declaration in declaredElement.GetDeclarationsIn(psiSourceFile))
         {
             HighlightDeclaration(declaration, consumer);
         }
     }
 }
Exemple #4
0
        private bool IsValidMemberOfSourceFile(IPsiSourceFile sourceFile, IDeclaredElement typeMember)
        {
            if (typeMember is ICompiledElement)
            {
                return(true);
            }

            if (!typeMember.HasDeclarationsIn(sourceFile))
            {
                return(false);
            }

            if (typeMember.GetDeclarationsIn(sourceFile)
                .Any(declaration => declaration.GetDocumentRange().IsValid() && declaration.GetNavigationRange().IsValid()))
            {
                return(true);
            }

            return(false);
        }