diff --git a/src/Libraries/NRefactory/ICSharpCode.Editor/ITextSource.cs b/src/Libraries/NRefactory/ICSharpCode.Editor/ITextSource.cs
index 1f9cda9e75..3eb6c18867 100644
--- a/src/Libraries/NRefactory/ICSharpCode.Editor/ITextSource.cs
+++ b/src/Libraries/NRefactory/ICSharpCode.Editor/ITextSource.cs
@@ -97,11 +97,31 @@ namespace ICSharpCode.Editor
/// Gets the index of the first occurrence of any character in the specified array.
///
/// Characters to search for
- /// Start index of the search.
+ /// Start index of the area to search.
/// Length of the area to search.
/// The first index where any character was found; or -1 if no occurrence was found.
int IndexOfAny(char[] anyOf, int startIndex, int count);
+ ///
+ /// Gets the index of the first occurrence of the specified search text in this text source.
+ ///
+ /// The search text
+ /// Start index of the area to search.
+ /// Length of the area to search.
+ /// String comparison to use.
+ /// The first index where the search term was found; or -1 if no occurrence was found.
+ int IndexOf(string searchText, int startIndex, int count, StringComparison comparisonType);
+
+ ///
+ /// Gets the index of the last occurrence of the specified search text in this text source.
+ ///
+ /// The search text
+ /// Start index of the area to search.
+ /// Length of the area to search.
+ /// String comparison to use.
+ /// The last index where the search term was found; or -1 if no occurrence was found.
+ int LastIndexOf(string searchText, int startIndex, int count, StringComparison comparisonType);
+
/* What about:
void Insert (int offset, string value);
void Remove (int offset, int count);
@@ -116,7 +136,7 @@ namespace ICSharpCode.Editor
IEnumerable SearchBackward (string pattern, int startIndex);
IEnumerable SearchBackwardIgnoreCase (string pattern, int startIndex);
- */
+ */
}
///
diff --git a/src/Libraries/NRefactory/ICSharpCode.Editor/ReadOnlyDocument.cs b/src/Libraries/NRefactory/ICSharpCode.Editor/ReadOnlyDocument.cs
index 059d9d8d90..442b387592 100644
--- a/src/Libraries/NRefactory/ICSharpCode.Editor/ReadOnlyDocument.cs
+++ b/src/Libraries/NRefactory/ICSharpCode.Editor/ReadOnlyDocument.cs
@@ -327,6 +327,18 @@ namespace ICSharpCode.Editor
return textSource.IndexOfAny(anyOf, startIndex, count);
}
+ ///
+ public int IndexOf(string searchText, int startIndex, int count, StringComparison comparisonType)
+ {
+ return textSource.IndexOf(searchText, startIndex, count, comparisonType);
+ }
+
+ ///
+ public int LastIndexOf(string searchText, int startIndex, int count, StringComparison comparisonType)
+ {
+ return textSource.LastIndexOf(searchText, startIndex, count, comparisonType);
+ }
+
object IServiceProvider.GetService(Type serviceType)
{
return null;
diff --git a/src/Libraries/NRefactory/ICSharpCode.Editor/StringTextSource.cs b/src/Libraries/NRefactory/ICSharpCode.Editor/StringTextSource.cs
index e498f09338..ca59e40ffe 100644
--- a/src/Libraries/NRefactory/ICSharpCode.Editor/StringTextSource.cs
+++ b/src/Libraries/NRefactory/ICSharpCode.Editor/StringTextSource.cs
@@ -102,5 +102,17 @@ namespace ICSharpCode.Editor
{
return text.IndexOfAny(anyOf, startIndex, count);
}
+
+ ///
+ public int IndexOf(string searchText, int startIndex, int count, StringComparison comparisonType)
+ {
+ return text.IndexOf(searchText, startIndex, count, comparisonType);
+ }
+
+ ///
+ public int LastIndexOf(string searchText, int startIndex, int count, StringComparison comparisonType)
+ {
+ return text.LastIndexOf(searchText, startIndex, count, comparisonType);
+ }
}
}
diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Demo/CSDemo.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Demo/CSDemo.cs
index 1ccb5de511..a65040678a 100644
--- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Demo/CSDemo.cs
+++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Demo/CSDemo.cs
@@ -225,7 +225,7 @@ namespace ICSharpCode.NRefactory.Demo
foreach (TreeNode t in c) {
AstNode node = t.Tag as AstNode;
if (node != null) {
- ResolveResult rr = v.GetResolveResult(node);
+ ResolveResult rr = v.GetResolveResultIfResolved(node);
if (rr != null)
t.Text = GetNodeTitle(node) + " " + rr.ToString();
else
@@ -282,10 +282,12 @@ namespace ICSharpCode.NRefactory.Demo
FindReferences fr = new FindReferences();
int referenceCount = 0;
- fr.ReferenceFound += delegate { referenceCount++; };
+ FoundReferenceCallback callback = delegate(AstNode matchNode, ResolveResult result) {
+ referenceCount++;
+ };
var searchScopes = fr.GetSearchScopes(entity);
- navigator = new CompositeResolveVisitorNavigator(searchScopes.ToArray());
+ navigator = new CompositeResolveVisitorNavigator(searchScopes.Select(s => s.GetNavigator(callback)).ToArray());
visitor = new ResolveVisitor(resolver, parsedFile, navigator);
visitor.Scan(compilationUnit);
diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ArrayCreateExpressionTests.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ArrayCreateExpressionTests.cs
index 2fb3c1ad7d..bb96d1e5b8 100644
--- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ArrayCreateExpressionTests.cs
+++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ArrayCreateExpressionTests.cs
@@ -57,6 +57,9 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
"new int[] { 1 }",
new ArrayCreateExpression {
Type = new PrimitiveType("int"),
+ AdditionalArraySpecifiers = {
+ new ArraySpecifier(0)
+ },
Initializer = new ArrayInitializerExpression {
Elements = { new PrimitiveExpression(1) }
}
@@ -70,7 +73,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
"new int[,] { { 1 } }",
new ArrayCreateExpression {
Type = new PrimitiveType("int"),
- Arguments = { new EmptyExpression(), new EmptyExpression() }, // TODO: can we improve the AST for this?
+ AdditionalArraySpecifiers = { new ArraySpecifier (2) },
Initializer = new ArrayInitializerExpression {
Elements = {
new ArrayInitializerExpression {
@@ -87,6 +90,9 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
ParseUtilCSharp.AssertExpression(
"new[] { 1, 10, 100, 1000 }",
new ArrayCreateExpression {
+ AdditionalArraySpecifiers = {
+ new ArraySpecifier(0)
+ },
Initializer = new ArrayInitializerExpression {
Elements = {
new PrimitiveExpression(1),
@@ -103,7 +109,9 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
ParseUtilCSharp.AssertExpression(
"new [,] { { 1, 10 }, { 100, 1000 } }",
new ArrayCreateExpression {
- Arguments = { new EmptyExpression(), new EmptyExpression() }, // TODO: can we improve the AST for this?
+ AdditionalArraySpecifiers = {
+ new ArraySpecifier(2),
+ },
Initializer = new ArrayInitializerExpression {
Elements = {
new ArrayInitializerExpression {
@@ -128,6 +136,9 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
ParseUtilCSharp.AssertExpression(
"new [] { a = 10 }",
new ArrayCreateExpression {
+ AdditionalArraySpecifiers = {
+ new ArraySpecifier(0)
+ },
Initializer = new ArrayInitializerExpression {
Elements = {
new AssignmentExpression(new IdentifierExpression("a"), new PrimitiveExpression(10))
diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/AttributeSectionTests.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/AttributeSectionTests.cs
index c1a7571a21..213238dc56 100644
--- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/AttributeSectionTests.cs
+++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/AttributeSectionTests.cs
@@ -88,7 +88,7 @@ public class Form1 {
}}});
}
- [Test, Ignore("Parser doesn't support attributes on type parameters")]
+ [Test]
public void AttributesOnTypeParameter()
{
ParseUtilCSharp.AssertGlobal(
@@ -148,7 +148,7 @@ public class Form1 {
// TODO: Tests for other contexts where attributes can appear
- [Test, Ignore("Parser does not support NamedArgumentExpression in attributes")]
+ [Test]
public void AttributeWithNamedArguments()
{
ParseUtilCSharp.AssertTypeMember(
diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs
index a5869b5a27..fa4c82ad62 100644
--- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs
+++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs
@@ -45,7 +45,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
}
var testCasePC = new SimpleProjectContent();
- ParsedFile parsedFile = new TypeSystemConvertVisitor(testCasePC, fileName).Convert(cu);
+ CSharpParsedFile parsedFile = new TypeSystemConvertVisitor(testCasePC, fileName).Convert(cu);
parsedFile.Freeze();
testCasePC.UpdateProjectContent(null, parsedFile);
return testCasePC;
diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Refactoring/TypeSystemAstBuilderTests.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Refactoring/TypeSystemAstBuilderTests.cs
index 7e90fd8ad4..b85b674dc1 100644
--- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Refactoring/TypeSystemAstBuilderTests.cs
+++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Refactoring/TypeSystemAstBuilderTests.cs
@@ -55,7 +55,7 @@ namespace OtherNS {
SimpleProjectContent pc;
ITypeResolveContext ctx;
ITypeDefinition baseClass, derivedClass, nestedClass, systemClass;
- ParsedFile parsedFile;
+ CSharpParsedFile parsedFile;
[SetUp]
public void SetUp()
diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/LinqTests.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/LinqTests.cs
index f23bb83c69..71e8ec078a 100644
--- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/LinqTests.cs
+++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/LinqTests.cs
@@ -313,5 +313,24 @@ class XYZ
Assert.AreEqual("GroupJoin", rr.Member.Name);
Assert.AreEqual("System.Int32", rr.Type.FullName);
}
+
+ [Test]
+ public void GroupWithQueryContinuation()
+ {
+ string program = @"using System; using System.Linq;
+class TestClass
+{
+ static void M(string[] args)
+ {
+ var query =
+ from w in ""one to three"".Split()
+ group w by w.Length into g
+ orderby g.Key descending
+ select new { g.Key, Count = g.Count(), Avg = g.Average ($w$ => w.Length) };
+ }
+}";
+ var rr = Resolve(program);
+ Assert.AreEqual("System.String", rr.Type.FullName);
+ }
}
}
diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/ResolverTestBase.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/ResolverTestBase.cs
index 75cc3f65d3..ee8de8cefc 100644
--- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/ResolverTestBase.cs
+++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/ResolverTestBase.cs
@@ -194,7 +194,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
SetUp();
- ParsedFile parsedFile = new ParsedFile("test.cs", resolver.CurrentUsingScope);
+ CSharpParsedFile parsedFile = new CSharpParsedFile("test.cs", resolver.CurrentUsingScope);
TypeSystemConvertVisitor convertVisitor = new TypeSystemConvertVisitor(parsedFile, resolver.CurrentUsingScope, null);
cu.AcceptVisitor(convertVisitor, null);
project.UpdateProjectContent(null, convertVisitor.ParsedFile);
@@ -259,7 +259,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
SetUp();
- ParsedFile parsedFile = new ParsedFile("test.cs", resolver.CurrentUsingScope);
+ CSharpParsedFile parsedFile = new CSharpParsedFile("test.cs", resolver.CurrentUsingScope);
TypeSystemConvertVisitor convertVisitor = new TypeSystemConvertVisitor(parsedFile, resolver.CurrentUsingScope, null);
cu.AcceptVisitor(convertVisitor, null);
project.UpdateProjectContent(null, convertVisitor.ParsedFile);
diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs
index 8146213d65..bbf4e00eb6 100644
--- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs
+++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs
@@ -20,6 +20,7 @@ using System;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+using ICSharpCode.NRefactory.CSharp.Resolver;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using ICSharpCode.NRefactory.TypeSystem.TestCase;
using NUnit.Framework;
@@ -132,14 +133,15 @@ namespace ICSharpCode.NRefactory.TypeSystem
var posArgs = typeTest.GetPositionalArguments(ctx);
Assert.AreEqual(3, posArgs.Count);
// first argument is (int)42
- Assert.AreEqual(42, (int)posArgs[0].GetValue(ctx));
+ Assert.AreEqual(42, (int)posArgs[0].ConstantValue);
// second argument is typeof(System.Action<>)
- IType rt = (IType)posArgs[1].GetValue(ctx);
- Assert.IsFalse(rt is ParameterizedType); // rt must not be constructed - it's just an unbound type
- Assert.AreEqual("System.Action", rt.FullName);
- Assert.AreEqual(1, rt.TypeParameterCount);
+ TypeOfResolveResult rt = (TypeOfResolveResult)posArgs[1];
+ Assert.IsFalse(rt.ReferencedType is ParameterizedType); // rt must not be constructed - it's just an unbound type
+ Assert.AreEqual("System.Action", rt.ReferencedType.FullName);
+ Assert.AreEqual(1, rt.ReferencedType.TypeParameterCount);
// third argument is typeof(IDictionary>)
- ParameterizedType crt = (ParameterizedType)posArgs[2].GetValue(ctx);
+ rt = (TypeOfResolveResult)posArgs[2];
+ ParameterizedType crt = (ParameterizedType)rt.ReferencedType;
Assert.AreEqual("System.Collections.Generic.IDictionary", crt.FullName);
Assert.AreEqual("System.String", crt.TypeArguments[0].FullName);
// ? for NUnit.TestAttribute (because that assembly isn't in ctx)
@@ -153,8 +155,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
var forwardAttribute = attributes.Single(a => a.AttributeType.Resolve(ctx).FullName == typeof(TypeForwardedToAttribute).FullName);
var posArgs = forwardAttribute.GetPositionalArguments(ctx);
Assert.AreEqual(1, posArgs.Count);
- IType rt = (IType)posArgs[0].GetValue(ctx);
- Assert.AreEqual("System.Func`2", rt.ReflectionName);
+ TypeOfResolveResult rt = (TypeOfResolveResult)posArgs[0];
+ Assert.AreEqual("System.Func`2", rt.ReferencedType.ReflectionName);
}
[Test]
@@ -254,33 +256,25 @@ namespace ICSharpCode.NRefactory.TypeSystem
Assert.IsTrue(f.IsStatic);
Assert.IsTrue(f.IsConst);
Assert.AreEqual(Accessibility.Public, f.Accessibility);
- Assert.AreSame(e, f.ConstantValue.GetValueType(ctx));
- Assert.AreEqual(typeof(short), f.ConstantValue.GetValue(ctx).GetType());
+ Assert.AreSame(e, f.ConstantValue.Resolve(ctx).Type);
+ Assert.AreEqual(typeof(short), f.ConstantValue.Resolve(ctx).ConstantValue.GetType());
}
Assert.AreEqual("First", e.Fields[0].Name);
- Assert.AreEqual(0, e.Fields[0].ConstantValue.GetValue(ctx));
+ Assert.AreEqual(0, e.Fields[0].ConstantValue.Resolve(ctx).ConstantValue);
Assert.AreEqual("Second", e.Fields[1].Name);
- Assert.AreSame(e, e.Fields[1].ConstantValue.GetValueType(ctx));
- Assert.AreEqual(1, e.Fields[1].ConstantValue.GetValue(ctx));
+ Assert.AreSame(e, e.Fields[1].ConstantValue.Resolve(ctx).Type);
+ Assert.AreEqual(1, e.Fields[1].ConstantValue.Resolve(ctx).ConstantValue);
Assert.AreEqual("Flag1", e.Fields[2].Name);
- Assert.AreEqual(0x10, e.Fields[2].ConstantValue.GetValue(ctx));
+ Assert.AreEqual(0x10, e.Fields[2].ConstantValue.Resolve(ctx).ConstantValue);
Assert.AreEqual("Flag2", e.Fields[3].Name);
- Assert.AreEqual(0x20, e.Fields[3].ConstantValue.GetValue(ctx));
+ Assert.AreEqual(0x20, e.Fields[3].ConstantValue.Resolve(ctx).ConstantValue);
Assert.AreEqual("CombinedFlags", e.Fields[4].Name);
- Assert.AreEqual(0x30, e.Fields[4].ConstantValue.GetValue(ctx));
- }
-
- [Test]
- public void GetNestedTypesFromGenericClassTest()
- {
- ITypeDefinition b = ctx.GetTypeDefinition(typeof(Base<>));
- // Base.GetNestedTypes() = { Base`1+Nested`1[`0, unbound] }
-
+ Assert.AreEqual(0x30, e.Fields[4].ConstantValue.Resolve(ctx).ConstantValue);
}
[Test]
@@ -336,20 +330,20 @@ namespace ICSharpCode.NRefactory.TypeSystem
{
IAttribute attr = ctx.GetTypeDefinition(typeof(ExplicitFieldLayoutStruct)).Attributes.Single();
Assert.AreEqual("System.Runtime.InteropServices.StructLayoutAttribute", attr.AttributeType.Resolve(ctx).FullName);
- IConstantValue arg1 = attr.GetPositionalArguments(ctx).Single();
- Assert.AreEqual("System.Runtime.InteropServices.LayoutKind", arg1.GetValueType(ctx).FullName);
- Assert.AreEqual((int)LayoutKind.Explicit, arg1.GetValue(ctx));
+ ResolveResult arg1 = attr.GetPositionalArguments(ctx).Single();
+ Assert.AreEqual("System.Runtime.InteropServices.LayoutKind", arg1.Type.FullName);
+ Assert.AreEqual((int)LayoutKind.Explicit, arg1.ConstantValue);
var namedArgs = attr.GetNamedArguments(ctx);
var arg2 = namedArgs[0];
Assert.AreEqual("CharSet", arg2.Key);
- Assert.AreEqual("System.Runtime.InteropServices.CharSet", arg2.Value.GetValueType(ctx).FullName);
- Assert.AreEqual((int)CharSet.Unicode, arg2.Value.GetValue(ctx));
+ Assert.AreEqual("System.Runtime.InteropServices.CharSet", arg2.Value.Type.FullName);
+ Assert.AreEqual((int)CharSet.Unicode, arg2.Value.ConstantValue);
var arg3 = namedArgs[1];
Assert.AreEqual("Pack", arg3.Key);
- Assert.AreEqual("System.Int32", arg3.Value.GetValueType(ctx).FullName);
- Assert.AreEqual(8, arg3.Value.GetValue(ctx));
+ Assert.AreEqual("System.Int32", arg3.Value.Type.FullName);
+ Assert.AreEqual(8, arg3.Value.ConstantValue);
}
[Test]
@@ -357,15 +351,15 @@ namespace ICSharpCode.NRefactory.TypeSystem
{
IField field = ctx.GetTypeDefinition(typeof(ExplicitFieldLayoutStruct)).Fields.Single(f => f.Name == "Field0");
Assert.AreEqual("System.Runtime.InteropServices.FieldOffsetAttribute", field.Attributes.Single().AttributeType.Resolve(ctx).FullName);
- IConstantValue arg = field.Attributes.Single().GetPositionalArguments(ctx).Single();
- Assert.AreEqual("System.Int32", arg.GetValueType(ctx).FullName);
- Assert.AreEqual(0, arg.GetValue(ctx));
+ ResolveResult arg = field.Attributes.Single().GetPositionalArguments(ctx).Single();
+ Assert.AreEqual("System.Int32", arg.Type.FullName);
+ Assert.AreEqual(0, arg.ConstantValue);
field = ctx.GetTypeDefinition(typeof(ExplicitFieldLayoutStruct)).Fields.Single(f => f.Name == "Field100");
Assert.AreEqual("System.Runtime.InteropServices.FieldOffsetAttribute", field.Attributes.Single().AttributeType.Resolve(ctx).FullName);
arg = field.Attributes.Single().GetPositionalArguments(ctx).Single();
- Assert.AreEqual("System.Int32", arg.GetValueType(ctx).FullName);
- Assert.AreEqual(100, arg.GetValue(ctx));
+ Assert.AreEqual("System.Int32", arg.Type.FullName);
+ Assert.AreEqual(100, arg.ConstantValue);
}
[Test]
@@ -374,8 +368,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
IMethod method = ctx.GetTypeDefinition(typeof(NonCustomAttributes)).Methods.Single(m => m.Name == "DllMethod");
IAttribute dllImport = method.Attributes.Single();
Assert.AreEqual("System.Runtime.InteropServices.DllImportAttribute", dllImport.AttributeType.Resolve(ctx).FullName);
- Assert.AreEqual("unmanaged.dll", dllImport.GetPositionalArguments(ctx)[0].GetValue(ctx));
- Assert.AreEqual((int)CharSet.Unicode, dllImport.GetNamedArguments(ctx).Single().Value.GetValue(ctx));
+ Assert.AreEqual("unmanaged.dll", dllImport.GetPositionalArguments(ctx)[0].ConstantValue);
+ Assert.AreEqual((int)CharSet.Unicode, dllImport.GetNamedArguments(ctx).Single().Value.ConstantValue);
}
[Test]
@@ -394,7 +388,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
{
IMethod method = ctx.GetTypeDefinition(typeof(NonCustomAttributes)).Methods.Single(m => m.Name == "DllMethod");
IAttribute marshalAs = method.ReturnTypeAttributes.Single();
- Assert.AreEqual((int)UnmanagedType.Bool, marshalAs.GetPositionalArguments(ctx).Single().GetValue(ctx));
+ Assert.AreEqual((int)UnmanagedType.Bool, marshalAs.GetPositionalArguments(ctx).Single().ConstantValue);
}
[Test]
diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.VB.Tests/ICSharpCode.NRefactory.VB.Tests.csproj b/src/Libraries/NRefactory/ICSharpCode.NRefactory.VB.Tests/ICSharpCode.NRefactory.VB.Tests.csproj
index 11ff834a12..aab1620cb7 100644
--- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.VB.Tests/ICSharpCode.NRefactory.VB.Tests.csproj
+++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.VB.Tests/ICSharpCode.NRefactory.VB.Tests.csproj
@@ -62,8 +62,7 @@
- ..\lib\nunit.framework.dll
- True
+ ..\..\Mono.Cecil\Test\libs\nunit-2.4.8\nunit.framework.dll
diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/Ast/CSharpModifierToken.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/Ast/CSharpModifierToken.cs
index 3fc7fa2912..28d72cb996 100644
--- a/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/Ast/CSharpModifierToken.cs
+++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/Ast/CSharpModifierToken.cs
@@ -1,6 +1,6 @@
//
// CSharpModifierToken.cs
-//
+//
// Author:
// Mike Krüger
//
@@ -37,14 +37,8 @@ namespace ICSharpCode.NRefactory.CSharp
public Modifiers Modifier {
get { return modifier; }
set {
- for (int i = 0; i < lengthTable.Count; i++) {
- if (lengthTable[i].Key == value) {
- this.modifier = value;
- this.tokenLength = lengthTable[i].Value;
- return;
- }
- }
- throw new ArgumentException ("Modifier " + value + " is invalid.");
+ this.tokenLength = GetModifierName(value).Length;
+ this.modifier = value;
}
}
@@ -56,30 +50,18 @@ namespace ICSharpCode.NRefactory.CSharp
// Not worth using a dictionary for such few elements.
// This table is sorted in the order that modifiers should be output when generating code.
- static readonly List> lengthTable = new List> () {
- new KeyValuePair(Modifiers.Public, "public".Length),
- new KeyValuePair(Modifiers.Protected, "protected".Length),
- new KeyValuePair(Modifiers.Private, "private".Length),
- new KeyValuePair(Modifiers.Internal, "internal".Length),
- new KeyValuePair(Modifiers.New, "new".Length),
- new KeyValuePair(Modifiers.Unsafe, "unsafe".Length),
- new KeyValuePair(Modifiers.Abstract, "abstract".Length),
- new KeyValuePair(Modifiers.Virtual, "virtual".Length),
- new KeyValuePair(Modifiers.Sealed, "sealed".Length),
- new KeyValuePair(Modifiers.Static, "static".Length),
- new KeyValuePair(Modifiers.Override, "override".Length),
- new KeyValuePair(Modifiers.Readonly, "readonly".Length),
- new KeyValuePair(Modifiers.Volatile, "volatile".Length),
- new KeyValuePair(Modifiers.Extern, "extern".Length),
- new KeyValuePair(Modifiers.Partial, "partial".Length),
- new KeyValuePair(Modifiers.Const, "const".Length),
-
- // even though it's used for patterns only, it needs to be in this table to be usable in the AST
- new KeyValuePair(Modifiers.Any, "any".Length)
+ static readonly Modifiers[] allModifiers = {
+ Modifiers.Public, Modifiers.Protected, Modifiers.Private, Modifiers.Internal,
+ Modifiers.New,
+ Modifiers.Unsafe,
+ Modifiers.Abstract, Modifiers.Virtual, Modifiers.Sealed, Modifiers.Static, Modifiers.Override,
+ Modifiers.Readonly, Modifiers.Volatile,
+ Modifiers.Extern, Modifiers.Partial, Modifiers.Const,
+ Modifiers.Any
};
public static IEnumerable AllModifiers {
- get { return lengthTable.Select(p => p.Key); }
+ get { return allModifiers; }
}
public CSharpModifierToken (AstLocation location, Modifiers modifier) : base (location, 0)
@@ -122,8 +104,9 @@ namespace ICSharpCode.NRefactory.CSharp
return "volatile";
case Modifiers.Unsafe:
return "unsafe";
- case Modifiers.Fixed:
- return "fixed";
+ case Modifiers.Any:
+ // even though it's used for patterns only, it needs to be in this list to be usable in the AST
+ return "any";
default:
throw new NotSupportedException("Invalid value for Modifiers");
}
diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Modifiers.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Modifiers.cs
index 700a3c04d1..fec58e1761 100644
--- a/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Modifiers.cs
+++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Modifiers.cs
@@ -58,7 +58,7 @@ namespace ICSharpCode.NRefactory.CSharp
//Overloads = 0x10000,
//WithEvents = 0x20000,
//Default = 0x40000,
- Fixed = 0x80000,
+ //Fixed = 0x80000,
//ProtectedOrInternal = Internal | Protected,
//ProtectedAndInternal = 0x100000, (not supported in C#)
diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs
index 62ad069cb8..cf5e9e2c84 100644
--- a/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs
+++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs
@@ -551,7 +551,8 @@ namespace ICSharpCode.NRefactory.CSharp
StartNode (arrayCreateExpression);
WriteKeyword ("new");
arrayCreateExpression.Type.AcceptVisitor (this, data);
- WriteCommaSeparatedListInBrackets (arrayCreateExpression.Arguments);
+ if (arrayCreateExpression.Arguments.Count > 0)
+ WriteCommaSeparatedListInBrackets (arrayCreateExpression.Arguments);
foreach (var specifier in arrayCreateExpression.AdditionalArraySpecifiers)
specifier.AcceptVisitor (this, data);
arrayCreateExpression.Initializer.AcceptVisitor (this, data);
diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs
index c0247bb75a..0d0ff8bd22 100644
--- a/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs
+++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs
@@ -195,9 +195,22 @@ namespace ICSharpCode.NRefactory.CSharp
if (attr.PosArguments != null) {
foreach (var arg in attr.PosArguments) {
+ var na = arg as NamedArgument;
+ if (na != null) {
+ var newArg = new NamedArgumentExpression ();
+ newArg.AddChild (Identifier.Create (na.Name, Convert (na.Location)), NamedArgumentExpression.Roles.Identifier);
+
+ var argLoc = LocationsBag.GetLocations (na);
+ if (argLoc != null)
+ newArg.AddChild (new CSharpTokenNode (Convert (argLoc[0]), 1), NamedArgumentExpression.Roles.Assign);
+ newArg.AddChild ((Expression)na.Expr.Accept (this), NamedExpression.Roles.Expression);
+ result.AddChild (newArg, Attribute.Roles.Argument);
+ continue;
+ }
result.AddChild ((Expression)arg.Expr.Accept (this), Attribute.Roles.Argument);
}
}
+ Console.WriteLine ("---");
if (attr.NamedArguments != null) {
foreach (NamedArgument na in attr.NamedArguments) {
var newArg = new NamedExpression ();
@@ -714,7 +727,14 @@ namespace ICSharpCode.NRefactory.CSharp
{
if (a.OptAttributes == null)
return;
- foreach (var attr in a.OptAttributes.Sections) {
+ AddAttributeSection (parent, a.OptAttributes);
+ }
+
+ public void AddAttributeSection (AstNode parent, Attributes attrs)
+ {
+ if (attrs == null)
+ return;
+ foreach (var attr in attrs.Sections) {
parent.AddChild (ConvertAttributeSection (attr), AttributedNode.AttributeRole);
}
}
@@ -2156,7 +2176,9 @@ namespace ICSharpCode.NRefactory.CSharp
if (arg == null)
continue;
TypeParameterDeclaration tp = new TypeParameterDeclaration();
- // TODO: attributes
+
+ AddAttributeSection (tp, arg.OptAttributes);
+
switch (arg.Variance) {
case Variance.Covariant:
tp.Variance = VarianceModifier.Covariant;
@@ -2432,7 +2454,11 @@ namespace ICSharpCode.NRefactory.CSharp
result.AddChild (ConvertToType (arrayCreationExpression.NewType), ArrayCreateExpression.Roles.Type);
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ArrayCreateExpression.Roles.LBracket);
+
+ var next = arrayCreationExpression.Rank;
if (arrayCreationExpression.Arguments != null) {
+ // skip first array rank.
+ next = next.Next;
var commaLocations = LocationsBag.GetLocations (arrayCreationExpression.Arguments);
for (int i = 0 ;i < arrayCreationExpression.Arguments.Count; i++) {
result.AddChild ((Expression)arrayCreationExpression.Arguments[i].Accept (this), ArrayCreateExpression.Roles.Argument);
@@ -2440,7 +2466,7 @@ namespace ICSharpCode.NRefactory.CSharp
result.AddChild (new CSharpTokenNode (Convert (commaLocations [commaLocations.Count - i]), 1), ArrayCreateExpression.Roles.Comma);
}
}
- var next = arrayCreationExpression.Rank.Next;
+
while (next != null) {
ArraySpecifier spec = new ArraySpecifier (next.Dimension);
var loc = LocationsBag.GetLocations (next);
@@ -2888,7 +2914,6 @@ namespace ICSharpCode.NRefactory.CSharp
var result = new QueryJoinClause ();
var location = LocationsBag.GetLocations (join);
result.AddChild (new CSharpTokenNode (Convert (join.Location), "join".Length), QueryJoinClause.JoinKeywordRole);
-
result.AddChild (Identifier.Create (join.JoinVariable.Name, Convert (join.JoinVariable.Location)), QueryJoinClause.JoinIdentifierRole);
if (location != null)
@@ -2898,11 +2923,17 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[1]), "on".Length), QueryJoinClause.OnKeywordRole);
- // TODO: on expression
+
+ var outer = join.OuterSelector.Statements.FirstOrDefault () as ContextualReturn;
+ if (outer != null)
+ result.AddChild ((Expression)outer.Expr.Accept (this), QueryJoinClause.OnExpressionRole);
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[2]), "equals".Length), QueryJoinClause.EqualsKeywordRole);
- // TODO: equals expression
+
+ var inner = join.InnerSelector.Statements.FirstOrDefault () as ContextualReturn;
+ if (inner != null)
+ result.AddChild ((Expression)inner.Expr.Accept (this), QueryJoinClause.EqualsExpressionRole);
return result;
}
@@ -2919,16 +2950,19 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), "in".Length), QueryJoinClause.InKeywordRole);
- result.AddChild ((Expression)join.Expr.Accept (this), QueryJoinClause.InExpressionRole);
+ var outer = join.OuterSelector.Statements.FirstOrDefault () as ContextualReturn;
+ if (outer != null)
+ result.AddChild ((Expression)outer.Expr.Accept (this), QueryJoinClause.OnExpressionRole);
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[1]), "on".Length), QueryJoinClause.OnKeywordRole);
-
- // TODO: on expression
+ result.AddChild ((Expression)join.Expr.Accept (this), QueryJoinClause.InExpressionRole);
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[2]), "equals".Length), QueryJoinClause.EqualsKeywordRole);
- // TODO: equals expression
+ var inner = join.InnerSelector.Statements.FirstOrDefault () as ContextualReturn;
+ if (inner != null)
+ result.AddChild ((Expression)inner.Expr.Accept (this), QueryJoinClause.EqualsExpressionRole);
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[3]), "into".Length), QueryJoinClause.IntoKeywordRole);
diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/Parser/ParsedFile.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/Parser/ParsedFile.cs
index 50c3ad8d11..984edaa2a9 100644
--- a/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/Parser/ParsedFile.cs
+++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/Parser/ParsedFile.cs
@@ -28,7 +28,7 @@ namespace ICSharpCode.NRefactory.CSharp
/// Represents a file that was parsed and converted for the type system.
///
[Serializable]
- public sealed class ParsedFile : AbstractFreezable, IParsedFile
+ public sealed class CSharpParsedFile : AbstractFreezable, IParsedFile
{
readonly string fileName;
readonly UsingScope rootUsingScope;
@@ -48,7 +48,7 @@ namespace ICSharpCode.NRefactory.CSharp
usingScopes = FreezeList(usingScopes);
}
- public ParsedFile(string fileName, UsingScope rootUsingScope)
+ public CSharpParsedFile(string fileName, UsingScope rootUsingScope)
{
if (fileName == null)
throw new ArgumentNullException("fileName");
diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs
index d055c90a1c..ab96afe447 100644
--- a/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs
+++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs
@@ -34,7 +34,7 @@ namespace ICSharpCode.NRefactory.CSharp
///
public class TypeSystemConvertVisitor : DepthFirstAstVisitor