public void Execute(Action<DaemonStageResult> commiter)
        {
            if (_process.InterruptFlag)
            {
                return;
            }


            var file = _process.SourceFile as ICSharpFile;

            if (file != null)
            {
                var highlights = new List<HighlightingInfo>();

                var processor = new RecursiveElementProcessor<IMethodDeclaration>(declaration =>
                {

                    var accessRights = declaration.GetAccessRights();

                    if (accessRights == AccessRights.PUBLIC && !declaration.IsStatic && !declaration.IsVirtual &&
                        !declaration.IsOverride)
                    {
                        var docRange = declaration.GetNameDocumentRange();

                        highlights.Add(new HighlightingInfo(docRange, new MakeMethodVirtualSuggestion(declaration)));
                    }
                });
  
                file.ProcessDescendants(processor);
                
                commiter(new DaemonStageResult(highlights));
            }

        }
Пример #2
0
        public override object Build(IPsiSourceFile sourceFile, bool isStartup)
        {
            if (!IsApplicable(sourceFile))
            {
                return(null);
            }

            var file = sourceFile.GetDominantPsiFile <JsonNewLanguage>();

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

            var cacheBuilder = new AsmDefCacheItemBuilder();
            var processor    = new RecursiveElementProcessor <IJsonNewLiteralExpression>(e =>
            {
                // Only accept the first name. If there are multiple name definitions, it's an error, and that's just tough luck
                if (e.IsNameLiteral() && !cacheBuilder.HasNameDefinition)
                {
                    cacheBuilder.SetNameDefinition(e.GetStringValue(), e.GetTreeStartOffset().Offset);
                }
                else if (e.IsReferenceLiteral())
                {
                    cacheBuilder.AddReference(e.GetStringValue());
                }
            });

            file.ProcessDescendants(processor);

            return(cacheBuilder.Build());
        }
Пример #3
0
        public void Execute(Action <DaemonStageResult> commiter)
        {
            if (_process.InterruptFlag)
            {
                return;
            }


            var file = _process.SourceFile as ICSharpFile;

            if (file != null)
            {
                var highlights = new List <HighlightingInfo>();

                var processor = new RecursiveElementProcessor <IMethodDeclaration>(declaration =>
                {
                    var accessRights = declaration.GetAccessRights();

                    if (accessRights == AccessRights.PUBLIC && !declaration.IsStatic && !declaration.IsVirtual &&
                        !declaration.IsOverride)
                    {
                        var docRange = declaration.GetNameDocumentRange();

                        highlights.Add(new HighlightingInfo(docRange, new MakeMethodVirtualSuggestion(declaration)));
                    }
                });

                file.ProcessDescendants(processor);

                commiter(new DaemonStageResult(highlights));
            }
        }
Пример #4
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));
            }
        }
        public override object Build(IPsiSourceFile sourceFile, bool isStartup)
        {
            if (!IsApplicable(sourceFile))
            {
                return(null);
            }

            // TODO: Check if this works for JS islands in HTML
            var jsFile = sourceFile.GetDominantPsiFile <JavaScriptLanguage>() as IJavaScriptFile;

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

            var processor = new RecursiveElementProcessor();

            jsFile.ProcessDescendants(processor);
            return(processor.CacheObject.IsEmpty ? null : processor.CacheObject);
        }
        /// <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));
            }
        }
        /// <summary>
        /// Executes the specified type member declaration.
        /// </summary>
        /// <param name="typeMemberDeclaration">
        /// The type member declaration.
        /// </param>
        private void Execute(ITypeMemberDeclaration typeMemberDeclaration)
        {
            var processor = new RecursiveElementProcessor(this.ReplaceReturnValue);

              typeMemberDeclaration.ProcessDescendants(processor);
        }
    /// <summary>Processes the specified file.</summary>
    /// <param name="project">The project.</param>
    /// <param name="file">The file.</param>
    /// <exception cref="ArgumentNullException">project</exception>
    private void Process([NotNull] IProject project, [NotNull] IProjectFile file)
    {
      if (project == null)
      {
        throw new ArgumentNullException("project");
      }

      if (file == null)
      {
        throw new ArgumentNullException("file");
      }

      var psiFile = file.GetPrimaryPsiFile();
      if (psiFile == null)
      {
        return;
      }

      var fileName = file.Location.ToString();
      if (project.Location != null)
      {
        var root = project.Location.ToString();
        if (fileName.StartsWith(root, StringComparison.InvariantCultureIgnoreCase))
        {
          fileName = "<" + project.Name + ">" + fileName.Substring(root.Length);
        }
      }

      this.ProgressIndicator.Text = fileName;
      this.CurrentFileName = fileName;

      var processor = new RecursiveElementProcessor(this.ProcessTreeNode);
      processor.Process(psiFile.Children());
    }
    /// <summary>
    /// Executes QuickFix or ContextAction. Returns post-execute method.
    /// </summary>
    /// <param name="solution">The solution.</param>
    /// <param name="progress">The progress.</param>
    /// <returns>Action to execute after document and PSI transaction finish. Use to open TextControls, navigate caret, etc.</returns>
    protected override Action<ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
    {
      var model = this.GetModel();
      if (model == null)
      {
        return null;
      }

      var processor = new RecursiveElementProcessor(this.ReplaceReturnValue);

      model.Method.ProcessDescendants(processor);

      FormattingUtils.Format(model.Method);

      return null;
    }