Accessing previous\next invocation expression from current invocation expression

When an element problem analyzer is called for a method invocation is it possible to get access to previous or next IInvocationExpression instance?

So if I have the following code:

var tmp = Observable.Return("Ollie")
               .Select(n => "Ollie Riches")
               .Reverse();



And I have an invocation expression analyzer:

public sealed class SelectAndReverseAnalyzer : ElementProblemAnalyzer<IInvocationExpression> {
     protected override void Run(IInvocationExpression expression, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
     {
          ...
     }
}



When the Run overload is called for the Reverse' method how can I get the invocation expression for the 'Select' method?


ta

Ollie
4 comments
Comment actions Permalink

I don't think there's a prescribed way of doing it, but you can always walk the tree, using the sibling and parent properties of the IInvocationExpression. If you want more control of this process, you might want to implement an IDaemonStageProcess, which allows you to take full control of walking the PSI tree of the file: http://confluence.jetbrains.com/display/ReSharper/2.4+Daemons+and+Daemon+Stages+%28R7%29

0
Comment actions Permalink

I was able to get all of the expressions during an instance of ElementProblemAnalyzer<T> using the following code:


var sourceFile = expression.GetSourceFile(); var psiFile = sourceFile.GetNonInjectedPsiFile<CSharpLanguage>(); var expressions = new List<IInvocationExpression>(); psiFile.ProcessChildren<IInvocationExpression>(expressions.Add);




ta

Ollie

0
Comment actions Permalink
Glad you got it working, but what you've done here is perhaps not very efficient - ReSharper is processing the file, and calling your code for each invocation it encounters. At which point, you start processing the file again. You'd be better off implementing an IDaemonStageProcess, where you could process the whole file in one go. It's essentially the same as a problem analyser, but it let's you walk the PSI tree in whatever manner you want, rather than walking it for you.
0
Comment actions Permalink

Matt - thought you would say that :)

I recon when I ahve it working end-to-end then I'll move it over to a daemon process.


thanks for the info

Ollie

0

Please sign in to leave a comment.