Browse Source

Re-enable resolver unit tests that failed due to the parser returning incorrect positions.

Fixed a bug that caused array initializers to fail to resolve when the parent variable initializer was not being resolved.
newNRvisualizers
Daniel Grunwald 15 years ago
parent
commit
b7fcc55308
  1. 4
      ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs
  2. 2
      ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/TypeParameterDeclaration.cs
  3. 4
      ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs
  4. 1
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/ArrayCreateTests.cs
  5. 2
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/LambdaTests.cs
  6. 2
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/NameLookupTests.cs
  7. 8
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/ObjectCreationTests.cs
  8. 4
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/ResolveAtLocationTests.cs
  9. 11
      ICSharpCode.NRefactory/PatternMatching/Pattern.cs

4
ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs

@ -444,9 +444,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -444,9 +444,9 @@ namespace ICSharpCode.NRefactory.CSharp
public abstract S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T));
#region Pattern Matching
protected static bool MatchString (string name1, string name2)
protected static bool MatchString (string pattern, string text)
{
return string.IsNullOrEmpty (name1) || name1 == name2;
return PatternMatching.Pattern.MatchString(pattern, text);
}
protected internal abstract bool DoMatch (AstNode other, PatternMatching.Match match);

2
ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/TypeParameterDeclaration.cs

@ -31,7 +31,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,7 +31,7 @@ namespace ICSharpCode.NRefactory.CSharp
public class TypeParameterDeclaration : AstNode
{
public static readonly Role<AttributeSection> AttributeRole = AttributedNode.AttributeRole;
public static readonly Role<CSharpTokenNode> VarianceRole = new Role<CSharpTokenNode>("Variance");
public static readonly Role<CSharpTokenNode> VarianceRole = new Role<CSharpTokenNode>("Variance", CSharpTokenNode.Null);
public override NodeType NodeType {
get { return NodeType.Unknown; }

4
ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs

@ -604,7 +604,8 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -604,7 +604,8 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
ResolveResult IAstVisitor<object, ResolveResult>.VisitVariableInitializer(VariableInitializer variableInitializer, object data)
{
if (resolverEnabled) {
ArrayInitializerExpression aie = variableInitializer.Initializer as ArrayInitializerExpression;
if (resolverEnabled || aie != null) {
ResolveResult result = errorResult;
if (variableInitializer.Parent is FieldDeclaration || variableInitializer.Parent is EventDeclaration) {
if (resolver.CurrentMember != null) {
@ -620,7 +621,6 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -620,7 +621,6 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
}
}
}
ArrayInitializerExpression aie = variableInitializer.Initializer as ArrayInitializerExpression;
ArrayType arrayType = result.Type as ArrayType;
if (aie != null && arrayType != null) {
StoreState(aie, resolver.Clone());

1
ICSharpCode.NRefactory.Tests/CSharp/Resolver/ArrayCreateTests.cs

@ -23,7 +23,6 @@ using NUnit.Framework; @@ -23,7 +23,6 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Resolver
{
[TestFixture]
[Ignore("Parser produces incorrect positions")]
public class ArrayCreateTests : ResolverTestBase
{
[Test]

2
ICSharpCode.NRefactory.Tests/CSharp/Resolver/LambdaTests.cs

@ -145,7 +145,7 @@ class TestClass { @@ -145,7 +145,7 @@ class TestClass {
Assert.AreEqual("System.Int32", lrr.Type.ReflectionName);
}
[Test, Ignore("Fails due to parser problem")]
[Test]
public void LambdaInInferred2DArrayInitializer()
{
string program = @"using System;

2
ICSharpCode.NRefactory.Tests/CSharp/Resolver/NameLookupTests.cs

@ -848,7 +848,7 @@ class B @@ -848,7 +848,7 @@ class B
Assert.AreEqual("B.x", mrr.Member.FullName);
}
[Test, Ignore("Parser produces incorrect positions")]
[Test]
public void SubstituteClassAndMethodTypeParametersAtOnce()
{
string program = @"class C<X> { static void M<T>(X a, T b) { $C<T>.M<X>$(b, a); } }";

8
ICSharpCode.NRefactory.Tests/CSharp/Resolver/ObjectCreationTests.cs

@ -111,7 +111,7 @@ class A { @@ -111,7 +111,7 @@ class A {
Assert.AreEqual(0, result.Member.Parameters.Count);
}
[Test, Ignore("Parser returns incorrect positions")]
[Test]
public void ChainedConstructorCall()
{
string program = @"using System;
@ -133,13 +133,13 @@ class C : B { @@ -133,13 +133,13 @@ class C : B {
{}
}
";
InvocationResolveResult mrr = Resolve<InvocationResolveResult>(program.Replace("base(b)", "$base(b)$"));
InvocationResolveResult mrr = Resolve<CSharpInvocationResolveResult>(program.Replace("base(b)", "$base(b)$"));
Assert.AreEqual("A..ctor", mrr.Member.FullName);
mrr = Resolve<InvocationResolveResult>(program.Replace("base(c)", "$base(c)$"));
mrr = Resolve<CSharpInvocationResolveResult>(program.Replace("base(c)", "$base(c)$"));
Assert.AreEqual("B..ctor", mrr.Member.FullName);
mrr = Resolve<InvocationResolveResult>(program.Replace("this(0)", "$this(0)$"));
mrr = Resolve<CSharpInvocationResolveResult>(program.Replace("this(0)", "$this(0)$"));
Assert.AreEqual("C..ctor", mrr.Member.FullName);
}

4
ICSharpCode.NRefactory.Tests/CSharp/Resolver/ResolveAtLocationTests.cs

@ -68,10 +68,10 @@ class A { void M() { @@ -68,10 +68,10 @@ class A { void M() {
Assert.AreEqual("System.Int32", rr.Type.FullName);
}
[Test, Ignore("Parser returns incorrect positions")]
[Test]
public void BaseCtorCall()
{
var rr = ResolveAtLocation<InvocationResolveResult>(@"using System;
var rr = ResolveAtLocation<CSharpInvocationResolveResult>(@"using System;
class A { public A() : ba$se() {} }");
Assert.AreEqual("System.Object..ctor", rr.Member.FullName);
}

11
ICSharpCode.NRefactory/PatternMatching/Pattern.cs

@ -28,6 +28,17 @@ namespace ICSharpCode.NRefactory.PatternMatching @@ -28,6 +28,17 @@ namespace ICSharpCode.NRefactory.PatternMatching
/// </summary>
public abstract class Pattern : INode
{
/// <summary>
/// Gets the string that matches any string.
/// </summary>
public static readonly string AnyString = string.Empty;
// TODO: use something other than string.Empty so that 'no value' and 'any value' can be distinguished
public static bool MatchString(string pattern, string text)
{
return string.IsNullOrEmpty(pattern) || pattern == text;
}
internal struct PossibleMatch
{
public readonly INode NextOther; // next node after the last matched node

Loading…
Cancel
Save