Source

Resharper Spell Checker / ReSpeller / Analyzers / StringLiteralTypoAnalyzer.cs

Full commit
using JetBrains.Application;
using JetBrains.DocumentModel;
using JetBrains.ReSharper.Daemon.Stages;
using JetBrains.ReSharper.Daemon.Stages.Dispatcher;
using JetBrains.ReSharper.Psi.Tree;
using ReSpeller.Highlightings;
using ReSpeller.SpellEngine;

namespace ReSpeller.Analyzers
{
  [ElementProblemAnalyzer(new[] { typeof(ILiteralExpression) })]
  public class StringLiteralTypoAnalyzer : ElementProblemAnalyzer<ILiteralExpression>
  {
    private readonly ISpellChecker myChecker = Shell.Instance.GetComponent<ISpellChecker>();

    protected override void Run(ILiteralExpression element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
    {
      if (!element.ConstantValue.IsString()) 
        return;
      DocumentRange literalRange = element.GetDocumentRange();
      if (!literalRange.IsValid())
        return;
      if (literalRange.GetText().StartsWith("@"))
        literalRange = literalRange.ExtendLeft(-1);
      DocumentRange innerLiteralRange = literalRange.ExtendLeft(-1).ExtendRight(-1);
      if (!literalRange.IsValid() && !innerLiteralRange.IsValid())
        return;
      AnalyzerHelper.GenerateRangeBasedHighlightings(myChecker, consumer, element.GetContainingFile(), innerLiteralRange, 
        range => new StringLiteralTypoHighlighting(range));
    }
  }
}