Browse Source

Squashed 'NRefactory/' changes from 2200240..a92606c

a92606c Some improvements to output visitor.
136fd88 Fix some parser issues.
41b4385 Port NRefactory to .NET 3.5.
3b6fe6f Adjust resolver to AST changes and disable failing unit tests.
93e9d1e Use implicit conversion operator to convert from Pattern to AST nodes.
b37ea77 Re-enabled the unit tests that were commented out.
defd426 AST bugfixes.
60d4fe9 Add pattern matching for query expressions. Pattern matching should now work for the complete C# AST.
b51f5a6 Add pattern matching for MemberDeclarations.

git-subtree-dir: NRefactory
git-subtree-split: a92606cb97ef6739d59b30a278d017cf64677f88
pull/129/head
Daniel Grunwald 15 years ago
parent
commit
39fcd7d72f
  1. 15
      ICSharpCode.NRefactory.Tests/CSharp/AstStructureTests.cs
  2. 38
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/AliasReferenceExpressionTests.cs
  3. 1
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/AnonymousMethodTests.cs
  4. 52
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ArrayObjectCreateExpressionTests.cs
  5. 151
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/CastExpressionTests.cs
  6. 60
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/DefaultValueExpressionTests.cs
  7. 28
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/IdentifierExpressionTests.cs
  8. 177
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/InvocationExpressionTests.cs
  9. 15
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/IsExpressionTests.cs
  10. 117
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/LambdaExpressionTests.cs
  11. 97
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/MemberReferenceExpressionTests.cs
  12. 18
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/PointerReferenceExpressionTests.cs
  13. 232
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/QueryExpressionTests.cs
  14. 4
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/SizeOfExpressionTests.cs
  15. 9
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/StackAllocExpressionTests.cs
  16. 97
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/TypeOfExpressionTests.cs
  17. 6
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/UnaryOperatorExpressionTests.cs
  18. 68
      ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/DelegateDeclarationTests.cs
  19. 198
      ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/TypeDeclarationTests.cs
  20. 2
      ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/UsingDeclarationTests.cs
  21. 41
      ICSharpCode.NRefactory.Tests/CSharp/Parser/ParseUtil.cs
  22. 15
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/FixedStatementTests.cs
  23. 20
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ForStatementTests.cs
  24. 56
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/TryCatchStatementTests.cs
  25. 3
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/YieldStatementTests.cs
  26. 113
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/EventDeclarationTests.cs
  27. 62
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/FieldDeclarationTests.cs
  28. 37
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/IndexerDeclarationTests.cs
  29. 266
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/MethodDeclarationTests.cs
  30. 16
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/OperatorDeclarationTests.cs
  31. 10
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/PropertyDeclarationTests.cs
  32. 2
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/InvocationTests.cs
  33. 10
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/NameLookupTests.cs
  34. 2
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/UnsafeCodeTests.cs
  35. 1
      ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj
  36. 1
      ICSharpCode.NRefactory.VB.Tests/ICSharpCode.NRefactory.VB.Tests.csproj
  37. 1
      ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj
  38. 6
      ICSharpCode.NRefactory/CSharp/Ast/AstLocation.cs
  39. 5
      ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs
  40. 18
      ICSharpCode.NRefactory/CSharp/Ast/AstNodeCollection.cs
  41. 2
      ICSharpCode.NRefactory/CSharp/Ast/AstType.cs
  42. 6
      ICSharpCode.NRefactory/CSharp/Ast/CSharpModifierToken.cs
  43. 2
      ICSharpCode.NRefactory/CSharp/Ast/CSharpTokenNode.cs
  44. 2
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayCreateExpression.cs
  45. 61
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/QueryExpression.cs
  46. 9
      ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/AttributeSection.cs
  47. 5
      ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Constraint.cs
  48. 19
      ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/DelegateDeclaration.cs
  49. 9
      ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeDeclaration.cs
  50. 7
      ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeParameterDeclaration.cs
  51. 7
      ICSharpCode.NRefactory/CSharp/Ast/Identifier.cs
  52. 2
      ICSharpCode.NRefactory/CSharp/Ast/MemberType.cs
  53. 25
      ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Pattern.cs
  54. 68
      ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Placeholder.cs
  55. 2
      ICSharpCode.NRefactory/CSharp/Ast/SimpleType.cs
  56. 2
      ICSharpCode.NRefactory/CSharp/Ast/Statements/BlockStatement.cs
  57. 2
      ICSharpCode.NRefactory/CSharp/Ast/Statements/FixedStatement.cs
  58. 3
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/Accessor.cs
  59. 4
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/AttributedNode.cs
  60. 14
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs
  61. 8
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/DestructorDeclaration.cs
  62. 11
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EnumMemberDeclaration.cs
  63. 25
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EventDeclaration.cs
  64. 22
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/FieldDeclaration.cs
  65. 34
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/IndexerDeclaration.cs
  66. 6
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MemberDeclaration.cs
  67. 14
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MethodDeclaration.cs
  68. 27
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs
  69. 14
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs
  70. 11
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/PropertyDeclaration.cs
  71. 77
      ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs
  72. 46
      ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs
  73. 83
      ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs
  74. 28
      ICSharpCode.NRefactory/CSharp/Resolver/CSharpResolver.cs
  75. 10
      ICSharpCode.NRefactory/CSharp/Resolver/MemberLookup.cs
  76. 2
      ICSharpCode.NRefactory/CSharp/Resolver/MemberTypeOrNamespaceReference.cs
  77. 2
      ICSharpCode.NRefactory/CSharp/Resolver/OverloadResolution.cs
  78. 49
      ICSharpCode.NRefactory/CSharp/Resolver/ResolveVisitor.cs
  79. 2
      ICSharpCode.NRefactory/CSharp/Resolver/SimpleTypeOrNamespaceReference.cs
  80. 2
      ICSharpCode.NRefactory/CSharp/Resolver/TypeInference.cs
  81. 17
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
  82. 2
      ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs
  83. 8
      ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs
  84. 4
      ICSharpCode.NRefactory/TypeSystem/IAttribute.cs
  85. 4
      ICSharpCode.NRefactory/TypeSystem/IConstantValue.cs
  86. 4
      ICSharpCode.NRefactory/TypeSystem/IEntity.cs
  87. 4
      ICSharpCode.NRefactory/TypeSystem/IExplicitInterfaceImplementation.cs
  88. 4
      ICSharpCode.NRefactory/TypeSystem/IField.cs
  89. 4
      ICSharpCode.NRefactory/TypeSystem/IFreezable.cs
  90. 4
      ICSharpCode.NRefactory/TypeSystem/IInterningProvider.cs
  91. 4
      ICSharpCode.NRefactory/TypeSystem/IMember.cs
  92. 11
      ICSharpCode.NRefactory/TypeSystem/IMethod.cs
  93. 4
      ICSharpCode.NRefactory/TypeSystem/INamedElement.cs
  94. 4
      ICSharpCode.NRefactory/TypeSystem/IParameter.cs
  95. 4
      ICSharpCode.NRefactory/TypeSystem/IParameterizedMember.cs
  96. 4
      ICSharpCode.NRefactory/TypeSystem/IProjectContent.cs
  97. 4
      ICSharpCode.NRefactory/TypeSystem/ISupportsInterning.cs
  98. 4
      ICSharpCode.NRefactory/TypeSystem/IType.cs
  99. 4
      ICSharpCode.NRefactory/TypeSystem/ITypeDefinition.cs
  100. 4
      ICSharpCode.NRefactory/TypeSystem/ITypeParameter.cs
  101. Some files were not shown because too many files have changed in this diff Show More

15
ICSharpCode.NRefactory.Tests/CSharp/AstStructureTests.cs

@ -27,5 +27,20 @@ namespace ICSharpCode.NRefactory.CSharp @@ -27,5 +27,20 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
}
[Test]
public void AstNodesDoNotDeriveFromEachOther()
{
// Ast nodes should derive only from abstract classes; not from concrete types.
// For example, we want to avoid that an AST consumer doing "if (node is PropertyDeclaration)"
// unknowingly also handles IndexerDeclarations.
foreach (Type type in typeof(AstNode).Assembly.GetExportedTypes()) {
if (type == typeof(CSharpModifierToken)) // CSharpModifierToken is the exception (though I'm not too happy about that)
continue;
if (type.IsSubclassOf(typeof(AstNode))) {
Assert.IsTrue(type.BaseType.IsAbstract, type.FullName);
}
}
}
}
}

38
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/AliasReferenceExpressionTests.cs

@ -8,27 +8,43 @@ using NUnit.Framework; @@ -8,27 +8,43 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
{
[TestFixture]
[TestFixture, Ignore("Aliases not yet implemented")]
public class AliasReferenceExpressionTests
{
[Test, Ignore]
[Test]
public void GlobalReferenceExpressionTest()
{
CSharpParser parser = new CSharpParser();
parser.ParseTypeReference(new StringReader("global::System"));
//Assert.IsTrue(tre.TypeReference.IsGlobal);
//Assert.AreEqual("System", tre.TypeReference.Type);
throw new NotImplementedException();
AstType type = parser.ParseTypeReference(new StringReader("global::System"));
Assert.IsNotNull(
new MemberType {
Target = new SimpleType("global"),
IsDoubleColon = true,
MemberName = "System"
}.Match(type)
);
}
[Test, Ignore]
[Test]
public void GlobalTypeDeclaration()
{
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("global::System.String a;");
//TypeReference typeRef = lvd.GetTypeForVariable(0);
//Assert.IsTrue(typeRef.IsGlobal);
//Assert.AreEqual("System.String", typeRef.Type);
throw new NotImplementedException();
Assert.IsNotNull(
new VariableDeclarationStatement {
Type = new MemberType {
Target = new MemberType {
Target = new SimpleType("global"),
IsDoubleColon = true,
MemberName = "System"
},
IsDoubleColon = false,
MemberName = "String",
},
Variables = {
new VariableInitializer("a")
}
}.Match(lvd)
);
}
// TODO: add tests for aliases other than 'global'

1
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/AnonymousMethodTests.cs

@ -47,6 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -47,6 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
public void SimpleAnonymousMethod()
{
AnonymousMethodExpression ame = Parse("delegate(int a, int b) { return a + b; }");
Assert.IsTrue(ame.HasParameterList);
Assert.AreEqual(2, ame.Parameters.Count());
Assert.AreEqual(1, ame.Body.Statements.Count());
Assert.IsTrue(ame.Body.Children.First() is ReturnStatement);

52
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ArrayObjectCreateExpressionTests.cs

@ -6,31 +6,51 @@ using NUnit.Framework; @@ -6,31 +6,51 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
{
[TestFixture, Ignore("Needs to be ported to new NRefactory")]
[TestFixture]
public class ArrayObjectCreateExpressionTests
{
[Test]
public void ArrayCreateExpressionTest1()
{
/*
ArrayCreateExpression ace = ParseUtilCSharp.ParseExpression<ArrayCreateExpression>("new int[5]");
Assert.AreEqual("System.Int32", ace.CreateType.Type);
Assert.IsTrue(ace.CreateType.IsKeyword);
Assert.AreEqual(1, ace.Arguments.Count);
Assert.AreEqual(new int[] {0}, ace.CreateType.RankSpecifier);
*/
throw new NotImplementedException();
ParseUtilCSharp.AssertExpression(
"new int[5]",
new ArrayCreateExpression {
Type = new PrimitiveType("int"),
Arguments = { new PrimitiveExpression(5) }
});
}
[Test]
[Test, Ignore("AdditionalArraySpecifiers not yet implemented")]
public void MultidimensionalNestedArray()
{
ParseUtilCSharp.AssertExpression(
"new int[5,2][,,][]",
new ArrayCreateExpression {
Type = new PrimitiveType("int"),
Arguments = { new PrimitiveExpression(5), new PrimitiveExpression(2) },
AdditionalArraySpecifiers = {
new ArraySpecifier(3),
new ArraySpecifier(1)
}
});
}
[Test, Ignore("Array initializers not yet implemented")]
public void ImplicitlyTypedArrayCreateExpression()
{
/*
ArrayCreateExpression ace = ParseUtilCSharp.ParseExpression<ArrayCreateExpression>("new[] { 1, 10, 100, 1000 }");
Assert.AreEqual("", ace.CreateType.Type);
Assert.AreEqual(0, ace.Arguments.Count);
Assert.AreEqual(4, ace.ArrayInitializer.CreateExpressions.Count);*/
throw new NotImplementedException();
ParseUtilCSharp.AssertExpression(
"new[] { 1, 10, 100, 1000 }",
new ArrayCreateExpression {
Initializer = new ArrayInitializerExpression {
Elements = {
new PrimitiveExpression(1),
new PrimitiveExpression(10),
new PrimitiveExpression(100),
new PrimitiveExpression(1000)
}
}
});
}
}
}

151
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/CastExpressionTests.cs

@ -9,132 +9,157 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -9,132 +9,157 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
[TestFixture, Ignore("Port unit tests to new DOM")]
public class CastExpressionTests
{
/*
[Test]
public void SimpleCastExpression()
{
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(MyObject)o");
Assert.AreEqual("MyObject", ce.CastTo.Type);
Assert.IsTrue(ce.Expression is IdentifierExpression);
Assert.AreEqual(CastType.Cast, ce.CastType);
ParseUtilCSharp.AssertExpression(
"(MyObject)o",
new CastExpression {
Type = new SimpleType("MyObject"),
Expression = new IdentifierExpression("o")
});
}
[Test]
public void ArrayCastExpression()
{
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(MyType[])o");
Assert.AreEqual("MyType", ce.CastTo.Type);
Assert.AreEqual(new int[] { 0 }, ce.CastTo.RankSpecifier);
Assert.IsTrue(ce.Expression is IdentifierExpression);
Assert.AreEqual(CastType.Cast, ce.CastType);
ParseUtilCSharp.AssertExpression(
"(MyType[])o",
new CastExpression {
Type = new SimpleType("MyType").MakeArrayType(1),
Expression = new IdentifierExpression("o")
});
}
[Test]
public void NullablePrimitiveCastExpression()
{
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(int?)o");
Assert.AreEqual("System.Nullable", ce.CastTo.Type);
Assert.AreEqual("System.Int32", ce.CastTo.GenericTypes[0].Type);
Assert.IsTrue(ce.Expression is IdentifierExpression);
Assert.AreEqual(CastType.Cast, ce.CastType);
ParseUtilCSharp.AssertExpression(
"(int?)o",
new CastExpression {
Type = new ComposedType { BaseType = new PrimitiveType("int"), HasNullableSpecifier = true },
Expression = new IdentifierExpression("o")
});
}
[Test]
public void NullableCastExpression()
{
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(MyType?)o");
Assert.AreEqual("System.Nullable", ce.CastTo.Type);
Assert.AreEqual("MyType", ce.CastTo.GenericTypes[0].Type);
Assert.IsTrue(ce.Expression is IdentifierExpression);
Assert.AreEqual(CastType.Cast, ce.CastType);
ParseUtilCSharp.AssertExpression(
"(MyType?)o",
new CastExpression {
Type = new ComposedType { BaseType = new SimpleType("MyType"), HasNullableSpecifier = true },
Expression = new IdentifierExpression("o")
});
}
[Test]
public void NullableTryCastExpression()
{
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("o as int?");
Assert.AreEqual("System.Nullable", ce.CastTo.Type);
Assert.IsTrue(ce.CastTo.IsKeyword);
Assert.AreEqual("System.Int32", ce.CastTo.GenericTypes[0].Type);
Assert.IsTrue(ce.Expression is IdentifierExpression);
Assert.AreEqual(CastType.TryCast, ce.CastType);
ParseUtilCSharp.AssertExpression(
"o as int?",
new AsExpression {
Type = new ComposedType { BaseType = new PrimitiveType("int"), HasNullableSpecifier = true },
Expression = new IdentifierExpression("o")
});
}
[Test]
public void GenericCastExpression()
{
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(List<string>)o");
Assert.AreEqual("List", ce.CastTo.Type);
Assert.AreEqual("System.String", ce.CastTo.GenericTypes[0].Type);
Assert.IsTrue(ce.Expression is IdentifierExpression);
Assert.AreEqual(CastType.Cast, ce.CastType);
ParseUtilCSharp.AssertExpression(
"(List<string>)o",
new CastExpression {
Type = new SimpleType("List") { TypeArguments = { new PrimitiveType("string") } },
Expression = new IdentifierExpression("o")
});
}
[Test]
public void GenericArrayCastExpression()
{
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(List<string>[])o");
Assert.AreEqual("List", ce.CastTo.Type);
Assert.AreEqual("System.String", ce.CastTo.GenericTypes[0].Type);
Assert.AreEqual(new int[] { 0 }, ce.CastTo.RankSpecifier);
Assert.IsTrue(ce.Expression is IdentifierExpression);
Assert.AreEqual(CastType.Cast, ce.CastType);
ParseUtilCSharp.AssertExpression(
"(List<string>[])o",
new CastExpression {
Type = new ComposedType {
BaseType = new SimpleType("List") { TypeArguments = { new PrimitiveType("string") } },
ArraySpecifiers = { new ArraySpecifier(1) }
},
Expression = new IdentifierExpression("o")
});
}
[Test]
public void GenericArrayAsCastExpression()
{
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("o as List<string>[]");
Assert.AreEqual("List", ce.CastTo.Type);
Assert.AreEqual("System.String", ce.CastTo.GenericTypes[0].Type);
Assert.AreEqual(new int[] { 0 }, ce.CastTo.RankSpecifier);
Assert.IsTrue(ce.Expression is IdentifierExpression);
Assert.AreEqual(CastType.TryCast, ce.CastType);
ParseUtilCSharp.AssertExpression(
"o as List<string>[]",
new AsExpression {
Type = new ComposedType {
BaseType = new SimpleType("List") { TypeArguments = { new PrimitiveType("string") } },
ArraySpecifiers = { new ArraySpecifier(1) }
},
Expression = new IdentifierExpression("o")
});
}
[Test]
public void CastMemberReferenceOnParenthesizedExpression()
{
// yes, we really wanted to evaluate .Member on expr and THEN cast the result to MyType
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(MyType)(expr).Member");
Assert.AreEqual("MyType", ce.CastTo.Type);
Assert.IsTrue(ce.Expression is MemberReferenceExpression);
Assert.AreEqual(CastType.Cast, ce.CastType);
// yes, we really want to evaluate .Member on expr and THEN cast the result to MyType
ParseUtilCSharp.AssertExpression(
"(MyType)(expr).Member",
new CastExpression {
Type = new SimpleType("MyType"),
Expression = new ParenthesizedExpression { Expression = new IdentifierExpression("expr") }.Member("Member")
});
}
[Test]
public void TryCastParenthesizedExpression()
{
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(o) as string");
Assert.AreEqual("System.String", ce.CastTo.ToString());
Assert.IsTrue(ce.Expression is ParenthesizedExpression);
Assert.AreEqual(CastType.TryCast, ce.CastType);
ParseUtilCSharp.AssertExpression(
"(o) as string",
new AsExpression {
Expression = new ParenthesizedExpression { Expression = new IdentifierExpression("o") },
Type = new PrimitiveType("string")
});
}
[Test]
public void CastNegation()
{
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(uint)-negativeValue");
Assert.AreEqual("System.UInt32", ce.CastTo.ToString());
Assert.IsTrue(ce.Expression is UnaryOperatorExpression);
Assert.AreEqual(CastType.Cast, ce.CastType);
ParseUtilCSharp.AssertExpression(
"(uint)-negativeValue",
new CastExpression {
Type = new PrimitiveType("uint"),
Expression = new UnaryOperatorExpression(
UnaryOperatorType.Minus,
new IdentifierExpression("negativeValue")
)});
}
*/
[Test]
public void SubtractionIsNotCast()
{
BinaryOperatorExpression boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>("(BigInt)-negativeValue");
Assert.IsTrue(boe.Left is ParenthesizedExpression);
Assert.IsTrue(boe.Right is IdentifierExpression);
ParseUtilCSharp.AssertExpression(
"(BigInt)-negativeValue",
new BinaryOperatorExpression {
Left = new ParenthesizedExpression { Expression = new IdentifierExpression("BigInt") },
Operator = BinaryOperatorType.Subtract,
Right = new IdentifierExpression("negativeValue")
});
}
[Test]
public void IntMaxValueToBigInt()
{
CastExpression ce = ParseUtilCSharp.ParseExpression<CastExpression>("(BigInt)int.MaxValue");
Assert.AreEqual("BigInt", ce.Type.ToString());
Assert.IsTrue(ce.Expression is MemberReferenceExpression);
ParseUtilCSharp.AssertExpression(
"(BigInt)int.MaxValue",
new CastExpression {
Type = new SimpleType("BigInt"),
Expression = new PrimitiveExpression("int").Member("MaxValue")
});
}
}
}

60
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/DefaultValueExpressionTests.cs

@ -6,48 +6,74 @@ using NUnit.Framework; @@ -6,48 +6,74 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
{
[TestFixture, Ignore("tests need to be ported")]
[TestFixture, Ignore("Aliases not yet implemented")]
public class DefaultValueExpressionTests
{
[Test]
public void SimpleDefaultValue()
{
DefaultValueExpression toe = ParseUtilCSharp.ParseExpression<DefaultValueExpression>("default(T)");
Assert.AreEqual("T", toe.Type);
Assert.AreEqual("T", ((SimpleType)toe.Type).Identifier);
}
/*
[Test]
public void FullQualifiedDefaultValue()
{
DefaultValueExpression toe = ParseUtilCSharp.ParseExpression<DefaultValueExpression>("default(global::MyNamespace.N1.MyType)");
Assert.IsTrue(toe.TypeReference.IsGlobal);
Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type);
ParseUtilCSharp.AssertExpression(
"default(global::MyNamespace.N1.MyType)",
new DefaultValueExpression {
Type = new MemberType {
Target = new MemberType {
Target = new MemberType {
Target = new SimpleType("global"),
IsDoubleColon = true,
MemberName = "MyNamespace"
},
MemberName = "N1"
},
MemberName = "MyType"
}
});
}
[Test]
public void GenericDefaultValue()
{
DefaultValueExpression toe = ParseUtilCSharp.ParseExpression<DefaultValueExpression>("default(MyNamespace.N1.MyType<string>)");
Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type);
Assert.AreEqual("System.String", toe.TypeReference.GenericTypes[0].Type);
ParseUtilCSharp.AssertExpression(
"default(MyNamespace.N1.MyType<string>)",
new DefaultValueExpression {
Type = new MemberType {
Target = new MemberType {
Target = new SimpleType("MyNamespace"),
MemberName = "N1"
},
MemberName = "MyType",
TypeArguments = { new PrimitiveType("string") }
}
});
}
[Test]
public void DefaultValueAsIntializer()
{
// This test is failing because we need a resolver for the "default:" / "default(" conflict.
LocalVariableDeclaration lvd = ParseUtilCSharp.ParseStatement<LocalVariableDeclaration>("T a = default(T);");
DefaultValueExpression dve = (DefaultValueExpression)lvd.Variables[0].Initializer;
Assert.AreEqual("T", dve.TypeReference.Type);
// This test was problematic (in old NRefactory) because we need a resolver for the "default:" / "default(" conflict.
ParseUtilCSharp.AssertStatement(
"T a = default(T);",
new VariableDeclarationStatement {
Type = new SimpleType("T"),
Variables = {
new VariableInitializer("a", new DefaultValueExpression { Type = new SimpleType("T") })
}});
}
[Test]
public void DefaultValueInReturnStatement()
{
ReturnStatement rs = ParseUtilCSharp.ParseStatement<ReturnStatement>("return default(T);");
DefaultValueExpression dve = (DefaultValueExpression)rs.Expression;
Assert.AreEqual("T", dve.TypeReference.Type);
}*/
ParseUtilCSharp.AssertStatement(
"return default(T);",
new ReturnStatement {
Expression = new DefaultValueExpression { Type = new SimpleType("T") }
});
}
}
}

28
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/IdentifierExpressionTests.cs

@ -39,7 +39,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -39,7 +39,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
CheckIdentifier(@"l\U00000065xer", "lexer");
}
[Test]
[Test, Ignore("The @ should not be part of IdentifierExpression.Identifier")]
public void TestKeyWordAsIdentifier()
{
CheckIdentifier("@int", "int");
@ -51,28 +51,36 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -51,28 +51,36 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
CheckIdentifier(@"i\u006et", "int");
}
[Test]
[Test, Ignore("The @ should not be part of IdentifierExpression.Identifier")]
public void TestKeyWordAsIdentifierStartingWithUnderscore()
{
CheckIdentifier("@_int", "_int");
}
[Test, Ignore]
[Test]
public void GenericMethodReference()
{
IdentifierExpression ident = ParseUtilCSharp.ParseExpression<IdentifierExpression>("M<int>");
Assert.AreEqual("M", ident.Identifier);
//Assert.AreEqual(1, ident.TypeArguments.Count);
throw new NotImplementedException();
Assert.IsNotNull(
new IdentifierExpression {
Identifier = "M" ,
TypeArguments = {
new PrimitiveType("int")
}
}.Match(ident));
}
[Test, Ignore]
[Test]
public void GenericMethodReference2()
{
IdentifierExpression ident = ParseUtilCSharp.ParseExpression<IdentifierExpression>("TargetMethod<string>");
Assert.AreEqual("TargetMethod", ident.Identifier);
//Assert.AreEqual(1, ident.TypeArguments.Count);
throw new NotImplementedException();
Assert.IsNotNull(
new IdentifierExpression {
Identifier = "TargetMethod" ,
TypeArguments = {
new PrimitiveType("string")
}
}.Match(ident));
}
}
}

177
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/InvocationExpressionTests.cs

@ -7,7 +7,7 @@ using NUnit.Framework; @@ -7,7 +7,7 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
{
[TestFixture, Ignore("Port unit tests to new DOM")]
[TestFixture]
public class InvocationExpressionTests
{
[Test]
@ -19,55 +19,71 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -19,55 +19,71 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
Assert.AreEqual("myMethod", ((IdentifierExpression)ie.Target).Identifier);
}
/* TODO port unit tests to new DOM
[Test]
public void GenericInvocationExpressionTest()
{
var expr = ParseUtilCSharp.ParseExpression<InvocationExpression>("myMethod<char>('a')");
Assert.AreEqual(1, expr.Arguments.Count());
Assert.IsTrue(expr.TargetObject is IdentifierExpression);
IdentifierExpression ident = (IdentifierExpression)expr.TargetObject;
Assert.AreEqual("myMethod", ident.Identifier);
Assert.AreEqual(1, ident.TypeArguments.Count);
Assert.AreEqual("System.Char", ident.TypeArguments[0].Type);
ParseUtilCSharp.AssertExpression(
"myMethod<char>('a')",
new InvocationExpression {
Target = new IdentifierExpression {
Identifier = "myMethod",
TypeArguments = { new PrimitiveType("char") }
},
Arguments = { new PrimitiveExpression('a') }
}
);
}
[Test]
public void GenericInvocation2ExpressionTest()
{
var expr = ParseUtilCSharp.ParseExpression<InvocationExpression>("myMethod<T,bool>()");
Assert.AreEqual(0, expr.Arguments.Count);
Assert.IsTrue(expr.TargetObject is IdentifierExpression);
IdentifierExpression ident = (IdentifierExpression)expr.TargetObject;
Assert.AreEqual("myMethod", ident.Identifier);
Assert.AreEqual(2, ident.TypeArguments.Count);
Assert.AreEqual("T", ident.TypeArguments[0].Type);
Assert.IsFalse(ident.TypeArguments[0].IsKeyword);
Assert.AreEqual("System.Boolean", ident.TypeArguments[1].Type);
Assert.IsTrue(ident.TypeArguments[1].IsKeyword);
ParseUtilCSharp.AssertExpression(
"myMethod<T,bool>()",
new InvocationExpression {
Target = new IdentifierExpression {
Identifier = "myMethod",
TypeArguments = {
new SimpleType("T"),
new PrimitiveType("bool")
}
}
}
);
}
[Test]
public void AmbiguousGrammarGenericMethodCall()
{
InvocationExpression ie = ParseUtilCSharp.ParseExpression<InvocationExpression>("F(G<A,B>(7))");
Assert.IsTrue(ie.TargetObject is IdentifierExpression);
Assert.AreEqual(1, ie.Arguments.Count);
ie = (InvocationExpression)ie.Arguments[0];
Assert.AreEqual(1, ie.Arguments.Count);
Assert.IsTrue(ie.Arguments[0] is PrimitiveExpression);
IdentifierExpression ident = (IdentifierExpression)ie.TargetObject;
Assert.AreEqual("G", ident.Identifier);
Assert.AreEqual(2, ident.TypeArguments.Count);
ParseUtilCSharp.AssertExpression(
"F(G<A,B>(7))",
new InvocationExpression {
Target = new IdentifierExpression("F"),
Arguments = {
new InvocationExpression {
Target = new IdentifierExpression {
Identifier = "G",
TypeArguments = { new SimpleType("A"), new SimpleType("B") }
},
Arguments = { new PrimitiveExpression(7) }
}}});
}
[Test]
[Test, Ignore("Mono Parser Bug???")]
public void AmbiguousGrammarNotAGenericMethodCall()
{
BinaryOperatorExpression boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>("F<A>+y");
Assert.AreEqual(BinaryOperatorType.GreaterThan, boe.Op);
Assert.IsTrue(boe.Left is BinaryOperatorExpression);
Assert.IsTrue(boe.Right is UnaryOperatorExpression);
ParseUtilCSharp.AssertExpression(
"F<A>+y",
new BinaryOperatorExpression {
Left = new BinaryOperatorExpression {
Left = new IdentifierExpression("F"),
Operator = BinaryOperatorType.LessThan,
Right = new IdentifierExpression("A")
},
Operator = BinaryOperatorType.GreaterThan,
Right = new UnaryOperatorExpression {
Operator = UnaryOperatorType.Plus,
Expression = new IdentifierExpression("y")
}});
}
[Test]
@ -76,80 +92,81 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -76,80 +92,81 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
// this test was written because this bug caused the AbstractASTVisitor to crash
InvocationExpression expr = ParseUtilCSharp.ParseExpression<InvocationExpression>("WriteLine(myMethod(,))", true);
Assert.IsTrue(expr.TargetObject is IdentifierExpression);
Assert.AreEqual("WriteLine", ((IdentifierExpression)expr.TargetObject).Identifier);
Assert.IsTrue(expr.Target is IdentifierExpression);
Assert.AreEqual("WriteLine", ((IdentifierExpression)expr.Target).Identifier);
Assert.AreEqual(1, expr.Arguments.Count); // here a second null parameter was added incorrectly
Assert.IsTrue(expr.Arguments[0] is InvocationExpression);
CheckSimpleInvoke((InvocationExpression)expr.Arguments[0]);
Assert.IsTrue(expr.Arguments.Single() is InvocationExpression);
}
[Test]
[Test, Ignore("Positions not yet accurate when parsing expression only (because class/method is added around it)")]
public void NestedInvocationPositions()
{
InvocationExpression expr = ParseUtilCSharp.ParseExpression<InvocationExpression>("a.B().C(args)");
Assert.AreEqual(new Location(8, 1), expr.StartLocation);
Assert.AreEqual(new Location(14, 1), expr.EndLocation);
MemberReferenceExpression mre = (MemberReferenceExpression)expr.TargetObject;
Assert.AreEqual(new Location(6, 1), mre.StartLocation);
Assert.AreEqual(new Location(8, 1), mre.EndLocation);
Assert.AreEqual(new AstLocation(1, 8), expr.StartLocation);
Assert.AreEqual(new AstLocation(1, 14), expr.EndLocation);
MemberReferenceExpression mre = (MemberReferenceExpression)expr.Target;
Assert.AreEqual(new AstLocation(1, 6), mre.StartLocation);
Assert.AreEqual(new AstLocation(1, 8), mre.EndLocation);
Assert.AreEqual(new Location(4, 1), mre.TargetObject.StartLocation);
Assert.AreEqual(new Location(6, 1), mre.TargetObject.EndLocation);
Assert.AreEqual(new AstLocation(1, 4), mre.Target.StartLocation);
Assert.AreEqual(new AstLocation(1, 6), mre.Target.EndLocation);
}
[Test]
public void InvocationOnGenericType()
{
InvocationExpression expr = ParseUtilCSharp.ParseExpression<InvocationExpression>("A<T>.Foo()");
MemberReferenceExpression mre = (MemberReferenceExpression)expr.TargetObject;
Assert.AreEqual("Foo", mre.MemberName);
TypeReferenceExpression tre = (TypeReferenceExpression)mre.TargetObject;
Assert.AreEqual("A", tre.TypeReference.Type);
Assert.AreEqual("T", tre.TypeReference.GenericTypes[0].Type);
ParseUtilCSharp.AssertExpression(
"A<T>.Foo()",
new IdentifierExpression {
Identifier = "A",
TypeArguments = { new SimpleType("T") }
}.Invoke("Foo")
);
}
[Test]
public void InvocationOnInnerClassInGenericType()
{
InvocationExpression expr = ParseUtilCSharp.ParseExpression<InvocationExpression>("A<T>.B.Foo()");
MemberReferenceExpression mre = (MemberReferenceExpression)expr.TargetObject;
Assert.AreEqual("Foo", mre.MemberName);
MemberReferenceExpression mre2 = (MemberReferenceExpression)mre.TargetObject;
Assert.AreEqual("B", mre2.MemberName);
TypeReferenceExpression tre = (TypeReferenceExpression)mre2.TargetObject;
Assert.AreEqual("A", tre.TypeReference.Type);
Assert.AreEqual("T", tre.TypeReference.GenericTypes[0].Type);
ParseUtilCSharp.AssertExpression(
"A<T>.B.Foo()",
new IdentifierExpression {
Identifier = "A",
TypeArguments = { new SimpleType("T") }
}.Member("B").Invoke("Foo")
);
}
[Test]
public void InvocationOnGenericInnerClassInGenericType()
{
InvocationExpression expr = ParseUtilCSharp.ParseExpression<InvocationExpression>("A<T>.B.C<U>.Foo()");
MemberReferenceExpression mre = (MemberReferenceExpression)expr.TargetObject;
Assert.AreEqual("Foo", mre.MemberName);
TypeReferenceExpression tre = (TypeReferenceExpression)mre.TargetObject;
InnerClassTypeReference ictr = (InnerClassTypeReference)tre.TypeReference;
Assert.AreEqual("B.C", ictr.Type);
Assert.AreEqual(1, ictr.GenericTypes.Count);
Assert.AreEqual("U", ictr.GenericTypes[0].Type);
Assert.AreEqual("A", ictr.BaseType.Type);
Assert.AreEqual(1, ictr.BaseType.GenericTypes.Count);
Assert.AreEqual("T", ictr.BaseType.GenericTypes[0].Type);
ParseUtilCSharp.AssertExpression(
"A<T>.B.C<U>.Foo()",
new MemberReferenceExpression {
Target = new IdentifierExpression {
Identifier = "A",
TypeArguments = { new SimpleType("T") }
}.Member("B"),
MemberName = "C",
TypeArguments = { new SimpleType("U") }
}.Invoke("Foo"));
}
[Test]
[Test, Ignore("named arguments not yet supported")]
public void InvocationWithNamedArgument()
{
InvocationExpression expr = ParseUtilCSharp.ParseExpression<InvocationExpression>("a(arg: ref v)");
Assert.AreEqual(1, expr.Arguments.Count);
NamedArgumentExpression nae = (NamedArgumentExpression)expr.Arguments[0];
Assert.AreEqual("arg", nae.Name);
DirectionExpression dir = (DirectionExpression)nae.Expression;
Assert.AreEqual(FieldDirection.Ref, dir.FieldDirection);
Assert.IsInstanceOf<IdentifierExpression>(dir.Expression);
}*/
ParseUtilCSharp.AssertExpression(
"a(arg: ref v)",
new InvocationExpression {
Target = new IdentifierExpression("a"),
Arguments = {
new NamedArgumentExpression {
Identifier = "arg",
Expression = new DirectionExpression {
FieldDirection = FieldDirection.Ref,
Expression = new IdentifierExpression("v")
}}}});
}
}
}

15
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/IsExpressionTests.cs

@ -9,15 +9,16 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -9,15 +9,16 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
[TestFixture]
public class IsExpressionTests
{
[Test, Ignore]
[Test]
public void GenericArrayIsExpression()
{
/* TODO
TypeOfIsExpression ce = ParseUtilCSharp.ParseExpression<TypeOfIsExpression>("o is List<string>[]");
Assert.AreEqual("List", ce.TypeReference.Type);
Assert.AreEqual("System.String", ce.TypeReference.GenericTypes[0].Type);
Assert.AreEqual(new int[] { 0 }, ce.TypeReference.RankSpecifier);
Assert.IsTrue(ce.Expression is IdentifierExpression);*/
ParseUtilCSharp.AssertExpression(
"o is List<string>[]",
new IsExpression {
Expression = new IdentifierExpression("o"),
Type = new SimpleType("List") { TypeArguments = { new PrimitiveType("string") } }.MakeArrayType(1)
}
);
}
[Test]

117
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/LambdaExpressionTests.cs

@ -6,84 +6,103 @@ using NUnit.Framework; @@ -6,84 +6,103 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
{
[TestFixture, Ignore("Port unit tests")]
[TestFixture]
public class LambdaExpressionTests
{
static LambdaExpression ParseCSharp(string program)
{
return ParseUtilCSharp.ParseExpression<LambdaExpression>(program);
}
[Test]
[Test, Ignore("Lambdas with expression body not yet supported")]
public void ImplicitlyTypedExpressionBody()
{
/*
LambdaExpression e = ParseCSharp("(x) => x + 1");
Assert.AreEqual("x", e.Parameters[0].ParameterName);
Assert.IsTrue(e.Parameters[0].TypeReference.IsNull);
Assert.IsTrue(e.ExpressionBody is BinaryOperatorExpression);
Assert.IsTrue(e.ReturnType.IsNull);*/
throw new NotImplementedException();
ParseUtilCSharp.AssertExpression(
"(x) => x + 1",
new LambdaExpression {
Parameters = { new ParameterDeclaration { Name = "x" } },
Body = new BinaryOperatorExpression(new IdentifierExpression("x"), BinaryOperatorType.Add, new PrimitiveExpression(1))
});
}
/* TODO Port unit tests
[Test]
[Test, Ignore("Lambdas with expression body not yet supported")]
public void ImplicitlyTypedExpressionBodyWithoutParenthesis()
{
LambdaExpression e = ParseCSharp("x => x + 1");
Assert.AreEqual("x", e.Parameters[0].ParameterName);
Assert.IsTrue(e.Parameters[0].TypeReference.IsNull);
Assert.IsTrue(e.ExpressionBody is BinaryOperatorExpression);
Assert.IsTrue(e.ReturnType.IsNull);
ParseUtilCSharp.AssertExpression(
"x => x + 1",
new LambdaExpression {
Parameters = { new ParameterDeclaration { Name = "x" } },
Body = new BinaryOperatorExpression(new IdentifierExpression("x"), BinaryOperatorType.Add, new PrimitiveExpression(1))
});
}
[Test]
public void ImplicitlyTypedStatementBody()
{
LambdaExpression e = ParseCSharp("(x) => { return x + 1; }");
Assert.AreEqual("x", e.Parameters[0].ParameterName);
Assert.IsTrue(e.Parameters[0].TypeReference.IsNull);
Assert.IsTrue(e.StatementBody.Children[0] is ReturnStatement);
Assert.IsTrue(e.ReturnType.IsNull);
ParseUtilCSharp.AssertExpression(
"(x) => { return x + 1; }",
new LambdaExpression {
Parameters = { new ParameterDeclaration { Name = "x" } },
Body = new BlockStatement {
new ReturnStatement {
Expression = new BinaryOperatorExpression(
new IdentifierExpression("x"), BinaryOperatorType.Add, new PrimitiveExpression(1))
}}});
}
[Test]
public void ImplicitlyTypedStatementBodyWithoutParenthesis()
{
LambdaExpression e = ParseCSharp("x => { return x + 1; }");
Assert.AreEqual("x", e.Parameters[0].ParameterName);
Assert.IsTrue(e.Parameters[0].TypeReference.IsNull);
Assert.IsTrue(e.StatementBody.Children[0] is ReturnStatement);
Assert.IsTrue(e.ReturnType.IsNull);
ParseUtilCSharp.AssertExpression(
"x => { return x + 1; }",
new LambdaExpression {
Parameters = { new ParameterDeclaration { Name = "x" } },
Body = new BlockStatement {
new ReturnStatement {
Expression = new BinaryOperatorExpression(
new IdentifierExpression("x"), BinaryOperatorType.Add, new PrimitiveExpression(1))
}}});
}
[Test]
public void ExplicitlyTypedStatementBody()
{
LambdaExpression e = ParseCSharp("(int x) => { return x + 1; }");
Assert.AreEqual("x", e.Parameters[0].ParameterName);
Assert.AreEqual("System.Int32", e.Parameters[0].TypeReference.Type);
Assert.IsTrue(e.StatementBody.Children[0] is ReturnStatement);
Assert.IsTrue(e.ReturnType.IsNull);
ParseUtilCSharp.AssertExpression(
"(int x) => { return x + 1; }",
new LambdaExpression {
Parameters = { new ParameterDeclaration { Type = new PrimitiveType("int"), Name = "x" } },
Body = new BlockStatement {
new ReturnStatement {
Expression = new BinaryOperatorExpression(
new IdentifierExpression("x"), BinaryOperatorType.Add, new PrimitiveExpression(1))
}}});
}
[Test]
public void ExplicitlyTypedStatementBodyWithRefParameter()
[Test, Ignore("Lambdas with expression body not yet supported")]
public void ExplicitlyTypedWithRefParameter()
{
LambdaExpression e = ParseCSharp("(ref int i) => i = 1");
Assert.AreEqual("i", e.Parameters[0].ParameterName);
Assert.IsTrue((e.Parameters[0].ParamModifier & ParameterModifiers.Ref) == ParameterModifiers.Ref);
Assert.AreEqual("System.Int32", e.Parameters[0].TypeReference.Type);
Assert.IsTrue(e.ReturnType.IsNull);
ParseUtilCSharp.AssertExpression(
"(ref int i) => i = 1",
new LambdaExpression {
Parameters = {
new ParameterDeclaration {
ParameterModifier = ParameterModifier.Ref,
Type = new PrimitiveType("int"),
Name = "x"
}
},
Body = new AssignmentExpression(new IdentifierExpression("i"), new PrimitiveExpression(1))
});
}
[Test]
[Test, Ignore("Lambdas with expression body not yet supported")]
public void LambdaExpressionContainingConditionalExpression()
{
LambdaExpression e = ParseCSharp("rr => rr != null ? rr.ResolvedType : null");
Assert.AreEqual("rr", e.Parameters[0].ParameterName);
Assert.IsTrue(e.ExpressionBody is ConditionalExpression);
Assert.IsTrue(e.ReturnType.IsNull);
}*/
ParseUtilCSharp.AssertExpression(
"rr => rr != null ? rr.ResolvedType : null",
new LambdaExpression {
Parameters = { new ParameterDeclaration { Name = "rr" } },
Body = new ConditionalExpression {
Condition = new BinaryOperatorExpression(
new IdentifierExpression("rr"), BinaryOperatorType.InEquality, new NullReferenceExpression()),
TrueExpression = new IdentifierExpression("rr").Member("ResolvedType"),
FalseExpression = new NullReferenceExpression()
}});
}
}
}

97
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/MemberReferenceExpressionTests.cs

@ -6,71 +6,84 @@ using NUnit.Framework; @@ -6,71 +6,84 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
{
[TestFixture, Ignore]
[TestFixture]
public class MemberReferenceExpressionTests
{
[Test]
public void SimpleFieldReferenceExpressionTest()
{
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("myTargetObject.myField");
//Assert.AreEqual("myField", fre.MemberName);
//Assert.IsTrue(fre.TargetObject is IdentifierExpression);
//Assert.AreEqual("myTargetObject", ((IdentifierExpression)fre.TargetObject).Identifier);
throw new NotImplementedException();
ParseUtilCSharp.AssertExpression(
"myTargetObject.myField",
new IdentifierExpression("myTargetObject").Member("myField")
);
}
[Test, Ignore("parser is broken and produces IdentifierExpression instead of PrimitiveType")]
public void ShortMaxValueTest()
{
ParseUtilCSharp.AssertExpression(
"short.MaxValue",
new PrimitiveType("short").Member("MaxValue")
);
}
[Test, Ignore("Parsing of @-identifiers is broken")]
public void IdentShortMaxValueTest()
{
ParseUtilCSharp.AssertExpression(
"@short.MaxValue",
new IdentifierExpression("short").Member("MaxValue")
);
}
/* TODO port unit tests
[Test]
public void GenericFieldReferenceExpressionTest()
{
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("SomeClass<string>.myField");
Assert.AreEqual("myField", fre.MemberName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference;
Assert.AreEqual("SomeClass", tr.Type);
Assert.AreEqual(1, tr.GenericTypes.Count);
Assert.AreEqual("System.String", tr.GenericTypes[0].Type);
ParseUtilCSharp.AssertExpression(
"SomeClass<string>.myField",
new IdentifierExpression("SomeClass") { TypeArguments = { new PrimitiveType("string") } }.Member("myField")
);
}
[Test]
public void FullNamespaceGenericFieldReferenceExpressionTest()
{
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("Namespace.Subnamespace.SomeClass<string>.myField");
Assert.AreEqual("myField", fre.MemberName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference;
Assert.AreEqual("Namespace.Subnamespace.SomeClass", tr.Type);
Assert.AreEqual(1, tr.GenericTypes.Count);
Assert.AreEqual("System.String", tr.GenericTypes[0].Type);
ParseUtilCSharp.AssertExpression(
"Namespace.Subnamespace.SomeClass<string>.myField",
new MemberReferenceExpression {
Target = new IdentifierExpression("Namespace").Member("Subnamespace"),
TypeArguments = { new PrimitiveType("string") }
}.Member("myField")
);
}
[Test]
[Test, Ignore("Aliases not yet implemented")]
public void GlobalFullNamespaceGenericFieldReferenceExpressionTest()
{
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("global::Namespace.Subnamespace.SomeClass<string>.myField");
Assert.AreEqual("myField", fre.MemberName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
TypeReference tr = ((TypeReferenceExpression)fre.TargetObject).TypeReference;
Assert.IsFalse(tr is InnerClassTypeReference);
Assert.AreEqual("Namespace.Subnamespace.SomeClass", tr.Type);
Assert.AreEqual(1, tr.GenericTypes.Count);
Assert.AreEqual("System.String", tr.GenericTypes[0].Type);
Assert.IsTrue(tr.IsGlobal);
ParseUtilCSharp.AssertExpression(
"global::Namespace.Subnamespace.SomeClass<string>.myField",
new MemberReferenceExpression {
Target = new MemberType {
Target = new SimpleType("global"),
IsDoubleColon = true,
MemberName = "Namespace"
}.Member("Subnamespace"),
TypeArguments = { new PrimitiveType("string") }
}.Member("myField")
);
}
[Test]
public void NestedGenericFieldReferenceExpressionTest()
{
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("MyType<string>.InnerClass<int>.myField");
Assert.AreEqual("myField", fre.MemberName);
Assert.IsTrue(fre.TargetObject is TypeReferenceExpression);
InnerClassTypeReference ic = (InnerClassTypeReference)((TypeReferenceExpression)fre.TargetObject).TypeReference;
Assert.AreEqual("InnerClass", ic.Type);
Assert.AreEqual(1, ic.GenericTypes.Count);
Assert.AreEqual("System.Int32", ic.GenericTypes[0].Type);
Assert.AreEqual("MyType", ic.BaseType.Type);
Assert.AreEqual(1, ic.BaseType.GenericTypes.Count);
Assert.AreEqual("System.String", ic.BaseType.GenericTypes[0].Type);
}*/
ParseUtilCSharp.AssertExpression(
"MyType<string>.InnerClass<int>.myField",
new MemberReferenceExpression {
Target = new IdentifierExpression("MyType") { TypeArguments = { new PrimitiveType("string") } },
MemberName = "InnerClass",
TypeArguments = { new PrimitiveType("int") }
}.Member("myField")
);
}
}
}

18
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/PointerReferenceExpressionTests.cs

@ -9,13 +9,25 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -9,13 +9,25 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
[TestFixture]
public class PointerReferenceExpressionTests
{
[Test, Ignore("where did PointerReferenceExpression.MemberName go?")]
[Test, Ignore("Parser bug!")]
public void PointerReferenceExpressionTest()
{
PointerReferenceExpression pre = ParseUtilCSharp.ParseExpression<PointerReferenceExpression>("myObj.field->b");
Assert.IsTrue(pre.Target is MemberReferenceExpression);
//Assert.AreEqual("b", pre.MemberName);
throw new NotImplementedException();
Assert.AreEqual("b", pre.MemberName);
}
[Test, Ignore("Parser bug!")]
public void PointerReferenceGenericMethodTest()
{
ParseUtilCSharp.AssertExpression(
"ptr->M<string>();",
new InvocationExpression {
Target = new PointerReferenceExpression {
Target = new IdentifierExpression("ptr"),
MemberName = "M",
TypeArguments = { new PrimitiveType("string") }
}});
}
}
}

232
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/QueryExpressionTests.cs

@ -6,104 +6,220 @@ using NUnit.Framework; @@ -6,104 +6,220 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
{
[TestFixture, Ignore]
[TestFixture, Ignore("Query expressions not yet implemented")]
public class QueryExpressionTests
{
[Test]
public void SimpleExpression()
{
/*
QueryExpression qe = ParseUtilCSharp.ParseExpression<QueryExpression>(
"from c in customers where c.City == \"London\" select c"
);
Assert.AreEqual("c", qe.FromClause.Sources.First().Identifier);
Assert.AreEqual("customers", ((IdentifierExpression)qe.FromClause.Sources.First().Expression).Identifier);
Assert.AreEqual(1, qe.MiddleClauses.Count);
Assert.IsInstanceOf(typeof(QueryExpressionWhereClause), qe.MiddleClauses[0]);
QueryExpressionWhereClause wc = (QueryExpressionWhereClause)qe.MiddleClauses[0];
Assert.IsInstanceOf(typeof(BinaryOperatorExpression), wc.Condition);
Assert.IsInstanceOf(typeof(QueryExpressionSelectClause), qe.SelectOrGroupClause);*/
throw new NotImplementedException();
ParseUtilCSharp.AssertExpression(
"from c in customers where c.City == \"London\" select c",
new QueryExpression {
Clauses = {
new QueryFromClause {
Identifier = "c",
Expression = new IdentifierExpression("customers")
},
new QueryWhereClause {
Condition = new BinaryOperatorExpression {
Left = new IdentifierExpression("c").Member("City"),
Operator = BinaryOperatorType.Equality,
Right = new PrimitiveExpression("London")
}
},
new QuerySelectClause {
Expression = new IdentifierExpression("c")
}
}});
}
/* TODO port unit tests
[Test]
public void ExpressionWithType1()
{
QueryExpression qe = ParseUtilCSharp.ParseExpression<QueryExpression>(
"from Customer c in customers select c"
);
Assert.AreEqual("c", qe.FromClause.Sources.First().Identifier);
Assert.AreEqual("Customer", qe.FromClause.Sources.First().Type.ToString());
Assert.AreEqual("customers", ((IdentifierExpression)qe.FromClause.Sources.First().Expression).Identifier);
Assert.IsInstanceOf(typeof(QueryExpressionSelectClause), qe.SelectOrGroupClause);
ParseUtilCSharp.AssertExpression(
"from Customer c in customers select c",
new QueryExpression {
Clauses = {
new QueryFromClause {
Type = new SimpleType("Customer"),
Identifier = "c",
Expression = new IdentifierExpression("customers")
},
new QuerySelectClause {
Expression = new IdentifierExpression("c")
}
}});
}
[Test]
public void ExpressionWithType2()
{
QueryExpression qe = ParseUtilCSharp.ParseExpression<QueryExpression>(
"from int c in customers select c"
);
Assert.AreEqual("c", qe.FromClause.Sources.First().Identifier);
Assert.AreEqual("System.Int32", qe.FromClause.Sources.First().Type.Type);
Assert.AreEqual("customers", ((IdentifierExpression)qe.FromClause.Sources.First().Expression).Identifier);
Assert.IsInstanceOf(typeof(QueryExpressionSelectClause), qe.SelectOrGroupClause);
ParseUtilCSharp.AssertExpression(
"from int c in customers select c",
new QueryExpression {
Clauses = {
new QueryFromClause {
Type = new PrimitiveType("int"),
Identifier = "c",
Expression = new IdentifierExpression("customers")
},
new QuerySelectClause {
Expression = new IdentifierExpression("c")
}
}});
}
[Test]
public void ExpressionWithType3()
{
QueryExpression qe = ParseUtilCSharp.ParseExpression<QueryExpression>(
"from S<int[]>? c in customers select c"
);
Assert.AreEqual("c", qe.FromClause.Sources.First().Identifier);
Assert.AreEqual("System.Nullable<S<System.Int32[]>>", qe.FromClause.Sources.First().Type.ToString());
Assert.AreEqual("customers", ((IdentifierExpression)qe.FromClause.Sources.First().Expression).Identifier);
Assert.IsInstanceOf(typeof(QueryExpressionSelectClause), qe.SelectOrGroupClause);
ParseUtilCSharp.AssertExpression(
"from S<int[]>? c in customers select c",
new QueryExpression {
Clauses = {
new QueryFromClause {
Type = new ComposedType {
BaseType = new SimpleType {
Identifier = "S",
TypeArguments = {
new PrimitiveType("int").MakeArrayType()
}
},
HasNullableSpecifier = true
},
Identifier = "c",
Expression = new IdentifierExpression("customers")
},
new QuerySelectClause {
Expression = new IdentifierExpression("c")
}
}});
}
[Test]
public void MultipleGenerators()
{
QueryExpression qe = ParseUtilCSharp.ParseExpression<QueryExpression>(@"
ParseUtilCSharp.AssertExpression(
@"
from c in customers
where c.City == ""London""
from o in c.Orders
where o.OrderDate.Year == 2005
select new { c.Name, o.OrderID, o.Total }");
Assert.AreEqual(3, qe.MiddleClauses.Count);
Assert.IsInstanceOf(typeof(QueryExpressionWhereClause), qe.MiddleClauses[0]);
Assert.IsInstanceOf(typeof(QueryExpressionFromClause), qe.MiddleClauses[1]);
Assert.IsInstanceOf(typeof(QueryExpressionWhereClause), qe.MiddleClauses[2]);
Assert.IsInstanceOf(typeof(QueryExpressionSelectClause), qe.SelectOrGroupClause);
select new { c.Name, o.OrderID, o.Total }",
new QueryExpression {
Clauses = {
new QueryFromClause {
Identifier = "c",
Expression = new IdentifierExpression("customers")
},
new QueryWhereClause {
Condition = new BinaryOperatorExpression {
Left = new IdentifierExpression("c").Member("City"),
Operator = BinaryOperatorType.Equality,
Right = new PrimitiveExpression("London")
}
},
new QueryFromClause {
Identifier = "o",
Expression = new IdentifierExpression("c").Member("Orders")
},
new QueryWhereClause {
Condition = new BinaryOperatorExpression {
Left = new IdentifierExpression("c").Member("OrderDate").Member("Year"),
Operator = BinaryOperatorType.Equality,
Right = new PrimitiveExpression(2005)
}
},
new QuerySelectClause {
Expression = new ObjectCreateExpression {
Initializer = new ArrayInitializerExpression {
Elements = {
new IdentifierExpression("c").Member("Name"),
new IdentifierExpression("o").Member("OrderID"),
new IdentifierExpression("o").Member("Total")
}
}
}
}
}});
}
[Test]
public void ExpressionWithOrderBy()
{
QueryExpression qe = ParseUtilCSharp.ParseExpression<QueryExpression>(
"from c in customers orderby c.Name select c"
);
Assert.AreEqual("c", qe.FromClause.Sources.First().Identifier);
Assert.AreEqual("customers", ((IdentifierExpression)qe.FromClause.Sources.First().Expression).Identifier);
Assert.IsInstanceOf(typeof(QueryExpressionOrderClause), qe.MiddleClauses[0]);
Assert.IsInstanceOf(typeof(QueryExpressionSelectClause), qe.SelectOrGroupClause);
ParseUtilCSharp.AssertExpression(
"from c in customers orderby c.Name select c",
new QueryExpression {
Clauses = {
new QueryFromClause {
Identifier = "c",
Expression = new IdentifierExpression("customers")
},
new QueryOrderClause {
Orderings = {
new QueryOrdering {
Expression = new IdentifierExpression("c").Member("Name")
}
}
},
new QuerySelectClause {
Expression = new IdentifierExpression("c")
}
}});
}
[Test]
public void ExpressionWithOrderByAndLet()
{
QueryExpression qe = ParseUtilCSharp.ParseExpression<QueryExpression>(
"from c in customers orderby c.Name let x = c select x"
ParseUtilCSharp.AssertExpression(
"from c in customers orderby c.Name descending let x = c select x",
new QueryExpression {
Clauses = {
new QueryFromClause {
Identifier = "c",
Expression = new IdentifierExpression("customers")
},
new QueryOrderClause {
Orderings = {
new QueryOrdering {
Expression = new IdentifierExpression("c").Member("Name"),
Direction = QueryOrderingDirection.Descending
}
}
},
new QueryLetClause {
Identifier = "x",
Expression = new IdentifierExpression("c")
},
new QuerySelectClause {
Expression = new IdentifierExpression("x")
}
}});
}
[Test]
public void QueryContinuation()
{
ParseUtilCSharp.AssertExpression(
"from a in b select c into d select e",
new QueryExpression {
Clauses = {
new QueryContinuationClause {
PrecedingQuery = new QueryExpression {
Clauses = {
new QueryFromClause {
Identifier = "a",
Expression = new IdentifierExpression("b")
},
new QuerySelectClause { Expression = new IdentifierExpression("c") }
}
},
Identifier = "d"
},
new QuerySelectClause { Expression = new IdentifierExpression("e") }
}
}
);
Assert.AreEqual("c", qe.FromClause.Sources.First().Identifier);
Assert.AreEqual("customers", ((IdentifierExpression)qe.FromClause.Sources.First().Expression).Identifier);
Assert.IsInstanceOf(typeof(QueryExpressionOrderClause), qe.MiddleClauses[0]);
Assert.IsInstanceOf(typeof(QueryExpressionLetClause), qe.MiddleClauses[1]);
Assert.IsInstanceOf(typeof(QueryExpressionSelectClause), qe.SelectOrGroupClause);
}*/
}
}
}

4
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/SizeOfExpressionTests.cs

@ -9,11 +9,11 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -9,11 +9,11 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
[TestFixture]
public class SizeOfExpressionTests
{
[Test, Ignore("type references not implemented yet")]
[Test]
public void SizeOfExpressionTest()
{
SizeOfExpression soe = ParseUtilCSharp.ParseExpression<SizeOfExpression>("sizeof(MyType)");
Assert.AreEqual("MyType", soe.Type);
Assert.AreEqual("MyType", ((SimpleType)soe.Type).Identifier);
}
}
}

9
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/StackAllocExpressionTests.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Linq;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
@ -9,11 +10,13 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -9,11 +10,13 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
[TestFixture]
public class StackAllocExpressionTests
{
[Test, Ignore]
[Test]
public void StackAllocExpressionTest()
{
var sae = ParseUtilCSharp.ParseExpression<StackAllocExpression>("stackalloc int[100]");
throw new NotImplementedException(); // TODO: verify type + length expression
var vd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("int* a = stackalloc int[100];");
StackAllocExpression sae = (StackAllocExpression)vd.Variables.Single().Initializer;
Assert.AreEqual("int", ((PrimitiveType)sae.Type).Keyword);
Assert.AreEqual(100, ((PrimitiveExpression)sae.CountExpression).Value);
}
}
}

97
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/TypeOfExpressionTests.cs

@ -6,86 +6,113 @@ using NUnit.Framework; @@ -6,86 +6,113 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
{
[TestFixture, Ignore]
[TestFixture]
public class TypeOfExpressionTests
{
[Test]
public void SimpleTypeOfExpressionTest()
{
//TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(MyNamespace.N1.MyType)");
//Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type);
throw new NotImplementedException();
ParseUtilCSharp.AssertExpression(
"typeof(MyNamespace.N1.MyType)",
new TypeOfExpression {
Type = new MemberType {
Target = new MemberType {
Target = new SimpleType("MyNamespace"),
MemberName = "N1"
},
MemberName = "MyType"
}});
}
/* TODO
[Test]
[Test, Ignore("Aliases not yet implemented")]
public void GlobalTypeOfExpressionTest()
{
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(global::System.Console)");
Assert.AreEqual("System.Console", toe.TypeReference.Type);
ParseUtilCSharp.AssertExpression(
"typeof(global::System.Console)",
new TypeOfExpression {
Type = new MemberType {
Target = new MemberType {
Target = new SimpleType("global"),
IsDoubleColon = true,
MemberName = "System"
},
MemberName = "Console"
}});
}
[Test]
public void PrimitiveTypeOfExpressionTest()
{
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(int)");
Assert.AreEqual("System.Int32", toe.TypeReference.Type);
Assert.AreEqual("int", ((PrimitiveType)toe.Type).Keyword);
}
[Test]
public void VoidTypeOfExpressionTest()
{
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(void)");
Assert.AreEqual("System.Void", toe.TypeReference.Type);
Assert.AreEqual("void", ((PrimitiveType)toe.Type).Keyword);
}
[Test]
public void ArrayTypeOfExpressionTest()
{
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(MyType[])");
Assert.AreEqual("MyType", toe.TypeReference.Type);
Assert.AreEqual(new int[] {0}, toe.TypeReference.RankSpecifier);
ParseUtilCSharp.AssertExpression(
"typeof(MyType[])",
new TypeOfExpression {
Type = new SimpleType("MyType").MakeArrayType()
});
}
[Test]
public void GenericTypeOfExpressionTest()
{
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(MyNamespace.N1.MyType<string>)");
Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type);
Assert.AreEqual("System.String", toe.TypeReference.GenericTypes[0].Type);
ParseUtilCSharp.AssertExpression(
"typeof(MyNamespace.N1.MyType<string>)",
new TypeOfExpression {
Type = new MemberType {
Target = new MemberType {
Target = new SimpleType("MyNamespace"),
MemberName = "N1"
},
MemberName = "MyType",
TypeArguments = { new PrimitiveType("string") }
}});
}
[Test]
public void NestedGenericTypeOfExpressionTest()
{
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(MyType<string>.InnerClass<int>.InnerInnerClass)");
InnerClassTypeReference ic = (InnerClassTypeReference)toe.TypeReference;
Assert.AreEqual("InnerInnerClass", ic.Type);
Assert.AreEqual(0, ic.GenericTypes.Count);
ic = (InnerClassTypeReference)ic.BaseType;
Assert.AreEqual("InnerClass", ic.Type);
Assert.AreEqual(1, ic.GenericTypes.Count);
Assert.AreEqual("System.Int32", ic.GenericTypes[0].Type);
Assert.AreEqual("MyType", ic.BaseType.Type);
Assert.AreEqual(1, ic.BaseType.GenericTypes.Count);
Assert.AreEqual("System.String", ic.BaseType.GenericTypes[0].Type);
ParseUtilCSharp.AssertExpression(
"typeof(MyType<string>.InnerClass<int>.InnerInnerClass)",
new TypeOfExpression {
Type = new MemberType {
Target = new MemberType {
Target = new SimpleType("MyType") { TypeArguments = { new PrimitiveType("string") } },
MemberName = "InnerClass",
TypeArguments = { new PrimitiveType("int") }
},
MemberName = "InnerInnerClass"
}});
}
[Test]
public void NullableTypeOfExpressionTest()
{
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(MyStruct?)");
Assert.AreEqual("System.Nullable", toe.TypeReference.Type);
Assert.AreEqual("MyStruct", toe.TypeReference.GenericTypes[0].Type);
ParseUtilCSharp.AssertExpression(
"typeof(MyStruct?)",
new TypeOfExpression {
Type = new ComposedType {
BaseType = new SimpleType("MyType"),
HasNullableSpecifier = true
}});
}
[Test]
[Test, Ignore("How do we represent unbound types in the AST?")]
public void UnboundTypeOfExpressionTest()
{
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(MyType<,>)");
Assert.AreEqual("MyType", toe.TypeReference.Type);
Assert.IsTrue(toe.TypeReference.GenericTypes[0].IsNull);
Assert.IsTrue(toe.TypeReference.GenericTypes[1].IsNull);
}*/
throw new NotImplementedException("How do we represent unbound types in the AST?");
}
}
}

6
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/UnaryOperatorExpressionTests.cs

@ -84,9 +84,9 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -84,9 +84,9 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
Assert.AreEqual(UnaryOperatorType.Dereference, uoe.Operator);
ParenthesizedExpression pe = (ParenthesizedExpression)uoe.Expression;
CastExpression ce = (CastExpression)pe.Expression;
//Assert.AreEqual("SomeType", ce.CastTo.Type);
//Assert.AreEqual(1, ce.CastTo.PointerNestingLevel);
Assert.Ignore("need to check target type"); // TODO
ComposedType type = (ComposedType)ce.Type;
Assert.AreEqual("SomeType", ((SimpleType)type.BaseType).Identifier);
Assert.AreEqual(1, type.PointerRank);
UnaryOperatorExpression adrOf = (UnaryOperatorExpression)ce.Expression;
Assert.AreEqual(UnaryOperatorType.AddressOf, adrOf.Operator);

68
ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/DelegateDeclarationTests.cs

@ -7,55 +7,41 @@ using NUnit.Framework; @@ -7,55 +7,41 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
{
[TestFixture, Ignore("delegates are completely broken at the moment")]
[TestFixture]
public class DelegateDeclarationTests
{
void TestParameters(DelegateDeclaration dd)
{
Assert.AreEqual(3, dd.Parameters.Count());
Assert.AreEqual("a", ((ParameterDeclaration)dd.Parameters.ElementAt(0)).Name);
//Assert.AreEqual("System.Int32", ((ParameterDeclaration)dd.Parameters.ElementAt(0)).TypeReference.Type);
Assert.Ignore("check types"); // TODO
Assert.AreEqual("secondParam", ((ParameterDeclaration)dd.Parameters.ElementAt(1)).Name);
//Assert.AreEqual("System.Int32", ((ParameterDeclaration)dd.Parameters.ElementAt(1)).TypeReference.Type);
Assert.AreEqual("lastParam", ((ParameterDeclaration)dd.Parameters.ElementAt(2)).Name);
//Assert.AreEqual("MyObj", ((ParameterDeclaration)dd.Parameters.ElementAt(2)).TypeReference.Type);
}
[Test]
public void SimpleCSharpDelegateDeclarationTest()
{
string program = "public delegate void MyDelegate(int a, int secondParam, MyObj lastParam);\n";
DelegateDeclaration dd = ParseUtilCSharp.ParseGlobal<DelegateDeclaration>(program);
Assert.AreEqual("MyDelegate", dd.Name);
//Assert.AreEqual("System.Void", dd.ReturnType.Type);
TestParameters(dd);
ParseUtilCSharp.AssertGlobal(
"public delegate void MyDelegate(int a, int secondParam, MyObj lastParam);",
new DelegateDeclaration {
Modifiers = Modifiers.Public,
ReturnType = new PrimitiveType("void"),
Name = "MyDelegate",
Parameters = {
new ParameterDeclaration(new PrimitiveType("int"), "a"),
new ParameterDeclaration(new PrimitiveType("int"), "secondParam"),
new ParameterDeclaration(new SimpleType("MyObj"), "lastParam")
}});
}
[Test, Ignore]
public void DelegateWithoutNameDeclarationTest()
{
string program = "public delegate void(int a, int secondParam, MyObj lastParam);\n";
DelegateDeclaration dd = ParseUtilCSharp.ParseGlobal<DelegateDeclaration>(program, true);
//Assert.AreEqual("System.Void", dd.ReturnType.Type);
//Assert.AreEqual("?", dd.Name);
TestParameters(dd);
}
[Test, Ignore]
[Test, Ignore("Generics not yet supported")]
public void GenericDelegateDeclarationTest()
{
string program = "public delegate T CreateObject<T>() where T : ICloneable;\n";
DelegateDeclaration dd = ParseUtilCSharp.ParseGlobal<DelegateDeclaration>(program);
Assert.AreEqual("CreateObject", dd.Name);
//Assert.AreEqual("T", dd.ReturnType.Type);
Assert.AreEqual(0, dd.Parameters.Count());
/*Assert.AreEqual(1, dd.Templates.Count);
Assert.AreEqual("T", dd.Templates[0].Name);
Assert.AreEqual(1, dd.Templates[0].Bases.Count);
Assert.AreEqual("ICloneable", dd.Templates[0].Bases[0].Type);*/ throw new NotImplementedException();
ParseUtilCSharp.AssertGlobal(
"public delegate T CreateObject<T>() where T : ICloneable;",
new DelegateDeclaration {
Modifiers = Modifiers.Public,
ReturnType = new SimpleType("T"),
Name = "CreateObject",
TypeParameters = { new TypeParameterDeclaration { Name = "T" } },
Constraints = {
new Constraint {
TypeParameter = "T",
BaseTypes = { new SimpleType("ICloneable") }
}
}});
}
[Test]
@ -66,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope @@ -66,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
Assert.AreEqual("MyDelegate", ((DelegateDeclaration)nd.Members.Single()).Name);
}
[Test, Ignore("inner classes not yet implemented")]
[Test]
public void DelegateDeclarationInClass()
{
string program = "class Outer { delegate void Inner(); }";

198
ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/TypeDeclarationTests.cs

@ -70,85 +70,111 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope @@ -70,85 +70,111 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
Assert.AreEqual(Modifiers.Static, td.Modifiers);
}
[Test, Ignore]
[Test, Ignore("Generics not yet supported")]
public void GenericClassTypeDeclarationTest()
{
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("public class G<T> {}");
Assert.AreEqual(ClassType.Class, td.ClassType);
Assert.AreEqual("G", td.Name);
Assert.AreEqual(Modifiers.Public, td.Modifiers);
/*Assert.AreEqual(0, td.BaseTypes.Count);
Assert.AreEqual(1, td.TypeArguments.Count());
Assert.AreEqual("T", td.TypeArguments.Single().Name);*/ throw new NotImplementedException();
ParseUtilCSharp.AssertGlobal(
"public class G<T> {}",
new TypeDeclaration {
Modifiers = Modifiers.Public,
ClassType = ClassType.Class,
Name = "G",
TypeParameters = { new TypeParameterDeclaration { Name = "T" } }
});
}
[Test, Ignore]
[Test, Ignore("Constraints not yet supported")]
public void GenericClassWithWhere()
{
string declr = @"
public class Test<T> where T : IMyInterface
{
}
";
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(declr);
Assert.AreEqual(ClassType.Class, td.ClassType);
Assert.AreEqual("Test", td.Name);
/*Assert.AreEqual(1, td.Templates.Count);
Assert.AreEqual("T", td.Templates[0].Name);
Assert.AreEqual("IMyInterface", td.Templates[0].Bases[0].Type);*/ throw new NotImplementedException();
ParseUtilCSharp.AssertGlobal(
@"public class Test<T> where T : IMyInterface { }",
new TypeDeclaration {
Modifiers = Modifiers.Public,
ClassType = ClassType.Class,
Name = "Test",
TypeParameters = { new TypeParameterDeclaration { Name = "T" } },
Constraints = {
new Constraint {
TypeParameter = "T",
BaseTypes = { new SimpleType("IMyInterface") }
}
}});
}
[Test, Ignore]
[Test, Ignore("Generic classes not yet supported")]
public void ComplexGenericClassTypeDeclarationTest()
{
string declr = @"
public class Generic<T, S> : System.IComparable where S : G<T[]> where T : MyNamespace.IMyInterface
{
}
";
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(declr);
Assert.AreEqual(ClassType.Class, td.ClassType);
Assert.AreEqual("Generic", td.Name);
Assert.AreEqual(Modifiers.Public, td.Modifiers);
/*Assert.AreEqual(1, td.BaseTypes.Count);
Assert.AreEqual("System.IComparable", td.BaseTypes[0].Type);
Assert.AreEqual(2, td.Templates.Count);
Assert.AreEqual("T", td.Templates[0].Name);
Assert.AreEqual("MyNamespace.IMyInterface", td.Templates[0].Bases[0].Type);
Assert.AreEqual("S", td.Templates[1].Name);
Assert.AreEqual("G", td.Templates[1].Bases[0].Type);
Assert.AreEqual(1, td.Templates[1].Bases[0].GenericTypes.Count);
Assert.IsTrue(td.Templates[1].Bases[0].GenericTypes[0].IsArrayType);
Assert.AreEqual("T", td.Templates[1].Bases[0].GenericTypes[0].Type);
Assert.AreEqual(new int[] {0}, td.Templates[1].Bases[0].GenericTypes[0].RankSpecifier);*/ throw new NotImplementedException();
ParseUtilCSharp.AssertGlobal(
"public class Generic<in T, out S> : System.IComparable where S : G<T[]>, new() where T : MyNamespace.IMyInterface",
new TypeDeclaration {
Modifiers = Modifiers.Public,
ClassType = ClassType.Class,
Name = "Generic",
TypeParameters = {
new TypeParameterDeclaration { Variance = VarianceModifier.Contravariant, Name = "T" },
new TypeParameterDeclaration { Variance = VarianceModifier.Covariant, Name = "S" }
},
BaseTypes = {
new MemberType {
Target = new SimpleType("System"),
MemberName = "IComparable"
}
},
Constraints = {
new Constraint {
TypeParameter = "S",
BaseTypes = {
new SimpleType {
Identifier = "G",
TypeArguments = { new SimpleType("T").MakeArrayType() }
},
new PrimitiveType("new")
}
},
new Constraint {
TypeParameter = "T",
BaseTypes = {
new MemberType {
Target = new SimpleType("MyNamespace"),
MemberName = "IMyInterface"
}
}
}
}
});
}
[Test, Ignore]
[Test, Ignore("Base types not yet implemented")]
public void ComplexClassTypeDeclarationTest()
{
string declr = @"
ParseUtilCSharp.AssertGlobal(
@"
[MyAttr()]
public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
{
}
";
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(declr);
Assert.AreEqual(ClassType.Class, td.ClassType);
Assert.AreEqual("MyClass", td.Name);
Assert.AreEqual(Modifiers.Public | Modifiers.Abstract, td.Modifiers);
Assert.AreEqual(1, td.Attributes.Count());
/* Assert.AreEqual(3, td.BaseTypes.Count);
Assert.AreEqual("MyBase", td.BaseTypes[0].Type);
Assert.AreEqual("Interface1", td.BaseTypes[1].Type);
Assert.AreEqual("My.Test.Interface2", td.BaseTypes[2].Type);*/ throw new NotImplementedException();
}",
new TypeDeclaration {
Attributes = {
new AttributeSection {
Attributes = {
new Attribute { Type = new SimpleType("MyAttr") }
}
}
},
Modifiers = Modifiers.Public | Modifiers.Abstract,
ClassType = ClassType.Class,
Name = "MyClass",
BaseTypes = {
new SimpleType("MyBase"),
new SimpleType("Interface1"),
new MemberType {
Target = new MemberType {
Target = new SimpleType("My"),
MemberName = "Test"
},
MemberName = "Interface2"
}
}});
}
[Test]
@ -178,27 +204,37 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2 @@ -178,27 +204,37 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
Assert.AreEqual("MyEnum", td.Name);
}
[Test, Ignore]
[Test, Ignore("Mono parser bug?")]
public void ContextSensitiveKeywordTest()
{
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("partial class partial<[partial: where] where> where where : partial<where> { }");
Assert.AreEqual(Modifiers.Partial, td.Modifiers);
Assert.AreEqual("partial", td.Name);
/*
Assert.AreEqual(1, td.Templates.Count);
TemplateDefinition tp = td.Templates[0];
Assert.AreEqual("where", tp.Name);
Assert.AreEqual(1, tp.Attributes.Count);
Assert.AreEqual("partial", tp.Attributes[0].AttributeTarget);
Assert.AreEqual(1, tp.Attributes[0].Attributes.Count);
Assert.AreEqual("where", tp.Attributes[0].Attributes[0].Name);
Assert.AreEqual(1, tp.Bases.Count);
Assert.AreEqual("partial", tp.Bases[0].Type);
Assert.AreEqual("where", tp.Bases[0].GenericTypes[0].Type);*/ throw new NotImplementedException();
ParseUtilCSharp.AssertGlobal(
"partial class partial<[partial: where] where> where where : partial<where> { }",
new TypeDeclaration {
Modifiers = Modifiers.Partial,
ClassType = ClassType.Class,
Name = "partial",
TypeParameters = {
new TypeParameterDeclaration {
Attributes = {
new AttributeSection {
AttributeTarget = AttributeTarget.Unknown,
Attributes = { new Attribute { Type = new SimpleType("where") } }
}
},
Name = "where"
}
},
Constraints = {
new Constraint {
TypeParameter = "where",
BaseTypes = {
new SimpleType {
Identifier = "partial",
TypeArguments = { new SimpleType("where") }
}
}
}
}});
}
[Test]

2
ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/UsingDeclarationTests.cs

@ -43,7 +43,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope @@ -43,7 +43,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
Assert.AreEqual("My.Name.Space", ud.Namespace);
}
[Test]
[Test, Ignore("Aliases to generic types not yet supported")]
public void UsingAliasDeclarationTest()
{
string program = "using TESTME=System;\n" +

41
ICSharpCode.NRefactory.Tests/CSharp/Parser/ParseUtil.cs

@ -11,7 +11,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser @@ -11,7 +11,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
/// <summary>
/// Helper methods for parser unit tests.
/// </summary>
public class ParseUtilCSharp
public static class ParseUtilCSharp
{
public static T ParseGlobal<T>(string code, bool expectErrors = false) where T : AstNode
{
@ -26,6 +26,14 @@ namespace ICSharpCode.NRefactory.CSharp.Parser @@ -26,6 +26,14 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
return (T)node;
}
public static void AssertGlobal(string code, AstNode expectedNode)
{
var node = ParseGlobal<AstNode>(code);
if (expectedNode.Match(node) == null) {
Assert.Fail("Expected '{0}' but was '{1}'", ToCSharp(expectedNode), ToCSharp(node));
}
}
public static T ParseStatement<T>(string stmt, bool expectErrors = false) where T : AstNode
{
CSharpParser parser = new CSharpParser();
@ -39,6 +47,14 @@ namespace ICSharpCode.NRefactory.CSharp.Parser @@ -39,6 +47,14 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
return (T)statement;
}
public static void AssertStatement(string code, CSharp.Statement expectedStmt)
{
var stmt = ParseStatement<CSharp.Statement>(code);
if (expectedStmt.Match(stmt) == null) {
Assert.Fail("Expected '{0}' but was '{1}'", ToCSharp(expectedStmt), ToCSharp(stmt));
}
}
public static T ParseExpression<T>(string expr, bool expectErrors = false) where T : AstNode
{
if (expectErrors) Assert.Ignore("errors not yet implemented");
@ -53,6 +69,14 @@ namespace ICSharpCode.NRefactory.CSharp.Parser @@ -53,6 +69,14 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
return (T)parsedExpression;
}
public static void AssertExpression(string code, CSharp.Expression expectedExpr)
{
var expr = ParseExpression<CSharp.Expression>(code);
if (expectedExpr.Match(expr) == null) {
Assert.Fail("Expected '{0}' but was '{1}'", ToCSharp(expectedExpr), ToCSharp(expr));
}
}
public static T ParseTypeMember<T>(string expr, bool expectErrors = false) where T : AttributedNode
{
if (expectErrors) Assert.Ignore("errors not yet implemented");
@ -67,5 +91,20 @@ namespace ICSharpCode.NRefactory.CSharp.Parser @@ -67,5 +91,20 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
Assert.IsTrue(type.IsAssignableFrom(m.GetType()), String.Format("Parsed member was {0} instead of {1} ({2})", m.GetType(), type, m));
return (T)m;
}
public static void AssertTypeMember(string code, CSharp.AttributedNode expectedMember)
{
var member = ParseTypeMember<CSharp.AttributedNode>(code);
if (expectedMember.Match(member) == null) {
Assert.Fail("Expected '{0}' but was '{1}'", ToCSharp(expectedMember), ToCSharp(member));
}
}
static string ToCSharp(AstNode node)
{
StringWriter w = new StringWriter();
node.AcceptVisitor(new OutputVisitor(w, new CSharpFormattingPolicy()), null);
return w.ToString();
}
}
}

15
ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/FixedStatementTests.cs

@ -6,14 +6,25 @@ using NUnit.Framework; @@ -6,14 +6,25 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
{
[TestFixture]
[TestFixture, Ignore("fixed is not implemented")]
public class FixedStatementTests
{
[Test]
public void FixedStatementTest()
{
FixedStatement fixedStmt = ParseUtilCSharp.ParseStatement<FixedStatement>("fixed (int* ptr = &myIntArr) { }");
// TODO : Extend test.
ParseUtilCSharp.AssertStatement(
"fixed (int* ptr = &myIntArr) { }",
new FixedStatement {
Type = new PrimitiveType("int").MakePointerType(),
Variables = {
new VariableInitializer {
Name = "ptr",
Initializer = new UnaryOperatorExpression(UnaryOperatorType.AddressOf, new IdentifierExpression("myIntArr"))
}
},
EmbeddedStatement = new BlockStatement()
});
}
}
}

20
ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ForStatementTests.cs

@ -10,11 +10,17 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements @@ -10,11 +10,17 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
[TestFixture]
public class ForStatementTests
{
[Test]
[Test, Ignore("variable type in foreach is broken")]
public void ForeachStatementTest()
{
ForeachStatement foreachStmt = ParseUtilCSharp.ParseStatement<ForeachStatement>("foreach (int i in myColl) {} ");
// TODO : Extend test.
ParseUtilCSharp.AssertStatement(
"foreach (int i in myColl) {} ",
new ForeachStatement {
VariableType = new PrimitiveType("int"),
VariableName = "i",
InExpression = new IdentifierExpression("myColl"),
EmbeddedStatement = new BlockStatement()
});
}
[Test, Ignore("for statement is broken when Initializers.Count()!=1")]
@ -40,7 +46,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements @@ -40,7 +46,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
Assert.IsTrue(inc.Expression is UnaryOperatorExpression);
}
[Test, Ignore("for statement is broken when Initializers.Count()!=1")]
[Test]
public void ForStatementTestMultipleInitializers()
{
ForStatement forStmt = ParseUtilCSharp.ParseStatement<ForStatement>("for (i = 0, j = 1; i < 6; ++i) {} ");
@ -48,10 +54,12 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements @@ -48,10 +54,12 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
Assert.IsTrue(forStmt.Iterators.All(i => i is ExpressionStatement));
}
[Test, Ignore("for statement is broken when Iterators.Count()!=1")]
[Test]
public void ForStatementTestMultipleIterators()
{
ForStatement forStmt = ParseUtilCSharp.ParseStatement<ForStatement>("for (int i = 5; i < 6; ++i, j--) {} ");
ForStatement forStmt = ParseUtilCSharp.ParseStatement<ForStatement>("for (int i = 5, j = 10; i < 6; ++i, j--) {} ");
Assert.AreEqual(1, forStmt.Initializers.Count());
Assert.AreEqual(2, ((VariableDeclarationStatement)forStmt.Initializers.Single()).Variables.Count());
Assert.AreEqual(2, forStmt.Iterators.Count());
Assert.IsTrue(forStmt.Iterators.All(i => i is ExpressionStatement));
}

56
ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/TryCatchStatementTests.cs

@ -7,7 +7,7 @@ using NUnit.Framework; @@ -7,7 +7,7 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
{
[TestFixture, Ignore]
[TestFixture]
public class TryCatchStatementTests
{
[Test]
@ -20,28 +20,54 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements @@ -20,28 +20,54 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
Assert.AreEqual(string.Empty, tryCatchStatement.CatchClauses.Single().VariableName);
}
/* TODO port tests
[Test]
public void SimpleTryCatchStatementTest2()
{
TryCatchStatement tryCatchStatement = ParseUtilCSharp.ParseStatement<TryCatchStatement>("try { } catch (Exception e) { } ");
Assert.IsTrue(tryCatchStatement.FinallyBlock.IsNull);
Assert.AreEqual(1, tryCatchStatement.CatchClauses.Count);
Assert.AreEqual("Exception", tryCatchStatement.CatchClauses[0].TypeReference.Type);
Assert.AreEqual("e", tryCatchStatement.CatchClauses[0].VariableName);
ParseUtilCSharp.AssertStatement(
"try { } catch (Exception e) { } ",
new TryCatchStatement {
TryBlock = new BlockStatement(),
CatchClauses = {
new CatchClause {
Type = new SimpleType("Exception"),
VariableName = "e",
Body = new BlockStatement()
}
}});
}
[Test]
public void SimpleTryCatchFinallyStatementTest()
{
TryCatchStatement tryCatchStatement = ParseUtilCSharp.ParseStatement<TryCatchStatement>("try { } catch (Exception) { } catch { } finally { } ");
Assert.IsFalse(tryCatchStatement.FinallyBlock.IsNull);
Assert.AreEqual(2, tryCatchStatement.CatchClauses.Count);
Assert.AreEqual("Exception", tryCatchStatement.CatchClauses[0].TypeReference.Type);
Assert.IsEmpty(tryCatchStatement.CatchClauses[0].VariableName);
Assert.IsTrue(tryCatchStatement.CatchClauses[1].TypeReference.IsNull);
Assert.IsEmpty(tryCatchStatement.CatchClauses[1].VariableName);
ParseUtilCSharp.AssertStatement(
"try { } catch (Exception) { } catch { } finally { } ",
new TryCatchStatement {
TryBlock = new BlockStatement(),
CatchClauses = {
new CatchClause {
Type = new SimpleType("Exception"),
Body = new BlockStatement()
},
new CatchClause { Body = new BlockStatement() }
},
FinallyBlock = new BlockStatement()
});
}
[Test]
public void TestEmptyFinallyDoesNotMatchNullFinally()
{
TryCatchStatement c1 = new TryCatchStatement {
TryBlock = new BlockStatement(),
CatchClauses = { new CatchClause { Body = new BlockStatement() } }
};
TryCatchStatement c2 = new TryCatchStatement {
TryBlock = new BlockStatement(),
CatchClauses = { new CatchClause { Body = new BlockStatement() } },
FinallyBlock = new BlockStatement()
};
Assert.IsNull(c1.Match(c2));
Assert.IsNull(c2.Match(c1)); // and vice versa
}
*/
}
}

3
ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/YieldStatementTests.cs

@ -21,8 +21,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements @@ -21,8 +21,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
[Test]
public void YieldBreakStatementTest()
{
YieldStatement yieldStmt = ParseUtilCSharp.ParseStatement<YieldStatement>("yield break;");
Assert.IsTrue(yieldStmt.Expression.IsNull);
ParseUtilCSharp.ParseStatement<YieldBreakStatement>("yield break;");
}
[Test]

113
ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/EventDeclarationTests.cs

@ -6,79 +6,84 @@ using NUnit.Framework; @@ -6,79 +6,84 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
{
[TestFixture, Ignore]
[TestFixture, Ignore("events are broken")]
public class EventDeclarationTests
{
[Test]
public void SimpleEventDeclarationTest()
{
CustomEventDeclaration ed = ParseUtilCSharp.ParseTypeMember<CustomEventDeclaration>("event System.EventHandler MyEvent;");
Assert.AreEqual("MyEvent", ed.Name);
//Assert.AreEqual("System.EventHandler", ed.TypeReference.Type);
Assert.Ignore(); // check type
Assert.IsTrue(ed.AddAccessor.IsNull);
Assert.IsTrue(ed.RemoveAccessor.IsNull);
ParseUtilCSharp.AssertTypeMember(
"event EventHandler MyEvent;",
new EventDeclaration {
ReturnType = new SimpleType("EventHandler"),
Variables = {
new VariableInitializer {
Name = "MyEvent"
}
}});
}
/* TODO Port tests
[Test]
public void MultipleEventDeclarationTest()
{
TypeDeclaration t = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("class C { public event EventHandler A, B; }");
Assert.AreEqual(2, t.Children.Count);
EventDeclaration ed = (EventDeclaration)t.Children[0];
Assert.AreEqual(Modifiers.Public, ed.Modifier);
Assert.AreEqual("EventHandler", ed.TypeReference.Type);
Assert.AreEqual("A", ed.Name);
ed = (EventDeclaration)t.Children[1];
Assert.AreEqual(Modifiers.Public, ed.Modifier);
Assert.AreEqual("EventHandler", ed.TypeReference.Type);
Assert.AreEqual("B", ed.Name);
ParseUtilCSharp.AssertTypeMember(
"public event EventHandler A = null, B = delegate {};",
new EventDeclaration {
Modifiers = Modifiers.Public,
ReturnType = new SimpleType("EventHandler"),
Variables = {
new VariableInitializer {
Name = "A",
Initializer = new NullReferenceExpression()
},
new VariableInitializer {
Name = "B",
Initializer = new AnonymousMethodExpression()
}
}});
}
[Test]
public void EventImplementingInterfaceDeclarationTest()
public void AddRemoveEventDeclarationTest()
{
EventDeclaration ed = ParseUtilCSharp.ParseTypeMember<EventDeclaration>("event EventHandler MyInterface.MyEvent;");
Assert.AreEqual("MyEvent", ed.Name);
Assert.AreEqual("EventHandler", ed.TypeReference.Type);
Assert.IsFalse(ed.HasAddRegion);
Assert.IsFalse(ed.HasRemoveRegion);
Assert.AreEqual("MyInterface", ed.InterfaceImplementations[0].InterfaceType.Type);
Assert.AreEqual("MyEvent", ed.InterfaceImplementations[0].MemberName);
ParseUtilCSharp.AssertTypeMember(
"public event System.EventHandler MyEvent { add { } remove { } }",
new CustomEventDeclaration {
Modifiers = Modifiers.Public,
ReturnType = new MemberType {
Target = new SimpleType("System"),
MemberName = "EventHandler"
},
Name = "MyEvent",
AddAccessor = new Accessor { Body = new BlockStatement() },
RemoveAccessor = new Accessor { Body = new BlockStatement() }
});
}
[Test]
public void EventImplementingGenericInterfaceDeclarationTest()
{
EventDeclaration ed = ParseUtilCSharp.ParseTypeMember<EventDeclaration>("event EventHandler MyInterface<string>.MyEvent;");
Assert.AreEqual("MyEvent", ed.Name);
Assert.AreEqual("EventHandler", ed.TypeReference.Type);
Assert.IsFalse(ed.HasAddRegion);
Assert.IsFalse(ed.HasRemoveRegion);
Assert.AreEqual("MyInterface", ed.InterfaceImplementations[0].InterfaceType.Type);
Assert.AreEqual("System.String", ed.InterfaceImplementations[0].InterfaceType.GenericTypes[0].Type);
Assert.AreEqual("MyEvent", ed.InterfaceImplementations[0].MemberName);
ParseUtilCSharp.AssertTypeMember(
"event EventHandler MyInterface<string>.MyEvent { add { } [Attr] remove {} }",
new CustomEventDeclaration {
ReturnType = new SimpleType("EventHandler"),
PrivateImplementationType = new SimpleType{
Identifier = "MyInterface",
TypeArguments = { new PrimitiveType("string") }
},
Name = "MyEvent",
AddAccessor = new Accessor { Body = new BlockStatement() },
RemoveAccessor = new Accessor {
Attributes = {
new AttributeSection {
Attributes = {
new Attribute { Type = new SimpleType("Attr") }
}
}
},
Body = new BlockStatement()
}
});
}
[Test]
public void AddRemoveEventDeclarationTest()
{
EventDeclaration ed = ParseUtilCSharp.ParseTypeMember<EventDeclaration>("event System.EventHandler MyEvent { add { } remove { } }");
Assert.AreEqual("MyEvent", ed.Name);
Assert.AreEqual("System.EventHandler", ed.TypeReference.Type);
Assert.IsTrue(ed.HasAddRegion);
Assert.IsTrue(ed.HasRemoveRegion);
}*/
}
}

62
ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/FieldDeclarationTests.cs

@ -6,22 +6,62 @@ using NUnit.Framework; @@ -6,22 +6,62 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
{
[TestFixture, Ignore]
[TestFixture]
public class FieldDeclarationTests
{
[Test]
[Test, Ignore("multidimensional array rank incorrect?")]
public void SimpleFieldDeclarationTest()
{
throw new NotImplementedException();
/*
FieldDeclaration fd = ParseUtilCSharp.ParseTypeMember<FieldDeclaration>("int[,,,] myField;");
Assert.AreEqual("System.Int32", fd.TypeReference.Type);
Assert.AreEqual(new int[] { 3 } , fd.TypeReference.RankSpecifier);
Assert.AreEqual(1, fd.Fields.Count);
Assert.AreEqual("myField", ((VariableDeclaration)fd.Fields[0]).Name);*/
ParseUtilCSharp.AssertTypeMember(
"int[,,,] myField;",
new FieldDeclaration {
ReturnType = new PrimitiveType("int").MakeArrayType(4),
Variables = { new VariableInitializer("myField") }
});
}
[Test]
public void MultipleFieldDeclarationTest()
{
ParseUtilCSharp.AssertTypeMember(
"int a = 1, b = 2;",
new FieldDeclaration {
ReturnType = new PrimitiveType("int"),
Variables = {
new VariableInitializer("a", new PrimitiveExpression(1)),
new VariableInitializer("b", new PrimitiveExpression(2)),
}
});
}
// TODO add more tests
[Test]
public void FieldWithArrayInitializer()
{
ParseUtilCSharp.AssertTypeMember(
"public static readonly int[] arr = { 1, 2, 3 };",
new FieldDeclaration {
Modifiers = Modifiers.Public | Modifiers.Static | Modifiers.Readonly,
ReturnType = new PrimitiveType("int").MakeArrayType(),
Variables = {
new VariableInitializer {
Name = "arr",
Initializer = new ArrayInitializerExpression {
Elements = {
new PrimitiveExpression(1),
new PrimitiveExpression(2),
new PrimitiveExpression(3)
}
}
}
}});
}
[Test, Ignore("How do we represent fixed-size fields in the AST?")]
public void FieldWithFixedSize()
{
ParseUtilCSharp.AssertTypeMember(
"public unsafe fixed int Field[100];",
new FieldDeclaration());
}
}
}

37
ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/IndexerDeclarationTests.cs

@ -13,13 +13,16 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -13,13 +13,16 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
[Test]
public void IndexerDeclarationTest()
{
IndexerDeclaration id = ParseUtilCSharp.ParseTypeMember<IndexerDeclaration>("int this[int a, string b] { get { } set { } }");
IndexerDeclaration id = ParseUtilCSharp.ParseTypeMember<IndexerDeclaration>("public int this[int a, string b] { get { } protected set { } }");
Assert.AreEqual(2, id.Parameters.Count());
Assert.IsNotNull(id.Getter, "No get region found!");
Assert.IsNotNull(id.Setter, "No set region found!");
Assert.AreEqual(Modifiers.Public, id.Modifiers);
Assert.AreEqual(Modifiers.None, id.Getter.Modifiers);
Assert.AreEqual(Modifiers.Protected, id.Setter.Modifiers);
}
[Test, Ignore("type reference is not yet implemented")]
[Test, Ignore("explicit interface implementation not yet supported")]
public void IndexerImplementingInterfaceTest()
{
IndexerDeclaration id = ParseUtilCSharp.ParseTypeMember<IndexerDeclaration>("int MyInterface.this[int a, string b] { get { } set { } }");
@ -27,21 +30,29 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -27,21 +30,29 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
Assert.IsNotNull(id.Getter, "No get region found!");
Assert.IsNotNull(id.Setter, "No set region found!");
Assert.AreEqual("MyInterface", id.PrivateImplementationType);
Assert.AreEqual("MyInterface", ((SimpleType)id.PrivateImplementationType).Identifier);
}
[Test, Ignore]
[Test, Ignore("explicit interface implementation not yet supported")]
public void IndexerImplementingGenericInterfaceTest()
{
throw new NotImplementedException();
/*
IndexerDeclaration id = ParseUtilCSharp.ParseTypeMember<IndexerDeclaration>("int MyInterface<string>.this[int a, string b] { get { } set { } }");
Assert.AreEqual(2, id.Parameters.Count);
Assert.IsNotNull(id.GetAccessor, "No get region found!");
Assert.IsNotNull(id.SetAccessor, "No set region found!");
Assert.AreEqual("MyInterface", id.InterfaceImplementations[0].InterfaceType.Type);
Assert.AreEqual("System.String", id.InterfaceImplementations[0].InterfaceType.GenericTypes[0].Type);*/
ParseUtilCSharp.AssertTypeMember(
"int MyInterface<string>.this[int a, string b] { get { } [Attr] set { } }",
new IndexerDeclaration {
ReturnType = new PrimitiveType("int"),
PrivateImplementationType = new SimpleType {
Identifier = "MyInterface",
TypeArguments = { new PrimitiveType("string") }
},
Parameters = {
new ParameterDeclaration(new PrimitiveType("int"), "a"),
new ParameterDeclaration(new PrimitiveType("string"), "b")
},
Getter = new Accessor { Body = new BlockStatement() },
Setter = new Accessor {
Attributes = { new AttributeSection(new Attribute { Type = new SimpleType("Attr") }) },
Body = new BlockStatement()
}});
}
}
}

266
ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/MethodDeclarationTests.cs

@ -3,49 +3,50 @@ @@ -3,49 +3,50 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
{
[TestFixture]
[TestFixture, Ignore("Generics not yet implemented")]
public class MethodDeclarationTests
{
[Test, Ignore("type references not yet implemented")]
[Test]
public void SimpleMethodDeclarationTest()
{
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("void MyMethod() {} ");
Assert.AreEqual("System.Void", md.ReturnType);
Assert.AreEqual("void", ((PrimitiveType)md.ReturnType).Keyword);
Assert.AreEqual(0, md.Parameters.Count());
Assert.IsFalse(md.IsExtensionMethod);
}
[Test, Ignore("type references not yet implemented")]
[Test]
public void AbstractMethodDeclarationTest()
{
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("abstract void MyMethod();");
Assert.AreEqual("System.Void", md.ReturnType);
Assert.AreEqual("void", ((PrimitiveType)md.ReturnType).Keyword);
Assert.AreEqual(0, md.Parameters.Count());
Assert.IsFalse(md.IsExtensionMethod);
Assert.IsTrue(md.Body.IsNull);
Assert.AreEqual(Modifiers.Abstract, md.Modifiers);
}
[Test, Ignore("type references not yet implemented")]
[Test]
public void DefiningPartialMethodDeclarationTest()
{
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("partial void MyMethod();");
Assert.AreEqual("System.Void", md.ReturnType);
Assert.AreEqual("void", ((PrimitiveType)md.ReturnType).Keyword);
Assert.AreEqual(0, md.Parameters.Count());
Assert.IsFalse(md.IsExtensionMethod);
Assert.IsTrue(md.Body.IsNull);
Assert.AreEqual(Modifiers.Partial, md.Modifiers);
}
[Test, Ignore("type references not yet implemented")]
[Test]
public void ImplementingPartialMethodDeclarationTest()
{
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("partial void MyMethod() { }");
Assert.AreEqual("System.Void", md.ReturnType);
Assert.AreEqual("void", ((PrimitiveType)md.ReturnType).Keyword);
Assert.AreEqual(0, md.Parameters.Count());
Assert.IsFalse(md.IsExtensionMethod);
Assert.IsFalse(md.Body.IsNull);
@ -81,6 +82,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -81,6 +82,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
Assert.AreEqual(2, md.StartLocation.Line, "StartLocation.Y");
Assert.AreEqual(5, md.EndLocation.Line, "EndLocation.Y");
Assert.AreEqual(3, md.StartLocation.Column, "StartLocation.X");
Assert.AreEqual(4, md.EndLocation.Column, "EndLocation.X");
}
[Test]
@ -89,142 +91,176 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -89,142 +91,176 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("void MyMethod(int) {} ", true);
Assert.AreEqual("System.Void", md.ReturnType);
Assert.AreEqual(1, md.Parameters.Count());
//Assert.AreEqual("?", ((ParameterDeclarationExpression)md.Parameters[0]).ParameterName);
Assert.AreEqual("int", ((PrimitiveType)md.Parameters.Single().Type).Keyword);
}
/* TODO: port unit tests
[Test]
public void GenericVoidMethodDeclarationTest()
{
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("void MyMethod<T>(T a) {} ");
Assert.AreEqual("System.Void", md.ReturnType);
Assert.AreEqual(1, md.Parameters.Count());
Assert.AreEqual("T", md.Parameters.Single().Type);
Assert.AreEqual("a", md.Parameters.Single().Name);
Assert.AreEqual(1, md.TypeParameters.Count());
Assert.AreEqual("T", md.Templates[0].Name);
ParseUtilCSharp.AssertTypeMember(
"void MyMethod<T>(T a) {} ",
new MethodDeclaration {
ReturnType = new PrimitiveType("void"),
Name = "MyMethod",
TypeParameters = { new TypeParameterDeclaration { Name = "T" } },
Parameters = { new ParameterDeclaration(new SimpleType("T"), "a") },
Body = new BlockStatement()
});
}
[Test]
public void GenericMethodDeclarationTest()
{
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("T MyMethod<T>(T a) {} ");
Assert.AreEqual("T", md.TypeReference.Type);
Assert.AreEqual(1, md.Parameters.Count);
Assert.AreEqual("T", ((ParameterDeclarationExpression)md.Parameters[0]).TypeReference.Type);
Assert.AreEqual("a", ((ParameterDeclarationExpression)md.Parameters[0]).ParameterName);
Assert.AreEqual(1, md.Templates.Count);
Assert.AreEqual("T", md.Templates[0].Name);
ParseUtilCSharp.AssertTypeMember(
"T MyMethod<T>(T a) {} ",
new MethodDeclaration {
ReturnType = new SimpleType("T"),
Name = "MyMethod",
TypeParameters = { new TypeParameterDeclaration { Name = "T" } },
Parameters = { new ParameterDeclaration(new SimpleType("T"), "a") },
Body = new BlockStatement()
});
}
[Test]
public void GenericMethodDeclarationWithConstraintTest()
{
string program = "T MyMethod<T>(T a) where T : ISomeInterface {} ";
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>(program);
Assert.AreEqual("T", md.TypeReference.Type);
Assert.AreEqual(1, md.Parameters.Count);
Assert.AreEqual("T", ((ParameterDeclarationExpression)md.Parameters[0]).TypeReference.Type);
Assert.AreEqual("a", ((ParameterDeclarationExpression)md.Parameters[0]).ParameterName);
Assert.AreEqual(1, md.Templates.Count);
Assert.AreEqual("T", md.Templates[0].Name);
Assert.AreEqual(1, md.Templates[0].Bases.Count);
Assert.AreEqual("ISomeInterface", md.Templates[0].Bases[0].Type);
ParseUtilCSharp.AssertTypeMember(
"T MyMethod<T>(T a) where T : ISomeInterface {} ",
new MethodDeclaration {
ReturnType = new SimpleType("T"),
Name = "MyMethod",
TypeParameters = { new TypeParameterDeclaration { Name = "T" } },
Parameters = { new ParameterDeclaration(new SimpleType("T"), "a") },
Constraints = {
new Constraint {
TypeParameter = "T",
BaseTypes = { new SimpleType("ISomeInterface") }
}
},
Body = new BlockStatement()
});
}
[Test]
public void GenericMethodInInterface()
{
const string program = @"interface MyInterface {
ParseUtilCSharp.AssertGlobal(
@"interface MyInterface {
T MyMethod<T>(T a) where T : ISomeInterface;
}
";
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program);
MethodDeclaration md = (MethodDeclaration)td.Children[0];
Assert.AreEqual("T", md.TypeReference.Type);
Assert.AreEqual(1, md.Parameters.Count);
Assert.AreEqual("T", ((ParameterDeclarationExpression)md.Parameters[0]).TypeReference.Type);
Assert.AreEqual("a", ((ParameterDeclarationExpression)md.Parameters[0]).ParameterName);
Assert.AreEqual(1, md.Templates.Count);
Assert.AreEqual("T", md.Templates[0].Name);
Assert.AreEqual(1, md.Templates[0].Bases.Count);
Assert.AreEqual("ISomeInterface", md.Templates[0].Bases[0].Type);
",
new TypeDeclaration {
ClassType = ClassType.Interface,
Members = {
new MethodDeclaration {
ReturnType = new SimpleType("T"),
Name = "MyMethod",
TypeParameters = { new TypeParameterDeclaration { Name = "T" } },
Parameters = { new ParameterDeclaration(new SimpleType("T"), "a") },
Constraints = {
new Constraint {
TypeParameter = "T",
BaseTypes = { new SimpleType("ISomeInterface") }
}
}
}}});
}
[Test]
public void GenericVoidMethodInInterface()
{
const string program = @"interface MyInterface {
ParseUtilCSharp.AssertGlobal(
@"interface MyInterface {
void MyMethod<T>(T a) where T : ISomeInterface;
}
";
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program);
MethodDeclaration md = (MethodDeclaration)td.Children[0];
Assert.AreEqual("System.Void", md.TypeReference.Type);
Assert.AreEqual(1, md.Parameters.Count);
Assert.AreEqual("T", ((ParameterDeclarationExpression)md.Parameters[0]).TypeReference.Type);
Assert.AreEqual("a", ((ParameterDeclarationExpression)md.Parameters[0]).ParameterName);
Assert.AreEqual(1, md.Templates.Count);
Assert.AreEqual("T", md.Templates[0].Name);
Assert.AreEqual(1, md.Templates[0].Bases.Count);
Assert.AreEqual("ISomeInterface", md.Templates[0].Bases[0].Type);
",
new TypeDeclaration {
ClassType = ClassType.Interface,
Members = {
new MethodDeclaration {
ReturnType = new PrimitiveType("void"),
Name = "MyMethod",
TypeParameters = { new TypeParameterDeclaration { Name = "T" } },
Parameters = { new ParameterDeclaration(new SimpleType("T"), "a") },
Constraints = {
new Constraint {
TypeParameter = "T",
BaseTypes = { new SimpleType("ISomeInterface") }
}
}
}}});
}
[Test]
public void ShadowingMethodInInterface()
{
const string program = @"interface MyInterface : IDisposable {
ParseUtilCSharp.AssertGlobal(
@"interface MyInterface : IDisposable {
new void Dispose();
}
";
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program);
MethodDeclaration md = (MethodDeclaration)td.Children[0];
Assert.AreEqual("System.Void", md.TypeReference.Type);
Assert.AreEqual(0, md.Parameters.Count);
Assert.AreEqual(Modifiers.New, md.Modifier);
",
new TypeDeclaration {
ClassType = ClassType.Interface,
BaseTypes = { new SimpleType("IDisposable") },
Members = {
new MethodDeclaration {
Modifiers = Modifiers.New,
ReturnType = new PrimitiveType("void"),
Name = "Dispose"
}}});
}
[Test]
public void MethodImplementingInterfaceTest()
{
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("int MyInterface.MyMethod() {} ");
Assert.AreEqual("System.Int32", md.TypeReference.Type);
Assert.AreEqual("MyInterface", md.InterfaceImplementations[0].InterfaceType.Type);
ParseUtilCSharp.AssertGlobal(
"int MyInterface.MyMethod() {} ",
new MethodDeclaration {
ReturnType = new PrimitiveType("int"),
PrivateImplementationType = new SimpleType("MyInterface"),
Name = "MyMethod",
Body = new BlockStatement()
});
}
[Test]
public void MethodImplementingGenericInterfaceTest()
{
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("int MyInterface<string>.MyMethod() {} ");
Assert.AreEqual("System.Int32", md.TypeReference.Type);
Assert.AreEqual("MyInterface", md.InterfaceImplementations[0].InterfaceType.Type);
Assert.AreEqual("System.String", md.InterfaceImplementations[0].InterfaceType.GenericTypes[0].Type);
ParseUtilCSharp.AssertGlobal(
"int MyInterface<string>.MyMethod() {} ",
new MethodDeclaration {
ReturnType = new PrimitiveType("int"),
PrivateImplementationType = new SimpleType("MyInterface") { TypeArguments = { new PrimitiveType("string") } },
Name = "MyMethod",
Body = new BlockStatement()
});
}
[Test]
public void VoidMethodImplementingInterfaceTest()
{
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("void MyInterface.MyMethod() {} ");
Assert.AreEqual("System.Void", md.TypeReference.Type);
Assert.AreEqual("MyInterface", md.InterfaceImplementations[0].InterfaceType.Type);
ParseUtilCSharp.AssertGlobal(
"void MyInterface.MyMethod() {} ",
new MethodDeclaration {
ReturnType = new PrimitiveType("void"),
PrivateImplementationType = new SimpleType("MyInterface"),
Name = "MyMethod",
Body = new BlockStatement()
});
}
[Test]
public void VoidMethodImplementingGenericInterfaceTest()
{
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("void MyInterface<string>.MyMethod() {} ");
Assert.AreEqual("System.Void", md.TypeReference.Type);
Assert.AreEqual("MyInterface", md.InterfaceImplementations[0].InterfaceType.Type);
Assert.AreEqual("System.String", md.InterfaceImplementations[0].InterfaceType.GenericTypes[0].Type);
ParseUtilCSharp.AssertGlobal(
"void MyInterface<string>.MyMethod() {} ",
new MethodDeclaration {
ReturnType = new PrimitiveType("void"),
PrivateImplementationType = new SimpleType("MyInterface"),
Name = "MyMethod",
Body = new BlockStatement()
});
}
[Test]
@ -234,9 +270,9 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -234,9 +270,9 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
"void a<T>() where T { }", true // expect errors
);
Assert.AreEqual("a", md.Name);
Assert.AreEqual(1, md.Templates.Count);
Assert.AreEqual("T", md.Templates[0].Name);
Assert.AreEqual(0, md.Templates[0].Bases.Count);
Assert.AreEqual(1, md.TypeParameters.Count);
Assert.AreEqual("T", md.TypeParameters.Single().Name);
Assert.AreEqual(0, md.Constraints.Count());
}
[Test]
@ -246,11 +282,11 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -246,11 +282,11 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
"public static int ToInt32(this string s) { return int.Parse(s); }"
);
Assert.AreEqual("ToInt32", md.Name);
Assert.AreEqual("s", md.Parameters.First().Name);
Assert.AreEqual(ParameterModifier.This, md.Parameters.First().ParameterModifier);
Assert.AreEqual("string", ((PrimitiveType)md.Parameters.First().Type).Keyword);
Assert.IsTrue(md.IsExtensionMethod);
Assert.AreEqual("s", md.Parameters[0].ParameterName);
Assert.AreEqual("System.String", md.Parameters[0].TypeReference.Type);
}
*/
[Test]
public void VoidExtensionMethodTest()
@ -265,7 +301,6 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -265,7 +301,6 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
Assert.IsTrue(md.IsExtensionMethod);
}
/* TODO
[Test]
public void MethodWithEmptyAssignmentErrorInBody()
{
@ -277,27 +312,32 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -277,27 +312,32 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
"}", true // expect errors
);
Assert.AreEqual("A", md.Name);
Assert.AreEqual(new Location(1, 2), md.Body.StartLocation);
Assert.AreEqual(new Location(2, 5), md.Body.EndLocation);
Assert.AreEqual(new AstLocation(1, 2), md.Body.StartLocation);
Assert.AreEqual(new AstLocation(2, 5), md.Body.EndLocation);
}
[Test]
public void OptionalParameterTest()
{
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>(
"public void Foo(string bar = null, int baz = 0) { }"
);
Assert.AreEqual("Foo", md.Name);
Assert.AreEqual("bar", md.Parameters[0].ParameterName);
Assert.AreEqual("System.String", md.Parameters[0].TypeReference.Type);
Assert.AreEqual(ParameterModifiers.In | ParameterModifiers.Optional, md.Parameters[0].ParamModifier);
Assert.IsNull(((PrimitiveExpression)md.Parameters[0].DefaultValue).Value);
Assert.AreEqual("baz", md.Parameters[1].ParameterName);
Assert.AreEqual("System.Int32", md.Parameters[1].TypeReference.Type);
Assert.AreEqual(ParameterModifiers.In | ParameterModifiers.Optional, md.Parameters[1].ParamModifier);
Assert.AreEqual(0, ((PrimitiveExpression)md.Parameters[1].DefaultValue).Value);
}*/
ParseUtilCSharp.AssertTypeMember(
"public void Foo(string bar = null, int baz = 0) { }",
new MethodDeclaration {
Modifiers = Modifiers.Public,
ReturnType = new PrimitiveType("void"),
Name = "Foo",
Body = new BlockStatement(),
Parameters = {
new ParameterDeclaration {
Type = new PrimitiveType("string"),
Name = "bar",
DefaultExpression = new NullReferenceExpression()
},
new ParameterDeclaration {
Type = new PrimitiveType("int"),
Name = "baz",
DefaultExpression = new PrimitiveExpression(0)
}
}});
}
}
}

16
ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/OperatorDeclarationTests.cs

@ -10,43 +10,43 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -10,43 +10,43 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
[TestFixture]
public class OperatorDeclarationTests
{
[Test, Ignore("type references not yet implemented")]
[Test]
public void ImplictOperatorDeclarationTest()
{
OperatorDeclaration od = ParseUtilCSharp.ParseTypeMember<OperatorDeclaration>("public static implicit operator double(MyObject f) { return 0.5d; }");
Assert.AreEqual(OperatorType.Implicit, od.OperatorType);
Assert.AreEqual(1, od.Parameters.Count());
Assert.AreEqual("System.Double", od.ReturnType);
Assert.AreEqual("double", ((PrimitiveType)od.ReturnType).Keyword);
Assert.AreEqual("op_Implicit", od.Name);
}
[Test, Ignore("type references not yet implemented")]
[Test]
public void ExplicitOperatorDeclarationTest()
{
OperatorDeclaration od = ParseUtilCSharp.ParseTypeMember<OperatorDeclaration>("public static explicit operator double(MyObject f) { return 0.5d; }");
Assert.AreEqual(OperatorType.Explicit, od.OperatorType);
Assert.AreEqual(1, od.Parameters.Count());
Assert.AreEqual("System.Double", od.ReturnType);
Assert.AreEqual("double", ((PrimitiveType)od.ReturnType).Keyword);
Assert.AreEqual("op_Explicit", od.Name);
}
[Test, Ignore("type references not yet implemented")]
[Test]
public void BinaryPlusOperatorDeclarationTest()
{
OperatorDeclaration od = ParseUtilCSharp.ParseTypeMember<OperatorDeclaration>("public static MyObject operator +(MyObject a, MyObject b) {}");
Assert.AreEqual(OperatorType.Addition, od.OperatorType);
Assert.AreEqual(2, od.Parameters.Count());
Assert.AreEqual("MyObject", od.ReturnType);
Assert.AreEqual("MyObject", ((SimpleType)od.ReturnType).Identifier);
Assert.AreEqual("op_Addition", od.Name);
}
[Test, Ignore("type references not yet implemented")]
[Test]
public void UnaryPlusOperatorDeclarationTest()
{
OperatorDeclaration od = ParseUtilCSharp.ParseTypeMember<OperatorDeclaration>("public static MyObject operator +(MyObject a) {}");
Assert.AreEqual(OperatorType.UnaryPlus, od.OperatorType);
Assert.AreEqual(1, od.Parameters.Count());
Assert.AreEqual("MyObject", od.ReturnType);
Assert.AreEqual("MyObject", ((SimpleType)od.ReturnType).Identifier);
Assert.AreEqual("op_UnaryPlus", od.Name);
}
}

10
ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/PropertyDeclarationTests.cs

@ -66,7 +66,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -66,7 +66,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
Assert.AreEqual(new AstLocation(4, code.IndexOf("}\n\t}") + 1 - line4Pos + 1), pd.Setter.Body.EndLocation);
}
[Test, Ignore("type references not yet implemented")]
[Test, Ignore("explicit interface implementation not yet implemented")]
public void PropertyImplementingInterfaceTest()
{
PropertyDeclaration pd = ParseUtilCSharp.ParseTypeMember<PropertyDeclaration>("int MyInterface.MyProperty { get {} } ");
@ -74,10 +74,10 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -74,10 +74,10 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
Assert.IsFalse(pd.Getter.IsNull);
Assert.IsTrue(pd.Setter.IsNull);
Assert.AreEqual("MyInterface", pd.PrivateImplementationType);
Assert.AreEqual("MyInterface", ((SimpleType)pd.PrivateImplementationType).Identifier);
}
[Test, Ignore("type references not yet implemented")]
[Test, Ignore("explicit interface implementation not yet implemented")]
public void PropertyImplementingGenericInterfaceTest()
{
PropertyDeclaration pd = ParseUtilCSharp.ParseTypeMember<PropertyDeclaration>("int MyInterface<string>.MyProperty { get {} } ");
@ -85,9 +85,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -85,9 +85,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
Assert.IsFalse(pd.Getter.IsNull);
Assert.IsTrue(pd.Setter.IsNull);
throw new NotImplementedException();
//Assert.AreEqual("MyInterface", pd.InterfaceImplementations[0].InterfaceType.Type);
//Assert.AreEqual("System.String", pd.InterfaceImplementations[0].InterfaceType.GenericTypes[0].Type);
Assert.IsNotNull(new SimpleType { Identifier = "MyInterface", TypeArguments = { new PrimitiveType("string") } }.Match(pd.PrivateImplementationType));
}
}
}

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

@ -122,7 +122,7 @@ class A { @@ -122,7 +122,7 @@ class A {
Assert.AreEqual("System.Void", Resolve(program).Type.ReflectionName);
}
[Test]
[Test, Ignore("parser is broken for events")]
public void EventCallTest()
{
string program = @"using System;

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

@ -366,7 +366,7 @@ class TestClass { @@ -366,7 +366,7 @@ class TestClass {
Assert.AreEqual("System.Collections.ArrayList", member.Type.FullName, "the full type should be resolved");
}
[Test]
[Test, Ignore("Parser position bug")]
public void ImportAliasNamespaceResolveTest()
{
NamespaceResolveResult ns;
@ -394,7 +394,7 @@ class TestClass { @@ -394,7 +394,7 @@ class TestClass {
Assert.AreEqual("System.Collections.ArrayList", rr.Type.FullName, "a");
}
[Test]
[Test, Ignore("Parser position bug")]
public void ResolveNamespaceSD_863()
{
string program = @"using System;
@ -432,7 +432,7 @@ namespace A.B { @@ -432,7 +432,7 @@ namespace A.B {
Assert.AreEqual("A.B.C", trr.Type.FullName);
}
[Test]
[Test, Ignore("parser is broken and produces IdentifierExpression instead of PrimitiveType")]
public void ShortMaxValueTest()
{
string program = @"using System;
@ -471,7 +471,7 @@ class TestClass { @@ -471,7 +471,7 @@ class TestClass {
Assert.AreEqual("XX.XX.Test", mrr.Member.FullName);
}
[Test]
[Test, Ignore("Parser position bug")]
public void ClassNameLookup1()
{
string program = @"namespace MainNamespace {
@ -490,7 +490,7 @@ namespace Test.Subnamespace { @@ -490,7 +490,7 @@ namespace Test.Subnamespace {
Assert.AreEqual("Test.Subnamespace.Test.TheClass", trr.Type.FullName);
}
[Test]
[Test, Ignore("Parser position bug")]
public void ClassNameLookup2()
{
string program = @"using Test.Subnamespace;

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

@ -9,7 +9,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -9,7 +9,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
[TestFixture]
public class UnsafeCodeTests : ResolverTestBase
{
[Test, Ignore("Parser produces parse tree that doesn't match DOM definition??")]
[Test, Ignore("fixed statement not implemented in parser")]
public void FixedStatement()
{
string program = @"using System;

1
ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj

@ -11,6 +11,7 @@ @@ -11,6 +11,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<PlatformTarget>x86</PlatformTarget>

1
ICSharpCode.NRefactory.VB.Tests/ICSharpCode.NRefactory.VB.Tests.csproj

@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>

1
ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj

@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
<AssemblyName>ICSharpCode.NRefactory.VB</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<AppDesignerFolder>Properties</AppDesignerFolder>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
<PlatformTarget>x86</PlatformTarget>

6
ICSharpCode.NRefactory/CSharp/Ast/AstLocation.cs

@ -57,11 +57,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -57,11 +57,11 @@ namespace ICSharpCode.NRefactory.CSharp
get { return column; }
}
public override bool Equals (object other)
public override bool Equals (object obj)
{
if (!(other is AstLocation))
if (!(obj is AstLocation))
return false;
return (AstLocation)other == this;
return (AstLocation)obj == this;
}
public override int GetHashCode ()

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

@ -606,6 +606,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -606,6 +606,11 @@ namespace ICSharpCode.NRefactory.CSharp
}
protected internal abstract bool DoMatch(AstNode other, Match match);
internal virtual bool DoMatchCollection(Role role, AstNode pos, Match match, Stack<Pattern.PossibleMatch> backtrackingStack)
{
return DoMatch(pos, match);
}
#endregion
// the Root role must be available when creating the null nodes, so we can't put it in the Roles class

18
ICSharpCode.NRefactory/CSharp/Ast/AstNodeCollection.cs

@ -174,18 +174,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -174,18 +174,12 @@ namespace ICSharpCode.NRefactory.CSharp
if (cur1 == null)
break;
Pattern pattern = cur1 as Pattern;
if (pattern == null && cur1.NodeType == NodeType.Placeholder)
pattern = cur1.GetChildByRole(TypePlaceholder.ChildRole) as Pattern;
if (pattern != null) {
Debug.Assert(stack.Count == patternStack.Count);
success = pattern.DoMatchCollection(role, cur2, match, stack);
Debug.Assert(stack.Count >= patternStack.Count);
while (stack.Count > patternStack.Count)
patternStack.Push(cur1.NextSibling);
} else {
success = cur1.DoMatch(cur2, match);
}
Debug.Assert(stack.Count == patternStack.Count);
success = cur1.DoMatchCollection(role, cur2, match, stack);
Debug.Assert(stack.Count >= patternStack.Count);
while (stack.Count > patternStack.Count)
patternStack.Push(cur1.NextSibling);
cur1 = cur1.NextSibling;
if (cur2 != null)
cur2 = cur2.NextSibling;

2
ICSharpCode.NRefactory/CSharp/Ast/AstType.cs

@ -40,7 +40,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -40,7 +40,7 @@ namespace ICSharpCode.NRefactory.CSharp
return new ComposedType { BaseType = this }.MakePointerType();
}
public virtual AstType MakeArrayType(int rank)
public virtual AstType MakeArrayType(int rank = 1)
{
return new ComposedType { BaseType = this }.MakeArrayType(rank);
}

6
ICSharpCode.NRefactory/CSharp/Ast/CSharpModifierToken.cs

@ -48,6 +48,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -48,6 +48,12 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
CSharpModifierToken o = other as CSharpModifierToken;
return o != null && this.modifier == o.modifier;
}
// 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<KeyValuePair<Modifiers, int>> lengthTable = new List<KeyValuePair<Modifiers, int>> () {

2
ICSharpCode.NRefactory/CSharp/Ast/CSharpTokenNode.cs

@ -88,7 +88,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -88,7 +88,7 @@ namespace ICSharpCode.NRefactory.CSharp
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
CSharpTokenNode o = other as CSharpTokenNode;
return o != null;
return o != null && !o.IsNull && !(o is CSharpModifierToken);
}
public override string ToString ()

2
ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArrayCreateExpression.cs

@ -41,7 +41,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -41,7 +41,7 @@ namespace ICSharpCode.NRefactory.CSharp
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
ArrayCreateExpression o = other as ArrayCreateExpression;
return o != null && this.Type.DoMatch(o.Type, match) && this.Arguments.DoMatch(o.Arguments, match) && this.Initializer.DoMatch(o.Initializer, match);
return o != null && this.Type.DoMatch(o.Type, match) && this.Arguments.DoMatch(o.Arguments, match) && this.AdditionalArraySpecifiers.DoMatch(o.AdditionalArraySpecifiers, match) && this.Initializer.DoMatch(o.Initializer, match);
}
}
}

61
ICSharpCode.NRefactory/CSharp/Ast/Expressions/QueryExpression.cs

@ -45,7 +45,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -45,7 +45,7 @@ namespace ICSharpCode.NRefactory.CSharp
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
QueryExpression o = other as QueryExpression;
return o != null && this.Clauses.DoMatch(o.Clauses, match);
return o != null && !o.IsNull && this.Clauses.DoMatch(o.Clauses, match);
}
}
@ -54,12 +54,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -54,12 +54,6 @@ namespace ICSharpCode.NRefactory.CSharp
public override NodeType NodeType {
get { return NodeType.QueryClause; }
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
QueryClause o = other as QueryClause;
throw new NotImplementedException();
}
}
/// <summary>
@ -103,6 +97,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -103,6 +97,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitQueryContinuationClause (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
QueryContinuationClause o = other as QueryContinuationClause;
return o != null && MatchString(this.Identifier, o.Identifier) && this.PrecedingQuery.DoMatch(o.PrecedingQuery, match);
}
}
public class QueryFromClause : QueryClause
@ -133,6 +133,13 @@ namespace ICSharpCode.NRefactory.CSharp @@ -133,6 +133,13 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitQueryFromClause (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
QueryFromClause o = other as QueryFromClause;
return o != null && this.Type.DoMatch(o.Type, match) && MatchString(this.Identifier, o.Identifier)
&& this.Expression.DoMatch(o.Expression, match);
}
}
public class QueryLetClause : QueryClause
@ -163,6 +170,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -163,6 +170,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitQueryLetClause (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
QueryLetClause o = other as QueryLetClause;
return o != null && MatchString(this.Identifier, o.Identifier) && this.Expression.DoMatch(o.Expression, match);
}
}
@ -181,6 +194,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -181,6 +194,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitQueryWhereClause (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
QueryWhereClause o = other as QueryWhereClause;
return o != null && this.Condition.DoMatch(o.Condition, match);
}
}
/// <summary>
@ -266,6 +285,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -266,6 +285,16 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitQueryJoinClause (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
QueryJoinClause o = other as QueryJoinClause;
return o != null && this.IsGroupJoin == o.IsGroupJoin
&& this.Type.DoMatch(o.Type, match) && MatchString(this.JoinIdentifier, o.JoinIdentifier)
&& this.InExpression.DoMatch(o.InExpression, match) && this.OnExpression.DoMatch(o.OnExpression, match)
&& this.EqualsExpression.DoMatch(o.EqualsExpression, match)
&& MatchString(this.IntoIdentifier, o.IntoIdentifier);
}
}
public class QueryOrderClause : QueryClause
@ -284,6 +313,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -284,6 +313,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitQueryOrderClause (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
QueryOrderClause o = other as QueryOrderClause;
return o != null && this.Orderings.DoMatch(o.Orderings, match);
}
}
public class QueryOrdering : AstNode
@ -340,6 +375,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -340,6 +375,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitQuerySelectClause (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
QuerySelectClause o = other as QuerySelectClause;
return o != null && this.Expression.DoMatch(o.Expression, match);
}
}
public class QueryGroupClause : QueryClause
@ -371,5 +412,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -371,5 +412,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitQueryGroupClause (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
QueryGroupClause o = other as QueryGroupClause;
return o != null && this.Projection.DoMatch(o.Projection, match) && this.Key.DoMatch(o.Key, match);
}
}
}

9
ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/AttributeSection.cs

@ -64,6 +64,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -64,6 +64,15 @@ namespace ICSharpCode.NRefactory.CSharp
return o != null && this.AttributeTarget == o.AttributeTarget && this.Attributes.DoMatch(o.Attributes, match);
}
public AttributeSection()
{
}
public AttributeSection(Attribute attr)
{
this.Attributes.Add(attr);
}
public static string GetAttributeTargetName(AttributeTarget attributeTarget)
{
switch (attributeTarget) {

5
ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Constraint.cs

@ -31,6 +31,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,6 +31,9 @@ namespace ICSharpCode.NRefactory.CSharp
/// <summary>
/// where TypeParameter : BaseTypes
/// </summary>
/// <remarks>
/// new(), struct and class constraints are represented using a PrimitiveType "new", "struct" or "class"
/// </remarks>
public class Constraint : AstNode
{
public readonly static Role<CSharpTokenNode> ColonRole = TypeDeclaration.ColonRole;
@ -51,8 +54,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -51,8 +54,6 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
// TODO: what about new(), struct and class constraints?
public AstNodeCollection<AstType> BaseTypes {
get { return GetChildrenByRole (BaseTypeRole); }
}

19
ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/DelegateDeclaration.cs

@ -40,6 +40,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -40,6 +40,11 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public AstType ReturnType {
get { return GetChildByRole (Roles.Type); }
set { SetChildByRole (Roles.Type, value); }
}
public string Name {
get {
return GetChildByRole (Roles.Identifier).Name;
@ -49,11 +54,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -49,11 +54,6 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public AstType ReturnType {
get { return GetChildByRole (Roles.Type); }
set { SetChildByRole (Roles.Type, value); }
}
public AstNodeCollection<TypeParameterDeclaration> TypeParameters {
get { return GetChildrenByRole (Roles.TypeParameter); }
}
@ -78,5 +78,14 @@ namespace ICSharpCode.NRefactory.CSharp @@ -78,5 +78,14 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitDelegateDeclaration (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
DelegateDeclaration o = other as DelegateDeclaration;
return o != null && this.MatchAttributesAndModifiers(o, match)
&& this.ReturnType.DoMatch(o.ReturnType, match) && MatchString(this.Name, o.Name)
&& this.TypeParameters.DoMatch(o.TypeParameters, match) && this.Parameters.DoMatch(o.Parameters, match)
&& this.Constraints.DoMatch(o.Constraints, match);
}
}
}

9
ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/TypeDeclaration.cs

@ -87,5 +87,14 @@ namespace ICSharpCode.NRefactory.CSharp @@ -87,5 +87,14 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitTypeDeclaration (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
TypeDeclaration o = other as TypeDeclaration;
return o != null && this.ClassType == o.ClassType && this.MatchAttributesAndModifiers(o, match)
&& MatchString(this.Name, o.Name) && this.TypeParameters.DoMatch(o.TypeParameters, match)
&& this.BaseTypes.DoMatch(o.BaseTypes, match) && this.Constraints.DoMatch(o.Constraints, match)
&& this.Members.DoMatch(o.Members, match);
}
}
}

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

@ -15,12 +15,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -15,12 +15,17 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class TypeParameterDeclaration : AstNode
{
public static readonly Role<AttributeSection> AttributeRole = AttributedNode.AttributeRole;
public static readonly Role<CSharpTokenNode> VarianceRole = new Role<CSharpTokenNode>("Variance");
public override NodeType NodeType {
get { return NodeType.Unknown; }
}
public AstNodeCollection<AttributeSection> Attributes {
get { return GetChildrenByRole (AttributeRole); }
}
public VarianceModifier Variance {
get; set;
}
@ -42,7 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -42,7 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
TypeParameterDeclaration o = other as TypeParameterDeclaration;
return o != null && this.Variance == o.Variance && MatchString(this.Name, o.Name);
return o != null && this.Variance == o.Variance && MatchString(this.Name, o.Name) && this.Attributes.DoMatch(o.Attributes, match);
}
}
}

7
ICSharpCode.NRefactory/CSharp/Ast/Identifier.cs

@ -43,6 +43,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -43,6 +43,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return default (S);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return other == null || other.IsNull;
}
}
public override NodeType NodeType {
@ -95,7 +100,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -95,7 +100,7 @@ namespace ICSharpCode.NRefactory.CSharp
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
Identifier o = other as Identifier;
return o != null && MatchString(this.Name, o.Name);
return o != null && !o.IsNull && MatchString(this.Name, o.Name);
}
}
}

2
ICSharpCode.NRefactory/CSharp/Ast/MemberType.cs

@ -77,7 +77,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -77,7 +77,7 @@ namespace ICSharpCode.NRefactory.CSharp
b.Append(this.MemberName);
if (this.TypeArguments.Any()) {
b.Append('<');
b.Append(string.Join(", ", this.TypeArguments));
b.Append(DotNet35Compat.StringJoin(", ", this.TypeArguments));
b.Append('>');
}
return b.ToString();

25
ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Pattern.cs

@ -29,34 +29,29 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching @@ -29,34 +29,29 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
}
}
internal virtual bool DoMatchCollection(Role role, AstNode pos, Match match, Stack<PossibleMatch> backtrackingStack)
public static implicit operator AstType(Pattern p)
{
return DoMatch(pos, match);
return p != null ? new TypePlaceholder(p) : null;
}
public AstType ToType()
public static implicit operator Expression(Pattern p)
{
return new TypePlaceholder(this);
return p != null ? new ExpressionPlaceholder(p) : null;
}
public Expression ToExpression()
public static implicit operator Statement(Pattern p)
{
return new ExpressionPlaceholder(this);
return p != null ? new StatementPlaceholder(p) : null;
}
public Statement ToStatement()
public static implicit operator BlockStatement(Pattern p)
{
return new StatementPlaceholder(this);
return p != null ? new BlockStatementPlaceholder(p) : null;
}
public BlockStatement ToBlock()
public static implicit operator VariableInitializer(Pattern p)
{
return new BlockStatementPlaceholder(this);
}
public VariableInitializer ToVariable()
{
return new VariablePlaceholder(this);
return p != null ? new VariablePlaceholder(p) : null;
}
// Make debugging easier by giving Patterns a ToString() implementation

68
ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Placeholder.cs

@ -2,16 +2,19 @@ @@ -2,16 +2,19 @@
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp.PatternMatching
{
// Placeholders do not store their child in the AST tree; but keep it as a separate child.
// This allows reusing the child in multiple placeholders; thus enabling the sharing of AST subtrees.
sealed class TypePlaceholder : AstType
{
public static readonly Role<AstNode> ChildRole = new Role<AstNode>("Child", AstNode.Null);
readonly AstNode child;
public TypePlaceholder(AstNode child)
{
AddChild(child, TypePlaceholder.ChildRole);
this.child = child;
}
public override NodeType NodeType {
@ -20,20 +23,27 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching @@ -20,20 +23,27 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, GetChildByRole(TypePlaceholder.ChildRole), data);
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, Match match)
{
return GetChildByRole(TypePlaceholder.ChildRole).DoMatch(other, match);
return child.DoMatch(other, match);
}
internal override bool DoMatchCollection(Role role, AstNode pos, Match match, Stack<Pattern.PossibleMatch> backtrackingStack)
{
return child.DoMatchCollection(role, pos, match, backtrackingStack);
}
}
sealed class ExpressionPlaceholder : Expression
{
readonly AstNode child;
public ExpressionPlaceholder(AstNode child)
{
AddChild(child, TypePlaceholder.ChildRole);
this.child = child;
}
public override NodeType NodeType {
@ -42,20 +52,27 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching @@ -42,20 +52,27 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, GetChildByRole(TypePlaceholder.ChildRole), data);
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, Match match)
{
return GetChildByRole(TypePlaceholder.ChildRole).DoMatch(other, match);
return child.DoMatch(other, match);
}
internal override bool DoMatchCollection(Role role, AstNode pos, Match match, Stack<Pattern.PossibleMatch> backtrackingStack)
{
return child.DoMatchCollection(role, pos, match, backtrackingStack);
}
}
sealed class StatementPlaceholder : Statement
{
readonly AstNode child;
public StatementPlaceholder(AstNode child)
{
AddChild(child, TypePlaceholder.ChildRole);
this.child = child;
}
public override NodeType NodeType {
@ -64,20 +81,27 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching @@ -64,20 +81,27 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, GetChildByRole(TypePlaceholder.ChildRole), data);
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, Match match)
{
return GetChildByRole(TypePlaceholder.ChildRole).DoMatch(other, match);
return child.DoMatch(other, match);
}
internal override bool DoMatchCollection(Role role, AstNode pos, Match match, Stack<Pattern.PossibleMatch> backtrackingStack)
{
return child.DoMatchCollection(role, pos, match, backtrackingStack);
}
}
sealed class BlockStatementPlaceholder : BlockStatement
{
readonly AstNode child;
public BlockStatementPlaceholder(AstNode child)
{
AddChild(child, TypePlaceholder.ChildRole);
this.child = child;
}
public override NodeType NodeType {
@ -86,20 +110,27 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching @@ -86,20 +110,27 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, GetChildByRole(TypePlaceholder.ChildRole), data);
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, Match match)
{
return GetChildByRole(TypePlaceholder.ChildRole).DoMatch(other, match);
return child.DoMatch(other, match);
}
internal override bool DoMatchCollection(Role role, AstNode pos, Match match, Stack<Pattern.PossibleMatch> backtrackingStack)
{
return child.DoMatchCollection(role, pos, match, backtrackingStack);
}
}
sealed class VariablePlaceholder : VariableInitializer
{
readonly AstNode child;
public VariablePlaceholder(AstNode child)
{
AddChild(child, TypePlaceholder.ChildRole);
this.child = child;
}
public override NodeType NodeType {
@ -108,12 +139,17 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching @@ -108,12 +139,17 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, GetChildByRole(TypePlaceholder.ChildRole), data);
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, Match match)
{
return GetChildByRole(TypePlaceholder.ChildRole).DoMatch(other, match);
return child.DoMatch(other, match);
}
internal override bool DoMatchCollection(Role role, AstNode pos, Match match, Stack<Pattern.PossibleMatch> backtrackingStack)
{
return child.DoMatchCollection(role, pos, match, backtrackingStack);
}
}
}

2
ICSharpCode.NRefactory/CSharp/Ast/SimpleType.cs

@ -76,7 +76,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -76,7 +76,7 @@ namespace ICSharpCode.NRefactory.CSharp
StringBuilder b = new StringBuilder(this.Identifier);
if (this.TypeArguments.Any()) {
b.Append('<');
b.Append(string.Join(", ", this.TypeArguments));
b.Append(DotNet35Compat.StringJoin(", ", this.TypeArguments));
b.Append('>');
}
return b.ToString();

2
ICSharpCode.NRefactory/CSharp/Ast/Statements/BlockStatement.cs

@ -77,7 +77,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -77,7 +77,7 @@ namespace ICSharpCode.NRefactory.CSharp
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
BlockStatement o = other as BlockStatement;
return o != null && this.Statements.DoMatch(o.Statements, match);
return o != null && !o.IsNull && this.Statements.DoMatch(o.Statements, match);
}
#region Builder methods

2
ICSharpCode.NRefactory/CSharp/Ast/Statements/FixedStatement.cs

@ -67,7 +67,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -67,7 +67,7 @@ namespace ICSharpCode.NRefactory.CSharp
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
FixedStatement o = other as FixedStatement;
return o != null && this.Variables.DoMatch(o.Variables, match) && this.EmbeddedStatement.DoMatch(o.EmbeddedStatement, match);
return o != null && this.Type.DoMatch(o.Type, match) && this.Variables.DoMatch(o.Variables, match) && this.EmbeddedStatement.DoMatch(o.EmbeddedStatement, match);
}
}
}

3
ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/Accessor.cs

@ -64,7 +64,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -64,7 +64,8 @@ namespace ICSharpCode.NRefactory.CSharp
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
throw new NotImplementedException();
Accessor o = other as Accessor;
return o != null && !o.IsNull && this.MatchAttributesAndModifiers(o, match) && this.Body.DoMatch(o.Body, match);
}
}
}

4
ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/AttributedNode.cs

@ -58,9 +58,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -58,9 +58,9 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.CSharp.PatternMatching.Match match)
protected bool MatchAttributesAndModifiers(AttributedNode o, PatternMatching.Match match)
{
throw new NotImplementedException();
return this.Modifiers == o.Modifiers && this.Attributes.DoMatch(o.Attributes, match);
}
}
}

14
ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs

@ -70,6 +70,13 @@ namespace ICSharpCode.NRefactory.CSharp @@ -70,6 +70,13 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitConstructorDeclaration (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
ConstructorDeclaration o = other as ConstructorDeclaration;
return o != null && this.MatchAttributesAndModifiers(o, match) && this.Parameters.DoMatch(o.Parameters, match)
&& this.Initializer.DoMatch(o.Initializer, match) && this.Body.DoMatch(o.Body, match);
}
}
public enum ConstructorInitializerType {
@ -98,6 +105,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -98,6 +105,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return default (S);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return other == null || other.IsNull;
}
}
public override NodeType NodeType {
@ -123,7 +135,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -123,7 +135,7 @@ namespace ICSharpCode.NRefactory.CSharp
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
ConstructorInitializer o = other as ConstructorInitializer;
return o != null && this.ConstructorInitializerType == o.ConstructorInitializerType && this.Arguments.DoMatch(o.Arguments, match);
return o != null && !o.IsNull && this.ConstructorInitializerType == o.ConstructorInitializerType && this.Arguments.DoMatch(o.Arguments, match);
}
}
}

8
ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/DestructorDeclaration.cs

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
//
// DestructorDeclaration.cs
//
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
@ -61,5 +61,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -61,5 +61,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitDestructorDeclaration (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
DestructorDeclaration o = other as DestructorDeclaration;
return o != null && this.MatchAttributesAndModifiers(o, match) && this.Body.DoMatch(o.Body, match);
}
}
}

11
ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EnumMemberDeclaration.cs

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
//
//
// EnumMemberDeclaration.cs
//
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
@ -53,6 +53,13 @@ namespace ICSharpCode.NRefactory.CSharp @@ -53,6 +53,13 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitEnumMemberDeclaration (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
EnumMemberDeclaration o = other as EnumMemberDeclaration;
return o != null && this.MatchAttributesAndModifiers(o, match)
&& MatchString(this.Name, o.Name) && this.Initializer.DoMatch(o.Initializer, match);
}
}
}

25
ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/EventDeclaration.cs

@ -28,8 +28,17 @@ using System.Collections.Generic; @@ -28,8 +28,17 @@ using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp
{
public class EventDeclaration : MemberDeclaration
public class EventDeclaration : AttributedNode
{
public override NodeType NodeType {
get { return NodeType.Member; }
}
public AstType ReturnType {
get { return GetChildByRole (Roles.Type); }
set { SetChildByRole(Roles.Type, value); }
}
public AstNodeCollection<VariableInitializer> Variables {
get { return GetChildrenByRole (Roles.Variable); }
}
@ -38,6 +47,13 @@ namespace ICSharpCode.NRefactory.CSharp @@ -38,6 +47,13 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitEventDeclaration (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
EventDeclaration o = other as EventDeclaration;
return o != null && this.MatchAttributesAndModifiers(o, match)
&& this.ReturnType.DoMatch(o.ReturnType, match) && this.Variables.DoMatch(o.Variables, match);
}
}
public class CustomEventDeclaration : MemberDeclaration
@ -67,5 +83,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -67,5 +83,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitCustomEventDeclaration (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
CustomEventDeclaration o = other as CustomEventDeclaration;
return o != null && this.MatchMember(o, match)
&& this.AddAccessor.DoMatch(o.AddAccessor, match) && this.RemoveAccessor.DoMatch(o.RemoveAccessor, match);
}
}
}

22
ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/FieldDeclaration.cs

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
//
// FieldDeclaration.cs
//
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
@ -29,9 +29,18 @@ using System.Linq; @@ -29,9 +29,18 @@ using System.Linq;
namespace ICSharpCode.NRefactory.CSharp
{
public class FieldDeclaration : MemberDeclaration
public class FieldDeclaration : AttributedNode
{
public AstNodeCollection<VariableInitializer> Variables {
public override NodeType NodeType {
get { return NodeType.Member; }
}
public AstType ReturnType {
get { return GetChildByRole (Roles.Type); }
set { SetChildByRole(Roles.Type, value); }
}
public AstNodeCollection<VariableInitializer> Variables {
get { return GetChildrenByRole (Roles.Variable); }
}
@ -39,5 +48,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -39,5 +48,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitFieldDeclaration (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
FieldDeclaration o = other as FieldDeclaration;
return o != null && this.MatchAttributesAndModifiers(o, match)
&& this.ReturnType.DoMatch(o.ReturnType, match) && this.Variables.DoMatch(o.Variables, match);
}
}
}

34
ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/IndexerDeclaration.cs

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
//
// IndexerDeclaration.cs
//
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
@ -29,13 +29,16 @@ using System.Linq; @@ -29,13 +29,16 @@ using System.Linq;
namespace ICSharpCode.NRefactory.CSharp
{
public class IndexerDeclaration : PropertyDeclaration
public class IndexerDeclaration : MemberDeclaration
{
public static readonly Role<Accessor> GetterRole = PropertyDeclaration.GetterRole;
public static readonly Role<Accessor> SetterRole = PropertyDeclaration.SetterRole;
public CSharpTokenNode LBracketToken {
get { return GetChildByRole (Roles.LBracket); }
}
public AstNodeCollection<ParameterDeclaration> Parameters {
public AstNodeCollection<ParameterDeclaration> Parameters {
get { return GetChildrenByRole (Roles.Parameter); }
}
@ -43,9 +46,34 @@ namespace ICSharpCode.NRefactory.CSharp @@ -43,9 +46,34 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RBracket); }
}
public CSharpTokenNode LBraceToken {
get { return GetChildByRole (Roles.LBrace); }
}
public Accessor Getter {
get { return GetChildByRole(GetterRole); }
set { SetChildByRole(GetterRole, value); }
}
public Accessor Setter {
get { return GetChildByRole(SetterRole); }
set { SetChildByRole(SetterRole, value); }
}
public CSharpTokenNode RBraceToken {
get { return GetChildByRole (Roles.RBrace); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitIndexerDeclaration (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
IndexerDeclaration o = other as IndexerDeclaration;
return o != null && this.MatchMember(o, match) && this.Parameters.DoMatch(o.Parameters, match)
&& this.Getter.DoMatch(o.Getter, match) && this.Setter.DoMatch(o.Setter, match);
}
}
}

6
ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MemberDeclaration.cs

@ -55,5 +55,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -55,5 +55,11 @@ namespace ICSharpCode.NRefactory.CSharp
public override NodeType NodeType {
get { return NodeType.Member; }
}
protected bool MatchMember(MemberDeclaration o, PatternMatching.Match match)
{
return MatchAttributesAndModifiers(o, match) && this.ReturnType.DoMatch(o.ReturnType, match)
&& this.PrivateImplementationType.DoMatch(o.PrivateImplementationType, match) && MatchString(this.Name, o.Name);
}
}
}

14
ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/MethodDeclaration.cs

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
//
// MethodDeclaration.cs
//
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
@ -39,7 +39,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -39,7 +39,7 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.LPar); }
}
public AstNodeCollection<ParameterDeclaration> Parameters {
public AstNodeCollection<ParameterDeclaration> Parameters {
get { return GetChildrenByRole (Roles.Parameter); }
}
@ -47,7 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -47,7 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RPar); }
}
public AstNodeCollection<Constraint> Constraints {
public AstNodeCollection<Constraint> Constraints {
get { return GetChildrenByRole (Roles.Constraint); }
}
@ -67,5 +67,13 @@ namespace ICSharpCode.NRefactory.CSharp @@ -67,5 +67,13 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitMethodDeclaration (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
MethodDeclaration o = other as MethodDeclaration;
return o != null && this.MatchMember(o, match) && this.TypeParameters.DoMatch(o.TypeParameters, match)
&& this.Parameters.DoMatch(o.Parameters, match) && this.Constraints.DoMatch(o.Constraints, match)
&& this.Body.DoMatch(o.Body, match);
}
}
}

27
ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/OperatorDeclaration.cs

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
//
// OperatorDeclaration.cs
//
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
@ -66,7 +66,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -66,7 +66,7 @@ namespace ICSharpCode.NRefactory.CSharp
Explicit
}
public class OperatorDeclaration : MemberDeclaration
public class OperatorDeclaration : AttributedNode
{
public static readonly Role<CSharpTokenNode> OperatorTypeRole = new Role<CSharpTokenNode>("OperatorType", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> OperatorKeywordRole = Roles.Keyword;
@ -76,11 +76,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -76,11 +76,16 @@ namespace ICSharpCode.NRefactory.CSharp
set;
}
public AstType ReturnType {
get { return GetChildByRole (Roles.Type); }
set { SetChildByRole(Roles.Type, value); }
}
public CSharpTokenNode LParToken {
get { return GetChildByRole (Roles.LPar); }
}
public AstNodeCollection<ParameterDeclaration> Parameters {
public AstNodeCollection<ParameterDeclaration> Parameters {
get { return GetChildrenByRole (Roles.Parameter); }
}
@ -103,9 +108,25 @@ namespace ICSharpCode.NRefactory.CSharp @@ -103,9 +108,25 @@ namespace ICSharpCode.NRefactory.CSharp
return Mono.CSharp.Operator.GetName((Mono.CSharp.Operator.OpType)type);
}
public override NodeType NodeType {
get { return NodeType.Member; }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitOperatorDeclaration (this, data);
}
public string Name {
get { return GetName(this.OperatorType); }
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
OperatorDeclaration o = other as OperatorDeclaration;
return o != null && this.MatchAttributesAndModifiers(o, match) && this.OperatorType == o.OperatorType
&& this.ReturnType.DoMatch(o.ReturnType, match)
&& this.Parameters.DoMatch(o.Parameters, match) && this.Body.DoMatch(o.Body, match);
}
}
}

14
ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs

@ -85,7 +85,19 @@ namespace ICSharpCode.NRefactory.CSharp @@ -85,7 +85,19 @@ namespace ICSharpCode.NRefactory.CSharp
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
ParameterDeclaration o = other as ParameterDeclaration;
return o != null && this.Attributes.DoMatch(o.Attributes, match) && this.ParameterModifier == o.ParameterModifier && MatchString(this.Name, o.Name) && this.DefaultExpression.DoMatch(o.DefaultExpression, match);
return o != null && this.Attributes.DoMatch(o.Attributes, match) && this.ParameterModifier == o.ParameterModifier
&& this.Type.DoMatch(o.Type, match) && MatchString(this.Name, o.Name)
&& this.DefaultExpression.DoMatch(o.DefaultExpression, match);
}
public ParameterDeclaration()
{
}
public ParameterDeclaration(AstType type, string name)
{
this.Type = type;
this.Name = name;
}
}
}

11
ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/PropertyDeclaration.cs

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
//
//
// PropertyDeclaration.cs
//
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
@ -53,5 +53,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -53,5 +53,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
return visitor.VisitPropertyDeclaration (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
PropertyDeclaration o = other as PropertyDeclaration;
return o != null && this.MatchMember(o, match)
&& this.Getter.DoMatch(o.Getter, match) && this.Setter.DoMatch(o.Setter, match);
}
}
}

77
ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs

@ -22,7 +22,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -22,7 +22,7 @@ namespace ICSharpCode.NRefactory.CSharp
readonly IOutputFormatter formatter;
readonly CSharpFormattingPolicy policy;
AstNode currentContainerNode;
readonly Stack<AstNode> containerStack = new Stack<AstNode>();
readonly Stack<AstNode> positionStack = new Stack<AstNode>();
/// <summary>
@ -65,21 +65,23 @@ namespace ICSharpCode.NRefactory.CSharp @@ -65,21 +65,23 @@ namespace ICSharpCode.NRefactory.CSharp
#region StartNode/EndNode
void StartNode(AstNode node)
{
Debug.Assert(currentContainerNode == null || node.Parent == currentContainerNode);
// Ensure that nodes are visited in the proper nested order.
// Jumps to different subtrees are allowed only for the child of a placeholder node.
Debug.Assert(containerStack.Count == 0 || node.Parent == containerStack.Peek() || containerStack.Peek().NodeType == NodeType.Placeholder);
if (positionStack.Count > 0)
WriteSpecialsUpToNode(node);
currentContainerNode = node;
containerStack.Push(node);
positionStack.Push(node.FirstChild);
formatter.StartNode(node);
}
object EndNode(AstNode node)
{
Debug.Assert(node == currentContainerNode);
Debug.Assert(node == containerStack.Peek());
AstNode pos = positionStack.Pop();
Debug.Assert(pos == null || pos.Parent == node);
WriteSpecials(pos, null);
currentContainerNode = node.Parent;
containerStack.Pop();
formatter.EndNode(node);
return null;
}
@ -146,13 +148,14 @@ namespace ICSharpCode.NRefactory.CSharp @@ -146,13 +148,14 @@ namespace ICSharpCode.NRefactory.CSharp
/// Writes a comma.
/// </summary>
/// <param name="nextNode">The next node after the comma.</param>
void Comma(AstNode nextNode)
/// <param name="noSpacesAfterComma">When set prevents printing a space after comma.</param>
void Comma(AstNode nextNode, bool noSpaceAfterComma = false)
{
WriteSpecialsUpToRole(AstNode.Roles.Comma, nextNode);
Space(policy.SpacesBeforeComma);
formatter.WriteToken(",");
lastWritten = LastWritten.Other;
Space(policy.SpacesAfterComma);
Space(!noSpaceAfterComma && policy.SpacesAfterComma);
}
void WriteCommaSeparatedList(IEnumerable<AstNode> list)
@ -179,12 +182,34 @@ namespace ICSharpCode.NRefactory.CSharp @@ -179,12 +182,34 @@ namespace ICSharpCode.NRefactory.CSharp
RPar();
}
void WriteCommaSeparatedListInBrackets(IEnumerable<AstNode> list)
#if DOTNET35
void WriteCommaSeparatedList(IEnumerable<VariableInitializer> list)
{
WriteCommaSeparatedList(list.SafeCast<VariableInitializer, AstNode>());
}
void WriteCommaSeparatedList(IEnumerable<AstType> list)
{
WriteCommaSeparatedList(list.SafeCast<AstType, AstNode>());
}
void WriteCommaSeparatedListInParenthesis(IEnumerable<Expression> list, bool spaceWithin)
{
WriteCommaSeparatedListInParenthesis(list.SafeCast<Expression, AstNode>(), spaceWithin);
}
void WriteCommaSeparatedListInParenthesis(IEnumerable<ParameterDeclaration> list, bool spaceWithin)
{
WriteCommaSeparatedListInParenthesis(list.SafeCast<ParameterDeclaration, AstNode>(), spaceWithin);
}
#endif
void WriteCommaSeparatedListInBrackets(IEnumerable<Expression> list)
{
WriteToken("[", AstNode.Roles.LBracket);
if (list.Any()) {
Space(policy.SpacesWithinBrackets);
WriteCommaSeparatedList(list);
WriteCommaSeparatedList(list.SafeCast<Expression, AstNode>());
Space(policy.SpacesWithinBrackets);
}
WriteToken("]", AstNode.Roles.RBracket);
@ -207,7 +232,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -207,7 +232,7 @@ namespace ICSharpCode.NRefactory.CSharp
void WriteIdentifier(string identifier, Role<Identifier> identifierRole = null)
{
WriteSpecialsUpToRole(identifierRole ?? AstNode.Roles.Identifier);
if (IsKeyword(identifier, currentContainerNode)) {
if (IsKeyword(identifier, containerStack.Peek())) {
if (lastWritten == LastWritten.KeywordOrIdentifier)
Space(); // this space is not strictly required, so we call Space()
formatter.WriteToken("@");
@ -265,7 +290,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -265,7 +290,8 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
void Semicolon()
{
if (currentContainerNode.Role != ForStatement.InitializerRole && currentContainerNode.Role != ForStatement.IteratorRole && currentContainerNode.Role != UsingStatement.ResourceAcquisitionRole) {
Role role = containerStack.Peek().Role; // get the role of the current node
if (!(role == ForStatement.InitializerRole || role == ForStatement.IteratorRole || role == UsingStatement.ResourceAcquisitionRole)) {
WriteToken(";", AstNode.Roles.Semicolon);
NewLine();
}
@ -351,7 +377,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -351,7 +377,7 @@ namespace ICSharpCode.NRefactory.CSharp
{
if (typeParameters.Any()) {
WriteToken("<", AstNode.Roles.LChevron);
WriteCommaSeparatedList(typeParameters);
WriteCommaSeparatedList(typeParameters.SafeCast<TypeParameterDeclaration, AstNode>());
WriteToken(">", AstNode.Roles.RChevron);
}
}
@ -1033,7 +1059,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1033,7 +1059,7 @@ namespace ICSharpCode.NRefactory.CSharp
StartNode(queryOrderClause);
WriteKeyword("orderby");
Space();
WriteCommaSeparatedList(queryOrderClause.Orderings);
WriteCommaSeparatedList(queryOrderClause.Orderings.SafeCast<QueryOrdering, AstNode>());
return EndNode(queryOrderClause);
}
@ -1083,7 +1109,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1083,7 +1109,8 @@ namespace ICSharpCode.NRefactory.CSharp
StartNode(attribute);
attribute.Type.AcceptVisitor(this, data);
Space(policy.BeforeMethodCallParentheses);
WriteCommaSeparatedListInParenthesis(attribute.Arguments, policy.WithinMethodCallParentheses);
if (attribute.Arguments.Count != 0 || !attribute.GetChildByRole(AstNode.Roles.LPar).IsNull)
WriteCommaSeparatedListInParenthesis(attribute.Arguments, policy.WithinMethodCallParentheses);
return EndNode(attribute);
}
@ -1096,9 +1123,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1096,9 +1123,10 @@ namespace ICSharpCode.NRefactory.CSharp
WriteToken(":", AttributeSection.Roles.Colon);
Space();
}
WriteCommaSeparatedList(attributeSection.Attributes);
WriteCommaSeparatedList(attributeSection.Attributes.SafeCast<Attribute, AstNode>());
WriteToken("]", AstNode.Roles.RBracket);
NewLine();
if (!(attributeSection.Parent is ParameterDeclaration))
NewLine();
return EndNode(attributeSection);
}
@ -1176,7 +1204,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1176,7 +1204,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (first) {
first = false;
} else {
Comma(member);
Comma(member, noSpaceAfterComma: true);
NewLine();
}
member.AcceptVisitor(this, data);
@ -1345,7 +1373,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1345,7 +1373,7 @@ namespace ICSharpCode.NRefactory.CSharp
LPar();
Space(policy.WithinForParentheses);
WriteCommaSeparatedList(forStatement.Initializers);
WriteCommaSeparatedList(forStatement.Initializers.SafeCast<Statement, AstNode>());
WriteToken(";", AstNode.Roles.Semicolon);
Space(policy.SpacesAfterSemicolon);
@ -1353,7 +1381,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1353,7 +1381,7 @@ namespace ICSharpCode.NRefactory.CSharp
WriteToken(";", AstNode.Roles.Semicolon);
Space(policy.SpacesAfterSemicolon);
WriteCommaSeparatedList(forStatement.Iterators);
WriteCommaSeparatedList(forStatement.Iterators.SafeCast<Statement, AstNode>());
Space(policy.WithinForParentheses);
RPar();
@ -1889,7 +1917,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1889,7 +1917,10 @@ namespace ICSharpCode.NRefactory.CSharp
{
StartNode(memberType);
memberType.Target.AcceptVisitor(this, data);
WriteToken(".", MemberType.Roles.Dot);
if (memberType.IsDoubleColon)
WriteToken("::", MemberType.Roles.Dot);
else
WriteToken(".", MemberType.Roles.Dot);
WriteIdentifier(memberType.MemberName);
WriteTypeArguments(memberType.TypeArguments);
return EndNode(memberType);
@ -1925,6 +1956,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1925,6 +1956,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
StartNode(primitiveType);
WriteKeyword(primitiveType.Keyword);
if (primitiveType.Keyword == "new") {
// new() constraint
LPar();
RPar();
}
return EndNode(primitiveType);
}
@ -1943,6 +1979,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1943,6 +1979,7 @@ namespace ICSharpCode.NRefactory.CSharp
public object VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration, object data)
{
StartNode(typeParameterDeclaration);
WriteAttributes(typeParameterDeclaration.Attributes);
switch (typeParameterDeclaration.Variance) {
case VarianceModifier.Invariant:
break;

46
ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs

@ -225,7 +225,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -225,7 +225,7 @@ namespace ICSharpCode.NRefactory.CSharp
var typeArgLocation = LocationsBag.GetLocations (c.MemberName);
if (typeArgLocation != null)
newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), TypeDeclaration.Roles.LChevron);
// AddTypeArguments (newType, typeArgLocation, c.MemberName.TypeArguments);
AddTypeParameters (newType, typeArgLocation, c.MemberName.TypeArguments);
if (typeArgLocation != null)
newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), TypeDeclaration.Roles.RChevron);
AddConstraints (newType, c);
@ -254,7 +254,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -254,7 +254,7 @@ namespace ICSharpCode.NRefactory.CSharp
var typeArgLocation = LocationsBag.GetLocations (s.MemberName);
if (typeArgLocation != null)
newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), TypeDeclaration.Roles.LChevron);
// AddTypeArguments (newType, typeArgLocation, s.MemberName.TypeArguments);
AddTypeParameters (newType, typeArgLocation, s.MemberName.TypeArguments);
if (typeArgLocation != null)
newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), TypeDeclaration.Roles.RChevron);
AddConstraints (newType, s);
@ -283,7 +283,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -283,7 +283,7 @@ namespace ICSharpCode.NRefactory.CSharp
var typeArgLocation = LocationsBag.GetLocations (i.MemberName);
if (typeArgLocation != null)
newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), MemberReferenceExpression.Roles.LChevron);
// AddTypeArguments (newType, typeArgLocation, i.MemberName.TypeArguments);
AddTypeParameters (newType, typeArgLocation, i.MemberName.TypeArguments);
if (typeArgLocation != null)
newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), MemberReferenceExpression.Roles.RChevron);
AddConstraints (newType, i);
@ -307,12 +307,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -307,12 +307,12 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null)
newDelegate.AddChild (new CSharpTokenNode (Convert (location[0]), "delegate".Length), TypeDeclaration.Roles.Keyword);
newDelegate.AddChild (ConvertToType (d.ReturnType), AstNode.Roles.Type);
newDelegate.AddChild (new Identifier (d.Name, Convert (d.MemberName.Location)), AstNode.Roles.Identifier);
newDelegate.AddChild (new Identifier (d.Basename, Convert (d.MemberName.Location)), AstNode.Roles.Identifier);
if (d.MemberName.TypeArguments != null) {
var typeArgLocation = LocationsBag.GetLocations (d.MemberName);
if (typeArgLocation != null)
newDelegate.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), TypeDeclaration.Roles.LChevron);
// AddTypeArguments (newDelegate, typeArgLocation, d.MemberName.TypeArguments);
AddTypeParameters (newDelegate, typeArgLocation, d.MemberName.TypeArguments);
if (typeArgLocation != null)
newDelegate.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), TypeDeclaration.Roles.RChevron);
AddConstraints (newDelegate, d);
@ -632,7 +632,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -632,7 +632,7 @@ namespace ICSharpCode.NRefactory.CSharp
var typeArgLocation = LocationsBag.GetLocations (m.MemberName);
if (typeArgLocation != null)
newMethod.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), MemberReferenceExpression.Roles.LChevron);
// AddTypeArguments (newMethod, typeArgLocation, m.MemberName.TypeArguments);
AddTypeParameters (newMethod, typeArgLocation, m.MemberName.TypeArguments);
if (typeArgLocation != null)
newMethod.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), MemberReferenceExpression.Roles.RChevron);
@ -1234,7 +1234,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1234,7 +1234,7 @@ namespace ICSharpCode.NRefactory.CSharp
statement.Remove ();
newSection.AddChild (statement, SwitchSection.Roles.EmbeddedStatement);
}
}
result.AddChild (newSection, SwitchStatement.SwitchSectionRole);
}
@ -1835,17 +1835,22 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1835,17 +1835,22 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
void AddTypeArguments (AstNode parent, LocationsBag.MemberLocations location, Mono.CSharp.TypeArguments typeArguments)
void AddTypeParameters (AstNode parent, List<Location> location, Mono.CSharp.TypeArguments typeArguments)
{
if (typeArguments == null || typeArguments.IsEmpty)
return;
for (int i = 0; i < typeArguments.Count; i++) {
if (location != null && i > 0 && i - 1 < location.Count)
parent.AddChild (new CSharpTokenNode (Convert (location[i - 1]), 1), InvocationExpression.Roles.Comma);
var arg = typeArguments.Args[i];
var arg = (TypeParameterName)typeArguments.Args[i];
if (arg == null)
continue;
parent.AddChild (ConvertToType (arg), InvocationExpression.Roles.TypeArgument);
TypeParameterDeclaration tp = new TypeParameterDeclaration();
// TODO: attributes
if (arg.Variance != Variance.None)
throw new NotImplementedException(); // TODO: variance
tp.AddChild (new Identifier (arg.Name, Convert (arg.Location)), InvocationExpression.Roles.Identifier);
parent.AddChild (tp, InvocationExpression.Roles.TypeParameter);
}
}
@ -1871,11 +1876,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1871,11 +1876,12 @@ namespace ICSharpCode.NRefactory.CSharp
Constraints c = d.Constraints[i];
var location = LocationsBag.GetLocations (c);
var constraint = new Constraint ();
parent.AddChild (new CSharpTokenNode (Convert (location[0]), "where".Length), InvocationExpression.Roles.Keyword);
parent.AddChild (new Identifier (c.TypeParameter.Value, Convert (c.TypeParameter.Location)), InvocationExpression.Roles.Identifier);
parent.AddChild (new CSharpTokenNode (Convert (location[1]), 1), Constraint.ColonRole);
constraint.AddChild (new CSharpTokenNode (Convert (location[0]), "where".Length), InvocationExpression.Roles.Keyword);
constraint.AddChild (new Identifier (c.TypeParameter.Value, Convert (c.TypeParameter.Location)), InvocationExpression.Roles.Identifier);
constraint.AddChild (new CSharpTokenNode (Convert (location[1]), 1), Constraint.ColonRole);
foreach (var expr in c.ConstraintExpressions)
parent.AddChild (ConvertToType (expr), Constraint.BaseTypeRole);
constraint.AddChild (ConvertToType (expr), Constraint.BaseTypeRole);
parent.AddChild (constraint, AstNode.Roles.Constraint);
}
}
@ -1892,7 +1898,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1892,7 +1898,7 @@ namespace ICSharpCode.NRefactory.CSharp
DirectionExpression direction = new DirectionExpression ();
direction.FieldDirection = arg.ArgType == Argument.AType.Out ? FieldDirection.Out : FieldDirection.Ref;
var argLocation = LocationsBag.GetLocations (arg);
if (location != null)
if (argLocation != null)
direction.AddChild (new CSharpTokenNode (Convert (argLocation[0]), "123".Length), InvocationExpression.Roles.Keyword);
direction.AddChild ((Expression)arg.Expr.Accept (this), InvocationExpression.Roles.Expression);
@ -2115,10 +2121,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -2115,10 +2121,10 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), "stackalloc".Length), StackAllocExpression.Roles.Keyword);
result.AddChild (ConvertToType (stackAllocExpression.TypeExpression), StackAllocExpression.Roles.Type);
if (location != null)
if (location != null && location.Count > 1)
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), StackAllocExpression.Roles.LBracket);
result.AddChild ((Expression)stackAllocExpression.CountExpression.Accept (this), StackAllocExpression.Roles.Expression);
if (location != null)
if (location != null && location.Count > 2)
result.AddChild (new CSharpTokenNode (Convert (location[2]), 1), StackAllocExpression.Roles.RBracket);
return result;
}
@ -2540,7 +2546,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -2540,7 +2546,7 @@ namespace ICSharpCode.NRefactory.CSharp
return EmptyList<AttributedNode>.Instance;
}
public IEnumerable<AstNode> ParseStatements(TextReader reader)
public IEnumerable<Statement> ParseStatements(TextReader reader)
{
string code = "void M() { " + reader.ReadToEnd() + "}";
var members = ParseTypeMembers(new StringReader(code));
@ -2548,10 +2554,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -2548,10 +2554,10 @@ namespace ICSharpCode.NRefactory.CSharp
if (method != null && method.Body != null)
return method.Body.Statements;
else
return EmptyList<AstNode>.Instance;
return EmptyList<Statement>.Instance;
}
public AstNode ParseTypeReference(TextReader reader)
public AstType ParseTypeReference(TextReader reader)
{
// TODO: add support for parsing type references
throw new NotImplementedException();

83
ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs

@ -145,9 +145,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -145,9 +145,11 @@ namespace ICSharpCode.NRefactory.CSharp
else if (td.ClassType == ClassType.Enum || td.ClassType == ClassType.Struct)
td.IsSealed = true; // enums/structs are implicitly sealed
//TODO ConvertTypeParameters(td.TypeParameters, typeDeclaration.TypeParameters, typeDeclaration.Constraints);
ConvertTypeParameters(td.TypeParameters, typeDeclaration.TypeParameters, typeDeclaration.Constraints);
// TODO: base type references?
foreach (AstType baseType in typeDeclaration.BaseTypes) {
td.BaseTypes.Add(ConvertType(baseType));
}
foreach (AttributedNode member in typeDeclaration.Members) {
member.AcceptVisitor(this, data);
@ -159,7 +161,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -159,7 +161,7 @@ namespace ICSharpCode.NRefactory.CSharp
public override IEntity VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data)
{
var td = CreateTypeDefinition(delegateDeclaration.Name);
var td = currentTypeDefinition = CreateTypeDefinition(delegateDeclaration.Name);
td.ClassType = ClassType.Delegate;
td.Region = MakeRegion(delegateDeclaration);
td.BaseTypes.Add(multicastDelegateReference);
@ -168,9 +170,14 @@ namespace ICSharpCode.NRefactory.CSharp @@ -168,9 +170,14 @@ namespace ICSharpCode.NRefactory.CSharp
ApplyModifiers(td, delegateDeclaration.Modifiers);
td.IsSealed = true; // delegates are implicitly sealed
// TODO: convert return type, convert parameters
AddDefaultMethodsToDelegate(td, SharedTypes.UnknownType, EmptyList<IParameter>.Instance);
ConvertTypeParameters(td.TypeParameters, delegateDeclaration.TypeParameters, delegateDeclaration.Constraints);
ITypeReference returnType = ConvertType(delegateDeclaration.ReturnType);
List<IParameter> parameters = new List<IParameter>();
ConvertParameters(parameters, delegateDeclaration.Parameters);
AddDefaultMethodsToDelegate(td, returnType, parameters);
currentTypeDefinition = (DefaultTypeDefinition)currentTypeDefinition.DeclaringTypeDefinition;
return td;
}
@ -299,7 +306,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -299,7 +306,7 @@ namespace ICSharpCode.NRefactory.CSharp
m.BodyRegion = MakeRegion(methodDeclaration.Body);
//TODO ConvertTypeParameters(m.TypeParameters, methodDeclaration.TypeParameters, methodDeclaration.Constraints);
ConvertTypeParameters(m.TypeParameters, methodDeclaration.TypeParameters, methodDeclaration.Constraints);
m.ReturnType = ConvertType(methodDeclaration.ReturnType);
ConvertAttributes(m.Attributes, methodDeclaration.Attributes.Where(s => s.AttributeTarget != AttributeTarget.Return));
ConvertAttributes(m.ReturnTypeAttributes, methodDeclaration.Attributes.Where(s => s.AttributeTarget == AttributeTarget.Return));
@ -318,7 +325,13 @@ namespace ICSharpCode.NRefactory.CSharp @@ -318,7 +325,13 @@ namespace ICSharpCode.NRefactory.CSharp
return m;
}
DefaultExplicitInterfaceImplementation ConvertInterfaceImplementation(AstNode interfaceType, string memberName)
void ConvertTypeParameters(IList<ITypeParameter> output, IEnumerable<TypeParameterDeclaration> typeParameters, IEnumerable<Constraint> constraints)
{
if (typeParameters.Any())
throw new NotImplementedException();
}
DefaultExplicitInterfaceImplementation ConvertInterfaceImplementation(AstType interfaceType, string memberName)
{
return new DefaultExplicitInterfaceImplementation(ConvertType(interfaceType), memberName);
}
@ -327,7 +340,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -327,7 +340,7 @@ namespace ICSharpCode.NRefactory.CSharp
#region Operators
public override IEntity VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, object data)
{
DefaultMethod m = new DefaultMethod(currentTypeDefinition, OperatorDeclaration.GetName(operatorDeclaration.OperatorType));
DefaultMethod m = new DefaultMethod(currentTypeDefinition, operatorDeclaration.Name);
m.EntityType = EntityType.Operator;
m.Region = MakeRegion(operatorDeclaration);
m.BodyRegion = MakeRegion(operatorDeclaration.Body);
@ -395,13 +408,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -395,13 +408,6 @@ namespace ICSharpCode.NRefactory.CSharp
public override IEntity VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data)
{
DefaultProperty p = new DefaultProperty(currentTypeDefinition, propertyDeclaration.Name);
HandlePropertyOrIndexer(p, propertyDeclaration);
currentTypeDefinition.Properties.Add(p);
return p;
}
void HandlePropertyOrIndexer(DefaultProperty p, PropertyDeclaration propertyDeclaration)
{
p.Region = MakeRegion(propertyDeclaration);
p.BodyRegion = MakeBraceRegion(propertyDeclaration);
ApplyModifiers(p, propertyDeclaration.Modifiers);
@ -413,13 +419,25 @@ namespace ICSharpCode.NRefactory.CSharp @@ -413,13 +419,25 @@ namespace ICSharpCode.NRefactory.CSharp
}
p.Getter = ConvertAccessor(propertyDeclaration.Getter, p.Accessibility);
p.Setter = ConvertAccessor(propertyDeclaration.Setter, p.Accessibility);
currentTypeDefinition.Properties.Add(p);
return p;
}
public override IEntity VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data)
{
DefaultProperty p = new DefaultProperty(currentTypeDefinition, "Items");
p.EntityType = EntityType.Indexer;
HandlePropertyOrIndexer(p, indexerDeclaration);
p.Region = MakeRegion(indexerDeclaration);
p.BodyRegion = MakeBraceRegion(indexerDeclaration);
ApplyModifiers(p, indexerDeclaration.Modifiers);
p.ReturnType = ConvertType(indexerDeclaration.ReturnType);
ConvertAttributes(p.Attributes, indexerDeclaration.Attributes);
if (!indexerDeclaration.PrivateImplementationType.IsNull) {
p.Accessibility = Accessibility.None;
p.InterfaceImplementations.Add(ConvertInterfaceImplementation(indexerDeclaration.PrivateImplementationType, p.Name));
}
p.Getter = ConvertAccessor(indexerDeclaration.Getter, p.Accessibility);
p.Setter = ConvertAccessor(indexerDeclaration.Setter, p.Accessibility);
ConvertParameters(p.Parameters, indexerDeclaration.Parameters);
currentTypeDefinition.Properties.Add(p);
return p;
@ -528,14 +546,14 @@ namespace ICSharpCode.NRefactory.CSharp @@ -528,14 +546,14 @@ namespace ICSharpCode.NRefactory.CSharp
#endregion
#region Types
ITypeReference ConvertType(AstNode node, bool isInUsingDeclaration = false)
ITypeReference ConvertType(AstType type, bool isInUsingDeclaration = false)
{
return ConvertType(node, currentTypeDefinition, currentMethod, usingScope, isInUsingDeclaration);
return ConvertType(type, currentTypeDefinition, currentMethod, usingScope, isInUsingDeclaration);
}
internal static ITypeReference ConvertType(AstNode node, ITypeDefinition parentTypeDefinition, IMethod parentMethodDefinition, UsingScope parentUsingScope, bool isInUsingDeclaration)
internal static ITypeReference ConvertType(AstType type, ITypeDefinition parentTypeDefinition, IMethod parentMethodDefinition, UsingScope parentUsingScope, bool isInUsingDeclaration)
{
SimpleType s = node as SimpleType;
SimpleType s = type as SimpleType;
if (s != null) {
List<ITypeReference> typeArguments = new List<ITypeReference>();
foreach (var ta in s.TypeArguments) {
@ -551,25 +569,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -551,25 +569,8 @@ namespace ICSharpCode.NRefactory.CSharp
}
return new SimpleTypeOrNamespaceReference(s.Identifier, typeArguments, parentTypeDefinition, parentUsingScope, isInUsingDeclaration);
}
IdentifierExpression ident = node as IdentifierExpression;
if (ident != null) {
// TODO: get rid of this code once the parser produces SimpleType instead of IdentifierExpression
List<ITypeReference> typeArguments = new List<ITypeReference>();
foreach (var ta in ident.TypeArguments) {
typeArguments.Add(ConvertType(ta, parentTypeDefinition, parentMethodDefinition, parentUsingScope, isInUsingDeclaration));
}
if (typeArguments.Count == 0 && parentMethodDefinition != null) {
// SimpleTypeOrNamespaceReference doesn't support method type parameters,
// so we directly handle them here.
foreach (ITypeParameter tp in parentMethodDefinition.TypeParameters) {
if (tp.Name == s.Identifier)
return tp;
}
}
return new SimpleTypeOrNamespaceReference(ident.Identifier, typeArguments, parentTypeDefinition, parentUsingScope, isInUsingDeclaration);
}
PrimitiveType p = node as PrimitiveType;
PrimitiveType p = type as PrimitiveType;
if (p != null) {
switch (p.Keyword) {
case "string":
@ -608,7 +609,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -608,7 +609,7 @@ namespace ICSharpCode.NRefactory.CSharp
return SharedTypes.UnknownType;
}
}
MemberType m = node as MemberType;
MemberType m = type as MemberType;
if (m != null) {
ITypeOrNamespaceReference t;
if (m.IsDoubleColon) {
@ -629,7 +630,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -629,7 +630,7 @@ namespace ICSharpCode.NRefactory.CSharp
}
return new MemberTypeOrNamespaceReference(t, m.MemberName, typeArguments, parentTypeDefinition, parentUsingScope);
}
ComposedType c = node as ComposedType;
ComposedType c = type as ComposedType;
if (c != null) {
ITypeReference t = ConvertType(c.BaseType, parentTypeDefinition, parentMethodDefinition, parentUsingScope, isInUsingDeclaration);
if (c.HasNullableSpecifier) {
@ -643,7 +644,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -643,7 +644,7 @@ namespace ICSharpCode.NRefactory.CSharp
}
return t;
}
Debug.WriteLine("Unknown node used as type: " + node);
Debug.WriteLine("Unknown node used as type: " + type);
return SharedTypes.UnknownType;
}
#endregion

28
ICSharpCode.NRefactory/CSharp/Resolver/CSharpResolver.cs

@ -26,13 +26,22 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -26,13 +26,22 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
internal readonly CancellationToken cancellationToken;
#region Constructor
public CSharpResolver(ITypeResolveContext context, CancellationToken cancellationToken = default(CancellationToken))
public CSharpResolver(ITypeResolveContext context)
{
if (context == null)
throw new ArgumentNullException("context");
this.context = context;
}
#if !DOTNET35
public CSharpResolver(ITypeResolveContext context, CancellationToken cancellationToken)
{
if (context == null)
throw new ArgumentNullException("context");
this.context = context;
this.cancellationToken = cancellationToken;
}
#endif
#endregion
#region Properties
@ -1513,12 +1522,9 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -1513,12 +1522,9 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
}
}
ResolveResult rr = LookupSimpleNameOrTypeName(
return LookupSimpleNameOrTypeName(
identifier, typeArguments,
isInvocationTarget ? SimpleNameLookupMode.InvocationTarget : SimpleNameLookupMode.Expression);
if (rr == ErrorResult && typeArguments.Count == 0)
rr = new UnknownIdentifierResolveResult(identifier);
return rr;
}
public ResolveResult LookupSimpleNamespaceOrTypeName(string identifier, IList<IType> typeArguments, bool isUsingDeclaration = false)
@ -1633,7 +1639,10 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -1633,7 +1639,10 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
}
// if we didn't find anything: repeat lookup with parent namespace
}
return ErrorResult;
if (typeArguments.Count == 0)
return new UnknownIdentifierResolveResult(identifier);
else
return ErrorResult;
}
/// <summary>
@ -1822,7 +1831,8 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -1822,7 +1831,8 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
} else {
// No candidate found at all (not even an inapplicable one).
// This can happen with empty method groups (as sometimes used with extension methods)
return new UnknownMethodResolveResult(mgrr.TargetType, mgrr.MethodName, mgrr.TypeArguments, CreateParameters(arguments, argumentNames));
return new UnknownMethodResolveResult(
mgrr.TargetType, mgrr.MethodName, mgrr.TypeArguments, CreateParameters(arguments, argumentNames));
}
}
UnknownMemberResolveResult umrr = target as UnknownMemberResolveResult;
@ -1840,9 +1850,9 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -1840,9 +1850,9 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
return ErrorResult;
}
static List<DefaultParameter> CreateParameters(ResolveResult[] arguments, string[] argumentNames)
static List<IParameter> CreateParameters(ResolveResult[] arguments, string[] argumentNames)
{
List<DefaultParameter> list = new List<DefaultParameter>();
List<IParameter> list = new List<IParameter>();
if (argumentNames == null) {
argumentNames = new string[arguments.Length];
} else {

10
ICSharpCode.NRefactory/CSharp/Resolver/MemberLookup.cs

@ -170,10 +170,10 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -170,10 +170,10 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
Predicate<IMember> memberFilter = delegate(IMember member) {
return !member.IsOverride && member.Name == name && IsAccessible(member, allowProtectedAccess);
};
members.AddRange(type.GetMethods(context, memberFilter));
members.AddRange(type.GetProperties(context, memberFilter));
members.AddRange(type.GetFields(context, memberFilter));
members.AddRange(type.GetEvents(context, memberFilter));
members.AddRange(type.GetMethods(context, memberFilter.SafeCast<IMember, IMethod>()).SafeCast<IMethod, IMember>());
members.AddRange(type.GetProperties(context, memberFilter.SafeCast<IMember, IProperty>()).SafeCast<IProperty, IMember>());
members.AddRange(type.GetFields(context, memberFilter.SafeCast<IMember, IField>()).SafeCast<IField, IMember>());
members.AddRange(type.GetEvents(context, memberFilter.SafeCast<IMember, IEvent>()).SafeCast<IEvent, IMember>());
if (isInvocation)
members.RemoveAll(m => !IsInvocable(m, context));
} else {
@ -183,7 +183,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -183,7 +183,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
return method.TypeParameters.Count == typeArgumentCount
&& !method.IsOverride && method.Name == name && IsAccessible(method, allowProtectedAccess);
};
members.AddRange(type.GetMethods(context, memberFilter));
members.AddRange(type.GetMethods(context, memberFilter).SafeCast<IMethod, IMember>());
}
// TODO: can't members also hide types?

2
ICSharpCode.NRefactory/CSharp/Resolver/MemberTypeOrNamespaceReference.cs

@ -62,7 +62,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -62,7 +62,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
if (typeArguments.Count == 0)
return target.ToString() + "." + identifier;
else
return target.ToString() + "." + identifier + "<" + string.Join(",", typeArguments) + ">";
return target.ToString() + "." + identifier + "<" + DotNet35Compat.StringJoin(",", typeArguments) + ">";
}
}
}

2
ICSharpCode.NRefactory/CSharp/Resolver/OverloadResolution.cs

@ -446,7 +446,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -446,7 +446,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
{
bool c1IsBetter = false;
bool c2IsBetter = false;
foreach (var pair in t1.Zip<IType, IType, Tuple<IType, IType>>(t2, Tuple.Create)) {
foreach (var pair in t1.Zip(t2, (a,b) => new { Item1 = a, Item2 = b })) {
switch (MoreSpecificFormalParameter(pair.Item1, pair.Item2)) {
case 1:
c1IsBetter = true;

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

@ -224,11 +224,11 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -224,11 +224,11 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
return VisitFieldOrEventDeclaration(eventDeclaration);
}
ResolveResult VisitFieldOrEventDeclaration(MemberDeclaration fieldDeclaration)
ResolveResult VisitFieldOrEventDeclaration(AttributedNode fieldOrEventDeclaration)
{
int initializerCount = fieldDeclaration.GetChildrenByRole(FieldDeclaration.Roles.Variable).Count();
int initializerCount = fieldOrEventDeclaration.GetChildrenByRole(FieldDeclaration.Roles.Variable).Count();
ResolveResult result = null;
for (AstNode node = fieldDeclaration.FirstChild; node != null; node = node.NextSibling) {
for (AstNode node = fieldOrEventDeclaration.FirstChild; node != null; node = node.NextSibling) {
if (node.Role == FieldDeclaration.Roles.Variable) {
if (resolver.CurrentTypeDefinition != null) {
resolver.CurrentMember = resolver.CurrentTypeDefinition.Fields.FirstOrDefault(f => f.Region.IsInside(node.StartLocation));
@ -309,14 +309,14 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -309,14 +309,14 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
}
// handle properties/indexers
ResolveResult VisitPropertyMember(PropertyDeclaration propertyDeclaration)
ResolveResult VisitPropertyMember(MemberDeclaration propertyOrIndexerDeclaration)
{
try {
if (resolver.CurrentTypeDefinition != null) {
resolver.CurrentMember = resolver.CurrentTypeDefinition.Properties.FirstOrDefault(p => p.Region.IsInside(propertyDeclaration.StartLocation));
resolver.CurrentMember = resolver.CurrentTypeDefinition.Properties.FirstOrDefault(p => p.Region.IsInside(propertyOrIndexerDeclaration.StartLocation));
}
for (AstNode node = propertyDeclaration.FirstChild; node != null; node = node.NextSibling) {
for (AstNode node = propertyOrIndexerDeclaration.FirstChild; node != null; node = node.NextSibling) {
if (node.Role == PropertyDeclaration.SetterRole && resolver.CurrentMember != null) {
resolver.PushBlock();
resolver.AddVariable(resolver.CurrentMember.ReturnType, "value");
@ -472,9 +472,9 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -472,9 +472,9 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
return ie != null && ie.Target == node;
}
IType ResolveType(AstNode node)
IType ResolveType(AstType type)
{
return MakeTypeReference(node).Resolve(resolver.Context);
return MakeTypeReference(type).Resolve(resolver.Context);
}
public override ResolveResult VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, object data)
@ -593,7 +593,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -593,7 +593,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
}
}
ResolveResult[] GetArguments(IEnumerable<AstNode> argumentExpressions, out string[] argumentNames)
ResolveResult[] GetArguments(IEnumerable<Expression> argumentExpressions, out string[] argumentNames)
{
argumentNames = null; // TODO: add support for named arguments
ResolveResult[] arguments = new ResolveResult[argumentExpressions.Count()];
@ -951,7 +951,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -951,7 +951,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
/// Creates a type reference for the specified type node.
/// If the type node is 'var', performs type inference on the initializer expression.
/// </summary>
ITypeReference MakeTypeReference(AstNode type, AstNode initializerExpression, bool isForEach)
ITypeReference MakeTypeReference(AstType type, AstNode initializerExpression, bool isForEach)
{
if (initializerExpression != null && IsVar(type)) {
return new VarTypeReference(this, resolver.Clone(), initializerExpression, isForEach);
@ -960,14 +960,16 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -960,14 +960,16 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
}
}
ITypeReference MakeTypeReference(AstNode type)
ITypeReference MakeTypeReference(AstType type)
{
return TypeSystemConvertVisitor.ConvertType(type, resolver.CurrentTypeDefinition, resolver.CurrentMember as IMethod, resolver.UsingScope, false);
}
static bool IsVar(AstNode returnType)
static bool IsVar(AstType returnType)
{
return returnType is IdentifierExpression && ((IdentifierExpression)returnType).Identifier == "var";
return returnType is SimpleType
&& ((SimpleType)returnType).Identifier == "var"
&& ((SimpleType)returnType).TypeArguments.Count == 0;
}
sealed class VarTypeReference : ITypeReference
@ -1072,25 +1074,36 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -1072,25 +1074,36 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
public override ResolveResult VisitPrimitiveType(PrimitiveType primitiveType, object data)
{
ScanChildren(primitiveType);
return new TypeResolveResult(MakeTypeReference(primitiveType).Resolve(resolver.Context));
return new TypeResolveResult(ResolveType(primitiveType));
}
public override ResolveResult VisitSimpleType(SimpleType simpleType, object data)
{
ScanChildren(simpleType);
return new TypeResolveResult(MakeTypeReference(simpleType).Resolve(resolver.Context));
return ResolveTypeOrNamespace(simpleType);
}
ResolveResult ResolveTypeOrNamespace(AstType type)
{
ITypeReference typeRef = MakeTypeReference(type);
ITypeOrNamespaceReference typeOrNsRef = typeRef as ITypeOrNamespaceReference;
if (typeOrNsRef != null) {
return typeOrNsRef.DoResolve(resolver.Context);
} else {
return new TypeResolveResult(typeRef.Resolve(resolver.Context));
}
}
public override ResolveResult VisitMemberType(MemberType memberType, object data)
{
ScanChildren(memberType);
return new TypeResolveResult(MakeTypeReference(memberType).Resolve(resolver.Context));
return ResolveTypeOrNamespace(memberType);
}
public override ResolveResult VisitComposedType(ComposedType composedType, object data)
{
ScanChildren(composedType);
return new TypeResolveResult(MakeTypeReference(composedType).Resolve(resolver.Context));
return new TypeResolveResult(ResolveType(composedType));
}
#endregion
@ -1135,7 +1148,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -1135,7 +1148,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
{
throw new NotImplementedException();
}
*/
*/
#endregion
public override ResolveResult VisitIdentifier(Identifier identifier, object data)

2
ICSharpCode.NRefactory/CSharp/Resolver/SimpleTypeOrNamespaceReference.cs

@ -57,7 +57,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -57,7 +57,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
if (typeArguments.Count == 0)
return identifier;
else
return identifier + "<" + string.Join(",", typeArguments) + ">";
return identifier + "<" + DotNet35Compat.StringJoin(",", typeArguments) + ">";
}
}
}

2
ICSharpCode.NRefactory/CSharp/Resolver/TypeInference.cs

@ -856,7 +856,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -856,7 +856,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
bool success;
IType[] result = InferTypeArgumentsFromBounds(
candidateDef.TypeParameters,
new ParameterizedType(candidateDef, candidateDef.TypeParameters),
new ParameterizedType(candidateDef, candidateDef.TypeParameters.SafeCast<ITypeParameter, IType>()),
lowerBounds, upperBounds,
out success);
if (success) {

17
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
<OutputType>Library</OutputType>
<RootNamespace>ICSharpCode.NRefactory</RootNamespace>
<AssemblyName>ICSharpCode.NRefactory</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<AppDesignerFolder>Properties</AppDesignerFolder>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
@ -15,6 +15,9 @@ @@ -15,6 +15,9 @@
<NoStdLib>False</NoStdLib>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<NoWarn>1591,0618</NoWarn>
<TargetFrameworkProfile />
<RunCodeAnalysis>False</RunCodeAnalysis>
<CodeAnalysisRules>-Microsoft.Design#CA1026;-Microsoft.Security#CA2104</CodeAnalysisRules>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -27,24 +30,27 @@ @@ -27,24 +30,27 @@
<OutputPath>bin\Debug\</OutputPath>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<DefineConstants>DEBUG;TRACE;FULL_AST</DefineConstants>
<DefineConstants>DEBUG;TRACE;FULL_AST;DOTNET35</DefineConstants>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<DefineConstants>TRACE;FULL_AST</DefineConstants>
<DefineConstants>TRACE;FULL_AST;DOTNET35</DefineConstants>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
<DebugType>Full</DebugType>
<Optimize>false</Optimize>
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<DebugType>None</DebugType>
<Optimize>true</Optimize>
<WarningLevel>4</WarningLevel>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@ -322,6 +328,7 @@ @@ -322,6 +328,7 @@
<Compile Include="Utils\BusyManager.cs" />
<Compile Include="Utils\CacheManager.cs" />
<Compile Include="Utils\CSharpPrimitiveCast.cs" />
<Compile Include="Utils\DotNet35Compat.cs" />
<Compile Include="Utils\EmptyList.cs" />
<Compile Include="Utils\ExtensionMethods.cs" />
<Compile Include="Utils\TreeTraversal.cs" />

2
ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs

@ -297,7 +297,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -297,7 +297,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
}
static readonly string DynamicAttributeFullName = typeof(DynamicAttribute).FullName;
const string DynamicAttributeFullName = "System.Runtime.CompilerServices.DynamicAttribute";
static bool HasDynamicAttribute(ICustomAttributeProvider attributeProvider, int typeIndex)
{

8
ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs

@ -70,15 +70,17 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -70,15 +70,17 @@ namespace ICSharpCode.NRefactory.TypeSystem
throw new ArgumentNullException("context");
HashSet<ITypeDefinition> typeDefinitions = new HashSet<ITypeDefinition>();
Func<IType, IEnumerable<ITypeDefinition>> recursion =
Func<ITypeDefinition, IEnumerable<ITypeDefinition>> recursion =
t => t.GetBaseTypes(context).Select(b => b.GetDefinition()).Where(d => d != null && typeDefinitions.Add(d));
ITypeDefinition typeDef = type as ITypeDefinition;
if (typeDef != null) {
typeDefinitions.Add(typeDef);
return TreeTraversal.PreOrder<ITypeDefinition>(typeDef, recursion);
return TreeTraversal.PreOrder(typeDef, recursion);
} else {
return TreeTraversal.PreOrder<ITypeDefinition>(recursion(type), recursion);
return TreeTraversal.PreOrder(
type.GetBaseTypes(context).Select(b => b.GetDefinition()).Where(d => d != null && typeDefinitions.Add(d)),
recursion);
}
}

4
ICSharpCode.NRefactory/TypeSystem/IAttribute.cs

@ -10,7 +10,9 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -10,7 +10,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// Represents an attribute.
/// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(IAttributeContract))]
#endif
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")]
public interface IAttribute : IFreezable
{
@ -35,6 +37,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -35,6 +37,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
IList<KeyValuePair<string, IConstantValue>> NamedArguments { get; }
}
#if WITH_CONTRACTS
[ContractClassFor(typeof(IAttribute))]
abstract class IAttributeContract : IFreezableContract, IAttribute
{
@ -63,4 +66,5 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -63,4 +66,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
}
}
#endif
}

4
ICSharpCode.NRefactory/TypeSystem/IConstantValue.cs

@ -6,7 +6,9 @@ using System.Diagnostics.Contracts; @@ -6,7 +6,9 @@ using System.Diagnostics.Contracts;
namespace ICSharpCode.NRefactory.TypeSystem
{
#if WITH_CONTRACTS
[ContractClass(typeof(IConstantValueContract))]
#endif
public interface IConstantValue : IFreezable
{
/// <summary>
@ -30,6 +32,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -30,6 +32,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
object GetValue(ITypeResolveContext context);
}
#if WITH_CONTRACTS
[ContractClassFor(typeof(IConstantValue))]
abstract class IConstantValueContract : IFreezableContract, IConstantValue
{
@ -46,4 +49,5 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -46,4 +49,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
return null;
}
}
#endif
}

4
ICSharpCode.NRefactory/TypeSystem/IEntity.cs

@ -7,7 +7,9 @@ using System.Diagnostics.Contracts; @@ -7,7 +7,9 @@ using System.Diagnostics.Contracts;
namespace ICSharpCode.NRefactory.TypeSystem
{
#if WITH_CONTRACTS
[ContractClass(typeof(IEntityContract))]
#endif
public interface IEntity : INamedElement, IFreezable
{
EntityType EntityType { get; }
@ -75,6 +77,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -75,6 +77,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
//bool IsAccessible(IClass callingClass, bool isAccessThoughReferenceOfCurrentClass);
}
#if WITH_CONTRACTS
[ContractClassFor(typeof(IEntity))]
abstract class IEntityContract : INamedElementContract, IEntity
{
@ -144,4 +147,5 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -144,4 +147,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
{
}
}
#endif
}

4
ICSharpCode.NRefactory/TypeSystem/IExplicitInterfaceImplementation.cs

@ -9,7 +9,9 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -9,7 +9,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// Represents an explicit interface implementation.
/// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(IExplicitInterfaceImplementationContract))]
#endif
public interface IExplicitInterfaceImplementation : IFreezable
{
/// <summary>
@ -23,6 +25,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -23,6 +25,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
string MemberName { get; }
}
#if WITH_CONTRACTS
[ContractClassFor(typeof(IExplicitInterfaceImplementation))]
abstract class IExplicitInterfaceImplementationContract : IFreezableContract, IExplicitInterfaceImplementation
{
@ -40,4 +43,5 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -40,4 +43,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
}
}
#endif
}

4
ICSharpCode.NRefactory/TypeSystem/IField.cs

@ -9,7 +9,9 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -9,7 +9,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// Represents a field or constant.
/// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(IFieldContract))]
#endif
public interface IField : IMember, IVariable
{
/// <summary>
@ -28,6 +30,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -28,6 +30,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
bool IsVolatile { get; }
}
#if WITH_CONTRACTS
[ContractClassFor(typeof(IField))]
abstract class IFieldContract : IMemberContract, IField
{
@ -63,4 +66,5 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -63,4 +66,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
get { return null; }
}
}
#endif
}

4
ICSharpCode.NRefactory/TypeSystem/IFreezable.cs

@ -6,7 +6,9 @@ using System.Diagnostics.Contracts; @@ -6,7 +6,9 @@ using System.Diagnostics.Contracts;
namespace ICSharpCode.NRefactory.TypeSystem
{
#if WITH_CONTRACTS
[ContractClass(typeof(IFreezableContract))]
#endif
public interface IFreezable
{
/// <summary>
@ -20,6 +22,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -20,6 +22,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
void Freeze();
}
#if WITH_CONTRACTS
[ContractClassFor(typeof(IFreezable))]
abstract class IFreezableContract : IFreezable
{
@ -33,4 +36,5 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -33,4 +36,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
Contract.Ensures(self.IsFrozen);
}
}
#endif
}

4
ICSharpCode.NRefactory/TypeSystem/IInterningProvider.cs

@ -25,7 +25,9 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -25,7 +25,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// and which are used only within a single type definition. Then a persistent file format could be organized so
/// that shared objects are loaded only once, yet non-shared objects get loaded lazily together with the class.
/// </remarks>
#if WITH_CONTRACTS
[ContractClass(typeof(IInterningProviderContract))]
#endif
public interface IInterningProvider
{
/// <summary>
@ -39,6 +41,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -39,6 +41,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
IList<T> InternList<T>(IList<T> list) where T : class;
}
#if WITH_CONTRACTS
[ContractClassFor(typeof(IInterningProvider))]
abstract class IInterningProviderContract : IInterningProvider
{
@ -54,4 +57,5 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -54,4 +57,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
return list;
}
}
#endif
}

4
ICSharpCode.NRefactory/TypeSystem/IMember.cs

@ -10,7 +10,9 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -10,7 +10,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// Method/field/entity.
/// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(IMemberContract))]
#endif
public interface IMember : IEntity
{
/// <summary>
@ -58,6 +60,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -58,6 +60,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
}
#if WITH_CONTRACTS
[ContractClassFor(typeof(IMember))]
abstract class IMemberContract : IEntityContract, IMember
{
@ -101,4 +104,5 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -101,4 +104,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
get { return false; }
}
}
#endif
}

11
ICSharpCode.NRefactory/TypeSystem/IMethod.cs

@ -10,7 +10,9 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -10,7 +10,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// Represents a method, constructor, destructor or operator.
/// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(IMethodContract))]
#endif
public interface IMethod : IParameterizedMember
{
/// <summary>
@ -30,6 +32,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -30,6 +32,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
bool IsOperator { get; }
}
#if WITH_CONTRACTS
[ContractClassFor(typeof(IMethod))]
abstract class IMethodContract : IParameterizedMemberContract, IMethod
{
@ -47,13 +50,6 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -47,13 +50,6 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
}
// IList<string> IMethod.HandlesClauses {
// get {
// Contract.Ensures(Contract.Result<IList<string>>() != null);
// return null;
// }
// }
bool IMethod.IsExtensionMethod {
get { return false; }
}
@ -70,4 +66,5 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -70,4 +66,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
get { return false; }
}
}
#endif
}

4
ICSharpCode.NRefactory/TypeSystem/INamedElement.cs

@ -6,7 +6,9 @@ using System.Diagnostics.Contracts; @@ -6,7 +6,9 @@ using System.Diagnostics.Contracts;
namespace ICSharpCode.NRefactory.TypeSystem
{
#if WITH_CONTRACTS
[ContractClass(typeof(INamedElementContract))]
#endif
public interface INamedElement
{
/// <summary>
@ -63,6 +65,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -63,6 +65,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
}
#if WITH_CONTRACTS
[ContractClassFor(typeof(INamedElement))]
abstract class INamedElementContract : INamedElement
{
@ -94,4 +97,5 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -94,4 +97,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
}
}
#endif
}

4
ICSharpCode.NRefactory/TypeSystem/IParameter.cs

@ -7,7 +7,9 @@ using System.Diagnostics.Contracts; @@ -7,7 +7,9 @@ using System.Diagnostics.Contracts;
namespace ICSharpCode.NRefactory.TypeSystem
{
#if WITH_CONTRACTS
[ContractClass(typeof(IParameterContract))]
#endif
public interface IParameter : IVariable, IFreezable
{
/// <summary>
@ -46,6 +48,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -46,6 +48,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
bool IsOptional { get; }
}
#if WITH_CONTRACTS
[ContractClassFor(typeof(IParameter))]
abstract class IParameterContract : IVariableContract, IParameter
{
@ -92,4 +95,5 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -92,4 +95,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
{
}
}
#endif
}

4
ICSharpCode.NRefactory/TypeSystem/IParameterizedMember.cs

@ -10,12 +10,15 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -10,12 +10,15 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// Represents a method or property.
/// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(IParameterizedMemberContract))]
#endif
public interface IParameterizedMember : IMember
{
IList<IParameter> Parameters { get; }
}
#if WITH_CONTRACTS
[ContractClassFor(typeof(IParameterizedMember))]
abstract class IParameterizedMemberContract : IMemberContract, IParameterizedMember
{
@ -26,4 +29,5 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -26,4 +29,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
}
}
#endif
}

4
ICSharpCode.NRefactory/TypeSystem/IProjectContent.cs

@ -10,12 +10,15 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -10,12 +10,15 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// Mutable container of all classes in an assembly.
/// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(IProjectContentContract))]
#endif
public interface IProjectContent : ITypeResolveContext
{
IList<IAttribute> AssemblyAttributes { get; }
}
#if WITH_CONTRACTS
[ContractClassFor(typeof(IProjectContent))]
abstract class IProjectContentContract : ITypeResolveContextContract, IProjectContent
{
@ -26,4 +29,5 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -26,4 +29,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
}
}
#endif
}

4
ICSharpCode.NRefactory/TypeSystem/ISupportsInterning.cs

@ -11,7 +11,9 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -11,7 +11,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// Interface for TypeSystem objects that support interning.
/// See <see cref="IInterningProvider"/> for more information.
/// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(ISupportsInterningContract))]
#endif
public interface ISupportsInterning
{
/// <summary>
@ -30,6 +32,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -30,6 +32,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
bool EqualsForInterning(ISupportsInterning other);
}
#if WITH_CONTRACTS
[ContractClassFor(typeof(ISupportsInterning))]
abstract class ISupportsInterningContract : ISupportsInterning
{
@ -48,4 +51,5 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -48,4 +51,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
return false;
}
}
#endif
}

4
ICSharpCode.NRefactory/TypeSystem/IType.cs

@ -7,7 +7,9 @@ using System.Diagnostics.Contracts; @@ -7,7 +7,9 @@ using System.Diagnostics.Contracts;
namespace ICSharpCode.NRefactory.TypeSystem
{
#if WITH_CONTRACTS
[ContractClass(typeof(ITypeContract))]
#endif
public interface IType : ITypeReference, INamedElement, IEquatable<IType>
{
/// <summary>
@ -90,6 +92,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -90,6 +92,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
IEnumerable<IEvent> GetEvents(ITypeResolveContext context, Predicate<IEvent> filter = null);
}
#if WITH_CONTRACTS
[ContractClassFor(typeof(IType))]
abstract class ITypeContract : ITypeReferenceContract, IType
{
@ -209,4 +212,5 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -209,4 +212,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
return this;
}
}
#endif
}

4
ICSharpCode.NRefactory/TypeSystem/ITypeDefinition.cs

@ -10,7 +10,9 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -10,7 +10,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// Represents a class, enum, interface, struct, delegate or VB module.
/// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(ITypeDefinitionContract))]
#endif
public interface ITypeDefinition : IType, IEntity
{
ClassType ClassType { get; }
@ -44,6 +46,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -44,6 +46,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
IEnumerable<IMember> Members { get; }
}
#if WITH_CONTRACTS
[ContractClassFor(typeof(ITypeDefinition))]
abstract class ITypeDefinitionContract : ITypeContract, ITypeDefinition
{
@ -181,4 +184,5 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -181,4 +184,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
#endregion
}
#endif
}

4
ICSharpCode.NRefactory/TypeSystem/ITypeParameter.cs

@ -11,7 +11,9 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -11,7 +11,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary>
/// Type parameter of a generic class/method.
/// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(ITypeParameterContract))]
#endif
public interface ITypeParameter : IType, IFreezable
{
/// <summary>
@ -99,6 +101,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -99,6 +101,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
Contravariant
};
#if WITH_CONTRACTS
[ContractClassFor(typeof(ITypeParameter))]
abstract class ITypeParameterContract : ITypeContract, ITypeParameter
{
@ -178,4 +181,5 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -178,4 +181,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
{
}
}
#endif
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save