Coder Social home page Coder Social logo

nrefactory's Introduction

Note: There is currently no maintainer for NRefactory.

If you need a C# parser / compiler frontend, use Microsoft.CodeAnalysis (Roslyn)
instead.

The refactorings in NRefactory have been ported to Roslyn:
    https://github.com/icsharpcode/RefactoringEssentials/

------------------------------------------------------------------------------

Overview of the NRefactory library:

Introductory documentation:
	 http://www.codeproject.com/Articles/408663/Using-NRefactory-for-analyzing-Csharp-code

How to download:
	- Binaries are provided as a NuGet package (http://nuget.org/packages/ICSharpCode.NRefactory)
	- Sourcecode is available on GitHub (https://github.com/icsharpcode/NRefactory)

How to compile:
	1. Get Mono.Cecil 0.9.6
		Get Cecil from https://github.com/jbevain/cecil ('git clone git://github.com/jbevain/cecil.git')
		or download Cecil from https://github.com/jbevain/cecil/ and unzip it into a directory named "cecil"
		next to the directory containing NRefactory.
	2. If you need the IKVM binding get it from https://github.com/mono/ikvm-fork and put it next to the NRefactory directory
		like Mono.Cecil - name it "ikvm".
	3. Open NRefactory.sln in your favorite .NET IDE and compile.

Features:
	- C# Parser
	- Abstract Syntax Tree with pattern-matching support
	- Semantic Analysis for C# (supports C# 5.0)
	- Code Completion for C#
	- Pretty Printer for C#
	- Lots of C# refactorings
	
Non-Features:
    - C# 6 is not supported.
	- VB support is not implemented.
	- NRefactory cannot generate IL code -- it's a compiler frontend, not a full compiler

Dependencies:
	.NET 4.0
	Mono.Cecil 0.9.6
	NRefactory contains a modified copy of mcs (Mono's C# compiler) for the C# parser.


Namespace overview:

ICSharpCode.NRefactory assembly
	ICSharpCode.NRefactory.Editor:
		Interfaces that abstract from the text editor control used.
		Maybe future AvalonEdit versions will directly implement these interfaces, but you could also write adapters for other editors.
	
	ICSharpCode.NRefactory.TypeSystem:
		Contains a language-independent representation of the .NET type system.
		The type system is divided into two portions: unresolved and resolved type systems.
	
	ICSharpCode.NRefactory.TypeSystem.Implementation:
		Contains default implementations for the type system interfaces.
	
	ICSharpCode.NRefactory.Semantics:
		Contains classes (ResolveResults) used to represent the semantics of a language element.
		ResolveResults can have child results, thus forming semantic trees.
	
	ICSharpCode.NRefactory.Documentation:
		Classes for working with .xml documentation files.
		See "doc/XML Documentation.html" for details.
	
	ICSharpCode.NRefactory.PatternMatching:
		Provides classes for pattern matching over the C# and VB ASTs.
		See "doc/Pattern Matching.html" for details.
	
	ICSharpCode.NRefactory.Util:
		Various helper classes.


ICSharpCode.NRefactory.CSharp assembly
	ICSharpCode.NRefactory.CSharp:
		Abstract Syntax Tree for C#
	
	ICSharpCode.NRefactory.CSharp.Completion:
		Code completion (IntelliSense) for C#
	
	ICSharpCode.NRefactory.CSharp.Resolver:
		Semantic analysis for C# (resolving the meaning of expressions)
	
	ICSharpCode.NRefactory.CSharp.Analysis:
		Semantic analysis for C# (additional analysis functionality)
	
	ICSharpCode.NRefactory.CSharp.TypeSystem:
		Contains type system implementations specific to C#.
	
	ICSharpCode.NRefactory.CSharp.Refactoring:
		Infrastructure for refactorings; and several built-in refactorings.

ICSharpCode.NRefactory.VB assembly
	ICSharpCode.NRefactory.VB:
		Abstract Syntax Tree for VB

ICSharpCode.NRefactory.Xml assembly
	ICSharpCode.NRefactory.Xml:
		Error-tolerant XML parser. Supports incremental parsing.
		When tags don't match correctly, the parser uses a heuristic to guess the parse tree.
		The heuristic tries to minimize the edit distance from the erroneous document to
		the fixed document, and it also considers the indentation.



Null-Object pattern:
	The NRefactory library makes extensive use of the null object pattern.
	As a result, NullReferenceExceptions should be very rare when working with this library.
	In the type system, both ITypeReference and IType use SpecialType.UnknownType to represent
	unknown types.
	Unless the XML documentation says otherwise, no method or property returning a ITypeReference
	or IType will return null.
	
	Note that the null object pattern is not used for ITypeDefinition:
	IProjectContent.GetClass() returns null when a type is not found. Take care to abort your
	operation or substitute UnknownType instead of passing the null to code expecting an IType.
	
	The pattern also extends to the C# resolver, which always produces a ResolveResult, even in
	error cases. Use ResolveResult.IsError to detect resolver errors.
	Also note that many resolver errors still have a meaningful type attached, this allows code
	completion to work in the presence of minor semantic errors.
	
	The C# AST makes use of special null nodes when accessing the getter of an AST property and no
	child node with that role exists. Check the IsNull property to test whether a node is a null node.
	Null nodes are not considered to be part of the AST (e.g. they don't have a parent).

FAQ:
Q:  What is the difference between NRefactory and Roslyn?
	- NRefactory is ready and stable, Roslyn is only a CTP at this point of time.
	- NRefactory does not have VB support.
	- NRefactory cannot compile code to IL; it's not a full compiler, just a frontend.
	- NRefactory C# AST is mutable and supports pattern matching; Roslyn is immutable and does not have built-in pattern matching.

Q:	What is the difference between types and type definitions?

A:	Basically, a type (IType) is any type in the .NET type system:
		- an array (ArrayType)
		- a pointer (PointerType)
		- a managed reference (ByReferenceType)
		- a parameterized type (ParameterizedType, e.g. List<int>)
		- a type parameter (ITypeParameter, e.g. T)
		- or a type definition (ITypeDefiniton)
	
	Type definitions are only classes, structs, enums and delegates.
	Every type definition is a type, but not every type is a type definition.
	NRefactory's ITypeDefinition derives from IType, so you can directly use any type definition
	as a type.
	In the other direction, you could try to cast a type to ITypeDefinition, or you can call the
	GetDefinition() method. The GetDefinition() method will also return the underlying
	ITypeDefinition if given a parameterized type, so "List<int>".GetDefinition() is "List<T>".


Q:	What is the difference between types and type references?
	I've seen lots of duplicated classes (ArrayType vs. ArrayTypeReference, etc.)
	
A:	If you've previously used the .NET Reflection API, the concept of type references will be new
	to you.
	
	NRefactory has the concept of the "unresolved type system": every assembly/project is stored
	in unresolved form.
	It is possible to load some source code into a project which contains the type reference
	"int[]" without having to load mscorlib into NRefactory.
	So inside the entities stored for the project, the array type is only referenced using an
	ITypeReference.
	This interface has a single method:
	    interface ITypeReference {
	       IType Resolve(ITypeResolutionContext context);
	    }
	By calling the Resolve()-method, you will get back the actual ArrayType.
	
	Not only type references are split up this way; pretty much every class in the type system
	comes in unresolved and resolved forms.


Q:  What is a compilation (ICompilation)?

A:	A compilation serves as the root object of the resolved type system.
	It consists of a main assembly and multiple referenced assemblies,
	and may also contain additional information like compiler options.


Q:  What's in an ITypeResolveContext?

A:  An ITypeResolveContext is an environment for looking up namespaces and types.
	It consists of the current compilation, the current type definition,
	and language-specific implementations may add additional information (e.g. the list of usings).
	
	Generally, you cannot resolve a type reference without knowing what kind of context is expected.


Q:	How do I get the IType or ITypeReference for a primitive type such as string or int?
	
A:	To get an IType for a primitive type, use:
		compilation.FindType(KnownTypeCode.Int32)
	
	To get an ITypeReference, use:
		KnownTypeReference.Int32
	
	It is also possible to use a System.Type for retrieving a type:
	   compilation.FindType(typeof(int))
	or
	   typeof(int).ToTypeReference().


Q:	Is it thread-safe?

A:	This question is a bit difficult to answer.
	NRefactory was designed to be usable in a multi-threaded IDE.
	But of course, this does not mean that everything is thread-safe.
	
	First off, there's no hidden static state, so any two operations working on independent data
	can be executed concurrently.
	[Actually, sometimes static state is used for caches, but those uses are thread-safe.]
	TODO: what about the C# parser? gmcs is full of static state...
		-> this is being worked on; for the time being, NRefactory uses a global lock during parsing;
		   so it's thread-safe but slow.
	
	Some instance methods may use hidden instance state, so it is not safe to e.g. use an instance
	of the CSharp.Resolver.TypeInference class concurrently.
	Instead, you need to create an instance on every thread.
	
	The type system itself is thread-safe. Both the unresolved and the resolved type systems are
	immutable.
	
	When you add to an IProjectContent, the existing project content isn't modified,
	but a new project content is created instead. All implementations of the type system interfaces
	are either immutable or freezable.
	
	And on the resolved type system side, ICompilation is immutable as well.
	Internally, the resolved type system will resolve elements only on demand, but this is done
	in a thread-safe manner.


Q:	What format do the .ToString() methods use?

A:	They don't use any particular format. They're merely intended as a debugging aid.
	Currently .ToString() usually matches .ReflectionName, but that may change in the future.

nrefactory's People

Contributors

adamconnelly avatar alanmcgovern avatar alyman avatar arturek avatar awatertree avatar cipriankhlud avatar davidkarlas avatar dgrunwald avatar directhex avatar dsrbecky avatar erik-kallen avatar eusebiu avatar guoxiao avatar khellang avatar kzu avatar leoji avatar lightyang0 avatar lucasmeijer avatar luiscubal avatar matejmiklecic avatar mkrueger avatar mrward avatar nieve avatar pentp avatar riviti avatar sebastiaanlubbers avatar siegfriedpammer avatar therzok avatar uriel6575 avatar wuttke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nrefactory's Issues

Method group conversion

This test passes:

        [Test]
        public void Test() {
            string program = @"using System;
class TestClass {
    int F();
    public void M() {
        Action f;
        $f = F$;
    }
}";
            var rr = Resolve<OperatorResolveResult>(program).Operands[1];
            Assert.That(rr, Is.InstanceOf<ConversionResolveResult>());
        }

However, when combining the declaration and initialization of the delegate:

class TestClass {
    int F();
    public void M() {
        Action f = F;
    }
}

there seems to be no ConversionResolveResult. This might be by design, but I find it strange to get different results depending on whether I combine the declaration and assignment.

Bracket positioning

What is the policy for the positioning of brackets?

It is kinda obvious who is using what as in, VS defaults to

void Name()
{
}

and MonoDev to

void Name() {
}

This also counts for the spaces before/after keyword/parameter/function/bracket etc...

PreProcessorDirective generation

I have several #region directives in my code, between members of my class and they arent generated... Looking in ICsharpCode, the CSharpOutputVisitor.VisitTypeDeclaration visits only the Members of the class...

When an AST is written out, lines following // comments are unindented.

Regardless of the formatting options, NRefactory always outputs lines that follow single-line comments completely unindented. I believe this is not intended behavior.

INPUT:

// This is the input file.
using System;

namespace ReproForNRefactoryCommentOutputBug
{
    public sealed class FileToBeParsedAndWritten
    {
        public int SomeFunction()
        {
            // When NRefactory writes out the AST of this source file, 
            // the line following this comment will not be indented.
            string text = "This line won't be indented.";
            string moreText = "But this line will be formatted correctly.";

            // This happens after all comments.
            return 42;
        }
    }
}

EXPECTED: The output file's lines will be indented according to the CSharpFormattingOptions.

ACTUAL: Any lines in the output that follow a comment will be completely unindented.

// This is the actual output.
using System;
namespace ReproForNRefactoryCommentOutputBug
{
    public sealed class FileToBeParsedAndWritten
    {
        public int SomeFunction ()
        {
            // When NRefactory writes out the AST of this source file, 
// the line following this comment will not be indented.
string text = "This line won't be indented.";
            string moreText = "But this line will be formatted correctly.";
            // This happens after all comments.
return 42;
        }
    }
}

Inherited interface implementations in the type system.

Given this code (which compiles, to my surprise)

interface I {
    void SomeMethod(int i);
}

class B {
    public void SomeMethod(int i) {}
}

class D : B, I {
}

, is there any possibility in the type system to determine that B.SomeMethod implements I.SomeMethod?

Parsing comments

When the code that need to be parsed starts with a comment, all comments are added to the end of the type.
For example:

// Test
using System;
class Test
{
// Another Test
public void Main (string[] args)
{
Console.WriteLine ("Hello, World");
}
}

Becomes:

using System;
class Test
{
public void Main (string[] args)
{
Console.WriteLine ("Hello, World");
}
}
// Test
// Another Test

Christoph

Identity of lambda parameters

I don't know whether this actually qualifies as an issue, but it did cause me some headache so I thought I'd report it.

The scenario is that I was creating a Dictionary<IVariable, MyProject.VariableData> containing all local variables defined in a function. This works well, except when it comes to lambda parameters, as there seems to be a few versions of those, as illustrated by this test:

        [Test]
        public void LambdaParameterIdentity() {
            string code = @"using System;
class TestClass {
    void F() {
        Func<int, int> f = $i => i + 1;
    }
}";
            CompilationUnit cu = new CSharpParser().Parse(new StringReader(code.Replace("$", "")), "test.cs");
            var dollar = FindDollarSigns(code).Single();
            SetUp();

            CSharpParsedFile parsedFile = cu.ToTypeSystem();
            project = project.UpdateProjectContent(null, parsedFile);
            compilation = project.CreateCompilation();

            FindNodeVisitor fnv = new FindNodeVisitor(new TextLocation(dollar.Line, dollar.Column), new TextLocation(dollar.Line, dollar.Column + 10));
            cu.AcceptVisitor(fnv);
            var lambda = (LambdaExpression)fnv.ResultNode;

            fnv = new FindNodeVisitor(new TextLocation(dollar.Line, dollar.Column + 5), new TextLocation(dollar.Line, dollar.Column + 6));
            cu.AcceptVisitor(fnv);
            var innerI = (IdentifierExpression)fnv.ResultNode;

            CSharpAstResolver resolver = new CSharpAstResolver(compilation, cu, parsedFile);

            var first  = resolver.Resolve(lambda.Parameters.First());
            var second = ((LambdaResolveResult)resolver.Resolve(lambda)).Parameters[0];
            var inner  = resolver.Resolve(innerI);

            Assert.AreSame(first, second);
            Assert.AreSame(first, inner);
        }

As demonstrated, the identity of the LocalResolveResult representing "i" will be different whether you

  1. Resolve the lambda expression and use the Parameters collection of LambdaResolveResult,
  2. Resolve the parameter in the LambdaExpression AstNode, or
  3. Resolve the identifier "i" inside the lambda body.

Indexer accessors do not get correct parameters.

Given this class:

public class IndexerTest
{
    public string this[int index] { get { return "Test"; } set {} }
}

the following test will fail with the TypeSystemConvertVisitor (but not with the CecilLoader):

    [Test]
    public void IndexerParameters()
    {
        var testClass = GetTypeDefinition(typeof(IndexerTest));
        IProperty p = testClass.Properties.Single(pr => pr.IsIndexer);
        Assert.AreEqual("Item", p.Name);
        Assert.AreEqual(new[] { "index" }, p.Getter.Parameters.Select(x => x.Name).ToArray());
        Assert.AreEqual(new[] { "index", "value" }, p.Setter.Parameters.Select(x => x.Name).ToArray());
    }

Suggestion: Visitor pattern(s) for ResolveResults

As a user of the library, I would be helped by a visitor pattern implementation for ResolveResults. Currently I have to do

...
if (rr is ThisResolveResult)
    Visit((ThisResolveResult)rr);
else if (rr is MemberResolveResult)
    Visit((MemberResolveResult)rr);
...

which works, but having the visitor pattern like for AstNodes would make it easier.

Parser crash on multiline object initializers

Hi, parser crashes on this code:

        var x = new
        {
            storeId = "simpsonsStore",
            fields = new[] { "name", "email", "phone" },
            data = new
            {
                //items = new[]
                //{
                //    new { name= "Lisa",  email="[email protected]",  phone="555-111-1224"  },
                //    new { name= "Bart",  email="[email protected]",  phone="555-222-1234" },
                //    new { name= "Homer", email="[email protected]",  phone="555-222-1244"  },
                //    new { name= "Marge", email="[email protected]", phone="555-222-1254"  }
                //}
            },
            //proxy = new
            //{
            //    type = "memory",
            //    reader = new
            //    {
            //        type = "json",
            //        root = "items"
            //    }
            //}
        };

Exception:

System.NotSupportedException occurred
Message=Specified method is not supported.
Source=ICSharpCode.NRefactory
StackTrace:
at ICSharpCode.NRefactory.TypeSystem.AnonymousType.ToTypeReference() in C:\Projects\SharpJs\lib\NRefactory\ICSharpCode.NRefactory\TypeSystem\AnonymousType.cs:line 76
InnerException:

Parsing errors (private, protected, protected internal classes)

the following test fails with the message "File contains parsing errors". The error says- "compilation error- namespace elements cannot be explicitly private, protected or protected internal". Is this an expected behaviour?
Similar tests with "protected class TestClass" and "protected internal class TestClass" also fail with the same error.

[Test()]
public void ParsingError ()
{
string result = RunContextAction (new UseVarKeywordAction (),
@"private class TestClass
{
void Test ()
{
$TestClass aVar = this;
}
}");
Assert.AreEqual (@"class TestClass
{
void Test ()
{
var aVar = this;
}
}", result);
}

ResolveResult for object creation

It would be really helpful if resolving this:

var x = new MyClass { Property1 = 1, Property2 = { "Value1", "Value2" } }

would result in some kind of ObjectCreationResolveResult that contains information about the set properties and invoked collection add methods.

Nesting anonymous types throws a NotSupportedException

Failing test:

        [Test]
        public void NestingAnonymousTypesShouldWork()
        {
            string program = @"using System;
class TestClass {
    void F() {
        var o = $new { a = 0, b = 1, c = new { d = 2, e = 3, f = 4 } }$;
    }
}";

            var result = Resolve<InvocationResolveResult>(program);
            Assert.That(result.Type.GetProperties().Select(p => p.Name), Is.EquivalentTo(new[] { "a", "b", "c" }));
            Assert.That(result.Type.GetProperties().Single(p => p.Name == "c").ReturnType.GetProperties().Select(p => p.Name), Is.EquivalentTo(new[] { "d", "e", "f" }));
        }

Formatter issues with if/else statements and // comments

There are a handful of problems involving formatting of if else statements, primarily if the if section is wrapped in a block that causes parts of the else section to be incorporated into comments, usually causing compiler errors.

public class A : B
{
    public void Test()
    {
        // Comment before
        if (conditionA) {
            DoSomething();
        }
        // Comment before else ends up incorporating it
        else if (conditionB) {
            DoSomethingElse();
        }
    }
}

Results in:

public class A : B
{
    public void Test ()
    {
        // Comment before
        if (conditionA) {
            DoSomething ();
        }
        // Comment before else ends up incorporating it else if (conditionB) {
            DoSomethingElse ();
        }
    }
}

When swapping the "else if" with just an "if" the following exception is thrown:

System.InvalidOperationException : Detected overlapping changes [TextReplaceAction: Offset=220, RemovalLength=1, >NewText=
]/[TextReplaceAction: Offset=220, RemovalLength=1, NewText=
]

Suggestion (perhaps): Resolve event accessors differently

Currently, the expression MyEvent += MyHandler is resolved to a compound AddAssign. This works, but it is a little unintuitive since the semantics is not an addition at all, but it's just syntactic sugar for a method invocation. I guess this also means that find references won't work for event add accessor

Failing test:

        [Test]
        public void FindAddEventAccessor()
        {
            Init(@"using System;
class Test {
 public event EventHandler MyEvent { add {} remove {} }
 static void T() {
  MyEvent += null;
 }
}");
            var test = compilation.MainAssembly.TopLevelTypeDefinitions.Single(t => t.Name == "Test");
            var addAccessor = test.Events.Single(m => m.Name == "MyEvent").AddAccessor;
            var actual = FindReferences(addAccessor).ToList();
            Assert.IsTrue(actual.Any(r => r.StartLocation.Line == 5));
        }

Tell whether an IMethod is a partial method without implementation

When running the type importer over this code:

class C { partial void M(); }

The resulting IType will contain the member void M(), as far as I can tell not with any indication that the method is a partial method without implementation. Some kind of indication of this fact (such as an IsPartialMethodWithoutImplementation property on IMethod) would be useful.

Parser crash on long verbatim strings

When parsing the test file written below, getting an exception during parsing:

Exception:
System.NotImplementedException occurred
Message=The method or operation is not implemented.
Source=ICSharpCode.NRefactory.CSharp
StackTrace:
at Mono.CSharp.SeekableStreamReader.ReadChars(Int32 fromPosition, Int32 toPosition) in C:\Projects\SharpJs\lib\NRefactory\ICSharpCode.NRefactory.CSharp\Parser\mcs\support.cs:line 258
InnerException:

Method:
public char[] ReadChars (int fromPosition, int toPosition)
{
char[] chars = new char[toPosition - fromPosition];
if (buffer_start <= fromPosition && toPosition <= buffer_start + buffer.Length) {
Array.Copy (buffer, fromPosition - buffer_start, chars, 0, chars.Length);
} else {
throw new NotImplementedException ();
}

        return chars;
    }

Info:
fromPosition =137
toPosition =7150
buffer_start = 4096
buffer_start <= fromPosition : FALSE - causes the exception

Test file to parse:


using System;

namespace test
{

public class ParserBufferBug
{
    static void foo()
    {
        var x = @"{

aliceblue: 'f0f8ff',
antiquewhite: 'faebd7',
aqua: '0ff',
aquamarine: '7fffd4',
azure: 'f0ffff',
beige: 'f5f5dc',
bisque: 'ffe4c4',
black: '000',
blanchedalmond: 'ffebcd',
blue: '00f',
blueviolet: '8a2be2',
brown: 'a52a2a',
burlywood: 'deb887',
burntsienna: 'ea7e5d',
cadetblue: '5f9ea0',
chartreuse: '7fff00',
chocolate: 'd2691e',
coral: 'ff7f50',
cornflowerblue: '6495ed',
cornsilk: 'fff8dc',
crimson: 'dc143c',
cyan: '0ff',
darkblue: '00008b',
darkcyan: '008b8b',
darkgoldenrod: 'b8860b',
darkgray: 'a9a9a9',
darkgreen: '006400',
darkgrey: 'a9a9a9',
darkkhaki: 'bdb76b',
darkmagenta: '8b008b',
darkolivegreen: '556b2f',
darkorange: 'ff8c00',
darkorchid: '9932cc',
darkred: '8b0000',
darksalmon: 'e9967a',
darkseagreen: '8fbc8f',
darkslateblue: '483d8b',
darkslategray: '2f4f4f',
darkslategrey: '2f4f4f',
darkturquoise: '00ced1',
darkviolet: '9400d3',
deeppink: 'ff1493',
deepskyblue: '00bfff',
dimgray: '696969',
dimgrey: '696969',
dodgerblue: '1e90ff',
firebrick: 'b22222',
floralwhite: 'fffaf0',
forestgreen: '228b22',
fuchsia: 'f0f',
gainsboro: 'dcdcdc',
ghostwhite: 'f8f8ff',
gold: 'ffd700',
goldenrod: 'daa520',
gray: '808080',
green: '008000',
greenyellow: 'adff2f',
grey: '808080',
honeydew: 'f0fff0',
hotpink: 'ff69b4',
indianred: 'cd5c5c',
indigo: '4b0082',
ivory: 'fffff0',
khaki: 'f0e68c',
lavender: 'e6e6fa',
lavenderblush: 'fff0f5',
lawngreen: '7cfc00',
lemonchiffon: 'fffacd',
lightblue: 'add8e6',
lightcoral: 'f08080',
lightcyan: 'e0ffff',
lightgoldenrodyellow: 'fafad2',
lightgray: 'd3d3d3',
lightgreen: '90ee90',
lightgrey: 'd3d3d3',
lightpink: 'ffb6c1',
lightsalmon: 'ffa07a',
lightseagreen: '20b2aa',
lightskyblue: '87cefa',
lightslategray: '789',
lightslategrey: '789',
lightsteelblue: 'b0c4de',
lightyellow: 'ffffe0',
lime: '0f0',
limegreen: '32cd32',
linen: 'faf0e6',
magenta: 'f0f',
maroon: '800000',
mediumaquamarine: '66cdaa',
mediumblue: '0000cd',
mediumorchid: 'ba55d3',
mediumpurple: '9370db',
mediumseagreen: '3cb371',
mediumslateblue: '7b68ee',
mediumspringgreen: '00fa9a',
mediumturquoise: '48d1cc',
mediumvioletred: 'c71585',
midnightblue: '191970',
mintcream: 'f5fffa',
mistyrose: 'ffe4e1',
moccasin: 'ffe4b5',
navajowhite: 'ffdead',
navy: '000080',
oldlace: 'fdf5e6',
olive: '808000',
olivedrab: '6b8e23',
orange: 'ffa500',
orangered: 'ff4500',
orchid: 'da70d6',
palegoldenrod: 'eee8aa',
palegreen: '98fb98',
paleturquoise: 'afeeee',
palevioletred: 'db7093',
papayawhip: 'ffefd5',
peachpuff: 'ffdab9',
peru: 'cd853f',
pink: 'ffc0cb',
plum: 'dda0dd',
powderblue: 'b0e0e6',
purple: '800080',
red: 'f00',
rosybrown: 'bc8f8f',
royalblue: '4169e1',
saddlebrown: '8b4513',
salmon: 'fa8072',
sandybrown: 'f4a460',
seagreen: '2e8b57',
seashell: 'fff5ee',
sienna: 'a0522d',
silver: 'c0c0c0',
skyblue: '87ceeb',
slateblue: '6a5acd',
slategray: '708090',
slategrey: '708090',
snow: 'fffafa',
springgreen: '00ff7f',
steelblue: '4682b4',
tan: 'd2b48c',
teal: '008080',
thistle: 'd8bfd8',
tomato: 'ff6347',
turquoise: '40e0d0',
violet: 'ee82ee',
wheat: 'f5deb3',
white: 'fff',
whitesmoke: 'f5f5f5',
yellow: 'ff0',
yellowgreen: '9acd32'
aliceblue: 'f0f8ff',
antiquewhite: 'faebd7',
aqua: '0ff',
aquamarine: '7fffd4',
azure: 'f0ffff',
beige: 'f5f5dc',
bisque: 'ffe4c4',
black: '000',
blanchedalmond: 'ffebcd',
blue: '00f',
blueviolet: '8a2be2',
brown: 'a52a2a',
burlywood: 'deb887',
burntsienna: 'ea7e5d',
cadetblue: '5f9ea0',
chartreuse: '7fff00',
chocolate: 'd2691e',
coral: 'ff7f50',
cornflowerblue: '6495ed',
cornsilk: 'fff8dc',
crimson: 'dc143c',
cyan: '0ff',
darkblue: '00008b',
darkcyan: '008b8b',
darkgoldenrod: 'b8860b',
darkgray: 'a9a9a9',
darkgreen: '006400',
darkgrey: 'a9a9a9',
darkkhaki: 'bdb76b',
darkmagenta: '8b008b',
darkolivegreen: '556b2f',
darkorange: 'ff8c00',
darkorchid: '9932cc',
darkred: '8b0000',
darksalmon: 'e9967a',
darkseagreen: '8fbc8f',
darkslateblue: '483d8b',
darkslategray: '2f4f4f',
darkslategrey: '2f4f4f',
darkturquoise: '00ced1',
darkviolet: '9400d3',
deeppink: 'ff1493',
deepskyblue: '00bfff',
dimgray: '696969',
dimgrey: '696969',
dodgerblue: '1e90ff',
firebrick: 'b22222',
floralwhite: 'fffaf0',
forestgreen: '228b22',
fuchsia: 'f0f',
gainsboro: 'dcdcdc',
ghostwhite: 'f8f8ff',
gold: 'ffd700',
goldenrod: 'daa520',
gray: '808080',
green: '008000',
greenyellow: 'adff2f',
grey: '808080',
honeydew: 'f0fff0',
hotpink: 'ff69b4',
indianred: 'cd5c5c',
indigo: '4b0082',
ivory: 'fffff0',
khaki: 'f0e68c',
lavender: 'e6e6fa',
lavenderblush: 'fff0f5',
lawngreen: '7cfc00',
lemonchiffon: 'fffacd',
lightblue: 'add8e6',
lightcoral: 'f08080',
lightcyan: 'e0ffff',
lightgoldenrodyellow: 'fafad2',
lightgray: 'd3d3d3',
lightgreen: '90ee90',
lightgrey: 'd3d3d3',
lightpink: 'ffb6c1',
lightsalmon: 'ffa07a',
lightseagreen: '20b2aa',
lightskyblue: '87cefa',
lightslategray: '789',
lightslategrey: '789',
lightsteelblue: 'b0c4de',
lightyellow: 'ffffe0',
lime: '0f0',
limegreen: '32cd32',
linen: 'faf0e6',
magenta: 'f0f',
maroon: '800000',
mediumaquamarine: '66cdaa',
mediumblue: '0000cd',
mediumorchid: 'ba55d3',
mediumpurple: '9370db',
mediumseagreen: '3cb371',
mediumslateblue: '7b68ee',
mediumspringgreen: '00fa9a',
mediumturquoise: '48d1cc',
mediumvioletred: 'c71585',
midnightblue: '191970',
mintcream: 'f5fffa',
mistyrose: 'ffe4e1',
moccasin: 'ffe4b5',
navajowhite: 'ffdead',
navy: '000080',
oldlace: 'fdf5e6',
olive: '808000',
olivedrab: '6b8e23',
orange: 'ffa500',
orangered: 'ff4500',
orchid: 'da70d6',
palegoldenrod: 'eee8aa',
palegreen: '98fb98',
paleturquoise: 'afeeee',
palevioletred: 'db7093',
papayawhip: 'ffefd5',
peachpuff: 'ffdab9',
peru: 'cd853f',
pink: 'ffc0cb',
plum: 'dda0dd',
powderblue: 'b0e0e6',
purple: '800080',
red: 'f00',
rosybrown: 'bc8f8f',
royalblue: '4169e1',
saddlebrown: '8b4513',
salmon: 'fa8072',
sandybrown: 'f4a460',
seagreen: '2e8b57',
seashell: 'fff5ee',
sienna: 'a0522d',
silver: 'c0c0c0',
skyblue: '87ceeb',
slateblue: '6a5acd',
slategray: '708090',
slategrey: '708090',
snow: 'fffafa',
springgreen: '00ff7f',
steelblue: '4682b4',
tan: 'd2b48c',
teal: '008080',
thistle: 'd8bfd8',
tomato: 'ff6347',
turquoise: '40e0d0',
violet: 'ee82ee',
wheat: 'f5deb3',
white: 'fff',
whitesmoke: 'f5f5f5',
yellow: 'ff0',
yellowgreen: '9acd32'
}";

    }


}

}

Method group conversion on generic methods

This test passes:

        [Test]
        public void GenericMethodGroups()
        {
            string program = @"using System;
class TestClass {
    void F<T>(T x) {}
    public void M() {
        System.Action<int> f;
        f = $F<int>$;
    }
}";
            var rr = Resolve<MethodGroupResolveResult>(program);
            Assert.That(rr.TypeArguments.Select(a => a.GetDefinition().Name).ToList(), Is.EqualTo(new[] { "Int32" }));
        }

but this one fails:

        [Test]
        public void GenericMethodGroups2()
        {
            string program = @"using System;
class TestClass {
    void F<T>(T x) {}
    public void M() {
        System.Action<int> f;
        f = $F$;
    }
}";
            var rr = Resolve<MethodGroupResolveResult>(program);
            Assert.That(rr.TypeArguments.Select(a => a.GetDefinition().Name).ToList(), Is.EqualTo(new[] { "Int32" }));
        }

The only difference is that the generic argument is explicitly specified in the first case, but not in the second one. This may or may not be by design, but if it is by design then it would be a major improvement if the member ConversionResolveResult.Conversion.Method would contain the specialized method in this case.

Inheriting nested types causes stack overflow

As this test shows:

    [Test]
    public void InheritingInnerClassShouldNotCauseStackOverflow() {
        string program = @"class Test : $Test.Base$, Test.ITest { public class Base {} interface ITest {} }";
        var result = Resolve(program);
    }

OperatorResolveResult.IsLiftedOperator

These tests fail:

        [Test]
        public void IsLiftedProperty()
        {
            string program = @"
class Test {
    static void Inc() {
        int? a = 0, b = 0;
        int? c = $a + b$;
    }
}";
            var irr = Resolve<OperatorResolveResult>(program);
            Assert.IsFalse(irr.IsError);
            Assert.IsTrue(irr.IsLiftedOperator);
        }

        [Test]
        public void IsLiftedProperty2()
        {
            string program = @"
class Test {
    static void Inc() {
        int? a = 0, b = 0;
        $b += a$;
    }
}";
            var irr = Resolve<OperatorResolveResult>(program);
            Assert.IsFalse(irr.IsError);
            Assert.IsTrue(irr.IsLiftedOperator);
        }

Can't access LambdaResolveResult.BodyExpression

Marked internal, can't find a different way to access the body of a lambda function. Am I missing something?
Currently, I'm hacking it using reflection, and all data looks ok.

Please help

Const IField returns IsStatic=false

IEntity.IsStatic documentation says that:

    /// <summary>
    /// Gets whether this entity is static.
    /// Returns true if either the 'static' or the 'const' modifier is set.
    /// </summary>

But IField that is a const, returns IsStatic=false, and IsConst = true

NullReferenceException when using FindReferencedEntities navigator

When using the FindReferencedEntities navigator, for some files a "NullReferenceException: Object reference not set to an instance of an object" occurs.

I have no experience in C# programming so please forgive the following code i wrote to reproduce the problem:

public class Reproduction {

    public static void Main(string[] args) {
        string filename = "./test.cs";

        CSharpParser parser = new CSharpParser();
        CompilationUnit compilationUnit = parser.Parse(new StreamReader(
            filename).ReadToEnd(), filename);

        CSharpParsedFile parsedFile = compilationUnit.ToTypeSystem();

        IProjectContent project = new CSharpProjectContent();
        ICompilation compilation;

        project = project.UpdateProjectContent(null, parsedFile);
        compilation = project.CreateCompilation();

        getReferencedEntities(compilationUnit, compilation, parsedFile);

    }

    public static void getReferencedEntities(CompilationUnit cunit, ICompilation compilation, CSharpParsedFile parsedFile) {
        var navigator = new FindReferencedEntities(delegate(AstNode node, IEntity entity){});
        CSharpAstResolver resolver = new CSharpAstResolver(parsedFile.GetResolver(
            compilation, cunit.StartLocation), cunit, parsedFile);
        resolver.ApplyNavigator(navigator);
    }

One file this is reproducible on can be found here: http://sharpmap.codeplex.com/SourceControl/changeset/view/96745#1376708

I include the stacktrace here, i hope it will help:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
at ICSharpCode.NRefactory.CSharp.Resolver.FindReferencedEntities.ProcessConversion (ICSharpCode.NRefactory.CSharp.Expression expression, ICSharpCode.NRefactory.Semantics.ResolveResult result, ICSharpCode.NRefactory.Semantics.Conversion conversion, IType targetType) [0x00000] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/FindReferencedEntities.cs:71
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ProcessConversion (ICSharpCode.NRefactory.CSharp.Expression expr, ICSharpCode.NRefactory.Semantics.ResolveResult rr, ICSharpCode.NRefactory.Semantics.Conversion conversion, IType targetType) [0x00083] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:338
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ProcessConversionResult (ICSharpCode.NRefactory.CSharp.Expression expr, ICSharpCode.NRefactory.Semantics.ConversionResolveResult rr) [0x00006] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:377
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ProcessConversionsInInvocation (ICSharpCode.NRefactory.CSharp.Expression target, IEnumerable1 arguments, ICSharpCode.NRefactory.CSharp.Resolver.CSharpInvocationResolveResult invocation) [0x000ab] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:409 at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ICSharpCode.NRefactory.CSharp.IAstVisitor<ICSharpCode.NRefactory.Semantics.ResolveResult>.VisitConstructorInitializer (ICSharpCode.NRefactory.CSharp.ConstructorInitializer constructorInitializer) [0x00060] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:3584 at ICSharpCode.NRefactory.CSharp.ConstructorInitializer.AcceptVisitor[ResolveResult] (IAstVisitor1 visitor) [0x00000] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/TypeMembers/ConstructorDeclaration.cs:163
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Resolve (ICSharpCode.NRefactory.CSharp.AstNode node) [0x00051] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:227
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Scan (ICSharpCode.NRefactory.CSharp.AstNode node) [0x0011a] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:199
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ScanChildren (ICSharpCode.NRefactory.CSharp.AstNode node) [0x0000c] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:277
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.VisitMethodMember (ICSharpCode.NRefactory.CSharp.EntityDeclaration member) [0x00024] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:752
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ICSharpCode.NRefactory.CSharp.IAstVisitor<ICSharpCode.NRefactory.Semantics.ResolveResult>.VisitConstructorDeclaration (ICSharpCode.NRefactory.CSharp.ConstructorDeclaration constructorDeclaration) [0x00000] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:775
at ICSharpCode.NRefactory.CSharp.ConstructorDeclaration.AcceptVisitor[ResolveResult](IAstVisitor1 visitor) [0x00000] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/TypeMembers/ConstructorDeclaration.cs:72 at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Resolve (ICSharpCode.NRefactory.CSharp.AstNode node) [0x00051] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:227 at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Scan (ICSharpCode.NRefactory.CSharp.AstNode node) [0x0011a] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:199 at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ScanChildren (ICSharpCode.NRefactory.CSharp.AstNode node) [0x0000c] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:277 at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.VisitTypeOrDelegate (ICSharpCode.NRefactory.CSharp.AstNode typeDeclaration, System.String name, Int32 typeParameterCount) [0x000d8] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:594 at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ICSharpCode.NRefactory.CSharp.IAstVisitor<ICSharpCode.NRefactory.Semantics.ResolveResult>.VisitTypeDeclaration (ICSharpCode.NRefactory.CSharp.TypeDeclaration typeDeclaration) [0x00000] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:608 at ICSharpCode.NRefactory.CSharp.TypeDeclaration.AcceptVisitor[ResolveResult](IAstVisitor1 visitor) [0x00000] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/TypeDeclaration.cs:94
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Resolve (ICSharpCode.NRefactory.CSharp.AstNode node) [0x00051] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:227
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Scan (ICSharpCode.NRefactory.CSharp.AstNode node) [0x0011a] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:199
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ScanChildren (ICSharpCode.NRefactory.CSharp.AstNode node) [0x0000c] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:277
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ICSharpCode.NRefactory.CSharp.IAstVisitor<ICSharpCode.NRefactory.Semantics.ResolveResult>.VisitNamespaceDeclaration (ICSharpCode.NRefactory.CSharp.NamespaceDeclaration namespaceDeclaration) [0x00044] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:560
at ICSharpCode.NRefactory.CSharp.NamespaceDeclaration.AcceptVisitor[ResolveResult](IAstVisitor1 visitor) [0x00000] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/NamespaceDeclaration.cs:123 at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Resolve (ICSharpCode.NRefactory.CSharp.AstNode node) [0x00051] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:227 at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Scan (ICSharpCode.NRefactory.CSharp.AstNode node) [0x0011a] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:199 at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ScanChildren (ICSharpCode.NRefactory.CSharp.AstNode node) [0x0000c] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:277 at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ICSharpCode.NRefactory.CSharp.IAstVisitor<ICSharpCode.NRefactory.Semantics.ResolveResult>.VisitCompilationUnit (ICSharpCode.NRefactory.CSharp.CompilationUnit unit) [0x0003e] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:546 at ICSharpCode.NRefactory.CSharp.CompilationUnit.AcceptVisitor[ResolveResult](IAstVisitor1 visitor) [0x00000] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/CompilationUnit.cs:105
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Resolve (ICSharpCode.NRefactory.CSharp.AstNode node) [0x00051] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:227
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Scan (ICSharpCode.NRefactory.CSharp.AstNode node) [0x0011a] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:199
at ICSharpCode.NRefactory.CSharp.Resolver.CSharpAstResolver.ApplyNavigator (IResolveVisitorNavigator navigator, CancellationToken cancellationToken) [0x00057] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/CSharpAstResolver.cs:132
at BugTest.Reproduction.getReferencedEntities (ICSharpCode.NRefactory.CSharp.CompilationUnit cunit, ICompilation compilation, ICSharpCode.NRefactory.CSharp.TypeSystem.CSharpParsedFile parsedFile) [0x00038] in /home/polygox/Projects/BugTest/BugTest/BugTest.cs:41
at BugTest.Reproduction.Main (System.String[] args) [0x00041] in /home/polygox/Projects/BugTest/BugTest/BugTest.cs:33
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
at ICSharpCode.NRefactory.CSharp.Resolver.FindReferencedEntities.ProcessConversion (ICSharpCode.NRefactory.CSharp.Expression expression, ICSharpCode.NRefactory.Semantics.ResolveResult result, ICSharpCode.NRefactory.Semantics.Conversion conversion, IType targetType) [0x00000] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/FindReferencedEntities.cs:71
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ProcessConversion (ICSharpCode.NRefactory.CSharp.Expression expr, ICSharpCode.NRefactory.Semantics.ResolveResult rr, ICSharpCode.NRefactory.Semantics.Conversion conversion, IType targetType) [0x00083] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:338
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ProcessConversionResult (ICSharpCode.NRefactory.CSharp.Expression expr, ICSharpCode.NRefactory.Semantics.ConversionResolveResult rr) [0x00006] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:377
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ProcessConversionsInInvocation (ICSharpCode.NRefactory.CSharp.Expression target, IEnumerable1 arguments, ICSharpCode.NRefactory.CSharp.Resolver.CSharpInvocationResolveResult invocation) [0x000ab] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:409 at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ICSharpCode.NRefactory.CSharp.IAstVisitor<ICSharpCode.NRefactory.Semantics.ResolveResult>.VisitConstructorInitializer (ICSharpCode.NRefactory.CSharp.ConstructorInitializer constructorInitializer) [0x00060] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:3584 at ICSharpCode.NRefactory.CSharp.ConstructorInitializer.AcceptVisitor[ResolveResult] (IAstVisitor1 visitor) [0x00000] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/TypeMembers/ConstructorDeclaration.cs:163
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Resolve (ICSharpCode.NRefactory.CSharp.AstNode node) [0x00051] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:227
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Scan (ICSharpCode.NRefactory.CSharp.AstNode node) [0x0011a] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:199
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ScanChildren (ICSharpCode.NRefactory.CSharp.AstNode node) [0x0000c] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:277
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.VisitMethodMember (ICSharpCode.NRefactory.CSharp.EntityDeclaration member) [0x00024] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:752
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ICSharpCode.NRefactory.CSharp.IAstVisitor<ICSharpCode.NRefactory.Semantics.ResolveResult>.VisitConstructorDeclaration (ICSharpCode.NRefactory.CSharp.ConstructorDeclaration constructorDeclaration) [0x00000] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:775
at ICSharpCode.NRefactory.CSharp.ConstructorDeclaration.AcceptVisitor[ResolveResult](IAstVisitor1 visitor) [0x00000] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/TypeMembers/ConstructorDeclaration.cs:72 at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Resolve (ICSharpCode.NRefactory.CSharp.AstNode node) [0x00051] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:227 at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Scan (ICSharpCode.NRefactory.CSharp.AstNode node) [0x0011a] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:199 at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ScanChildren (ICSharpCode.NRefactory.CSharp.AstNode node) [0x0000c] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:277 at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.VisitTypeOrDelegate (ICSharpCode.NRefactory.CSharp.AstNode typeDeclaration, System.String name, Int32 typeParameterCount) [0x000d8] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:594 at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ICSharpCode.NRefactory.CSharp.IAstVisitor<ICSharpCode.NRefactory.Semantics.ResolveResult>.VisitTypeDeclaration (ICSharpCode.NRefactory.CSharp.TypeDeclaration typeDeclaration) [0x00000] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:608 at ICSharpCode.NRefactory.CSharp.TypeDeclaration.AcceptVisitor[ResolveResult](IAstVisitor1 visitor) [0x00000] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/TypeDeclaration.cs:94
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Resolve (ICSharpCode.NRefactory.CSharp.AstNode node) [0x00051] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:227
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Scan (ICSharpCode.NRefactory.CSharp.AstNode node) [0x0011a] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:199
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ScanChildren (ICSharpCode.NRefactory.CSharp.AstNode node) [0x0000c] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:277
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ICSharpCode.NRefactory.CSharp.IAstVisitor<ICSharpCode.NRefactory.Semantics.ResolveResult>.VisitNamespaceDeclaration (ICSharpCode.NRefactory.CSharp.NamespaceDeclaration namespaceDeclaration) [0x00044] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:560
at ICSharpCode.NRefactory.CSharp.NamespaceDeclaration.AcceptVisitor[ResolveResult](IAstVisitor1 visitor) [0x00000] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/NamespaceDeclaration.cs:123 at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Resolve (ICSharpCode.NRefactory.CSharp.AstNode node) [0x00051] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:227 at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Scan (ICSharpCode.NRefactory.CSharp.AstNode node) [0x0011a] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:199 at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ScanChildren (ICSharpCode.NRefactory.CSharp.AstNode node) [0x0000c] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:277 at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ICSharpCode.NRefactory.CSharp.IAstVisitor<ICSharpCode.NRefactory.Semantics.ResolveResult>.VisitCompilationUnit (ICSharpCode.NRefactory.CSharp.CompilationUnit unit) [0x0003e] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:546 at ICSharpCode.NRefactory.CSharp.CompilationUnit.AcceptVisitor[ResolveResult](IAstVisitor1 visitor) [0x00000] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/CompilationUnit.cs:105
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Resolve (ICSharpCode.NRefactory.CSharp.AstNode node) [0x00051] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:227
at ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Scan (ICSharpCode.NRefactory.CSharp.AstNode node) [0x0011a] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs:199
at ICSharpCode.NRefactory.CSharp.Resolver.CSharpAstResolver.ApplyNavigator (IResolveVisitorNavigator navigator, CancellationToken cancellationToken) [0x00057] in /home/polygox/work/nref5/NRefactory/ICSharpCode.NRefactory.CSharp/Resolver/CSharpAstResolver.cs:132
at BugTest.Reproduction.getReferencedEntities (ICSharpCode.NRefactory.CSharp.CompilationUnit cunit, ICompilation compilation, ICSharpCode.NRefactory.CSharp.TypeSystem.CSharpParsedFile parsedFile) [0x00038] in /home/polygox/Projects/BugTest/BugTest/BugTest.cs:41
at BugTest.Reproduction.Main (System.String[] args) [0x00041] in /home/polygox/Projects/BugTest/BugTest/BugTest.cs:33
Die Anwendung wurde durch ein Signal beendet: SIGHUP

Static methods are reported as having "this" as the target

Failing test:

        [Test]
        public void Test() {
            string program = @"using System;
class TestClass {
    static void F() {}
    public void M() {
        $F()$;
    }
}";
            var rr = Resolve<CSharpInvocationResolveResult>(program);
            Assert.That(rr.TargetResult, Is.Not.InstanceOf<ThisResolveResult>());
        }

Implicit type parameter conversion

Failing test:

        [Test]
        public void ImplicitTypeParameterConversion()
        {
            string program = @"using System;
class Test {
    public void M<T, U>() where T : U {
    T t = default(T);
    U u = $(U)t$;
}";
            var c = GetConversion(program);
            Assert.IsTrue(c.IsValid);   // This part passes

            program = @"using System;
class Test {
    public void M<T, U>() where T : U {
    T t = default(T);
    U u = $t$;
}";
            c = GetConversion(program);
            Assert.IsTrue(c.IsValid); // This part fails
        }

Also, the conversion reported in the (passing) first part of the test is an identity conversion, which is not necessarily true.

NullReferenceException occurs in ICSharpCpde.NRefactory.CSharp.Resolver.MethodGroupResolveResult.PerformOverloadResolution

Sometimes, when launching ResolveVisitor.Scan(CompilationUnit) a NullReferenceException occurs in PerformOverloadResolution method. It is caused by the fact that 'resolver' variable in MethodGroupResolveResult is null and that is why in line:

var extensionMethods = this.GetExtensionMethods(); //line 173

we've got null. In next line we try to check condition:

if(extensionMethods.Count > 0) //line 175

which results in throwing an exception. I tried debugging but I didn't found out what cause it. I scan hundreds of .cs files and only in a few of them this exception is thrown.
Underneath I enclose StackTrace:

In ICSharpCode.NRefactory.CSharp.Resolver.MethodGroupResolveResult.PerformOverloadResolution(ITypeResolveContext context, ResolveResult[] arguments, String[] argumentNames, Boolean allowExtensionMethods, Boolean allowExpandingParams) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\MethodGroupResolveResult.cs:line 175
In ICSharpCode.NRefactory.CSharp.Resolver.CSharpResolver.ResolveInvocation(ResolveResult target, ResolveResult[] arguments, String[] argumentNames) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\CSharpResolver.cs:line 2242
In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ResolveInvocationOnGivenTarget(ResolveResult target, InvocationExpression invocationExpression) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line1415
In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.VisitInvocationExpression(InvocationExpression invocationExpression, Object data) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 1403
In ICSharpCode.NRefactory.CSharp.InvocationExpression.AcceptVisitor[T,S](IAstVisitor2 visitor, T data) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Ast\Expressions\InvocationExpression.cs:line 55 In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Resolve(AstNode node) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 196 In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Scan(AstNode node) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 176 In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ScanChildren(AstNode node) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 232 In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.VisitExpressionStatement(ExpressionStatement expressionStatement, Object data) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 2180 In ICSharpCode.NRefactory.CSharp.ExpressionStatement.AcceptVisitor[T,S](IAstVisitor2 visitor, T data) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Ast\Statements\ExpressionStatement.cs:line 45
In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Scan(AstNode node) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 172
In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ScanChildren(AstNode node) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 232
In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.VisitBlockStatement(BlockStatement blockStatement, Object data) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 2001
In ICSharpCode.NRefactory.CSharp.BlockStatement.AcceptVisitor[T,S](IAstVisitor2 visitor, T data) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Ast\Statements\BlockStatement.cs:line 110 In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Scan(AstNode node) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 172 In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ScanChildren(AstNode node) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 232 In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.VisitMethodMember(AttributedNode member) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 529 In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.VisitMethodDeclaration(MethodDeclaration methodDeclaration, Object data) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 542 In ICSharpCode.NRefactory.CSharp.MethodDeclaration.AcceptVisitor[T,S](IAstVisitor2 visitor, T data) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Ast\TypeMembers\MethodDeclaration.cs:line 68
In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Scan(AstNode node) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 172
In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.VisitTypeOrDelegate(AstNode typeDeclaration) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 408
In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.VisitTypeDeclaration(TypeDeclaration typeDeclaration, Object data) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 420
In ICSharpCode.NRefactory.CSharp.TypeDeclaration.AcceptVisitor[T,S](IAstVisitor2 visitor, T data) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Ast\GeneralScope\TypeDeclaration.cs:line 105 In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Scan(AstNode node) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 172 In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ScanChildren(AstNode node) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 232 In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, Object data) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 372 In ICSharpCode.NRefactory.CSharp.NamespaceDeclaration.AcceptVisitor[T,S](IAstVisitor2 visitor, T data) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Ast\GeneralScope\NamespaceDeclaration.cs:line 114
In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Scan(AstNode node) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 172
In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.ScanChildren(AstNode node) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 232
In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.VisitCompilationUnit(CompilationUnit unit, Object data) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 358
In ICSharpCode.NRefactory.CSharp.CompilationUnit.AcceptVisitor[T,S](IAstVisitor`2 visitor, T data) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Ast\CompilationUnit.cs:line 88
In ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor.Scan(AstNode node) in C:\Users\dfa\Desktop\dlls\NewNRefactory\ICSharpCode.NRefactory\CSharp\Resolver\ResolveVisitor.cs:line 172
In Kruk.Tracker.CSharp.SourceAnalyser.SourceAnalyser.Refers() in C:\Users\dfa\svn\TestingProject\trunk\Tracker\SourceAnalyser\SourceAnalyser.cs:line 213

If necessary I can provide more information or support to fix the issue.

Error parsing enums, w/ and w/o explicit initializers

The parser errors out on enums with member declarations. Having explicit initializers makes no difference.

enum SimpleEnumTest
{
    field1,
    field2,
    field3
}

enum SimpleEnumTest2
{
    field1 = 0,
    field2 = 1,
    field3 = 2
}

Demo & Resolver

Hi!

I put this text to demo, then i selected node:

  • Member NamespaceDelcaration (Name=PC)
  • Member Type Declaration (ClassType=Class Name="A"...)
  • Member MemberDeclaration (...Name="M"...)
  • MemberType(...MemberName="MyClass")

then click "Resolve" then i got "UnknownMemberResolveResult ?.MyClass

namespace PC
{
    // Define an alias for the nested namespace.
    using Project = PC.MyCompany.Project;
    class A
    {
        Project.MyClass M()
        {
            // Use the alias
            Project.MyClass mc = new Project.MyClass();
            return mc;
        }
    }
    namespace MyCompany
    {
        namespace Project
        {
            public class MyClass { }
        }
    }
}

OR you can add this test:

[Test]
        public void UsingTest()
        {
            string program = @"namespace PC
{
    // Define an alias for the nested namespace.
    using Project = PC.MyCompany.Project;
    class A
    {
        Project.MyClass M()
        {
            // Use the alias
            $Project.MyClass$ mc = new Project.MyClass();
            return mc;
        }
    }
    namespace MyCompany
    {
        namespace Project
        {
            public class MyClass { }
        }
    }
}
";
            var mrr = Resolve(program);
            Assert.AreEqual("PC.MyCompany.Project.MyClass", mrr.Type.FullName);
        }

Resolve error in arrays in assembly attribute value

Code sample:
public partial class MyAttribute : Attribute
{
public string[] Sources { get; set; }
}

[assembly: My(Sources = new string[]{"a", "b", "c"})]

When resolving the assembly attribute usage, array is resolved with error, and is resolved to string[][](array of array of strings), instead of string[](array of strings)

Preprocessor blocks using #elif results in missing nodes.

Single pairs of #if/#endif work fine generating InactiveCode Comments for excluded code, "Take" property on PreProcessorDirective is correct.

class Foo
{
#if false
    int nop;
#endif
}

AST is fine for the above using either true or false, however once #elif is introduced there are problems:

class Foo
{
#if AAA
    int nop1;
#elif BBB
    int nop2;
#endif
}

Changing AAA & BBB in the above for true/false gives the following results:

  1. false, false
    nop1: OK; PreProcessorDirective (Take == false), InactiveCode Comment for "int nop1"
    nop2: "Take" Wrong & Missing Node; PreProcessorDirective (Take == true, should be false), no node for nop2 at all
  2. true, false
    nop1: OK, PreProcessorDirective (Take == true), TypeMember for "int nop1"
    nop2: "Take" Wrong, PreProcessorDirective (Take == true, should be false), InactiveCode Comment for "int nop2"
  3. false, true
    nop1: OK, PreProcessorDirective (Take == false), InactiveCode Comment for "int nop1"
    nop2: OK, PreProcessorDirective (Take == true), TypeMember for "int nop2"
  4. true, true (same as 2)
    nop1: OK, PreProcessorDirective (Take == true), TypeMember for "int nop1"
    nop2: "Take" Wrong, PreProcessorDirective (Take == true, should be false), InactiveCode Comment for "int nop2"

The problem seems to be in Mono.CSharp.Tokenizer.ParsePreprocessingDirective. When stepping through all of the above seem to be processed correctly. However, the "Take" property is initialized as true and then set to false (via SkipIf) if the #if eval(expression) is false. SkipIf is never called for #elif though so "Take" is never set correctly.

Determining if a ThisResolveResult represents this. or base.

It would help me a lot to have a way to determine if a ThisResolveResult represents a "this." or a "base."

This could either be a property bool IsBaseReference, or a separate IType OriginalType property.

Another possibility to achieve what I need could be to add a new bool IsVirtualCall to InvocationResolveResult, which would be false if calling the base implementation.

CSharpProjectContent bug (and resolution)

Hello,

first of all, I would like to thank you for this great piece of code.

Today I have found a weird bug in NRefactory that caused me some days of headaches, with TypeDeclarations that seemed to have their members defined twice. The issue is caused by the protected constructor of the CSharpProjectContent class, that does not set the right comparer for the parsedFiles member; would you be so kind as to add the Platform.FileNameComparer comparer where it should, please? It is a single line fix. I am new to GitHub (and Git, in general), otherwise I would have tried by myself.

Thank you.

Efran

Parser does not handle inheritance

Try the following sample in the demo app. The generated tree does not contain any nodes related to inheritance. Parsing and Generating the sample loses a great deal of information:

interface IInheritanceTest
{
    void TestMethod();
}


class InheritanceTestParent : IInheritanceTest
{
    public InheritanceTestParent(int i)
    {

    }

    public void TestMethod()
    {

    }
}

class InheritanceTestChild : InheritanceTestParent
{
    public InheritanceTestChild(int i)
        : base(i)
    {
        TestMethod();
    }
}

Staticity of accessors

Given this type:

    public class ClassWithStaticAndNonStaticMembers
    {
        public static event System.EventHandler Event1 { add {} remove{} }
        public event System.EventHandler Event2 { add {} remove{} }
        public static event System.EventHandler Event3;
        public event System.EventHandler Event4;

        public static int Prop1 { get { return 0; } set {} }
        public int Prop2 { get { return 0; } set {} }
        public static int Prop3 { get; set; }
        public int Prop4 { get; set; }
    }

The following test will fail:

        [Test]
        public void StaticityOfAccessors() {
            ITypeDefinition type = GetTypeDefinition(typeof(ClassWithStaticAndNonStaticMembers));
            var evt1 = type.Events.Single(e => e.Name == "Event1");
            Assert.That(evt1.IsStatic, Is.True);
            Assert.That(evt1.AddAccessor.IsStatic, Is.True);
            Assert.That(evt1.RemoveAccessor.IsStatic, Is.True);

            var evt2 = type.Events.Single(e => e.Name == "Event2");
            Assert.That(evt2.IsStatic, Is.False);
            Assert.That(evt2.AddAccessor.IsStatic, Is.False);
            Assert.That(evt2.RemoveAccessor.IsStatic, Is.False);

            var evt3 = type.Events.Single(e => e.Name == "Event3");
            Assert.That(evt3.IsStatic, Is.True);
            Assert.That(evt3.AddAccessor.IsStatic, Is.True);
            Assert.That(evt3.RemoveAccessor.IsStatic, Is.True);

            var evt4 = type.Events.Single(e => e.Name == "Event4");
            Assert.That(evt4.IsStatic, Is.False);
            Assert.That(evt4.AddAccessor.IsStatic, Is.False);
            Assert.That(evt4.RemoveAccessor.IsStatic, Is.False);

            var prop1 = type.Properties.Single(e => e.Name == "Prop1");
            Assert.That(prop1.IsStatic, Is.True);
            Assert.That(prop1.Getter.IsStatic, Is.True);
            Assert.That(prop1.Setter.IsStatic, Is.True);

            var prop2 = type.Properties.Single(e => e.Name == "Prop2");
            Assert.That(prop2.IsStatic, Is.False);
            Assert.That(prop2.Getter.IsStatic, Is.False);
            Assert.That(prop2.Setter.IsStatic, Is.False);

            var prop3 = type.Properties.Single(e => e.Name == "Prop3");
            Assert.That(prop3.IsStatic, Is.True);
            Assert.That(prop3.Getter.IsStatic, Is.True);
            Assert.That(prop3.Setter.IsStatic, Is.True);

            var prop4 = type.Properties.Single(e => e.Name == "Prop4");
            Assert.That(prop4.IsStatic, Is.False);
            Assert.That(prop4.Getter.IsStatic, Is.False);
            Assert.That(prop4.Setter.IsStatic, Is.False);
        }

Parser Regression in ObjectCreate initialization

When initializing a list as in the code below:

class Foo : Bar {
    public void Bar() {
        var a = new List<String> { "one", "two", "three" };
    }
}

The parser creates extra braces in the initialization (I was able to isolate it to the parser) so the resulting code would have extra braces (modified formatting since extra AST nodes are the problem):

class Foo : Bar  {
    public void Bar ()  {
        var a = new List<String> { { "one" }, { "two" }, { "three" } };
    }
}

I created a bisect script and boo program and was able to isolate the initial broken changeset to d6d1f08

To recreate, I ran git bisect as follows and placed the two scripts on the parent directory to NRefactory:

git bisect start HEAD 3eee3
git bisect run ../bisector.sh
ObjectCreateParserRegression.boo
import System.IO
import ICSharpCode.NRefactory.CSharp

code = """
class Foo : Bar {
    public void Bar() {
        var a = new List<String> { "one", "two", "three" };
    }
}
"""
parser = CSharpParser()
compilationUnit = parser.Parse(StringReader(code), "foo.cs", 0)
writer = StringWriter()
outVisitor = CSharpOutputVisitor(writer, CSharpFormattingOptions())
compilationUnit.AcceptVisitor(outVisitor)
print writer.ToString()
bisector.sh
WORKING_DIR=$PWD
echo $WORKING_DIR
BASE_DIR=NRefactory/ICSharpCode.NRefactory
cd ${BASE_DIR}.CSharp
echo "Cleaning"
xbuild /t:Clean > /dev/null 2>&1
echo "Building"
xbuild > /dev/null 2>&1
echo "Compile Script"
cd $WORKING_DIR
booc -lib:${BASE_DIR}/bin/Debug/ ObjectCreateParserRegression.boo > /dev/null 2>&1
mv ObjectCreateParserRegression.exe* $BASE_DIR/bin/Debug
echo "Run Script"
cd ${BASE_DIR}/bin/Debug
OPEN_BRACE_COUNT=$(mono ./ObjectCreateParserRegression.exe | grep '{' | wc -l)
cd $WORKING_DIR
# Correct result should have three open braces
if [ $OPEN_BRACE_COUNT -ne "3" ]; then
    echo "FAIL"$OPEN_BRACE_COUNT
    exit 1
fi
echo "SUCCESS"$OPEN_BRACE_COUNT

Exception when parsing System.EnterpriseServices assembly

Mono.Cecil.dll!Mono.Cecil.MetadataReader.GetModuleFileName(string name = "System.EnterpriseServices.Wrapper.dll") Line 569 + 0x19 bytes C#
Mono.Cecil.dll!Mono.Cecil.MetadataReader.ReadModules() Line 557 + 0x12 bytes C#
Mono.Cecil.dll!Mono.Cecil.AssemblyDefinition.get_Modules.AnonymousMethod__1(Mono.Cecil.AssemblyDefinition _ = {Mono.Cecil.AssemblyDefinition}, Mono.Cecil.MetadataReader reader = {Mono.Cecil.MetadataReader}) Line 65 + 0xb bytes C#
Mono.Cecil.dll!Mono.Cecil.ModuleDefinition.Read<Mono.Cecil.AssemblyDefinition,Mono.Collections.Generic.Collection<Mono.Cecil.ModuleDefinition>>(Mono.Cecil.AssemblyDefinition item = {Mono.Cecil.AssemblyDefinition}, System.Func<Mono.Cecil.AssemblyDefinition,Mono.Cecil.MetadataReader,Mono.Collections.Generic.Collection<Mono.Cecil.ModuleDefinition>> read = {Method = Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation.}) Line 818 + 0x14 bytes C#
Mono.Cecil.dll!Mono.Cecil.AssemblyDefinition.Modules.get() Line 65 + 0x8a bytes C#
ICSharpCode.NRefactory.dll!ICSharpCode.NRefactory.TypeSystem.CecilLoader.LoadAssembly(Mono.Cecil.AssemblyDefinition assemblyDefinition = {Mono.Cecil.AssemblyDefinition}) Line 123 + 0xc bytes C#
ICSharpCode.NRefactory.dll!ICSharpCode.NRefactory.TypeSystem.CecilLoader.LoadAssemblyFile(string fileName = "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.EnterpriseServices.dll") Line 198 + 0xb bytes C#
SharpJs.exe!SharpKit.SkProject.LoadAssemblies.AnonymousMethod__0(int i = 10) Line 29 + 0x35 bytes C#

Target of extension method invocation

        [Test]
        public void FirstParameterToExtensionMethod()
        {
            string program = @"
namespace N {
    public class X {}
    public static class Ex {
        public static void F(this X x, int y, int z) {}
    }
    class C {
        public void M() {
            X a = null;
            int b = 0, c = 0;
            // BEGIN
            $a.F(b, c)$;
            // END
        }
    }
}";
            var rr = Resolve<CSharpInvocationResolveResult>(program);
            Assert.IsFalse(rr.IsError);
            Assert.That(rr.IsExtensionMethodInvocation, Is.True);
            Assert.That(rr.Arguments[0], Is.InstanceOf<LocalResolveResult>());
            Assert.That(((LocalResolveResult)rr.Arguments[0]).Variable.Name, Is.EqualTo("a"));
            Assert.That(rr.Arguments[1], Is.InstanceOf<LocalResolveResult>());
            Assert.That(((LocalResolveResult)rr.Arguments[1]).Variable.Name, Is.EqualTo("b"));
            Assert.That(rr.Arguments[2], Is.InstanceOf<LocalResolveResult>());
            Assert.That(((LocalResolveResult)rr.Arguments[2]).Variable.Name, Is.EqualTo("c"));
        }

Implicit "this." in resolve results

The following test passes:

[Test]
public void ImplicitThisReferences() {
    string program = @"
        using System;
        using System.Linq;
        class Test {
            int x;
            public void Main (string[] args) {
                $x$ = 1;
            }
        }";

    var rr = Resolve<MemberResolveResult>(program);
    Assert.That(rr.TargetResult is TypeResolveResult);
}

It's usable, but I think it would be more useful to have the TargetResult be a ThisRessolveResult instead because, after all, that's what the semantics of the expression is.

NuGet?

Hi, do you have any plans to publish to NRefactory to NuGet? I've started using it for a new project I'm working on, which I would like to distribute through NuGet, and I'd love to be able to include this as a dependent NuGet package.

Resolving of dynamic object members

All dynamic object member nodes are resolved to the same TypeResolveResult, which makes it hard to backreference which member was resolved:

Example:
dynamic x = new object();
x.Name = "adasdf";
x.Hello();

TypeResolveResult is the same instance for 'Name' and 'Hello' nodes.
If they were different instances, they could have been resolved back using a dictionary.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.