icsharpcode/NRefactory — pull request #99 by riviti (2012-08-21 14:43:35+00:00)
Title: My GSoC 2012 work

So, this is the work I have done as part of GSoC 2012. Mostly plain Code Actions and Code Issues, but also some other things.

Code Action providers
---------------------
I'll list them by the message used for the actions in most cases. Since the context they apply to is missing,
the description is a bit terse, but hopefully that is not a huge problem.

* Convert initializer to explicit initializations
* Convert statements to initializer
* Add catch type
* Convert anonymous delegate to lambda
* Convert lambda to anonymous delegate
* Convert extension method invocation to static method invocation
* Convert static method invocation to extension method invocation
* Iterate via foreach
* Move declaration to outer scope

Code Issue inspectors
---------------------
Like with the Code Actions, I'll just list the title text for the issue.

* Format string syntax error
* Parameter can be demoted to base type
* Call to base.Equals resolves to Object equals which is reference equality
* Call to virtual member from constructor
* Exceptions should be rethrown using empty "throw;"
* Call to base.GetHashCode() resolves to Object.GetHashCode() which is reference based
* Incorrect ordering of parameters to exceptions with inconsistent parameter ordering
* Optional parameter is passed the default value and can be skipped
* Redundant catch clause
* Redundant .ToString()
* Reference to static member via derived type
* Static field in generic type
* [ThreadStatic] on instance field
* 'value' parameter unused
* Variable can be moved to nested scope

Other things things worth mentioning
------------------------------------
* I've implemented a parser for composite format strings, ie the syntax used in string.Format and related functions. (see below)
* Added a NamingHelper class, generating unique, unused variable names with (some) relevance.

The Composite Format String parser
----------------------------------
It is a little more than "just" a parser in that it not only parses valid format strings, but it also tries to parse ones with
syntactical errors, ie

"An invalid format item: {0 and then some text"

Is parsed as one text segment "An invalid format item: ", a format item "{0" and another text segment " and then some text".
Of course that stuff is best-effort ;-)

Current state
-------------
Most Code Actions and Code Issues seem to work fine. Those that need some work still are:

* Variable can be moved to nested scope
* Needs better dependency checking
* There seems to be a problem with if's and else's regarding possible places to move the initializer to
* Parameter can be demoted
* Needs more semantic checks. While I'm not aware of any case that fails right now, there are missing things.
For example, there is no explicit check for whether the picked operators are the same with the demoted type. I ran out of time :-/