Browse Source

Squashed 'NRefactory/' changes from 56fde51..b8330be

b8330be Remove parent pointer from ITypeParameter and enable sharing type parameters.
ca6b0e1 fixed primitve types.
094cac4 Added some creation constructors.
b7cd75a Fixed unit test.
9fedc31 Handled undocumented expressions.
7d4ef1a Added support for quoted identifiers.
f30490c Add some parser unit tests.
307559c Remove NextStatement/PrevStatement properties - too many properties can be confusing (e.g. a loop's EmbeddedStatement would show up next to those two properties)
90542d2 Fix parsing of query continuations for queries with multiple from clauses.
ccd06a4 Fixed query expression tests. Had to add a new node type: AnonymousTypeCreateExpression.
d4eaffb Make pattern matching AST independent from C# AST.
e8d472b Rename FixedVariableInitializer.Initializer to CountExpression (this makes it consistent with StackAllocExpression).
16715bb Renamed CSharpFormattingPolicy to CSharpFormattingOptions.
92df3e5 Fixed some TypeReferenceExpression tests.
f4450d1 Fixed some invocation expression tests.
42463a4 Fixed unit test TestIdentifierContainingEscapeSequence.
021a9fb Fixed typeofexpression tests.
bd51bee Fixed GlobalFullNamespaceGenericFieldReferenceExpressionTest.
040e164 Fixed lambdaexpression tests.
0722289 Updated mcs, fixed failing unit test.
c35eb4d Enabled typ declaration tests.
94c18d6 Fixed delegate declaration tests.
a45fa11 Fixed event declaration tests.
9083bee Fixed constructor declaration tests.
2e82144 * TypeDeclarationTests.cs: * PropertyDeclarationTests.cs: enabled property declaration tests.
873c185 Added attribute section parsing / fixed indexer declaration tests.
2353804 Fixed field declaration tests.
4e60911 Fixed method declaration tests.
58caab2 Fixed statement unit tests.
cad9d18 Fixed fixed statement.
a4ce5aa Updated mcs/fixed pointer reference expression bug.
ca77589 Fixed partial modifier.
8c7e017 Fixed UsingDeclarationTests.
293dba5 Worked on pointer reference expression.
cc209b4 Fixed ArrayObjectCreateExpression tests.
58856b1 Activated cast expression tests.
c0e20a6 Fixed qualified alias member tests.
44388b2 Fixed anonymous method tests.

git-subtree-dir: NRefactory
git-subtree-split: b8330bebd6a1cb3a2895fc924f472292bc1cf85e
pull/129/head
Daniel Grunwald 15 years ago
parent
commit
6c62b4c954
  1. 4
      ICSharpCode.NRefactory.Demo/MainForm.cs
  2. 4
      ICSharpCode.NRefactory.Tests/CSharp/InsertParenthesesVisitorTests.cs
  3. 11
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/AliasReferenceExpressionTests.cs
  4. 6
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/AnonymousMethodTests.cs
  5. 4
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ArrayObjectCreateExpressionTests.cs
  6. 4
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/CastExpressionTests.cs
  7. 2
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ConditionalExpressionTests.cs
  8. 2
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/DefaultValueExpressionTests.cs
  9. 11
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/IdentifierExpressionTests.cs
  10. 2
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/InvocationExpressionTests.cs
  11. 10
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/LambdaExpressionTests.cs
  12. 20
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/MemberReferenceExpressionTests.cs
  13. 4
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/PointerReferenceExpressionTests.cs
  14. 77
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/QueryExpressionTests.cs
  15. 14
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/TypeOfExpressionTests.cs
  16. 48
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/TypeReferenceExpressionTests.cs
  17. 57
      ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/AttributeSectionTests.cs
  18. 2
      ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/DelegateDeclarationTests.cs
  19. 17
      ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/TypeDeclarationTests.cs
  20. 3
      ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/UsingDeclarationTests.cs
  21. 21
      ICSharpCode.NRefactory.Tests/CSharp/Parser/ParseUtil.cs
  22. 5
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/BlockStatementTests.cs
  23. 30
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/FixedStatementTests.cs
  24. 4
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ForStatementTests.cs
  25. 2
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/GotoStatementTests.cs
  26. 5
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/TryCatchStatementTests.cs
  27. 18
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/UsingStatementTests.cs
  28. 191
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/VariableDeclarationStatementTests.cs
  29. 4
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/ConstructorDeclarationTests.cs
  30. 4
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/EventDeclarationTests.cs
  31. 15
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/FieldDeclarationTests.cs
  32. 4
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/IndexerDeclarationTests.cs
  33. 21
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/MethodDeclarationTests.cs
  34. 7
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/PropertyDeclarationTests.cs
  35. 14
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/LambdaTests.cs
  36. 8
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/OverloadResolutionTests.cs
  37. 14
      ICSharpCode.NRefactory.Tests/FormattingTests/TestBlankLineFormatting.cs
  38. 32
      ICSharpCode.NRefactory.Tests/FormattingTests/TestBraceStlye.cs
  39. 16
      ICSharpCode.NRefactory.Tests/FormattingTests/TestFormattingBugs.cs
  40. 168
      ICSharpCode.NRefactory.Tests/FormattingTests/TestSpacingVisitor.cs
  41. 120
      ICSharpCode.NRefactory.Tests/FormattingTests/TestStatementIndentation.cs
  42. 40
      ICSharpCode.NRefactory.Tests/FormattingTests/TestTypeLevelIndentation.cs
  43. 6
      ICSharpCode.NRefactory.Tests/FormattingTests/TextEditorTestAdapter.cs
  44. 8
      ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj
  45. 2
      ICSharpCode.NRefactory.Tests/TypeSystem/GetAllBaseTypesTest.cs
  46. 25
      ICSharpCode.NRefactory.Tests/TypeSystem/TestInterningProvider.cs
  47. 10
      ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs
  48. 84
      ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs
  49. 36
      ICSharpCode.NRefactory/CSharp/Ast/AstNodeCollection.cs
  50. 58
      ICSharpCode.NRefactory/CSharp/Ast/AstType.cs
  51. 14
      ICSharpCode.NRefactory/CSharp/Ast/DepthFirstAstVisitor.cs
  52. 18
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/AnonymousMethodExpression.cs
  53. 79
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/AnonymousTypeCreateExpression.cs
  54. 10
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/AsExpression.cs
  55. 7
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/AssignmentExpression.cs
  56. 10
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/CastExpression.cs
  57. 9
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/CheckedExpression.cs
  58. 11
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/ConditionalExpression.cs
  59. 9
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/DefaultValueExpression.cs
  60. 10
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/DirectionExpression.cs
  61. 38
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/Expression.cs
  62. 18
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/IndexerExpression.cs
  63. 18
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/InvocationExpression.cs
  64. 19
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/MemberReferenceExpression.cs
  65. 4
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/NamedArgumentExpression.cs
  66. 22
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/NullReferenceExpression.cs
  67. 18
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/ObjectCreateExpression.cs
  68. 9
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/ParenthesizedExpression.cs
  69. 9
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/SizeOfExpression.cs
  70. 9
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/TypeOfExpression.cs
  71. 9
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/TypeReferenceExpression.cs
  72. 9
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/UncheckedExpression.cs
  73. 25
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/UndocumentedExpression.cs
  74. 92
      ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/AttributeSection.cs
  75. 13
      ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/NamespaceDeclaration.cs
  76. 16
      ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/UsingAliasDeclaration.cs
  77. 14
      ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/UsingDeclaration.cs
  78. 5
      ICSharpCode.NRefactory/CSharp/Ast/IAstVisitor.cs
  79. 10
      ICSharpCode.NRefactory/CSharp/Ast/Identifier.cs
  80. 7
      ICSharpCode.NRefactory/CSharp/Ast/NodeType.cs
  81. 54
      ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Choice.cs
  82. 42
      ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/OptionalNode.cs
  83. 95
      ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Pattern.cs
  84. 242
      ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Placeholder.cs
  85. 36
      ICSharpCode.NRefactory/CSharp/Ast/Statements/BlockStatement.cs
  86. 11
      ICSharpCode.NRefactory/CSharp/Ast/Statements/CheckedStatement.cs
  87. 9
      ICSharpCode.NRefactory/CSharp/Ast/Statements/ReturnStatement.cs
  88. 60
      ICSharpCode.NRefactory/CSharp/Ast/Statements/Statement.cs
  89. 36
      ICSharpCode.NRefactory/CSharp/Ast/Statements/SwitchStatement.cs
  90. 9
      ICSharpCode.NRefactory/CSharp/Ast/Statements/ThrowStatement.cs
  91. 36
      ICSharpCode.NRefactory/CSharp/Ast/Statements/TryCatchStatement.cs
  92. 11
      ICSharpCode.NRefactory/CSharp/Ast/Statements/UncheckedStatement.cs
  93. 8
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs
  94. 12
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/FixedVariableInitializer.cs
  95. 38
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/VariableInitializer.cs
  96. 18
      ICSharpCode.NRefactory/CSharp/Formatter/AstFormattingVisitor.cs
  97. 24
      ICSharpCode.NRefactory/CSharp/Formatter/CSharpFormattingOptions.cs
  98. 125
      ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs
  99. 696
      ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs
  100. 8
      ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs
  101. Some files were not shown because too many files have changed in this diff Show More

4
ICSharpCode.NRefactory.Demo/MainForm.cs

@ -1,4 +1,4 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt) // This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System; using System;
@ -126,7 +126,7 @@ namespace ICSharpCode.NRefactory.Demo
void CSharpGenerateCodeButtonClick(object sender, EventArgs e) void CSharpGenerateCodeButtonClick(object sender, EventArgs e)
{ {
StringWriter w = new StringWriter(); StringWriter w = new StringWriter();
OutputVisitor output = new OutputVisitor(w, new CSharpFormattingPolicy()); OutputVisitor output = new OutputVisitor(w, new CSharpFormattingOptions());
compilationUnit.AcceptVisitor(output, null); compilationUnit.AcceptVisitor(output, null);
csharpCodeTextBox.Text = w.ToString(); csharpCodeTextBox.Text = w.ToString();
} }

4
ICSharpCode.NRefactory.Tests/CSharp/InsertParenthesesVisitorTests.cs

@ -10,12 +10,12 @@ namespace ICSharpCode.NRefactory.CSharp
[TestFixture] [TestFixture]
public class InsertParenthesesVisitorTests public class InsertParenthesesVisitorTests
{ {
CSharpFormattingPolicy policy; CSharpFormattingOptions policy;
[SetUp] [SetUp]
public void SetUp() public void SetUp()
{ {
policy = new CSharpFormattingPolicy(); policy = new CSharpFormattingOptions();
} }
string InsertReadable(Expression expr) string InsertReadable(Expression expr)

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

@ -5,10 +5,11 @@
using System; using System;
using System.IO; using System.IO;
using NUnit.Framework; using NUnit.Framework;
using ICSharpCode.NRefactory.PatternMatching;
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
{ {
[TestFixture, Ignore("Aliases not yet implemented")] [TestFixture]
public class AliasReferenceExpressionTests public class AliasReferenceExpressionTests
{ {
[Test] [Test]
@ -16,12 +17,12 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
{ {
CSharpParser parser = new CSharpParser(); CSharpParser parser = new CSharpParser();
AstType type = parser.ParseTypeReference(new StringReader("global::System")); AstType type = parser.ParseTypeReference(new StringReader("global::System"));
Assert.IsNotNull( Assert.IsTrue(
new MemberType { new MemberType {
Target = new SimpleType("global"), Target = new SimpleType("global"),
IsDoubleColon = true, IsDoubleColon = true,
MemberName = "System" MemberName = "System"
}.Match(type) }.IsMatch(type)
); );
} }
@ -29,7 +30,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
public void GlobalTypeDeclaration() public void GlobalTypeDeclaration()
{ {
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("global::System.String a;"); VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("global::System.String a;");
Assert.IsNotNull( Assert.IsTrue(
new VariableDeclarationStatement { new VariableDeclarationStatement {
Type = new MemberType { Type = new MemberType {
Target = new MemberType { Target = new MemberType {
@ -43,7 +44,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
Variables = { Variables = {
new VariableInitializer("a") new VariableInitializer("a")
} }
}.Match(lvd) }.IsMatch(lvd)
); );
} }

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

@ -34,7 +34,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
Assert.AreEqual(0, ame.Body.Statements.Count()); Assert.AreEqual(0, ame.Body.Statements.Count());
} }
[Test, Ignore("Parameter list is broken")] [Test]
public void EmptyAnonymousMethod() public void EmptyAnonymousMethod()
{ {
AnonymousMethodExpression ame = Parse("delegate() {}"); AnonymousMethodExpression ame = Parse("delegate() {}");
@ -43,14 +43,14 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
Assert.IsTrue(ame.HasParameterList); Assert.IsTrue(ame.HasParameterList);
} }
[Test, Ignore("Parameter list is broken")] [Test]
public void SimpleAnonymousMethod() public void SimpleAnonymousMethod()
{ {
AnonymousMethodExpression ame = Parse("delegate(int a, int b) { return a + b; }"); AnonymousMethodExpression ame = Parse("delegate(int a, int b) { return a + b; }");
Assert.IsTrue(ame.HasParameterList); Assert.IsTrue(ame.HasParameterList);
Assert.AreEqual(2, ame.Parameters.Count()); Assert.AreEqual(2, ame.Parameters.Count());
Assert.AreEqual(1, ame.Body.Statements.Count()); Assert.AreEqual(1, ame.Body.Statements.Count());
Assert.IsTrue(ame.Body.Children.First() is ReturnStatement); Assert.IsTrue(ame.Body.Statements.First() is ReturnStatement);
} }
} }
} }

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

@ -20,7 +20,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
}); });
} }
[Test, Ignore("AdditionalArraySpecifiers not yet implemented")] [Test]
public void MultidimensionalNestedArray() public void MultidimensionalNestedArray()
{ {
ParseUtilCSharp.AssertExpression( ParseUtilCSharp.AssertExpression(
@ -35,7 +35,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
}); });
} }
[Test, Ignore("Array initializers not yet implemented")] [Test]
public void ImplicitlyTypedArrayCreateExpression() public void ImplicitlyTypedArrayCreateExpression()
{ {
ParseUtilCSharp.AssertExpression( ParseUtilCSharp.AssertExpression(

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

@ -6,7 +6,7 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
{ {
[TestFixture, Ignore("Port unit tests to new DOM")] [TestFixture]
public class CastExpressionTests public class CastExpressionTests
{ {
[Test] [Test]
@ -151,7 +151,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
}); });
} }
[Test] [Test, Ignore ("TODO")]
public void IntMaxValueToBigInt() public void IntMaxValueToBigInt()
{ {
ParseUtilCSharp.AssertExpression( ParseUtilCSharp.AssertExpression(

2
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ConditionalExpressionTests.cs

@ -30,7 +30,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
Assert.IsTrue(ce.FalseExpression is MemberReferenceExpression); Assert.IsTrue(ce.FalseExpression is MemberReferenceExpression);
} }
[Test, Ignore("crashes the parser")] [Test]
public void ConditionalIsWithNullableExpressionTest() public void ConditionalIsWithNullableExpressionTest()
{ {
ConditionalExpression ce = ParseUtilCSharp.ParseExpression<ConditionalExpression>("a is b? ? a() : a.B"); ConditionalExpression ce = ParseUtilCSharp.ParseExpression<ConditionalExpression>("a is b? ? a() : a.B");

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

@ -6,7 +6,7 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
{ {
[TestFixture, Ignore("Aliases not yet implemented")] [TestFixture]
public class DefaultValueExpressionTests public class DefaultValueExpressionTests
{ {
[Test] [Test]

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

@ -3,6 +3,7 @@
using System; using System;
using NUnit.Framework; using NUnit.Framework;
using ICSharpCode.NRefactory.PatternMatching;
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
{ {
@ -33,7 +34,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
CheckIdentifier(@"\u006cexer", "lexer"); CheckIdentifier(@"\u006cexer", "lexer");
} }
[Test, Ignore("Mono parser bug?")] [Test]
public void TestIdentifierContainingEscapeSequence() public void TestIdentifierContainingEscapeSequence()
{ {
CheckIdentifier(@"l\U00000065xer", "lexer"); CheckIdentifier(@"l\U00000065xer", "lexer");
@ -61,26 +62,26 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
public void GenericMethodReference() public void GenericMethodReference()
{ {
IdentifierExpression ident = ParseUtilCSharp.ParseExpression<IdentifierExpression>("M<int>"); IdentifierExpression ident = ParseUtilCSharp.ParseExpression<IdentifierExpression>("M<int>");
Assert.IsNotNull( Assert.IsTrue(
new IdentifierExpression { new IdentifierExpression {
Identifier = "M" , Identifier = "M" ,
TypeArguments = { TypeArguments = {
new PrimitiveType("int") new PrimitiveType("int")
} }
}.Match(ident)); }.IsMatch(ident));
} }
[Test] [Test]
public void GenericMethodReference2() public void GenericMethodReference2()
{ {
IdentifierExpression ident = ParseUtilCSharp.ParseExpression<IdentifierExpression>("TargetMethod<string>"); IdentifierExpression ident = ParseUtilCSharp.ParseExpression<IdentifierExpression>("TargetMethod<string>");
Assert.IsNotNull( Assert.IsTrue(
new IdentifierExpression { new IdentifierExpression {
Identifier = "TargetMethod" , Identifier = "TargetMethod" ,
TypeArguments = { TypeArguments = {
new PrimitiveType("string") new PrimitiveType("string")
} }
}.Match(ident)); }.IsMatch(ident));
} }
} }
} }

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

@ -153,7 +153,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
}.Invoke("Foo")); }.Invoke("Foo"));
} }
[Test, Ignore("named arguments not yet supported")] [Test]
public void InvocationWithNamedArgument() public void InvocationWithNamedArgument()
{ {
ParseUtilCSharp.AssertExpression( ParseUtilCSharp.AssertExpression(

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

@ -9,7 +9,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
[TestFixture] [TestFixture]
public class LambdaExpressionTests public class LambdaExpressionTests
{ {
[Test, Ignore("Lambdas with expression body not yet supported")] [Test]
public void ImplicitlyTypedExpressionBody() public void ImplicitlyTypedExpressionBody()
{ {
ParseUtilCSharp.AssertExpression( ParseUtilCSharp.AssertExpression(
@ -20,7 +20,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
}); });
} }
[Test, Ignore("Lambdas with expression body not yet supported")] [Test]
public void ImplicitlyTypedExpressionBodyWithoutParenthesis() public void ImplicitlyTypedExpressionBodyWithoutParenthesis()
{ {
ParseUtilCSharp.AssertExpression( ParseUtilCSharp.AssertExpression(
@ -73,7 +73,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
}}}); }}});
} }
[Test, Ignore("Lambdas with expression body not yet supported")] [Test]
public void ExplicitlyTypedWithRefParameter() public void ExplicitlyTypedWithRefParameter()
{ {
ParseUtilCSharp.AssertExpression( ParseUtilCSharp.AssertExpression(
@ -83,14 +83,14 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
new ParameterDeclaration { new ParameterDeclaration {
ParameterModifier = ParameterModifier.Ref, ParameterModifier = ParameterModifier.Ref,
Type = new PrimitiveType("int"), Type = new PrimitiveType("int"),
Name = "x" Name = "i"
} }
}, },
Body = new AssignmentExpression(new IdentifierExpression("i"), new PrimitiveExpression(1)) Body = new AssignmentExpression(new IdentifierExpression("i"), new PrimitiveExpression(1))
}); });
} }
[Test, Ignore("Lambdas with expression body not yet supported")] [Test]
public void LambdaExpressionContainingConditionalExpression() public void LambdaExpressionContainingConditionalExpression()
{ {
ParseUtilCSharp.AssertExpression( ParseUtilCSharp.AssertExpression(

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

@ -57,19 +57,23 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
); );
} }
[Test, Ignore("Aliases not yet implemented")] [Test]
public void GlobalFullNamespaceGenericFieldReferenceExpressionTest() public void GlobalFullNamespaceGenericFieldReferenceExpressionTest()
{ {
ParseUtilCSharp.AssertExpression( var target = new MemberType {
"global::Namespace.Subnamespace.SomeClass<string>.myField",
new MemberReferenceExpression {
Target = new MemberType {
Target = new SimpleType("global"), Target = new SimpleType("global"),
IsDoubleColon = true, IsDoubleColon = true,
MemberName = "Namespace" MemberName = "Namespace"
}.Member("Subnamespace"), }.Member("Subnamespace").Member ("SomeClass");
TypeArguments = { new PrimitiveType("string") }
}.Member("myField") target.AddChild (new PrimitiveType("string"), MemberReferenceExpression.Roles.TypeArgument);
ParseUtilCSharp.AssertExpression(
"global::Namespace.Subnamespace.SomeClass<string>.myField",
new MemberReferenceExpression {
Target = target,
MemberName = "myField"
}
); );
} }

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

@ -9,7 +9,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
[TestFixture] [TestFixture]
public class PointerReferenceExpressionTests public class PointerReferenceExpressionTests
{ {
[Test, Ignore("Parser bug!")] [Test]
public void PointerReferenceExpressionTest() public void PointerReferenceExpressionTest()
{ {
PointerReferenceExpression pre = ParseUtilCSharp.ParseExpression<PointerReferenceExpression>("myObj.field->b"); PointerReferenceExpression pre = ParseUtilCSharp.ParseExpression<PointerReferenceExpression>("myObj.field->b");
@ -17,7 +17,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
Assert.AreEqual("b", pre.MemberName); Assert.AreEqual("b", pre.MemberName);
} }
[Test, Ignore("Parser bug!")] [Test]
public void PointerReferenceGenericMethodTest() public void PointerReferenceGenericMethodTest()
{ {
ParseUtilCSharp.AssertExpression( ParseUtilCSharp.AssertExpression(

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

@ -6,7 +6,7 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
{ {
[TestFixture, Ignore("Query expressions not yet implemented")] [TestFixture]
public class QueryExpressionTests public class QueryExpressionTests
{ {
[Test] [Test]
@ -125,19 +125,17 @@ select new { c.Name, o.OrderID, o.Total }",
}, },
new QueryWhereClause { new QueryWhereClause {
Condition = new BinaryOperatorExpression { Condition = new BinaryOperatorExpression {
Left = new IdentifierExpression("c").Member("OrderDate").Member("Year"), Left = new IdentifierExpression("o").Member("OrderDate").Member("Year"),
Operator = BinaryOperatorType.Equality, Operator = BinaryOperatorType.Equality,
Right = new PrimitiveExpression(2005) Right = new PrimitiveExpression(2005)
} }
}, },
new QuerySelectClause { new QuerySelectClause {
Expression = new ObjectCreateExpression { Expression = new AnonymousTypeCreateExpression {
Initializer = new ArrayInitializerExpression { Initializer = {
Elements = { new IdentifierExpression("c").Member("Name"),
new IdentifierExpression("c").Member("Name"), new IdentifierExpression("o").Member("OrderID"),
new IdentifierExpression("o").Member("OrderID"), new IdentifierExpression("o").Member("Total")
new IdentifierExpression("o").Member("Total")
}
} }
} }
} }
@ -221,5 +219,66 @@ select new { c.Name, o.OrderID, o.Total }",
} }
); );
} }
[Test]
public void QueryContinuationWithMultipleFrom()
{
ParseUtilCSharp.AssertExpression(
"from a in b from c in d select e into f select g",
new QueryExpression {
Clauses = {
new QueryContinuationClause {
PrecedingQuery = new QueryExpression {
Clauses = {
new QueryFromClause {
Identifier = "a",
Expression = new IdentifierExpression("b")
},
new QueryFromClause {
Identifier = "c",
Expression = new IdentifierExpression("d")
},
new QuerySelectClause { Expression = new IdentifierExpression("e") }
}
},
Identifier = "f"
},
new QuerySelectClause { Expression = new IdentifierExpression("g") }
}
}
);
}
[Test]
public void MultipleQueryContinuation()
{
ParseUtilCSharp.AssertExpression(
"from a in b select c into d select e into f select g",
new QueryExpression {
Clauses = {
new QueryContinuationClause {
PrecedingQuery = 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") }
}
},
Identifier = "f"
},
new QuerySelectClause { Expression = new IdentifierExpression("g") }
}});
}
} }
} }

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

@ -24,7 +24,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
}}); }});
} }
[Test, Ignore("Aliases not yet implemented")] [Test]
public void GlobalTypeOfExpressionTest() public void GlobalTypeOfExpressionTest()
{ {
ParseUtilCSharp.AssertExpression( ParseUtilCSharp.AssertExpression(
@ -108,11 +108,17 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
}}); }});
} }
[Test, Ignore("How do we represent unbound types in the AST?")] [Test]
public void UnboundTypeOfExpressionTest() public void UnboundTypeOfExpressionTest()
{ {
TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(MyType<,>)"); var type = new SimpleType("MyType");
throw new NotImplementedException("How do we represent unbound types in the AST?"); type.AddChild (new SimpleType (), SimpleType.Roles.TypeArgument);
type.AddChild (new SimpleType (), SimpleType.Roles.TypeArgument);
ParseUtilCSharp.AssertExpression(
"typeof(MyType<,>)",
new TypeOfExpression {
Type = type
});
} }
} }
} }

48
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/TypeReferenceExpressionTests.cs

@ -3,44 +3,60 @@
using System; using System;
using NUnit.Framework; using NUnit.Framework;
using ICSharpCode.NRefactory.PatternMatching;
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
{ {
[TestFixture, Ignore] [TestFixture]
public class TypeReferenceExpressionTests public class TypeReferenceExpressionTests
{ {
[Test] [Test]
public void GlobalTypeReferenceExpression() public void GlobalTypeReferenceExpression()
{ {
/*TypeReferenceExpression tr = ParseUtilCSharp.ParseExpression<TypeReferenceExpression>("global::System"); TypeReferenceExpression tr = ParseUtilCSharp.ParseExpression<TypeReferenceExpression>("global::System");
Assert.AreEqual("System", tr.TypeReference.Type); Assert.IsTrue (tr.IsMatch (new TypeReferenceExpression () {
Assert.IsTrue(tr.TypeReference.IsGlobal);*/ Type = new MemberType () {
throw new NotImplementedException(); Target = new SimpleType ("global"),
IsDoubleColon = true,
MemberName = "System"
}
}));
} }
/* TODO [Test, Ignore ("Doesn't work")]
[Test]
public void GlobalTypeReferenceExpressionWithoutTypeName() public void GlobalTypeReferenceExpressionWithoutTypeName()
{ {
TypeReferenceExpression tr = ParseUtilCSharp.ParseExpression<TypeReferenceExpression>("global::", true); TypeReferenceExpression tr = ParseUtilCSharp.ParseExpression<TypeReferenceExpression>("global::", true);
Assert.AreEqual("?", tr.TypeReference.Type); Assert.IsTrue (tr.IsMatch (new TypeReferenceExpression () {
Assert.IsTrue(tr.TypeReference.IsGlobal); Type = new MemberType () {
Target = new SimpleType ("global"),
IsDoubleColon = true,
}
}));
} }
[Test] [Test, Ignore("Primitive types as member reference target are not supported yet")]
public void IntReferenceExpression() public void IntReferenceExpression()
{ {
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("int.MaxValue"); MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("int.MaxValue");
Assert.AreEqual("MaxValue", fre.MemberName); Assert.IsTrue (fre.IsMatch (new MemberReferenceExpression () {
Assert.AreEqual("System.Int32", ((TypeReferenceExpression)fre.TargetObject).TypeReference.Type); Target = new TypeReferenceExpression () {
Type = new PrimitiveType("int")
},
MemberName = "MaxValue"
}));
} }
[Test] /* [Test]
public void StandaloneIntReferenceExpression() public void StandaloneIntReferenceExpression()
{ {
// doesn't work because a = int; gives a compiler error.
// But how do we handle this case for code completion?
TypeReferenceExpression tre = ParseUtilCSharp.ParseExpression<TypeReferenceExpression>("int"); TypeReferenceExpression tre = ParseUtilCSharp.ParseExpression<TypeReferenceExpression>("int");
Assert.AreEqual("System.Int32", tre.TypeReference.Type); Assert.IsNotNull (tre.Match (new TypeReferenceExpression () {
} Type = new SimpleType ("int")
*/ }));
}*/
} }
} }

57
ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/AttributeSectionTests.cs

@ -3,28 +3,31 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions;
using ICSharpCode.NRefactory.PatternMatching;
using NUnit.Framework; using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
{ {
[TestFixture, Ignore] [TestFixture]
public class AttributeSectionTests public class AttributeSectionTests
{ {
[Test, Ignore] [Test, Ignore("Parser crash")]
public void GlobalAttributeCSharp() public void GlobalAttributeCSharp()
{ {
string program = @"[global::Microsoft.VisualBasic.CompilerServices.DesignerGenerated()] string program = @"[global::Microsoft.VisualBasic.CompilerServices.DesignerGenerated()]
[someprefix::DesignerGenerated()] [someprefix::DesignerGenerated()]
public class Form1 { public class Form1 {
}"; }";
// TODO This old NRefactory test checked that [global] attributes are incorrectly applied to the following type???
//TypeDeclaration decl = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program); TypeDeclaration decl = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program);
//Assert.AreEqual("Microsoft.VisualBasic.CompilerServices.DesignerGenerated", decl.Attributes.First().Attributes.Single().Name); Assert.AreEqual(2, decl.Attributes.Count);
//Assert.AreEqual("someprefix.DesignerGenerated", decl.Attributes.Last().Attributes.Single().Name); Assert.AreEqual("global::Microsoft.VisualBasic.CompilerServices.DesignerGenerated",
decl.Attributes.First().Attributes.Single().Type.ToString());
Assert.AreEqual("someprefix::DesignerGenerated", decl.Attributes.Last().Attributes.Single().Type.ToString());
} }
[Test] [Test, Ignore("assembly/module attributes are broken")]
public void AssemblyAttributeCSharp() public void AssemblyAttributeCSharp()
{ {
string program = @"[assembly: System.Attribute()]"; string program = @"[assembly: System.Attribute()]";
@ -33,7 +36,7 @@ public class Form1 {
Assert.AreEqual("assembly", decl.AttributeTarget); Assert.AreEqual("assembly", decl.AttributeTarget);
} }
[Test] [Test, Ignore("assembly/module attributes are broken")]
public void AssemblyAttributeCSharpWithNamedArguments() public void AssemblyAttributeCSharpWithNamedArguments()
{ {
string program = @"[assembly: Foo(1, namedArg: 2, prop = 3)]"; string program = @"[assembly: Foo(1, namedArg: 2, prop = 3)]";
@ -43,16 +46,25 @@ public class Form1 {
Assert.AreEqual("Foo", a.Type); Assert.AreEqual("Foo", a.Type);
Assert.AreEqual(3, a.Arguments.Count()); Assert.AreEqual(3, a.Arguments.Count());
// TODO: check arguments Assert.IsTrue(a.Arguments.ElementAt(0).IsMatch(new PrimitiveExpression(1)));
Assert.IsTrue(a.Arguments.ElementAt(1).IsMatch(new NamedArgumentExpression {
Identifier = "namedArg",
Expression = new PrimitiveExpression(2)
}));
Assert.IsTrue(a.Arguments.ElementAt(2).IsMatch(new AssignmentExpression {
Left = new IdentifierExpression("prop"),
Operator = AssignmentOperatorType.Assign,
Right = new PrimitiveExpression(3)
}));
} }
[Test] [Test, Ignore("assembly/module attributes are broken")]
public void ModuleAttributeCSharp() public void ModuleAttributeCSharp()
{ {
string program = @"[module: System.Attribute()]"; string program = @"[module: System.Attribute()]";
AttributeSection decl = ParseUtilCSharp.ParseGlobal<AttributeSection>(program); AttributeSection decl = ParseUtilCSharp.ParseGlobal<AttributeSection>(program);
Assert.AreEqual(new AstLocation(1, 1), decl.StartLocation); Assert.AreEqual(new AstLocation(1, 1), decl.StartLocation);
Assert.AreEqual(AttributeTarget.Module, decl.AttributeTarget); Assert.AreEqual("module", decl.AttributeTarget);
} }
[Test] [Test]
@ -62,7 +74,28 @@ public class Form1 {
TypeDeclaration type = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program); TypeDeclaration type = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program);
AttributeSection decl = type.Attributes.Single(); AttributeSection decl = type.Attributes.Single();
Assert.AreEqual(new AstLocation(1, 1), decl.StartLocation); Assert.AreEqual(new AstLocation(1, 1), decl.StartLocation);
Assert.AreEqual(AttributeTarget.Type, decl.AttributeTarget); Assert.AreEqual("type", decl.AttributeTarget);
}
[Test, Ignore("Parser doesn't support attributes on type parameters")]
public void AttributesOnTypeParameter()
{
string program = @"class Test<[A,B]C> {}";
TypeDeclaration type = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program);
Assert.IsTrue(
new TypeParameterDeclaration {
Attributes = {
new AttributeSection {
Attributes = {
new Attribute { Type = new SimpleType("A") },
new Attribute { Type = new SimpleType("B") }
}
}
},
Name = "C"
}.IsMatch(type.TypeParameters.Single()));
} }
// TODO: Tests for other contexts where attributes can appear
} }
} }

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

@ -26,7 +26,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
}}); }});
} }
[Test, Ignore("Generics not yet supported")] [Test]
public void GenericDelegateDeclarationTest() public void GenericDelegateDeclarationTest()
{ {
ParseUtilCSharp.AssertGlobal( ParseUtilCSharp.AssertGlobal(

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

@ -18,8 +18,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
Assert.AreEqual(ClassType.Class, td.ClassType); Assert.AreEqual(ClassType.Class, td.ClassType);
Assert.AreEqual("MyClass", td.Name); Assert.AreEqual("MyClass", td.Name);
//Assert.AreEqual("My.Base.Class", td.BaseTypes[0].Type); Assert.AreEqual("My.Base.Class", td.BaseTypes.First ().ToString ());
Assert.Ignore("need to check base type"); // TODO
Assert.AreEqual(Modifiers.None, td.Modifiers); Assert.AreEqual(Modifiers.None, td.Modifiers);
} }
@ -37,7 +36,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
Assert.AreEqual(2, td.EndLocation.Column, "EndLocation.Y"); Assert.AreEqual(2, td.EndLocation.Column, "EndLocation.Y");
} }
[Test, Ignore("partial modifier is broken")] [Test]
public void SimplePartialClassTypeDeclarationTest() public void SimplePartialClassTypeDeclarationTest()
{ {
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("partial class MyClass { }"); TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("partial class MyClass { }");
@ -47,7 +46,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
Assert.AreEqual(Modifiers.Partial, td.Modifiers); Assert.AreEqual(Modifiers.Partial, td.Modifiers);
} }
[Test, Ignore("nested classes are broken")] [Test]
public void NestedClassesTest() public void NestedClassesTest()
{ {
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("class MyClass { partial class P1 {} public partial class P2 {} static class P3 {} internal static class P4 {} }"); TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("class MyClass { partial class P1 {} public partial class P2 {} static class P3 {} internal static class P4 {} }");
@ -70,7 +69,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
Assert.AreEqual(Modifiers.Static, td.Modifiers); Assert.AreEqual(Modifiers.Static, td.Modifiers);
} }
[Test, Ignore("Generics not yet supported")] [Test]
public void GenericClassTypeDeclarationTest() public void GenericClassTypeDeclarationTest()
{ {
ParseUtilCSharp.AssertGlobal( ParseUtilCSharp.AssertGlobal(
@ -83,7 +82,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
}); });
} }
[Test, Ignore("Constraints not yet supported")] [Test]
public void GenericClassWithWhere() public void GenericClassWithWhere()
{ {
ParseUtilCSharp.AssertGlobal( ParseUtilCSharp.AssertGlobal(
@ -101,7 +100,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
}}); }});
} }
[Test, Ignore("Generic classes not yet supported")] [Test, Ignore ("Mono parser bug.")]
public void ComplexGenericClassTypeDeclarationTest() public void ComplexGenericClassTypeDeclarationTest()
{ {
ParseUtilCSharp.AssertGlobal( ParseUtilCSharp.AssertGlobal(
@ -144,7 +143,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
}); });
} }
[Test, Ignore("Base types not yet implemented")] [Test]
public void ComplexClassTypeDeclarationTest() public void ComplexClassTypeDeclarationTest()
{ {
ParseUtilCSharp.AssertGlobal( ParseUtilCSharp.AssertGlobal(
@ -217,7 +216,7 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
new TypeParameterDeclaration { new TypeParameterDeclaration {
Attributes = { Attributes = {
new AttributeSection { new AttributeSection {
AttributeTarget = AttributeTarget.Unknown, AttributeTarget = "partial",
Attributes = { new Attribute { Type = new SimpleType("where") } } Attributes = { new Attribute { Type = new SimpleType("where") } }
} }
}, },

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

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

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

@ -1,9 +1,11 @@
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) // Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt) // This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.PatternMatching;
using NUnit.Framework; using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser namespace ICSharpCode.NRefactory.CSharp.Parser
@ -29,7 +31,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
public static void AssertGlobal(string code, AstNode expectedNode) public static void AssertGlobal(string code, AstNode expectedNode)
{ {
var node = ParseGlobal<AstNode>(code); var node = ParseGlobal<AstNode>(code);
if (expectedNode.Match(node) == null) { if (!expectedNode.IsMatch(node)) {
Assert.Fail("Expected '{0}' but was '{1}'", ToCSharp(expectedNode), ToCSharp(node)); Assert.Fail("Expected '{0}' but was '{1}'", ToCSharp(expectedNode), ToCSharp(node));
} }
} }
@ -50,20 +52,19 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
public static void AssertStatement(string code, CSharp.Statement expectedStmt) public static void AssertStatement(string code, CSharp.Statement expectedStmt)
{ {
var stmt = ParseStatement<CSharp.Statement>(code); var stmt = ParseStatement<CSharp.Statement>(code);
if (expectedStmt.Match(stmt) == null) { if (!expectedStmt.IsMatch(stmt)) {
Assert.Fail("Expected '{0}' but was '{1}'", ToCSharp(expectedStmt), ToCSharp(stmt)); Assert.Fail("Expected '{0}' but was '{1}'", ToCSharp(expectedStmt), ToCSharp(stmt));
} }
} }
public static T ParseExpression<T>(string expr, bool expectErrors = false) where T : AstNode public static T ParseExpression<T>(string expr, bool expectErrors = false) where T : AstNode
{ {
if (expectErrors) Assert.Ignore("errors not yet implemented");
CSharpParser parser = new CSharpParser(); CSharpParser parser = new CSharpParser();
AstNode parsedExpression = parser.ParseExpression(new StringReader(expr)); AstNode parsedExpression = parser.ParseExpression(new StringReader(expr));
Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors"); Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors");
if (expectErrors && parsedExpression == null)
return default (T);
Type type = typeof(T); Type type = typeof(T);
Assert.IsTrue(type.IsAssignableFrom(parsedExpression.GetType()), String.Format("Parsed expression was {0} instead of {1} ({2})", parsedExpression.GetType(), type, parsedExpression)); Assert.IsTrue(type.IsAssignableFrom(parsedExpression.GetType()), String.Format("Parsed expression was {0} instead of {1} ({2})", parsedExpression.GetType(), type, parsedExpression));
return (T)parsedExpression; return (T)parsedExpression;
@ -72,15 +73,13 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
public static void AssertExpression(string code, CSharp.Expression expectedExpr) public static void AssertExpression(string code, CSharp.Expression expectedExpr)
{ {
var expr = ParseExpression<CSharp.Expression>(code); var expr = ParseExpression<CSharp.Expression>(code);
if (expectedExpr.Match(expr) == null) { if (!expectedExpr.IsMatch(expr)) {
Assert.Fail("Expected '{0}' but was '{1}'", ToCSharp(expectedExpr), ToCSharp(expr)); Assert.Fail("Expected '{0}' but was '{1}'", ToCSharp(expectedExpr), ToCSharp(expr));
} }
} }
public static T ParseTypeMember<T>(string expr, bool expectErrors = false) where T : AttributedNode public static T ParseTypeMember<T>(string expr, bool expectErrors = false) where T : AttributedNode
{ {
if (expectErrors) Assert.Ignore("errors not yet implemented");
CSharpParser parser = new CSharpParser(); CSharpParser parser = new CSharpParser();
var members = parser.ParseTypeMembers(new StringReader(expr)); var members = parser.ParseTypeMembers(new StringReader(expr));
@ -95,7 +94,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
public static void AssertTypeMember(string code, CSharp.AttributedNode expectedMember) public static void AssertTypeMember(string code, CSharp.AttributedNode expectedMember)
{ {
var member = ParseTypeMember<CSharp.AttributedNode>(code); var member = ParseTypeMember<CSharp.AttributedNode>(code);
if (expectedMember.Match(member) == null) { if (!expectedMember.IsMatch(member)) {
Assert.Fail("Expected '{0}' but was '{1}'", ToCSharp(expectedMember), ToCSharp(member)); Assert.Fail("Expected '{0}' but was '{1}'", ToCSharp(expectedMember), ToCSharp(member));
} }
} }
@ -103,7 +102,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
static string ToCSharp(AstNode node) static string ToCSharp(AstNode node)
{ {
StringWriter w = new StringWriter(); StringWriter w = new StringWriter();
node.AcceptVisitor(new OutputVisitor(w, new CSharpFormattingPolicy()), null); node.AcceptVisitor(new OutputVisitor(w, new CSharpFormattingOptions()), null);
return w.ToString(); return w.ToString();
} }
} }

5
ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/BlockStatementTests.cs

@ -17,7 +17,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
Assert.AreEqual(0, blockStmt.Statements.Count()); Assert.AreEqual(0, blockStmt.Statements.Count());
} }
[Test, Ignore("position isn't correct when only parsing a block")] [Test]
public void ComplexBlockStatementPositionTest() public void ComplexBlockStatementPositionTest()
{ {
string code = @"{ string code = @"{
@ -30,7 +30,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
}; };
}"; }";
BlockStatement blockStmt = ParseUtilCSharp.ParseStatement<BlockStatement>(code); BlockStatement blockStmt = ParseUtilCSharp.ParseStatement<BlockStatement>(code);
Assert.AreEqual(1, blockStmt.StartLocation.Column); // start column gets moved by ParseStatement
// Assert.AreEqual(1, blockStmt.StartLocation.Column);
Assert.AreEqual(1, blockStmt.StartLocation.Line); Assert.AreEqual(1, blockStmt.StartLocation.Line);
Assert.AreEqual(2, blockStmt.EndLocation.Column); Assert.AreEqual(2, blockStmt.EndLocation.Column);
Assert.AreEqual(9, blockStmt.EndLocation.Line); Assert.AreEqual(9, blockStmt.EndLocation.Line);

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

@ -6,21 +6,43 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
{ {
[TestFixture, Ignore("fixed is not implemented")] [TestFixture]
public class FixedStatementTests public class FixedStatementTests
{ {
[Test] [Test]
public void FixedStatementTest() public void FixedStatementTest()
{ {
FixedStatement fixedStmt = ParseUtilCSharp.ParseStatement<FixedStatement>("fixed (int* ptr = &myIntArr) { }");
ParseUtilCSharp.AssertStatement( ParseUtilCSharp.AssertStatement(
"fixed (int* ptr = &myIntArr) { }", "fixed (int* ptr = myIntArr) { }",
new FixedStatement { new FixedStatement {
Type = new PrimitiveType("int").MakePointerType(), Type = new PrimitiveType("int").MakePointerType(),
Variables = { Variables = {
new VariableInitializer { new VariableInitializer {
Name = "ptr", Name = "ptr",
Initializer = new UnaryOperatorExpression(UnaryOperatorType.AddressOf, new IdentifierExpression("myIntArr")) Initializer = new IdentifierExpression("myIntArr")
}
},
EmbeddedStatement = new BlockStatement()
});
}
[Test]
public void FixedStatementWithMultipleVariables()
{
ParseUtilCSharp.AssertStatement(
"fixed (int* ptr1 = &myIntArr[1], ptr2 = myIntArr) { }",
new FixedStatement {
Type = new PrimitiveType("int").MakePointerType(),
Variables = {
new VariableInitializer {
Name = "ptr1",
Initializer = new UnaryOperatorExpression(
UnaryOperatorType.AddressOf,
new IndexerExpression { Target = new IdentifierExpression("myIntArr"), Arguments = { new PrimitiveExpression(1) } })
},
new VariableInitializer {
Name = "ptr2",
Initializer = new IdentifierExpression("myIntArr")
} }
}, },
EmbeddedStatement = new BlockStatement() EmbeddedStatement = new BlockStatement()

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

@ -10,7 +10,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
[TestFixture] [TestFixture]
public class ForStatementTests public class ForStatementTests
{ {
[Test, Ignore("variable type in foreach is broken")] [Test]
public void ForeachStatementTest() public void ForeachStatementTest()
{ {
ParseUtilCSharp.AssertStatement( ParseUtilCSharp.AssertStatement(
@ -23,7 +23,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
}); });
} }
[Test, Ignore("for statement is broken when Initializers.Count()!=1")] [Test]
public void EmptyForStatementTest() public void EmptyForStatementTest()
{ {
ForStatement forStmt = ParseUtilCSharp.ParseStatement<ForStatement>("for (;;) ;"); ForStatement forStmt = ParseUtilCSharp.ParseStatement<ForStatement>("for (;;) ;");

2
ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/GotoStatementTests.cs

@ -10,7 +10,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
[TestFixture] [TestFixture]
public class GotoStatementTests public class GotoStatementTests
{ {
[Test, Ignore("regular goto statement is broken")] [Test]
public void GotoStatementTest() public void GotoStatementTest()
{ {
var gotoStmt = ParseUtilCSharp.ParseStatement<GotoStatement>("goto myLabel;"); var gotoStmt = ParseUtilCSharp.ParseStatement<GotoStatement>("goto myLabel;");

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

@ -4,6 +4,7 @@
using System; using System;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using ICSharpCode.NRefactory.PatternMatching;
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
{ {
@ -66,8 +67,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
CatchClauses = { new CatchClause { Body = new BlockStatement() } }, CatchClauses = { new CatchClause { Body = new BlockStatement() } },
FinallyBlock = new BlockStatement() FinallyBlock = new BlockStatement()
}; };
Assert.IsNull(c1.Match(c2)); Assert.IsFalse(c1.IsMatch(c2));
Assert.IsNull(c2.Match(c1)); // and vice versa Assert.IsFalse(c2.IsMatch(c1)); // and vice versa
} }
} }
} }

18
ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/UsingStatementTests.cs

@ -2,6 +2,7 @@
// This code is distributed under MIT X11 license (for details please see \doc\license.txt) // This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System; using System;
using System.Linq;
using NUnit.Framework; using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
@ -9,11 +10,22 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
[TestFixture] [TestFixture]
public class UsingStatementTests public class UsingStatementTests
{ {
[Test] [Test, Ignore("Parser doesn't report the VariableDeclarationStatement")]
public void UsingStatementTest() public void UsingStatementWithVariableDeclaration()
{ {
UsingStatement usingStmt = ParseUtilCSharp.ParseStatement<UsingStatement>("using (MyVar var = new MyVar()) { } "); UsingStatement usingStmt = ParseUtilCSharp.ParseStatement<UsingStatement>("using (MyVar var = new MyVar()) { } ");
// TODO : Extend test. VariableDeclarationStatement varDecl = (VariableDeclarationStatement)usingStmt.ResourceAcquisition;
Assert.AreEqual("var", varDecl.Variables.Single().Name);
Assert.IsTrue(varDecl.Variables.Single().Initializer is ObjectCreateExpression);
Assert.AreEqual("MyVar", ((SimpleType)varDecl.Type).Identifier);
Assert.IsTrue(usingStmt.EmbeddedStatement is BlockStatement);
}
public void UsingStatementWithExpression()
{
UsingStatement usingStmt = ParseUtilCSharp.ParseStatement<UsingStatement>("using (new MyVar()) { } ");
Assert.IsTrue(usingStmt.ResourceAcquisition is ObjectCreateExpression);
Assert.IsTrue(usingStmt.EmbeddedStatement is BlockStatement);
} }
} }
} }

191
ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/VariableDeclarationStatementTests.cs

@ -3,11 +3,12 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.PatternMatching;
using NUnit.Framework; using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
{ {
[TestFixture, Ignore] [TestFixture]
public class VariableDeclarationStatementTests public class VariableDeclarationStatementTests
{ {
[Test] [Test]
@ -15,191 +16,143 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
{ {
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("int a = 5;"); VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("int a = 5;");
Assert.AreEqual(1, lvd.Variables.Count()); Assert.AreEqual(1, lvd.Variables.Count());
/*Assert.AreEqual("a", ((VariableDeclaration)lvd.Variables[0]).Name); Assert.AreEqual("a", lvd.Variables.First ().Name);
TypeReference type = lvd.GetTypeForVariable(0); var type = lvd.Type;
Assert.AreEqual("System.Int32", type.Type); Assert.AreEqual("int", type.ToString ());
Assert.AreEqual(5, ((PrimitiveExpression)lvd.Variables[0].Initializer).Value);*/ throw new NotImplementedException(); Assert.AreEqual(5, ((PrimitiveExpression)lvd.Variables.First ().Initializer).Value);
} }
/* TODO port unit tests
[Test] [Test]
public void VoidPointerVariableDeclarationTest() public void VoidPointerVariableDeclarationTest()
{ {
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("void *a;"); VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("void *a;");
Assert.AreEqual(1, lvd.Variables.Count); Assert.IsTrue(new VariableDeclarationStatement(new PrimitiveType("void").MakePointerType(), "a").IsMatch(lvd));
Assert.AreEqual("a", ((VariableDeclaration)lvd.Variables[0]).Name);
TypeReference type = lvd.GetTypeForVariable(0);
Assert.AreEqual("System.Void", type.Type);
Assert.AreEqual(1, type.PointerNestingLevel);
} }
[Test] [Test]
public void ComplexGenericVariableDeclarationStatementTest() public void ComplexGenericVariableDeclarationStatementTest()
{ {
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("Generic<Namespace.Printable, G<Printable[]> > where = new Generic<Namespace.Printable, G<Printable[]>>();"); VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("Generic<Namespace.Printable, G<Printable[]> > where = new Generic<Namespace.Printable, G<Printable[]>>();");
Assert.AreEqual(1, lvd.Variables.Count); AstType type = new SimpleType("Generic") {
Assert.AreEqual("where", ((VariableDeclaration)lvd.Variables[0]).Name); TypeArguments = {
TypeReference type = lvd.GetTypeForVariable(0); new MemberType { Target = new SimpleType("Namespace"), MemberName = "Printable" },
Assert.AreEqual("Generic", type.Type); new SimpleType("G") { TypeArguments = { new SimpleType("Printable").MakeArrayType() } }
Assert.AreEqual(2, type.GenericTypes.Count); }};
Assert.AreEqual("Namespace.Printable", type.GenericTypes[0].Type); Assert.IsTrue(new VariableDeclarationStatement(type, "where", new ObjectCreateExpression { Type = type.Clone() }).IsMatch(lvd));
Assert.AreEqual(0, type.GenericTypes[0].GenericTypes.Count);
Assert.AreEqual("G", type.GenericTypes[1].Type);
Assert.AreEqual(1, type.GenericTypes[1].GenericTypes.Count);
Assert.AreEqual("Printable", type.GenericTypes[1].GenericTypes[0].Type);
// TODO: Check initializer
} }
[Test] [Test]
public void NestedGenericVariableDeclarationStatementTest() public void NestedGenericVariableDeclarationStatementTest()
{ {
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("MyType<string>.InnerClass<int>.InnerInnerClass a;"); VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("MyType<string>.InnerClass<int>.InnerInnerClass a;");
Assert.AreEqual(1, lvd.Variables.Count); AstType type = new MemberType {
InnerClassTypeReference ic = (InnerClassTypeReference)lvd.GetTypeForVariable(0); Target = new MemberType {
Assert.AreEqual("InnerInnerClass", ic.Type); Target = new SimpleType("MyType") { TypeArguments = { new PrimitiveType("string") } },
Assert.AreEqual(0, ic.GenericTypes.Count); MemberName = "InnerClass",
ic = (InnerClassTypeReference)ic.BaseType; TypeArguments = { new PrimitiveType("int") }
Assert.AreEqual("InnerClass", ic.Type); },
Assert.AreEqual(1, ic.GenericTypes.Count); MemberName = "InnerInnerClass"
Assert.AreEqual("System.Int32", ic.GenericTypes[0].Type); };
Assert.AreEqual("MyType", ic.BaseType.Type); Assert.IsTrue(new VariableDeclarationStatement(type, "a").IsMatch(lvd));
Assert.AreEqual(1, ic.BaseType.GenericTypes.Count);
Assert.AreEqual("System.String", ic.BaseType.GenericTypes[0].Type);
} }
[Test] [Test]
public void GenericWithArrayVariableDeclarationStatementTest1() public void GenericWithArrayVariableDeclarationStatementTest1()
{ {
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("G<int>[] a;"); VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("G<int>[] a;");
Assert.AreEqual(1, lvd.Variables.Count); AstType type = new SimpleType("G") {
TypeReference type = lvd.GetTypeForVariable(0); TypeArguments = { new PrimitiveType("int") }
Assert.AreEqual("G", type.Type); }.MakeArrayType();
Assert.AreEqual(1, type.GenericTypes.Count); Assert.IsTrue(new VariableDeclarationStatement(type, "a").IsMatch(lvd));
Assert.AreEqual("System.Int32", type.GenericTypes[0].Type);
Assert.AreEqual(0, type.GenericTypes[0].GenericTypes.Count);
Assert.IsFalse(type.GenericTypes[0].IsArrayType);
Assert.AreEqual(new int[] {0}, type.RankSpecifier);
} }
[Test] [Test]
public void GenericWithArrayVariableDeclarationStatementTest2() public void GenericWithArrayVariableDeclarationStatementTest2()
{ {
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("G<int[]> a;"); VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("G<int[]> a;");
Assert.AreEqual(1, lvd.Variables.Count); AstType type = new SimpleType("G") {
TypeReference type = lvd.GetTypeForVariable(0); TypeArguments = { new PrimitiveType("int").MakeArrayType() }
Assert.AreEqual("G", type.Type); };
Assert.AreEqual(1, type.GenericTypes.Count); Assert.IsTrue(new VariableDeclarationStatement(type, "a").IsMatch(lvd));
Assert.AreEqual("System.Int32", type.GenericTypes[0].Type);
Assert.AreEqual(0, type.GenericTypes[0].GenericTypes.Count);
Assert.IsFalse(type.IsArrayType);
Assert.AreEqual(new int[] {0}, type.GenericTypes[0].RankSpecifier);
} }
[Test] [Test]
public void GenericVariableDeclarationStatementTest2() public void GenericVariableDeclarationStatementTest2()
{ {
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("G<G<int> > a;"); VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("G<G<int> > a;");
Assert.AreEqual(1, lvd.Variables.Count); AstType type = new SimpleType("G") {
TypeReference type = lvd.GetTypeForVariable(0); TypeArguments = {
Assert.AreEqual("G", type.Type); new SimpleType("G") { TypeArguments = { new PrimitiveType("int") } }
Assert.AreEqual(1, type.GenericTypes.Count); }
Assert.AreEqual("G", type.GenericTypes[0].Type); };
Assert.AreEqual(1, type.GenericTypes[0].GenericTypes.Count); Assert.IsTrue(new VariableDeclarationStatement(type, "a").IsMatch(lvd));
Assert.AreEqual("System.Int32", type.GenericTypes[0].GenericTypes[0].Type);
} }
[Test] [Test]
public void GenericVariableDeclarationStatementTest2WithoutSpace() public void GenericVariableDeclarationStatementTest2WithoutSpace()
{ {
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("G<G<int>> a;"); VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("G<G<int>> a;");
Assert.AreEqual(1, lvd.Variables.Count); AstType type = new SimpleType("G") {
TypeReference type = lvd.GetTypeForVariable(0); TypeArguments = {
Assert.AreEqual("G", type.Type); new SimpleType("G") { TypeArguments = { new PrimitiveType("int") } }
Assert.AreEqual(1, type.GenericTypes.Count); }
Assert.AreEqual("G", type.GenericTypes[0].Type); };
Assert.AreEqual(1, type.GenericTypes[0].GenericTypes.Count); Assert.IsTrue(new VariableDeclarationStatement(type, "a").IsMatch(lvd));
Assert.AreEqual("System.Int32", type.GenericTypes[0].GenericTypes[0].Type);
} }
[Test] [Test]
public void GenericVariableDeclarationStatementTest() public void GenericVariableDeclarationStatementTest()
{ {
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("G<int> a;"); VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("G<int> a;");
Assert.AreEqual(1, lvd.Variables.Count); AstType type = new SimpleType("G") {
TypeReference type = lvd.GetTypeForVariable(0); TypeArguments = { new PrimitiveType("int") }
Assert.AreEqual("G", type.Type); };
Assert.AreEqual(1, type.GenericTypes.Count); Assert.IsTrue(new VariableDeclarationStatement(type, "a").IsMatch(lvd));
Assert.AreEqual("System.Int32", type.GenericTypes[0].Type);
} }
[Test] [Test]
public void SimpleVariableDeclarationStatementTest() public void SimpleVariableDeclarationStatementTest()
{ {
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("MyVar var = new MyVar();"); VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("MyVar var = new MyVar();");
Assert.AreEqual(1, lvd.Variables.Count); Assert.IsTrue(new VariableDeclarationStatement(new SimpleType("MyVar"), "var", new ObjectCreateExpression { Type = new SimpleType("MyVar") }).IsMatch(lvd));
Assert.AreEqual("var", ((VariableDeclaration)lvd.Variables[0]).Name);
TypeReference type = lvd.GetTypeForVariable(0);
Assert.AreEqual("MyVar", type.Type);
// TODO: Check initializer
} }
[Test] [Test]
public void SimpleVariableDeclarationStatementTest1() public void SimpleVariableDeclarationStatementTest1()
{ {
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("yield yield = new yield();"); VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("yield yield = new yield();");
Assert.AreEqual(1, lvd.Variables.Count); Assert.IsTrue(new VariableDeclarationStatement(new SimpleType("yield"), "yield", new ObjectCreateExpression { Type = new SimpleType("yield") }).IsMatch(lvd));
Assert.AreEqual("yield", ((VariableDeclaration)lvd.Variables[0]).Name);
TypeReference type = lvd.GetTypeForVariable(0);
Assert.AreEqual("yield", type.Type);
// TODO: Check initializer
} }
[Test] [Test]
public void NullableVariableDeclarationStatementTest1() public void NullableVariableDeclarationStatementTest1()
{ {
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("int? a;"); VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("int? a;");
Assert.AreEqual(1, lvd.Variables.Count); Assert.IsTrue(new VariableDeclarationStatement(new PrimitiveType("int").MakeNullableType(), "a").IsMatch(lvd));
Assert.AreEqual("a", ((VariableDeclaration)lvd.Variables[0]).Name);
TypeReference type = lvd.GetTypeForVariable(0);
Assert.AreEqual("System.Nullable", type.Type);
Assert.AreEqual("System.Int32", type.GenericTypes[0].Type);
} }
[Test] [Test]
public void NullableVariableDeclarationStatementTest2() public void NullableVariableDeclarationStatementTest2()
{ {
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("DateTime? a;"); VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("DateTime? a;");
Assert.AreEqual(1, lvd.Variables.Count); Assert.IsTrue(new VariableDeclarationStatement(new SimpleType("DateTime").MakeNullableType(), "a").IsMatch(lvd));
Assert.AreEqual("a", ((VariableDeclaration)lvd.Variables[0]).Name);
TypeReference type = lvd.GetTypeForVariable(0);
Assert.AreEqual("System.Nullable", type.Type);
Assert.AreEqual("DateTime", type.GenericTypes[0].Type);
} }
[Test] [Test, Ignore("The parser creates nested ComposedTypes while MakeArrayType() adds the specifier to the existing ComposedType")]
public void NullableVariableDeclarationStatementTest3() public void NullableVariableDeclarationStatementTest3()
{ {
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("DateTime?[] a;"); VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("DateTime?[] a;");
Assert.AreEqual(1, lvd.Variables.Count); Assert.IsTrue(new VariableDeclarationStatement(new SimpleType("DateTime").MakeNullableType().MakeArrayType(), "a").IsMatch(lvd));
Assert.AreEqual("a", ((VariableDeclaration)lvd.Variables[0]).Name);
TypeReference type = lvd.GetTypeForVariable(0);
Assert.IsTrue(type.IsArrayType);
Assert.AreEqual("System.Nullable", type.Type);
Assert.AreEqual("DateTime", type.GenericTypes[0].Type);
} }
[Test] [Test]
public void NullableVariableDeclarationStatementTest4() public void NullableVariableDeclarationStatementTest4()
{ {
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("SomeStruct<int?>? a;"); VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("SomeStruct<int?>? a;");
Assert.AreEqual(1, lvd.Variables.Count); AstType type = new SimpleType("SomeStruct") {
Assert.AreEqual("a", ((VariableDeclaration)lvd.Variables[0]).Name); TypeArguments = { new PrimitiveType("int").MakeNullableType() }
TypeReference type = lvd.GetTypeForVariable(0); }.MakeNullableType();
Assert.AreEqual("System.Nullable", type.Type); Assert.IsTrue(new VariableDeclarationStatement(type, "a").IsMatch(lvd));
Assert.AreEqual("SomeStruct", type.GenericTypes[0].Type);
Assert.AreEqual("System.Nullable", type.GenericTypes[0].GenericTypes[0].Type);
Assert.AreEqual("System.Int32", type.GenericTypes[0].GenericTypes[0].GenericTypes[0].Type);
} }
[Test] [Test]
@ -216,11 +169,39 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
public void PositionTestWithModifier() public void PositionTestWithModifier()
{ {
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("\nconst double w = 7;"); VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("\nconst double w = 7;");
Assert.AreEqual(Modifiers.Const, lvd.Modifier); Assert.AreEqual(Modifiers.Const, lvd.Modifiers);
Assert.AreEqual(2, lvd.StartLocation.Line); Assert.AreEqual(2, lvd.StartLocation.Line);
Assert.AreEqual(1, lvd.StartLocation.Column); Assert.AreEqual(1, lvd.StartLocation.Column);
Assert.AreEqual(2, lvd.EndLocation.Line); Assert.AreEqual(2, lvd.EndLocation.Line);
Assert.AreEqual(20, lvd.EndLocation.Column); Assert.AreEqual(20, lvd.EndLocation.Column);
}*/ }
[Test, Ignore("Nested arrays are broken in the parser")]
public void NestedArray()
{
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("DateTime[,][] a;");
Assert.IsTrue(new VariableDeclarationStatement(new SimpleType("DateTime").MakeArrayType(1).MakeArrayType(2), "a").IsMatch(lvd));
}
[Test, Ignore("Nested pointers are broken in the parser")]
public void NestedPointers()
{
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("DateTime*** a;");
Assert.IsTrue(new VariableDeclarationStatement(new SimpleType("DateTime").MakePointerType().MakePointerType().MakePointerType(), "a").IsMatch(lvd));
}
[Test, Ignore("The parser creates nested ComposedTypes while MakeArrayType() adds the specifier to the existing ComposedType")]
public void ArrayOfPointers()
{
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("DateTime*[] a;");
Assert.IsTrue(new VariableDeclarationStatement(new SimpleType("DateTime").MakePointerType().MakeArrayType(), "a").IsMatch(lvd));
}
[Test, Ignore("The parser creates nested ComposedTypes while MakeArrayType() adds the specifier to the existing ComposedType")]
public void ArrayOfNullables()
{
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("DateTime?[] a;");
Assert.IsTrue(new VariableDeclarationStatement(new SimpleType("DateTime").MakeNullableType().MakeArrayType(), "a").IsMatch(lvd));
}
} }
} }

4
ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/ConstructorDeclarationTests.cs

@ -17,7 +17,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
Assert.IsTrue(cd.Initializer.IsNull); Assert.IsTrue(cd.Initializer.IsNull);
} }
[Test, Ignore("Constructor initializer is broken")] [Test]
public void ConstructorDeclarationTest2() public void ConstructorDeclarationTest2()
{ {
ConstructorDeclaration cd = ParseUtilCSharp.ParseTypeMember<ConstructorDeclaration>("MyClass() : this(5) {}"); ConstructorDeclaration cd = ParseUtilCSharp.ParseTypeMember<ConstructorDeclaration>("MyClass() : this(5) {}");
@ -25,7 +25,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
Assert.AreEqual(1, cd.Initializer.Arguments.Count()); Assert.AreEqual(1, cd.Initializer.Arguments.Count());
} }
[Test, Ignore("Constructor initializer is broken")] [Test]
public void ConstructorDeclarationTest3() public void ConstructorDeclarationTest3()
{ {
ConstructorDeclaration cd = ParseUtilCSharp.ParseTypeMember<ConstructorDeclaration>("MyClass() : base(1, 2, 3) {}"); ConstructorDeclaration cd = ParseUtilCSharp.ParseTypeMember<ConstructorDeclaration>("MyClass() : base(1, 2, 3) {}");

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

@ -6,7 +6,7 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
{ {
[TestFixture, Ignore("events are broken")] [TestFixture]
public class EventDeclarationTests public class EventDeclarationTests
{ {
[Test] [Test]
@ -38,7 +38,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
}, },
new VariableInitializer { new VariableInitializer {
Name = "B", Name = "B",
Initializer = new AnonymousMethodExpression() Initializer = new AnonymousMethodExpression() { Body = new BlockStatement ()}
} }
}}); }});
} }

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

@ -9,7 +9,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
[TestFixture] [TestFixture]
public class FieldDeclarationTests public class FieldDeclarationTests
{ {
[Test, Ignore("multidimensional array rank incorrect?")] [Test]
public void SimpleFieldDeclarationTest() public void SimpleFieldDeclarationTest()
{ {
ParseUtilCSharp.AssertTypeMember( ParseUtilCSharp.AssertTypeMember(
@ -56,12 +56,21 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
}}); }});
} }
[Test, Ignore("How do we represent fixed-size fields in the AST?")] [Test]
public void FieldWithFixedSize() public void FieldWithFixedSize()
{ {
ParseUtilCSharp.AssertTypeMember( ParseUtilCSharp.AssertTypeMember(
"public unsafe fixed int Field[100];", "public unsafe fixed int Field[100];",
new FieldDeclaration()); new FixedFieldDeclaration() {
Modifiers = Modifiers.Public | Modifiers.Unsafe,
ReturnType = new PrimitiveType("int"),
Variables = {
new FixedVariableInitializer {
Name = "Field",
CountExpression = new PrimitiveExpression(100)
}
}
});
} }
} }
} }

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

@ -22,7 +22,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
Assert.AreEqual(Modifiers.Protected, id.Setter.Modifiers); Assert.AreEqual(Modifiers.Protected, id.Setter.Modifiers);
} }
[Test, Ignore("explicit interface implementation not yet supported")] [Test]
public void IndexerImplementingInterfaceTest() public void IndexerImplementingInterfaceTest()
{ {
IndexerDeclaration id = ParseUtilCSharp.ParseTypeMember<IndexerDeclaration>("int MyInterface.this[int a, string b] { get { } set { } }"); IndexerDeclaration id = ParseUtilCSharp.ParseTypeMember<IndexerDeclaration>("int MyInterface.this[int a, string b] { get { } set { } }");
@ -33,7 +33,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
Assert.AreEqual("MyInterface", ((SimpleType)id.PrivateImplementationType).Identifier); Assert.AreEqual("MyInterface", ((SimpleType)id.PrivateImplementationType).Identifier);
} }
[Test, Ignore("explicit interface implementation not yet supported")] [Test]
public void IndexerImplementingGenericInterfaceTest() public void IndexerImplementingGenericInterfaceTest()
{ {
ParseUtilCSharp.AssertTypeMember( ParseUtilCSharp.AssertTypeMember(

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

@ -8,7 +8,7 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
{ {
[TestFixture, Ignore("Generics not yet implemented")] [TestFixture]
public class MethodDeclarationTests public class MethodDeclarationTests
{ {
[Test] [Test]
@ -89,7 +89,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
public void MethodWithUnnamedParameterDeclarationTest() public void MethodWithUnnamedParameterDeclarationTest()
{ {
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("void MyMethod(int) {} ", true); MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>("void MyMethod(int) {} ", true);
Assert.AreEqual("System.Void", md.ReturnType); Assert.AreEqual("void", md.ReturnType.ToString ());
Assert.AreEqual(1, md.Parameters.Count()); Assert.AreEqual(1, md.Parameters.Count());
Assert.AreEqual("int", ((PrimitiveType)md.Parameters.Single().Type).Keyword); Assert.AreEqual("int", ((PrimitiveType)md.Parameters.Single().Type).Keyword);
} }
@ -202,6 +202,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
", ",
new TypeDeclaration { new TypeDeclaration {
ClassType = ClassType.Interface, ClassType = ClassType.Interface,
Name = "MyInterface",
BaseTypes = { new SimpleType("IDisposable") }, BaseTypes = { new SimpleType("IDisposable") },
Members = { Members = {
new MethodDeclaration { new MethodDeclaration {
@ -214,7 +215,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
[Test] [Test]
public void MethodImplementingInterfaceTest() public void MethodImplementingInterfaceTest()
{ {
ParseUtilCSharp.AssertGlobal( ParseUtilCSharp.AssertTypeMember(
"int MyInterface.MyMethod() {} ", "int MyInterface.MyMethod() {} ",
new MethodDeclaration { new MethodDeclaration {
ReturnType = new PrimitiveType("int"), ReturnType = new PrimitiveType("int"),
@ -227,7 +228,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
[Test] [Test]
public void MethodImplementingGenericInterfaceTest() public void MethodImplementingGenericInterfaceTest()
{ {
ParseUtilCSharp.AssertGlobal( ParseUtilCSharp.AssertTypeMember(
"int MyInterface<string>.MyMethod() {} ", "int MyInterface<string>.MyMethod() {} ",
new MethodDeclaration { new MethodDeclaration {
ReturnType = new PrimitiveType("int"), ReturnType = new PrimitiveType("int"),
@ -240,7 +241,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
[Test] [Test]
public void VoidMethodImplementingInterfaceTest() public void VoidMethodImplementingInterfaceTest()
{ {
ParseUtilCSharp.AssertGlobal( ParseUtilCSharp.AssertTypeMember (
"void MyInterface.MyMethod() {} ", "void MyInterface.MyMethod() {} ",
new MethodDeclaration { new MethodDeclaration {
ReturnType = new PrimitiveType("void"), ReturnType = new PrimitiveType("void"),
@ -253,11 +254,11 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
[Test] [Test]
public void VoidMethodImplementingGenericInterfaceTest() public void VoidMethodImplementingGenericInterfaceTest()
{ {
ParseUtilCSharp.AssertGlobal( ParseUtilCSharp.AssertTypeMember (
"void MyInterface<string>.MyMethod() {} ", "void MyInterface<string>.MyMethod() {} ",
new MethodDeclaration { new MethodDeclaration {
ReturnType = new PrimitiveType("void"), ReturnType = new PrimitiveType("void"),
PrivateImplementationType = new SimpleType("MyInterface"), PrivateImplementationType = new SimpleType("MyInterface") { TypeArguments = { new PrimitiveType("string") } },
Name = "MyMethod", Name = "MyMethod",
Body = new BlockStatement() Body = new BlockStatement()
}); });
@ -305,15 +306,15 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
public void MethodWithEmptyAssignmentErrorInBody() public void MethodWithEmptyAssignmentErrorInBody()
{ {
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>( MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>(
"void A\n" + "void A ()\n" +
"{\n" + "{\n" +
"int a = 3;\n" + "int a = 3;\n" +
" = 4;\n" + " = 4;\n" +
"}", true // expect errors "}", true // expect errors
); );
Assert.AreEqual("A", md.Name); Assert.AreEqual("A", md.Name);
Assert.AreEqual(new AstLocation(1, 2), md.Body.StartLocation); Assert.AreEqual(new AstLocation(2, 1), md.Body.StartLocation);
Assert.AreEqual(new AstLocation(2, 5), md.Body.EndLocation); Assert.AreEqual(new AstLocation(5, 2), md.Body.EndLocation);
} }
[Test] [Test]

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

@ -5,6 +5,7 @@ using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using ICSharpCode.NRefactory.PatternMatching;
namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
{ {
@ -66,7 +67,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
Assert.AreEqual(new AstLocation(4, code.IndexOf("}\n\t}") + 1 - line4Pos + 1), pd.Setter.Body.EndLocation); Assert.AreEqual(new AstLocation(4, code.IndexOf("}\n\t}") + 1 - line4Pos + 1), pd.Setter.Body.EndLocation);
} }
[Test, Ignore("explicit interface implementation not yet implemented")] [Test]
public void PropertyImplementingInterfaceTest() public void PropertyImplementingInterfaceTest()
{ {
PropertyDeclaration pd = ParseUtilCSharp.ParseTypeMember<PropertyDeclaration>("int MyInterface.MyProperty { get {} } "); PropertyDeclaration pd = ParseUtilCSharp.ParseTypeMember<PropertyDeclaration>("int MyInterface.MyProperty { get {} } ");
@ -77,7 +78,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
Assert.AreEqual("MyInterface", ((SimpleType)pd.PrivateImplementationType).Identifier); Assert.AreEqual("MyInterface", ((SimpleType)pd.PrivateImplementationType).Identifier);
} }
[Test, Ignore("explicit interface implementation not yet implemented")] [Test]
public void PropertyImplementingGenericInterfaceTest() public void PropertyImplementingGenericInterfaceTest()
{ {
PropertyDeclaration pd = ParseUtilCSharp.ParseTypeMember<PropertyDeclaration>("int MyInterface<string>.MyProperty { get {} } "); PropertyDeclaration pd = ParseUtilCSharp.ParseTypeMember<PropertyDeclaration>("int MyInterface<string>.MyProperty { get {} } ");
@ -85,7 +86,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
Assert.IsFalse(pd.Getter.IsNull); Assert.IsFalse(pd.Getter.IsNull);
Assert.IsTrue(pd.Setter.IsNull); Assert.IsTrue(pd.Setter.IsNull);
Assert.IsNotNull(new SimpleType { Identifier = "MyInterface", TypeArguments = { new PrimitiveType("string") } }.Match(pd.PrivateImplementationType)); Assert.IsTrue(new SimpleType { Identifier = "MyInterface", TypeArguments = { new PrimitiveType("string") } }.IsMatch(pd.PrivateImplementationType));
} }
} }
} }

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

@ -274,5 +274,19 @@ class TestClass {
var lrr = Resolve<LocalResolveResult>(program); var lrr = Resolve<LocalResolveResult>(program);
Assert.AreEqual("System.Int32", lrr.Type.ReflectionName); Assert.AreEqual("System.Int32", lrr.Type.ReflectionName);
} }
/* TODO write test for this
class A
{
static void Foo(string x, Action<Action> y) { Console.WriteLine(1); }
static void Foo(object x, Func<Func<int>, int> y) { Console.WriteLine(2); }
static void Main()
{
Foo(null, x => x()); // Prints 1
Foo(null, x => (x())); // Prints 2
}
}
*/
} }
} }

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

@ -138,7 +138,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
// static void Foo<T>(T? ignored = default(T?)) where T : struct // static void Foo<T>(T? ignored = default(T?)) where T : struct
var m1 = MakeMethod(); var m1 = MakeMethod();
m1.TypeParameters.Add(new DefaultTypeParameter(m1, 0, "T") { HasValueTypeConstraint = true }); m1.TypeParameters.Add(new DefaultTypeParameter(EntityType.Method, 0, "T") { HasValueTypeConstraint = true });
m1.Parameters.Add(MakeOptionalParameter( m1.Parameters.Add(MakeOptionalParameter(
NullableType.Create(m1.TypeParameters[0], context), NullableType.Create(m1.TypeParameters[0], context),
"ignored" "ignored"
@ -146,12 +146,12 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
// class ClassConstraint<T> where T : class {} // class ClassConstraint<T> where T : class {}
DefaultTypeDefinition classConstraint = new DefaultTypeDefinition(dummyClass, "ClassConstraint"); DefaultTypeDefinition classConstraint = new DefaultTypeDefinition(dummyClass, "ClassConstraint");
classConstraint.TypeParameters.Add(new DefaultTypeParameter(classConstraint, 0, "T") { HasReferenceTypeConstraint = true }); classConstraint.TypeParameters.Add(new DefaultTypeParameter(EntityType.TypeDefinition, 0, "T") { HasReferenceTypeConstraint = true });
// static void Foo<T>(ClassConstraint<T> ignored = default(ClassConstraint<T>)) // static void Foo<T>(ClassConstraint<T> ignored = default(ClassConstraint<T>))
// where T : class // where T : class
var m2 = MakeMethod(); var m2 = MakeMethod();
m2.TypeParameters.Add(new DefaultTypeParameter(m2, 0, "T") { HasReferenceTypeConstraint = true }); m2.TypeParameters.Add(new DefaultTypeParameter(EntityType.Method, 0, "T") { HasReferenceTypeConstraint = true });
m2.Parameters.Add(MakeOptionalParameter( m2.Parameters.Add(MakeOptionalParameter(
new ParameterizedType(classConstraint, new[] { m2.TypeParameters[0] }), new ParameterizedType(classConstraint, new[] { m2.TypeParameters[0] }),
"ignored" "ignored"
@ -159,7 +159,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
// static void Foo<T>() // static void Foo<T>()
var m3 = MakeMethod(); var m3 = MakeMethod();
m3.TypeParameters.Add(new DefaultTypeParameter(m3, 0, "T")); m3.TypeParameters.Add(new DefaultTypeParameter(EntityType.Method, 0, "T"));
// Call: Foo<int>(); // Call: Foo<int>();
OverloadResolution o; OverloadResolution o;

14
ICSharpCode.NRefactory.Tests/FormattingTests/TestBlankLineFormatting.cs

@ -37,7 +37,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestBlankLinesAfterUsings () public void TestBlankLinesAfterUsings ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.BlankLinesAfterUsings = 2; policy.BlankLinesAfterUsings = 2;
var adapter = Test (policy, @"using System; var adapter = Test (policy, @"using System;
@ -65,7 +65,7 @@ namespace Test
[Test()] [Test()]
public void TestBlankLinesBeforeUsings () public void TestBlankLinesBeforeUsings ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.BlankLinesAfterUsings = 0; policy.BlankLinesAfterUsings = 0;
policy.BlankLinesBeforeUsings = 2; policy.BlankLinesBeforeUsings = 2;
@ -94,7 +94,7 @@ namespace Test
[Test()] [Test()]
public void TestBlankLinesBeforeFirstDeclaration () public void TestBlankLinesBeforeFirstDeclaration ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.BlankLinesBeforeFirstDeclaration = 2; policy.BlankLinesBeforeFirstDeclaration = 2;
var adapter = Test (policy, @"namespace Test var adapter = Test (policy, @"namespace Test
@ -125,7 +125,7 @@ namespace Test
[Test()] [Test()]
public void TestBlankLinesBetweenTypes () public void TestBlankLinesBetweenTypes ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.BlankLinesBetweenTypes = 1; policy.BlankLinesBetweenTypes = 1;
var adapter = Test (policy, @"namespace Test var adapter = Test (policy, @"namespace Test
@ -173,7 +173,7 @@ namespace Test
[Test()] [Test()]
public void TestBlankLinesBetweenFields () public void TestBlankLinesBetweenFields ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.BlankLinesBetweenFields = 1; policy.BlankLinesBetweenFields = 1;
var adapter = Test (policy, @"class Test var adapter = Test (policy, @"class Test
@ -203,7 +203,7 @@ namespace Test
[Test()] [Test()]
public void TestBlankLinesBetweenEventFields () public void TestBlankLinesBetweenEventFields ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.BlankLinesBetweenEventFields = 1; policy.BlankLinesBetweenEventFields = 1;
var adapter = Test (policy, @"class Test var adapter = Test (policy, @"class Test
@ -234,7 +234,7 @@ namespace Test
[Test()] [Test()]
public void TestBlankLinesBetweenMembers () public void TestBlankLinesBetweenMembers ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.BlankLinesBetweenMembers = 1; policy.BlankLinesBetweenMembers = 1;
var adapter = Test (policy,@"class Test var adapter = Test (policy,@"class Test

32
ICSharpCode.NRefactory.Tests/FormattingTests/TestBraceStlye.cs

@ -37,7 +37,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestNamespaceBraceStyle () public void TestNamespaceBraceStyle ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.NamespaceBraceStyle = BraceStyle.EndOfLine; policy.NamespaceBraceStyle = BraceStyle.EndOfLine;
policy.ClassBraceStyle = BraceStyle.DoNotChange; policy.ClassBraceStyle = BraceStyle.DoNotChange;
@ -67,7 +67,7 @@ namespace B {
[Test()] [Test()]
public void TestClassBraceStlye () public void TestClassBraceStlye ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
Test (policy, Test (policy,
@ -79,7 +79,7 @@ namespace B {
[Test()] [Test()]
public void TestStructBraceStyle () public void TestStructBraceStyle ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StructBraceStyle = BraceStyle.NextLine; policy.StructBraceStyle = BraceStyle.NextLine;
Test (policy, Test (policy,
@ -92,7 +92,7 @@ namespace B {
[Test()] [Test()]
public void TestInterfaceBraceStyle () public void TestInterfaceBraceStyle ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.InterfaceBraceStyle = BraceStyle.NextLine; policy.InterfaceBraceStyle = BraceStyle.NextLine;
Test (policy, Test (policy,
@ -105,7 +105,7 @@ namespace B {
[Test()] [Test()]
public void TestEnumBraceStyle () public void TestEnumBraceStyle ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.EnumBraceStyle = BraceStyle.NextLineShifted; policy.EnumBraceStyle = BraceStyle.NextLineShifted;
Test (policy, @"enum Test { Test (policy, @"enum Test {
@ -120,7 +120,7 @@ namespace B {
[Test()] [Test()]
public void TestMethodBraceStlye () public void TestMethodBraceStlye ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.MethodBraceStyle = BraceStyle.NextLine; policy.MethodBraceStyle = BraceStyle.NextLine;
Test (policy, @"class Test Test (policy, @"class Test
@ -138,7 +138,7 @@ namespace B {
[Test()] [Test()]
public void TestConstructorBraceStyle () public void TestConstructorBraceStyle ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ConstructorBraceStyle = BraceStyle.NextLine; policy.ConstructorBraceStyle = BraceStyle.NextLine;
Test (policy, @"class Test Test (policy, @"class Test
@ -156,7 +156,7 @@ namespace B {
[Test()] [Test()]
public void TestDestructorBraceStyle () public void TestDestructorBraceStyle ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.DestructorBraceStyle = BraceStyle.NextLine; policy.DestructorBraceStyle = BraceStyle.NextLine;
Test (policy, @"class Test Test (policy, @"class Test
@ -174,7 +174,7 @@ namespace B {
[Test()] [Test()]
public void TestPropertyBraceStyle () public void TestPropertyBraceStyle ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.PropertyBraceStyle = BraceStyle.NextLine; policy.PropertyBraceStyle = BraceStyle.NextLine;
Test (policy, @"class Test Test (policy, @"class Test
@ -197,7 +197,7 @@ namespace B {
[Test()] [Test()]
public void TestPropertyGetBraceStyle () public void TestPropertyGetBraceStyle ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.PropertyGetBraceStyle = BraceStyle.NextLine; policy.PropertyGetBraceStyle = BraceStyle.NextLine;
Test (policy, @"class Test Test (policy, @"class Test
@ -225,7 +225,7 @@ namespace B {
public void TestAllowPropertyGetBlockInline () public void TestAllowPropertyGetBlockInline ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.PropertyBraceStyle = BraceStyle.DoNotChange; policy.PropertyBraceStyle = BraceStyle.DoNotChange;
policy.AllowPropertyGetBlockInline = true; policy.AllowPropertyGetBlockInline = true;
policy.AllowPropertySetBlockInline = false; policy.AllowPropertySetBlockInline = false;
@ -265,7 +265,7 @@ namespace B {
[Test()] [Test()]
public void TestAllowPropertySetBlockInline () public void TestAllowPropertySetBlockInline ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.PropertyBraceStyle = BraceStyle.DoNotChange; policy.PropertyBraceStyle = BraceStyle.DoNotChange;
policy.AllowPropertyGetBlockInline = false; policy.AllowPropertyGetBlockInline = false;
policy.AllowPropertySetBlockInline = true; policy.AllowPropertySetBlockInline = true;
@ -305,7 +305,7 @@ namespace B {
[Test()] [Test()]
public void TestPropertySetBraceStyle () public void TestPropertySetBraceStyle ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.PropertySetBraceStyle = BraceStyle.NextLine; policy.PropertySetBraceStyle = BraceStyle.NextLine;
Test (policy, @"class Test Test (policy, @"class Test
@ -332,7 +332,7 @@ namespace B {
[Test()] [Test()]
public void TestEventBraceStyle () public void TestEventBraceStyle ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.EventBraceStyle = BraceStyle.NextLine; policy.EventBraceStyle = BraceStyle.NextLine;
policy.EventAddBraceStyle = BraceStyle.NextLine; policy.EventAddBraceStyle = BraceStyle.NextLine;
policy.EventRemoveBraceStyle = BraceStyle.NextLine; policy.EventRemoveBraceStyle = BraceStyle.NextLine;
@ -363,7 +363,7 @@ namespace B {
[Test()] [Test()]
public void TestAllowEventAddBlockInline () public void TestAllowEventAddBlockInline ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.AllowEventAddBlockInline = true; policy.AllowEventAddBlockInline = true;
policy.AllowEventRemoveBlockInline = false; policy.AllowEventRemoveBlockInline = false;
@ -388,7 +388,7 @@ namespace B {
[Test()] [Test()]
public void TestAllowEventRemoveBlockInline () public void TestAllowEventRemoveBlockInline ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.AllowEventAddBlockInline = false; policy.AllowEventAddBlockInline = false;
policy.AllowEventRemoveBlockInline = true; policy.AllowEventRemoveBlockInline = true;

16
ICSharpCode.NRefactory.Tests/FormattingTests/TestFormattingBugs.cs

@ -40,7 +40,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestBug325187 () public void TestBug325187 ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.PlaceElseOnNewLine = true; policy.PlaceElseOnNewLine = true;
TestStatementFormatting (policy, TestStatementFormatting (policy,
@ -62,7 +62,7 @@ Console.WriteLine (""Bad indent"");",
[Test()] [Test()]
public void TestBug415469 () public void TestBug415469 ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
TestStatementFormatting (policy, TestStatementFormatting (policy,
@"switch (condition) { @"switch (condition) {
@ -86,7 +86,7 @@ case CONDITION2:
[Test()] [Test()]
public void TestBug540043 () public void TestBug540043 ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
TestStatementFormatting (policy, TestStatementFormatting (policy,
@"using (IDisposable a = null) @"using (IDisposable a = null)
@ -105,7 +105,7 @@ using (IDisposable b = null) {
[Test()] [Test()]
public void TestBug655635 () public void TestBug655635 ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
TestStatementFormatting (policy, TestStatementFormatting (policy,
@"try { @"try {
@ -121,7 +121,7 @@ using (IDisposable b = null) {
}"); }");
} }
void TestStatementFormatting (CSharpFormattingPolicy policy, string input, string expectedOutput) void TestStatementFormatting (CSharpFormattingOptions policy, string input, string expectedOutput)
{ {
var result = GetResult (policy, @"class Test var result = GetResult (policy, @"class Test
{ {
@ -143,7 +143,7 @@ using (IDisposable b = null) {
[Test()] [Test()]
public void TestBug659675 () public void TestBug659675 ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
TestStatementFormatting (policy, "@string=@int;", "@string = @int;"); TestStatementFormatting (policy, "@string=@int;", "@string = @int;");
} }
@ -153,7 +153,7 @@ using (IDisposable b = null) {
[Test()] [Test()]
public void TestBug670213 () public void TestBug670213 ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.MethodBraceStyle = BraceStyle.EndOfLine; policy.MethodBraceStyle = BraceStyle.EndOfLine;
Test (policy, @"class Test Test (policy, @"class Test
@ -176,7 +176,7 @@ using (IDisposable b = null) {
[Test()] [Test()]
public void TestBug677261 () public void TestBug677261 ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ConstructorBraceStyle = BraceStyle.EndOfLine; policy.ConstructorBraceStyle = BraceStyle.EndOfLine;
Test (policy, @"class Test Test (policy, @"class Test

168
ICSharpCode.NRefactory.Tests/FormattingTests/TestSpacingVisitor.cs

@ -37,7 +37,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestFieldSpacesBeforeComma1 () public void TestFieldSpacesBeforeComma1 ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
policy.SpaceBeforeFieldDeclarationComma = false; policy.SpaceBeforeFieldDeclarationComma = false;
policy.SpaceAfterFieldDeclarationComma = false; policy.SpaceAfterFieldDeclarationComma = false;
@ -53,7 +53,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestFieldSpacesBeforeComma2 () public void TestFieldSpacesBeforeComma2 ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
policy.SpaceBeforeFieldDeclarationComma = true; policy.SpaceBeforeFieldDeclarationComma = true;
policy.SpaceAfterFieldDeclarationComma = true; policy.SpaceAfterFieldDeclarationComma = true;
@ -69,7 +69,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestFixedFieldSpacesBeforeComma () public void TestFixedFieldSpacesBeforeComma ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
policy.SpaceAfterFieldDeclarationComma = true; policy.SpaceAfterFieldDeclarationComma = true;
policy.SpaceBeforeFieldDeclarationComma = true; policy.SpaceBeforeFieldDeclarationComma = true;
@ -85,7 +85,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestConstFieldSpacesBeforeComma () public void TestConstFieldSpacesBeforeComma ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
policy.SpaceAfterFieldDeclarationComma = false; policy.SpaceAfterFieldDeclarationComma = false;
policy.SpaceBeforeFieldDeclarationComma = false; policy.SpaceBeforeFieldDeclarationComma = false;
@ -101,7 +101,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestBeforeMethodDeclarationParentheses () public void TestBeforeMethodDeclarationParentheses ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeMethodDeclarationParentheses = true; policy.SpaceBeforeMethodDeclarationParentheses = true;
Test (policy, @"public abstract class Test Test (policy, @"public abstract class Test
@ -117,7 +117,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestBeforeConstructorDeclarationParenthesesDestructorCase () public void TestBeforeConstructorDeclarationParenthesesDestructorCase ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeConstructorDeclarationParentheses = true; policy.SpaceBeforeConstructorDeclarationParentheses = true;
Test (policy, @"class Test Test (policy, @"class Test
@ -134,7 +134,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
}"); }");
} }
static void TestBinaryOperator (CSharpFormattingPolicy policy, string op) static void TestBinaryOperator (CSharpFormattingOptions policy, string op)
{ {
var result = GetResult (policy, "class Test { void TestMe () { result = left" + op + "right; } }"); var result = GetResult (policy, "class Test { void TestMe () { result = left" + op + "right; } }");
@ -148,7 +148,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestSpacesAroundMultiplicativeOperator () public void TestSpacesAroundMultiplicativeOperator ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceAroundMultiplicativeOperator = true; policy.SpaceAroundMultiplicativeOperator = true;
TestBinaryOperator (policy, "*"); TestBinaryOperator (policy, "*");
@ -158,7 +158,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestSpacesAroundShiftOperator () public void TestSpacesAroundShiftOperator ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceAroundShiftOperator = true; policy.SpaceAroundShiftOperator = true;
TestBinaryOperator (policy, "<<"); TestBinaryOperator (policy, "<<");
TestBinaryOperator (policy, ">>"); TestBinaryOperator (policy, ">>");
@ -167,7 +167,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestSpacesAroundAdditiveOperator () public void TestSpacesAroundAdditiveOperator ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceAroundAdditiveOperator = true; policy.SpaceAroundAdditiveOperator = true;
TestBinaryOperator (policy, "+"); TestBinaryOperator (policy, "+");
@ -177,7 +177,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestSpacesAroundBitwiseOperator () public void TestSpacesAroundBitwiseOperator ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceAroundBitwiseOperator = true; policy.SpaceAroundBitwiseOperator = true;
TestBinaryOperator (policy, "&"); TestBinaryOperator (policy, "&");
@ -188,7 +188,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestSpacesAroundRelationalOperator () public void TestSpacesAroundRelationalOperator ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceAroundRelationalOperator = true; policy.SpaceAroundRelationalOperator = true;
TestBinaryOperator (policy, "<"); TestBinaryOperator (policy, "<");
@ -200,7 +200,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestSpacesAroundEqualityOperator () public void TestSpacesAroundEqualityOperator ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceAroundEqualityOperator = true; policy.SpaceAroundEqualityOperator = true;
TestBinaryOperator (policy, "=="); TestBinaryOperator (policy, "==");
@ -210,7 +210,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestSpacesAroundLogicalOperator () public void TestSpacesAroundLogicalOperator ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceAroundLogicalOperator = true; policy.SpaceAroundLogicalOperator = true;
TestBinaryOperator (policy, "&&"); TestBinaryOperator (policy, "&&");
@ -220,7 +220,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestConditionalOperator () public void TestConditionalOperator ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeConditionalOperatorCondition = true; policy.SpaceBeforeConditionalOperatorCondition = true;
policy.SpaceAfterConditionalOperatorCondition = true; policy.SpaceAfterConditionalOperatorCondition = true;
policy.SpaceBeforeConditionalOperatorSeparator = true; policy.SpaceBeforeConditionalOperatorSeparator = true;
@ -256,7 +256,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestBeforeMethodCallParenthesesSpace () public void TestBeforeMethodCallParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeMethodCallParentheses = true; policy.SpaceBeforeMethodCallParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -288,7 +288,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestWithinMethodCallParenthesesSpace () public void TestWithinMethodCallParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceWithinMethodCallParentheses = true; policy.SpaceWithinMethodCallParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -318,7 +318,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestBeforeIfParenthesesSpace () public void TestBeforeIfParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeIfParentheses = true; policy.SpaceBeforeIfParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -335,7 +335,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestWithinIfParenthesesSpace () public void TestWithinIfParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpacesWithinIfParentheses = true; policy.SpacesWithinIfParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -352,7 +352,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestBeforeWhileParenthesesSpace () public void TestBeforeWhileParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeWhileParentheses = true; policy.SpaceBeforeWhileParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -369,7 +369,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestWithinWhileParenthesesSpace () public void TestWithinWhileParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpacesWithinWhileParentheses = true; policy.SpacesWithinWhileParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -387,7 +387,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestBeforeForParenthesesSpace () public void TestBeforeForParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeForParentheses = true; policy.SpaceBeforeForParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -404,7 +404,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestWithinForParenthesesSpace () public void TestWithinForParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpacesWithinForParentheses = true; policy.SpacesWithinForParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -421,7 +421,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestBeforeForeachParenthesesSpace () public void TestBeforeForeachParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeForeachParentheses = true; policy.SpaceBeforeForeachParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -438,7 +438,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestWithinForeachParenthesesSpace () public void TestWithinForeachParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpacesWithinForeachParentheses = true; policy.SpacesWithinForeachParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -455,7 +455,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestBeforeCatchParenthesesSpace () public void TestBeforeCatchParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeCatchParentheses = true; policy.SpaceBeforeCatchParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -472,7 +472,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestWithinCatchParenthesesSpace () public void TestWithinCatchParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpacesWithinCatchParentheses = true; policy.SpacesWithinCatchParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -489,7 +489,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestBeforeLockParenthesesSpace () public void TestBeforeLockParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeLockParentheses = true; policy.SpaceBeforeLockParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -506,7 +506,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestWithinLockParenthesesSpace () public void TestWithinLockParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpacesWithinLockParentheses = true; policy.SpacesWithinLockParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -523,7 +523,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestSpacesAfterForSemicolon () public void TestSpacesAfterForSemicolon ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceAfterForSemicolon = true; policy.SpaceAfterForSemicolon = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -541,7 +541,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestSpacesBeforeForSemicolon () public void TestSpacesBeforeForSemicolon ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeForSemicolon = true; policy.SpaceBeforeForSemicolon = true;
policy.SpaceAfterForSemicolon = false; policy.SpaceAfterForSemicolon = false;
@ -560,7 +560,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestSpacesAfterTypecast () public void TestSpacesAfterTypecast ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceAfterTypecast = true; policy.SpaceAfterTypecast = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -578,7 +578,7 @@ return (Test)null;
[Test()] [Test()]
public void TestBeforeUsingParenthesesSpace () public void TestBeforeUsingParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeUsingParentheses = true; policy.SpaceBeforeUsingParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -595,7 +595,7 @@ return (Test)null;
[Test()] [Test()]
public void TestWithinUsingParenthesesSpace () public void TestWithinUsingParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpacesWithinUsingParentheses = true; policy.SpacesWithinUsingParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -609,7 +609,7 @@ return (Test)null;
Assert.AreEqual (@"( a )", result.GetTextAt (i1, i2 - i1)); Assert.AreEqual (@"( a )", result.GetTextAt (i1, i2 - i1));
} }
static void TestAssignmentOperator (CSharpFormattingPolicy policy, string op) static void TestAssignmentOperator (CSharpFormattingOptions policy, string op)
{ {
var result = GetResult (policy, "class Test { void TestMe () { left" + op + "right; } }"); var result = GetResult (policy, "class Test { void TestMe () { left" + op + "right; } }");
@ -623,7 +623,7 @@ return (Test)null;
[Test()] [Test()]
public void TestAroundAssignmentSpace () public void TestAroundAssignmentSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceAroundAssignment = true; policy.SpaceAroundAssignment = true;
TestAssignmentOperator (policy, "="); TestAssignmentOperator (policy, "=");
@ -642,7 +642,7 @@ return (Test)null;
[Test()] [Test()]
public void TestAroundAssignmentSpaceInDeclarations () public void TestAroundAssignmentSpaceInDeclarations ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceAroundAssignment = true; policy.SpaceAroundAssignment = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
void TestMe () void TestMe ()
@ -659,7 +659,7 @@ return (Test)null;
[Test()] [Test()]
public void TestBeforeSwitchParenthesesSpace () public void TestBeforeSwitchParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeSwitchParentheses = true; policy.SpaceBeforeSwitchParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -676,7 +676,7 @@ return (Test)null;
[Test()] [Test()]
public void TestWithinSwitchParenthesesSpace () public void TestWithinSwitchParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpacesWithinSwitchParentheses = true; policy.SpacesWithinSwitchParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -693,7 +693,7 @@ return (Test)null;
[Test()] [Test()]
public void TestWithinParenthesesSpace () public void TestWithinParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpacesWithinParentheses = true; policy.SpacesWithinParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -710,7 +710,7 @@ return (Test)null;
[Test()] [Test()]
public void TestWithinMethodDeclarationParenthesesSpace () public void TestWithinMethodDeclarationParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceWithinMethodDeclarationParentheses = true; policy.SpaceWithinMethodDeclarationParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -726,7 +726,7 @@ return (Test)null;
[Test()] [Test()]
public void TestWithinCastParenthesesSpace () public void TestWithinCastParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpacesWithinCastParentheses = true; policy.SpacesWithinCastParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -743,7 +743,7 @@ return (Test)null;
[Test()] [Test()]
public void TestWithinSizeOfParenthesesSpace () public void TestWithinSizeOfParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpacesWithinSizeOfParentheses = true; policy.SpacesWithinSizeOfParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -760,7 +760,7 @@ return (Test)null;
[Test()] [Test()]
public void TestBeforeSizeOfParentheses () public void TestBeforeSizeOfParentheses ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeSizeOfParentheses = true; policy.SpaceBeforeSizeOfParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -777,7 +777,7 @@ return (Test)null;
[Test()] [Test()]
public void TestWithinTypeOfParenthesesSpace () public void TestWithinTypeOfParenthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpacesWithinTypeOfParentheses = true; policy.SpacesWithinTypeOfParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -794,7 +794,7 @@ return (Test)null;
[Test()] [Test()]
public void TestBeforeTypeOfParentheses () public void TestBeforeTypeOfParentheses ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeTypeOfParentheses = true; policy.SpaceBeforeTypeOfParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -812,7 +812,7 @@ return (Test)null;
[Test()] [Test()]
public void TestWithinCheckedExpressionParanthesesSpace () public void TestWithinCheckedExpressionParanthesesSpace ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpacesWithinCheckedExpressionParantheses = true; policy.SpacesWithinCheckedExpressionParantheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -841,7 +841,7 @@ return (Test)null;
[Test()] [Test()]
public void TestSpaceBeforeNewParentheses () public void TestSpaceBeforeNewParentheses ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeNewParentheses = true; policy.SpaceBeforeNewParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -858,7 +858,7 @@ return (Test)null;
[Test()] [Test()]
public void TestWithinNewParentheses () public void TestWithinNewParentheses ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpacesWithinNewParentheses = true; policy.SpacesWithinNewParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -875,7 +875,7 @@ return (Test)null;
[Test()] [Test()]
public void TestBetweenEmptyNewParentheses () public void TestBetweenEmptyNewParentheses ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpacesBetweenEmptyNewParentheses = true; policy.SpacesBetweenEmptyNewParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -892,7 +892,7 @@ return (Test)null;
[Test()] [Test()]
public void TestBeforeNewParameterComma () public void TestBeforeNewParameterComma ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeNewParameterComma = true; policy.SpaceBeforeNewParameterComma = true;
policy.SpaceAfterNewParameterComma = false; policy.SpaceAfterNewParameterComma = false;
@ -910,7 +910,7 @@ return (Test)null;
[Test()] [Test()]
public void TestAfterNewParameterComma () public void TestAfterNewParameterComma ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceAfterNewParameterComma = true; policy.SpaceAfterNewParameterComma = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -927,7 +927,7 @@ return (Test)null;
[Test()] [Test()]
public void TestFieldDeclarationComma () public void TestFieldDeclarationComma ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeFieldDeclarationComma = false; policy.SpaceBeforeFieldDeclarationComma = false;
policy.SpaceAfterFieldDeclarationComma = true; policy.SpaceAfterFieldDeclarationComma = true;
@ -955,7 +955,7 @@ return (Test)null;
[Test()] [Test()]
public void TestBeforeMethodDeclarationParameterComma () public void TestBeforeMethodDeclarationParameterComma ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeMethodDeclarationParameterComma = true; policy.SpaceBeforeMethodDeclarationParameterComma = true;
policy.SpaceAfterMethodDeclarationParameterComma = false; policy.SpaceAfterMethodDeclarationParameterComma = false;
@ -976,7 +976,7 @@ return (Test)null;
[Test()] [Test()]
public void TestAfterMethodDeclarationParameterComma () public void TestAfterMethodDeclarationParameterComma ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeMethodDeclarationParameterComma = false; policy.SpaceBeforeMethodDeclarationParameterComma = false;
policy.SpaceAfterMethodDeclarationParameterComma = true; policy.SpaceAfterMethodDeclarationParameterComma = true;
@ -997,7 +997,7 @@ return (Test)null;
[Test()] [Test()]
public void TestSpacesInLambdaExpression () public void TestSpacesInLambdaExpression ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpacesWithinWhileParentheses = true; policy.SpacesWithinWhileParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -1014,7 +1014,7 @@ return (Test)null;
[Test()] [Test()]
public void TestBeforeLocalVariableDeclarationComma () public void TestBeforeLocalVariableDeclarationComma ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeLocalVariableDeclarationComma = true; policy.SpaceBeforeLocalVariableDeclarationComma = true;
policy.SpaceAfterLocalVariableDeclarationComma = false; policy.SpaceAfterLocalVariableDeclarationComma = false;
@ -1041,7 +1041,7 @@ return (Test)null;
[Test()] [Test()]
public void TestLocalVariableDeclarationComma () public void TestLocalVariableDeclarationComma ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeLocalVariableDeclarationComma = true; policy.SpaceBeforeLocalVariableDeclarationComma = true;
policy.SpaceAfterLocalVariableDeclarationComma = true; policy.SpaceAfterLocalVariableDeclarationComma = true;
@ -1071,7 +1071,7 @@ return (Test)null;
[Test()] [Test()]
public void TestBeforeConstructorDeclarationParentheses () public void TestBeforeConstructorDeclarationParentheses ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeConstructorDeclarationParentheses = true; policy.SpaceBeforeConstructorDeclarationParentheses = true;
var result = GetResult (policy, @"class Test var result = GetResult (policy, @"class Test
@ -1092,7 +1092,7 @@ return (Test)null;
[Test()] [Test()]
public void TestBeforeConstructorDeclarationParameterComma () public void TestBeforeConstructorDeclarationParameterComma ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeConstructorDeclarationParameterComma = true; policy.SpaceBeforeConstructorDeclarationParameterComma = true;
policy.SpaceAfterConstructorDeclarationParameterComma = false; policy.SpaceAfterConstructorDeclarationParameterComma = false;
@ -1115,7 +1115,7 @@ return (Test)null;
[Test()] [Test()]
public void TestAfterConstructorDeclarationParameterComma () public void TestAfterConstructorDeclarationParameterComma ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeConstructorDeclarationParameterComma = false; policy.SpaceBeforeConstructorDeclarationParameterComma = false;
policy.SpaceAfterConstructorDeclarationParameterComma = true; policy.SpaceAfterConstructorDeclarationParameterComma = true;
@ -1136,7 +1136,7 @@ return (Test)null;
[Test()] [Test()]
public void TestWithinConstructorDeclarationParentheses () public void TestWithinConstructorDeclarationParentheses ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceWithinConstructorDeclarationParentheses = true; policy.SpaceWithinConstructorDeclarationParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -1152,7 +1152,7 @@ return (Test)null;
[Test()] [Test()]
public void TestBetweenEmptyConstructorDeclarationParentheses () public void TestBetweenEmptyConstructorDeclarationParentheses ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBetweenEmptyConstructorDeclarationParentheses = true; policy.SpaceBetweenEmptyConstructorDeclarationParentheses = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -1171,7 +1171,7 @@ return (Test)null;
[Test()] [Test()]
public void TestBeforeDelegateDeclarationParentheses () public void TestBeforeDelegateDeclarationParentheses ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeDelegateDeclarationParentheses = true; policy.SpaceBeforeDelegateDeclarationParentheses = true;
var result = GetResult (policy, @"delegate void Test();"); var result = GetResult (policy, @"delegate void Test();");
@ -1182,7 +1182,7 @@ return (Test)null;
[Test()] [Test()]
public void TestBeforeDelegateDeclarationParenthesesComplex () public void TestBeforeDelegateDeclarationParenthesesComplex ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeDelegateDeclarationParentheses = true; policy.SpaceBeforeDelegateDeclarationParentheses = true;
var result = GetResult (policy, "delegate void TestDelegate\t\t\t();"); var result = GetResult (policy, "delegate void TestDelegate\t\t\t();");
@ -1193,7 +1193,7 @@ return (Test)null;
[Test()] [Test()]
public void TestBeforeDelegateDeclarationParameterComma () public void TestBeforeDelegateDeclarationParameterComma ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeDelegateDeclarationParameterComma = true; policy.SpaceBeforeDelegateDeclarationParameterComma = true;
policy.SpaceAfterDelegateDeclarationParameterComma = false; policy.SpaceAfterDelegateDeclarationParameterComma = false;
@ -1213,7 +1213,7 @@ return (Test)null;
[Test()] [Test()]
public void TestAfterDelegateDeclarationParameterComma () public void TestAfterDelegateDeclarationParameterComma ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeDelegateDeclarationParameterComma = false; policy.SpaceBeforeDelegateDeclarationParameterComma = false;
policy.SpaceAfterDelegateDeclarationParameterComma = true; policy.SpaceAfterDelegateDeclarationParameterComma = true;
@ -1233,7 +1233,7 @@ return (Test)null;
[Test()] [Test()]
public void TestWithinDelegateDeclarationParentheses () public void TestWithinDelegateDeclarationParentheses ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceWithinDelegateDeclarationParentheses = true; policy.SpaceWithinDelegateDeclarationParentheses = true;
var result = GetResult (policy, @"delegate void Test (int a);"); var result = GetResult (policy, @"delegate void Test (int a);");
@ -1245,7 +1245,7 @@ return (Test)null;
[Test()] [Test()]
public void TestBetweenEmptyDelegateDeclarationParentheses () public void TestBetweenEmptyDelegateDeclarationParentheses ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBetweenEmptyDelegateDeclarationParentheses = true; policy.SpaceBetweenEmptyDelegateDeclarationParentheses = true;
var result = GetResult (policy, @"delegate void Test();"); var result = GetResult (policy, @"delegate void Test();");
@ -1260,7 +1260,7 @@ return (Test)null;
[Test()] [Test()]
public void TestBeforeMethodCallParentheses () public void TestBeforeMethodCallParentheses ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeMethodCallParentheses = true; policy.SpaceBeforeMethodCallParentheses = true;
var result = GetResult (policy, @"class FooBar var result = GetResult (policy, @"class FooBar
@ -1283,7 +1283,7 @@ return (Test)null;
[Test()] [Test()]
public void TestBeforeMethodCallParameterComma () public void TestBeforeMethodCallParameterComma ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeMethodCallParameterComma = true; policy.SpaceBeforeMethodCallParameterComma = true;
policy.SpaceAfterMethodCallParameterComma = false; policy.SpaceAfterMethodCallParameterComma = false;
@ -1308,7 +1308,7 @@ return (Test)null;
[Test()] [Test()]
public void TestAfterMethodCallParameterComma () public void TestAfterMethodCallParameterComma ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeMethodCallParameterComma = false; policy.SpaceBeforeMethodCallParameterComma = false;
policy.SpaceAfterMethodCallParameterComma = true; policy.SpaceAfterMethodCallParameterComma = true;
@ -1333,7 +1333,7 @@ return (Test)null;
[Test()] [Test()]
public void TestWithinMethodCallParentheses () public void TestWithinMethodCallParentheses ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceWithinMethodCallParentheses = true; policy.SpaceWithinMethodCallParentheses = true;
var result = GetResult (policy, @"class FooBar var result = GetResult (policy, @"class FooBar
@ -1351,7 +1351,7 @@ return (Test)null;
[Test()] [Test()]
public void TestBetweenEmptyMethodCallParentheses () public void TestBetweenEmptyMethodCallParentheses ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBetweenEmptyMethodCallParentheses = true; policy.SpaceBetweenEmptyMethodCallParentheses = true;
var result = GetResult (policy, @"class FooBar var result = GetResult (policy, @"class FooBar
@ -1373,7 +1373,7 @@ return (Test)null;
public void TestBeforeIndexerDeclarationBracket () public void TestBeforeIndexerDeclarationBracket ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeIndexerDeclarationBracket = true; policy.SpaceBeforeIndexerDeclarationBracket = true;
var result = GetResult (policy, @"class FooBar var result = GetResult (policy, @"class FooBar
@ -1397,7 +1397,7 @@ return (Test)null;
[Test()] [Test()]
public void TestBeforeIndexerDeclarationParameterComma () public void TestBeforeIndexerDeclarationParameterComma ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeIndexerDeclarationParameterComma = true; policy.SpaceBeforeIndexerDeclarationParameterComma = true;
policy.SpaceAfterIndexerDeclarationParameterComma = false; policy.SpaceAfterIndexerDeclarationParameterComma = false;
@ -1418,7 +1418,7 @@ return (Test)null;
[Test()] [Test()]
public void TestAfterIndexerDeclarationParameterComma () public void TestAfterIndexerDeclarationParameterComma ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceAfterIndexerDeclarationParameterComma = true; policy.SpaceAfterIndexerDeclarationParameterComma = true;
var result = GetResult (policy, @"class FooBar var result = GetResult (policy, @"class FooBar
@ -1437,7 +1437,7 @@ return (Test)null;
[Test()] [Test()]
public void TestWithinIndexerDeclarationBracket () public void TestWithinIndexerDeclarationBracket ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceWithinIndexerDeclarationBracket = true; policy.SpaceWithinIndexerDeclarationBracket = true;
var result = GetResult (policy, @"class FooBar var result = GetResult (policy, @"class FooBar
@ -1460,7 +1460,7 @@ return (Test)null;
[Test()] [Test()]
public void TestSpacesWithinBrackets () public void TestSpacesWithinBrackets ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpacesWithinBrackets = true; policy.SpacesWithinBrackets = true;
policy.SpacesBeforeBrackets = false; policy.SpacesBeforeBrackets = false;
@ -1484,7 +1484,7 @@ return (Test)null;
[Test()] [Test()]
public void TestSpacesBeforeBrackets () public void TestSpacesBeforeBrackets ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpacesBeforeBrackets = true; policy.SpacesBeforeBrackets = true;
var result = GetResult (policy, @"class Test var result = GetResult (policy, @"class Test
@ -1508,7 +1508,7 @@ return (Test)null;
[Test()] [Test()]
public void TestBeforeBracketComma () public void TestBeforeBracketComma ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeBracketComma = true; policy.SpaceBeforeBracketComma = true;
policy.SpaceAfterBracketComma = false; policy.SpaceAfterBracketComma = false;
@ -1527,7 +1527,7 @@ return (Test)null;
[Test()] [Test()]
public void TestAfterBracketComma () public void TestAfterBracketComma ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceAfterBracketComma = true; policy.SpaceAfterBracketComma = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -1547,7 +1547,7 @@ return (Test)null;
[Test()] [Test()]
public void TestSpacesBeforeArrayDeclarationBrackets () public void TestSpacesBeforeArrayDeclarationBrackets ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.SpaceBeforeArrayDeclarationBrackets = true; policy.SpaceBeforeArrayDeclarationBrackets = true;
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
@ -1567,7 +1567,7 @@ return (Test)null;
[Test()] [Test()]
public void TestRemoveWhitespacesBeforeSemicolon () public void TestRemoveWhitespacesBeforeSemicolon ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
var result = GetResult (policy, @"class Test { var result = GetResult (policy, @"class Test {
void TestMe () void TestMe ()
{ {

120
ICSharpCode.NRefactory.Tests/FormattingTests/TestStatementIndentation.cs

@ -37,7 +37,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestInvocationIndentation () public void TestInvocationIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
Test (policy, Test (policy,
@ -58,7 +58,7 @@ this.TestMethod ();
[Test()] [Test()]
public void TestIndentBlocks () public void TestIndentBlocks ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.IndentBlocks = true; policy.IndentBlocks = true;
var adapter = Test (policy, var adapter = Test (policy,
@ -94,7 +94,7 @@ this.TestMethod ();
[Test()] [Test()]
public void TestBreakIndentation () public void TestBreakIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
Test (policy, Test (policy,
@ -115,7 +115,7 @@ this.TestMethod ();
[Test()] [Test()]
public void TestCheckedIndentation () public void TestCheckedIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
@ -137,7 +137,7 @@ checked {
[Test()] [Test()]
public void TestBaseIndentation () public void TestBaseIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
Test (policy, @"class Test { Test (policy, @"class Test {
@ -156,7 +156,7 @@ checked {
[Test()] [Test()]
public void TestUncheckedIndentation () public void TestUncheckedIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
Test (policy, @"class Test { Test (policy, @"class Test {
@ -178,7 +178,7 @@ unchecked {
[Test()] [Test()]
public void TestContinueIndentation () public void TestContinueIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
Test (policy, @"class Test { Test (policy, @"class Test {
@ -198,7 +198,7 @@ continue;
[Test()] [Test()]
public void TestEmptyStatementIndentation () public void TestEmptyStatementIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
Test (policy, @"class Test { Test (policy, @"class Test {
@ -217,7 +217,7 @@ continue;
[Test()] [Test()]
public void TestFixedStatementIndentation () public void TestFixedStatementIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
Test (policy, @"class Test { Test (policy, @"class Test {
@ -239,7 +239,7 @@ fixed (object* obj = &obj)
[Test()] [Test()]
public void TestFixedForcementAdd () public void TestFixedForcementAdd ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLine; policy.StatementBraceStyle = BraceStyle.EndOfLine;
policy.FixedBraceForcement = BraceForcement.AddBraces; policy.FixedBraceForcement = BraceForcement.AddBraces;
@ -269,7 +269,7 @@ fixed (object* obj = &obj)
[Test()] [Test()]
public void TestForeachIndentation () public void TestForeachIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLine; policy.StatementBraceStyle = BraceStyle.EndOfLine;
Test (policy, @"class Test Test (policy, @"class Test
@ -292,7 +292,7 @@ foreach (var obj in col) {
[Test()] [Test()]
public void TestForIndentation () public void TestForIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
@ -314,7 +314,7 @@ for (;;) {
[Test()] [Test()]
public void TestGotoIndentation () public void TestGotoIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
Test (policy, @"class Test { Test (policy, @"class Test {
@ -334,7 +334,7 @@ goto label;
[Test()] [Test()]
public void TestReturnIndentation () public void TestReturnIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
Test (policy, @"class Test { Test (policy, @"class Test {
@ -354,7 +354,7 @@ return;
[Test()] [Test()]
public void TestLockIndentation () public void TestLockIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
Test (policy, @"class Test { Test (policy, @"class Test {
@ -376,7 +376,7 @@ lock (this) {
[Test()] [Test()]
public void TestThrowIndentation () public void TestThrowIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
@ -397,7 +397,7 @@ throw new NotSupportedException ();
[Test()] [Test()]
public void TestUnsafeIndentation () public void TestUnsafeIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
@ -420,7 +420,7 @@ unsafe {
[Test()] [Test()]
public void TestUsingIndentation () public void TestUsingIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
@ -442,7 +442,7 @@ using (var o = new MyObj()) {
[Test()] [Test()]
public void TestUsingForcementAdd () public void TestUsingForcementAdd ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLine; policy.StatementBraceStyle = BraceStyle.EndOfLine;
policy.UsingBraceForcement = BraceForcement.AddBraces; policy.UsingBraceForcement = BraceForcement.AddBraces;
@ -472,7 +472,7 @@ using (var o = new MyObj()) {
[Test()] [Test()]
public void TestUsingForcementDoNotChange () public void TestUsingForcementDoNotChange ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLine; policy.StatementBraceStyle = BraceStyle.EndOfLine;
policy.UsingBraceForcement = BraceForcement.DoNotChange; policy.UsingBraceForcement = BraceForcement.DoNotChange;
@ -501,7 +501,7 @@ using (var o = new MyObj()) {
[Test()] [Test()]
public void TestUsingAlignment () public void TestUsingAlignment ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.AlignEmbeddedUsingStatements = true; policy.AlignEmbeddedUsingStatements = true;
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
@ -535,7 +535,7 @@ using (var o = new MyObj()) {
[Test()] [Test()]
public void TestVariableDeclarationIndentation () public void TestVariableDeclarationIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
Test (policy, @"class Test { Test (policy, @"class Test {
@ -555,7 +555,7 @@ Test a;
[Test()] [Test()]
public void TestConstantVariableDeclarationIndentation () public void TestConstantVariableDeclarationIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
Test (policy, @"class Test { Test (policy, @"class Test {
@ -575,7 +575,7 @@ const int a = 5;
[Test()] [Test()]
public void TestYieldIndentation () public void TestYieldIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
Test (policy, @"class Test { Test (policy, @"class Test {
@ -595,7 +595,7 @@ yield return null;
[Test()] [Test()]
public void TestWhileIndentation () public void TestWhileIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
@ -618,7 +618,7 @@ while (true)
[Test()] [Test()]
public void TestDoWhileIndentation () public void TestDoWhileIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
Test (policy, @"class Test { Test (policy, @"class Test {
@ -640,7 +640,7 @@ do {
[Test()] [Test()]
public void TestForeachBracketPlacement () public void TestForeachBracketPlacement ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLine; policy.StatementBraceStyle = BraceStyle.EndOfLine;
Test (policy, @"class Test Test (policy, @"class Test
@ -663,7 +663,7 @@ do {
[Test()] [Test()]
public void TestForeachBracketPlacement2 () public void TestForeachBracketPlacement2 ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.NextLineShifted2; policy.StatementBraceStyle = BraceStyle.NextLineShifted2;
Test (policy, @"class Test Test (policy, @"class Test
@ -688,7 +688,7 @@ do {
[Test()] [Test()]
public void TestForEachBraceForcementAdd () public void TestForEachBraceForcementAdd ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.NextLine; policy.StatementBraceStyle = BraceStyle.NextLine;
policy.ForEachBraceForcement = BraceForcement.AddBraces; policy.ForEachBraceForcement = BraceForcement.AddBraces;
@ -720,7 +720,7 @@ do {
[Test()] [Test()]
public void TestForBraceForcementAdd () public void TestForBraceForcementAdd ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.NextLine; policy.StatementBraceStyle = BraceStyle.NextLine;
policy.ForBraceForcement = BraceForcement.AddBraces; policy.ForBraceForcement = BraceForcement.AddBraces;
@ -753,7 +753,7 @@ do {
[Test()] [Test()]
public void TestForEachBraceForcementRemove () public void TestForEachBraceForcementRemove ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.NextLine; policy.StatementBraceStyle = BraceStyle.NextLine;
policy.ForEachBraceForcement = BraceForcement.RemoveBraces; policy.ForEachBraceForcement = BraceForcement.RemoveBraces;
@ -790,7 +790,7 @@ do {
[Test()] [Test()]
public void TestIfBracketPlacement () public void TestIfBracketPlacement ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLine; policy.StatementBraceStyle = BraceStyle.EndOfLine;
@ -814,7 +814,7 @@ do {
[Test()] [Test()]
public void TestAllowIfBlockInline () public void TestAllowIfBlockInline ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLine; policy.StatementBraceStyle = BraceStyle.EndOfLine;
policy.AllowIfBlockInline = true; policy.AllowIfBlockInline = true;
@ -884,7 +884,7 @@ do {
[Test()] [Test()]
public void TestIfElseBracketPlacement () public void TestIfElseBracketPlacement ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLine; policy.StatementBraceStyle = BraceStyle.EndOfLine;
@ -909,7 +909,7 @@ do {
[Test()] [Test()]
public void TestIfForcementRemove () public void TestIfForcementRemove ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.NextLine; policy.StatementBraceStyle = BraceStyle.NextLine;
policy.IfElseBraceForcement = BraceForcement.RemoveBraces; policy.IfElseBraceForcement = BraceForcement.RemoveBraces;
@ -947,7 +947,7 @@ do {
[Test()] [Test()]
public void TestIfAlignment () public void TestIfAlignment ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.AlignEmbeddedIfStatements = true; policy.AlignEmbeddedIfStatements = true;
policy.ClassBraceStyle = BraceStyle.EndOfLine; policy.ClassBraceStyle = BraceStyle.EndOfLine;
@ -981,7 +981,7 @@ if (b) {
[Test()] [Test()]
public void TestIfForcementAdd () public void TestIfForcementAdd ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLine; policy.StatementBraceStyle = BraceStyle.EndOfLine;
policy.IfElseBraceForcement = BraceForcement.AddBraces; policy.IfElseBraceForcement = BraceForcement.AddBraces;
@ -1008,7 +1008,7 @@ if (b) {
[Test()] [Test()]
public void TestIfForcementWithComment () public void TestIfForcementWithComment ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLine; policy.StatementBraceStyle = BraceStyle.EndOfLine;
policy.IfElseBraceForcement = BraceForcement.AddBraces; policy.IfElseBraceForcement = BraceForcement.AddBraces;
@ -1036,7 +1036,7 @@ if (b) {
[Test()] [Test()]
public void TestIfElseForcementAdd () public void TestIfElseForcementAdd ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLine; policy.StatementBraceStyle = BraceStyle.EndOfLine;
policy.IfElseBraceForcement = BraceForcement.AddBraces; policy.IfElseBraceForcement = BraceForcement.AddBraces;
@ -1067,7 +1067,7 @@ if (b) {
[Test()] [Test()]
public void TestIfElseIFForcementAdd () public void TestIfElseIFForcementAdd ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLine; policy.StatementBraceStyle = BraceStyle.EndOfLine;
policy.IfElseBraceForcement = BraceForcement.AddBraces; policy.IfElseBraceForcement = BraceForcement.AddBraces;
@ -1098,7 +1098,7 @@ if (b) {
[Test()] [Test()]
public void TestElseOnNewLine () public void TestElseOnNewLine ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.PlaceElseOnNewLine = true; policy.PlaceElseOnNewLine = true;
Test (policy, @"class Test Test (policy, @"class Test
@ -1129,7 +1129,7 @@ if (b) {
[Test()] [Test()]
public void TestElseIfOnNewLine () public void TestElseIfOnNewLine ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.PlaceElseIfOnNewLine = true; policy.PlaceElseIfOnNewLine = true;
Test (policy, @"class Test Test (policy, @"class Test
@ -1160,7 +1160,7 @@ if (b) {
[Test()] [Test()]
public void TestElseOnNewLineOff () public void TestElseOnNewLineOff ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.PlaceElseOnNewLine = false; policy.PlaceElseOnNewLine = false;
Test (policy, @"class Test Test (policy, @"class Test
@ -1191,7 +1191,7 @@ if (b) {
[Test()] [Test()]
public void TestSimpleIfElseComment () public void TestSimpleIfElseComment ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLine; policy.StatementBraceStyle = BraceStyle.EndOfLine;
policy.PlaceElseIfOnNewLine = false; // for simple statements it must be new line. policy.PlaceElseIfOnNewLine = false; // for simple statements it must be new line.
@ -1218,7 +1218,7 @@ if (b) {
[Test()] [Test()]
public void TestWhileForcementRemove () public void TestWhileForcementRemove ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.NextLine; policy.StatementBraceStyle = BraceStyle.NextLine;
policy.WhileBraceForcement = BraceForcement.RemoveBraces; policy.WhileBraceForcement = BraceForcement.RemoveBraces;
@ -1256,7 +1256,7 @@ if (b) {
[Test()] [Test()]
public void TestFixedBracketPlacement () public void TestFixedBracketPlacement ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.NextLineShifted; policy.StatementBraceStyle = BraceStyle.NextLineShifted;
policy.FixedBraceForcement = BraceForcement.AddBraces; policy.FixedBraceForcement = BraceForcement.AddBraces;
@ -1285,7 +1285,7 @@ if (b) {
[Test()] [Test()]
public void TestForBracketPlacement () public void TestForBracketPlacement ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLineWithoutSpace; policy.StatementBraceStyle = BraceStyle.EndOfLineWithoutSpace;
Test (policy, @"class Test Test (policy, @"class Test
@ -1309,7 +1309,7 @@ if (b) {
[Test()] [Test()]
public void TestCheckedBracketPlacement () public void TestCheckedBracketPlacement ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLineWithoutSpace; policy.StatementBraceStyle = BraceStyle.EndOfLineWithoutSpace;
@ -1334,7 +1334,7 @@ if (b) {
[Test()] [Test()]
public void TestUncheckedBracketPlacement () public void TestUncheckedBracketPlacement ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLineWithoutSpace; policy.StatementBraceStyle = BraceStyle.EndOfLineWithoutSpace;
@ -1359,7 +1359,7 @@ if (b) {
[Test()] [Test()]
public void TestLockBracketPlacement () public void TestLockBracketPlacement ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLine; policy.StatementBraceStyle = BraceStyle.EndOfLine;
@ -1387,7 +1387,7 @@ if (b) {
[Test()] [Test()]
public void TestUnsafeBracketPlacement () public void TestUnsafeBracketPlacement ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLine; policy.StatementBraceStyle = BraceStyle.EndOfLine;
@ -1415,7 +1415,7 @@ if (b) {
[Test()] [Test()]
public void TestUsingBracketPlacement () public void TestUsingBracketPlacement ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLine; policy.StatementBraceStyle = BraceStyle.EndOfLine;
@ -1443,7 +1443,7 @@ if (b) {
[Test()] [Test()]
public void TestWhileBracketPlacement () public void TestWhileBracketPlacement ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLine; policy.StatementBraceStyle = BraceStyle.EndOfLine;
@ -1471,7 +1471,7 @@ if (b) {
[Test()] [Test()]
public void TestDoWhileBracketPlacement () public void TestDoWhileBracketPlacement ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLine; policy.StatementBraceStyle = BraceStyle.EndOfLine;
@ -1499,7 +1499,7 @@ if (b) {
[Test()] [Test()]
public void TestSwitchFormatting1 () public void TestSwitchFormatting1 ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.IndentSwitchBody = true; policy.IndentSwitchBody = true;
policy.IndentCaseBody = true; policy.IndentCaseBody = true;
@ -1532,7 +1532,7 @@ if (b) {
[Test()] [Test()]
public void TestSwitchFormatting2 () public void TestSwitchFormatting2 ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.IndentSwitchBody = false; policy.IndentSwitchBody = false;
policy.IndentCaseBody = false; policy.IndentCaseBody = false;
@ -1565,7 +1565,7 @@ if (b) {
[Test()] [Test()]
public void TestTryCatchBracketPlacement () public void TestTryCatchBracketPlacement ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.StatementBraceStyle = BraceStyle.EndOfLine; policy.StatementBraceStyle = BraceStyle.EndOfLine;
@ -1592,7 +1592,7 @@ if (b) {
[Test()] [Test()]
public void TestPlaceCatchOnNewLine () public void TestPlaceCatchOnNewLine ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.PlaceCatchOnNewLine = true; policy.PlaceCatchOnNewLine = true;
@ -1624,7 +1624,7 @@ if (b) {
[Test()] [Test()]
public void TestPlaceFinallyOnNewLine () public void TestPlaceFinallyOnNewLine ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.PlaceFinallyOnNewLine = true; policy.PlaceFinallyOnNewLine = true;
Test (policy, @"class Test Test (policy, @"class Test
@ -1655,7 +1655,7 @@ if (b) {
[Test()] [Test()]
public void TestPlaceWhileOnNewLine () public void TestPlaceWhileOnNewLine ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.PlaceWhileOnNewLine = true; policy.PlaceWhileOnNewLine = true;

40
ICSharpCode.NRefactory.Tests/FormattingTests/TestTypeLevelIndentation.cs

@ -37,7 +37,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestClassIndentation () public void TestClassIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.DoNotChange; policy.ClassBraceStyle = BraceStyle.DoNotChange;
Test (policy, Test (policy,
@ -49,7 +49,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestClassIndentationInNamespaces () public void TestClassIndentationInNamespaces ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.NamespaceBraceStyle = BraceStyle.EndOfLine; policy.NamespaceBraceStyle = BraceStyle.EndOfLine;
policy.ClassBraceStyle = BraceStyle.DoNotChange; policy.ClassBraceStyle = BraceStyle.DoNotChange;
@ -63,7 +63,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
[Test()] [Test()]
public void TestNoIndentationInNamespaces () public void TestNoIndentationInNamespaces ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.NamespaceBraceStyle = BraceStyle.EndOfLine; policy.NamespaceBraceStyle = BraceStyle.EndOfLine;
policy.ClassBraceStyle = BraceStyle.DoNotChange; policy.ClassBraceStyle = BraceStyle.DoNotChange;
policy.IndentNamespaceBody = false; policy.IndentNamespaceBody = false;
@ -78,7 +78,7 @@ class Test {}
[Test()] [Test()]
public void TestClassIndentationInNamespacesCase2 () public void TestClassIndentationInNamespacesCase2 ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.NamespaceBraceStyle = BraceStyle.NextLine; policy.NamespaceBraceStyle = BraceStyle.NextLine;
policy.ClassBraceStyle = BraceStyle.NextLine; policy.ClassBraceStyle = BraceStyle.NextLine;
policy.ConstructorBraceStyle = BraceStyle.NextLine; policy.ConstructorBraceStyle = BraceStyle.NextLine;
@ -108,7 +108,7 @@ namespace MonoDevelop.CSharp.Formatting
[Test()] [Test()]
public void TestIndentClassBody () public void TestIndentClassBody ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.IndentClassBody = true; policy.IndentClassBody = true;
Test (policy, Test (policy,
@"class Test @"class Test
@ -134,7 +134,7 @@ Test a;
[Test()] [Test()]
public void TestIndentInterfaceBody () public void TestIndentInterfaceBody ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.IndentInterfaceBody = true; policy.IndentInterfaceBody = true;
Test (policy, Test (policy,
@ -159,7 +159,7 @@ Test Foo ();
[Test()] [Test()]
public void TestIndentStructBody () public void TestIndentStructBody ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.IndentStructBody = true; policy.IndentStructBody = true;
Test (policy, Test (policy,
@ -184,7 +184,7 @@ Test Foo ();
[Test()] [Test()]
public void TestIndentEnumBody () public void TestIndentEnumBody ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.IndentEnumBody = true; policy.IndentEnumBody = true;
Test (policy, Test (policy,
@ -209,7 +209,7 @@ A
[Test()] [Test()]
public void TestIndentMethodBody () public void TestIndentMethodBody ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.IndentMethodBody = true; policy.IndentMethodBody = true;
Test (policy, Test (policy,
@ -252,7 +252,7 @@ A
[Test()] [Test()]
public void TestIndentMethodBodyOperatorCase () public void TestIndentMethodBodyOperatorCase ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.IndentMethodBody = true; policy.IndentMethodBody = true;
var adapter = Test (policy, var adapter = Test (policy,
@ -286,7 +286,7 @@ A
[Test()] [Test()]
public void TestIndentPropertyBody () public void TestIndentPropertyBody ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.IndentPropertyBody = true; policy.IndentPropertyBody = true;
var adapter = Test (policy, var adapter = Test (policy,
@ -319,7 +319,7 @@ set;
[Test()] [Test()]
public void TestIndentPropertyOneLine () public void TestIndentPropertyOneLine ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.PropertyFormatting = PropertyFormatting.AllowOneLine; policy.PropertyFormatting = PropertyFormatting.AllowOneLine;
policy.AllowPropertyGetBlockInline = true; policy.AllowPropertyGetBlockInline = true;
policy.AllowPropertySetBlockInline = true; policy.AllowPropertySetBlockInline = true;
@ -338,7 +338,7 @@ set;
[Test()] [Test()]
public void TestIndentPropertyOneLineCase2 () public void TestIndentPropertyOneLineCase2 ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.PropertyFormatting = PropertyFormatting.AllowOneLine; policy.PropertyFormatting = PropertyFormatting.AllowOneLine;
policy.AllowPropertyGetBlockInline = true; policy.AllowPropertyGetBlockInline = true;
policy.AllowPropertySetBlockInline = true; policy.AllowPropertySetBlockInline = true;
@ -357,7 +357,7 @@ set;
[Test()] [Test()]
public void TestIndentPropertyBodyIndexerCase () public void TestIndentPropertyBodyIndexerCase ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.IndentPropertyBody = true; policy.IndentPropertyBody = true;
var adapter = Test (policy, var adapter = Test (policy,
@ -402,7 +402,7 @@ set {
[Test()] [Test()]
public void TestPropertyAlignment () public void TestPropertyAlignment ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.PropertyFormatting = PropertyFormatting.AllowOneLine; policy.PropertyFormatting = PropertyFormatting.AllowOneLine;
var adapter = Test (policy, var adapter = Test (policy,
@"class Test @"class Test
@ -435,7 +435,7 @@ set {
[Test()] [Test()]
public void TestIndentNamespaceBody () public void TestIndentNamespaceBody ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.ClassBraceStyle = BraceStyle.DoNotChange; policy.ClassBraceStyle = BraceStyle.DoNotChange;
policy.NamespaceBraceStyle = BraceStyle.EndOfLine; policy.NamespaceBraceStyle = BraceStyle.EndOfLine;
policy.IndentNamespaceBody = true; policy.IndentNamespaceBody = true;
@ -458,7 +458,7 @@ class FooBar {}
[Test()] [Test()]
public void TestMethodIndentation () public void TestMethodIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.MethodBraceStyle = BraceStyle.DoNotChange; policy.MethodBraceStyle = BraceStyle.DoNotChange;
Test (policy, Test (policy,
@ -475,7 +475,7 @@ MyType TestMethod () {}
[Test()] [Test()]
public void TestPropertyIndentation () public void TestPropertyIndentation ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.PropertyBraceStyle = BraceStyle.DoNotChange; policy.PropertyBraceStyle = BraceStyle.DoNotChange;
Test (policy, Test (policy,
@ -491,7 +491,7 @@ MyType TestMethod () {}
[Test()] [Test()]
public void TestPropertyIndentationCase2 () public void TestPropertyIndentationCase2 ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
Test (policy, Test (policy,
@"class Test @"class Test
@ -514,7 +514,7 @@ set;
[Test()] [Test()]
public void TestIndentEventBody () public void TestIndentEventBody ()
{ {
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); CSharpFormattingOptions policy = new CSharpFormattingOptions ();
policy.IndentEventBody = true; policy.IndentEventBody = true;
var adapter = Test (policy, var adapter = Test (policy,

6
ICSharpCode.NRefactory.Tests/FormattingTests/TextEditorTestAdapter.cs

@ -221,7 +221,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
public abstract class TestBase public abstract class TestBase
{ {
protected static ITextEditorAdapter GetResult (CSharpFormattingPolicy policy, string input) protected static ITextEditorAdapter GetResult (CSharpFormattingOptions policy, string input)
{ {
var adapter = new TextEditorTestAdapter (input); var adapter = new TextEditorTestAdapter (input);
var visitior = new AstFormattingVisitor (policy, adapter); var visitior = new AstFormattingVisitor (policy, adapter);
@ -233,7 +233,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
return adapter; return adapter;
} }
protected static ITextEditorAdapter Test (CSharpFormattingPolicy policy, string input, string expectedOutput) protected static ITextEditorAdapter Test (CSharpFormattingOptions policy, string input, string expectedOutput)
{ {
var adapter = new TextEditorTestAdapter (input); var adapter = new TextEditorTestAdapter (input);
var visitior = new AstFormattingVisitor (policy, adapter); var visitior = new AstFormattingVisitor (policy, adapter);
@ -245,7 +245,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
return adapter; return adapter;
} }
protected static void Continue (CSharpFormattingPolicy policy, ITextEditorAdapter adapter, string expectedOutput) protected static void Continue (CSharpFormattingOptions policy, ITextEditorAdapter adapter, string expectedOutput)
{ {
var visitior = new AstFormattingVisitor (policy, adapter); var visitior = new AstFormattingVisitor (policy, adapter);

8
ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj

@ -34,22 +34,24 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputPath>..\ICSharpCode.NRefactory\bin\Debug\</OutputPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputPath>..\ICSharpCode.NRefactory\bin\Release\</OutputPath>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="nunit.framework">
<HintPath>..\..\Mono.Cecil\Test\libs\nunit-2.4.8\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core"> <Reference Include="System.Core">
</Reference> </Reference>
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq"> <Reference Include="System.Xml.Linq">
</Reference> </Reference>
<Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
<HintPath>..\..\Mono.Cecil\Test\libs\nunit-2.4.8\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="CSharp\Analysis\DefiniteAssignmentTests.cs" /> <Compile Include="CSharp\Analysis\DefiniteAssignmentTests.cs" />

2
ICSharpCode.NRefactory.Tests/TypeSystem/GetAllBaseTypesTest.cs

@ -84,7 +84,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
{ {
// class C<X> : C<C<X>> {} // class C<X> : C<C<X>> {}
DefaultTypeDefinition c = new DefaultTypeDefinition(mscorlib, string.Empty, "C"); DefaultTypeDefinition c = new DefaultTypeDefinition(mscorlib, string.Empty, "C");
c.TypeParameters.Add(new DefaultTypeParameter(c, 0, "X")); c.TypeParameters.Add(new DefaultTypeParameter(EntityType.TypeDefinition, 0, "X"));
c.BaseTypes.Add(new ParameterizedType(c, new [] { new ParameterizedType(c, new [] { c.TypeParameters[0] }) })); c.BaseTypes.Add(new ParameterizedType(c, new [] { new ParameterizedType(c, new [] { c.TypeParameters[0] }) }));
Assert.AreEqual(new [] { c }, c.GetAllBaseTypes(context).ToArray()); Assert.AreEqual(new [] { c }, c.GetAllBaseTypes(context).ToArray());
} }

25
ICSharpCode.NRefactory.Tests/TypeSystem/TestInterningProvider.cs

@ -140,15 +140,36 @@ namespace ICSharpCode.NRefactory.TypeSystem
} }
} }
IProjectContent[] LoadProjects(CecilLoader loader)
{
const string dir = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\";
return new IProjectContent[] {
loader.LoadAssemblyFile(dir + "mscorlib.dll"),
loader.LoadAssemblyFile(dir + "System.dll"),
loader.LoadAssemblyFile(dir + "System.Core.dll"),
loader.LoadAssemblyFile(dir + "System.Xml.dll"),
loader.LoadAssemblyFile(dir + "System.Xml.Linq.dll"),
loader.LoadAssemblyFile(dir + "System.Data.dll"),
loader.LoadAssemblyFile(dir + "System.Drawing.dll"),
loader.LoadAssemblyFile(dir + "System.Windows.Forms.dll"),
loader.LoadAssemblyFile(dir + "WindowsBase.dll"),
loader.LoadAssemblyFile(dir + "PresentationCore.dll"),
loader.LoadAssemblyFile(dir + "PresentationFramework.dll")
};
}
[Test] [Test]
public void PrintStatistics() public void PrintStatistics()
{ {
long startMemory = GC.GetTotalMemory(true); long startMemory = GC.GetTotalMemory(true);
IProjectContent pc = new CecilLoader().LoadAssemblyFile(typeof(object).Assembly.Location); IProjectContent[] pc = LoadProjects(new CecilLoader());
long memoryWithFullPC = GC.GetTotalMemory(true) - startMemory; long memoryWithFullPC = GC.GetTotalMemory(true) - startMemory;
InterningProvider p = new InterningProvider(); InterningProvider p = new InterningProvider();
p.InternProject(pc); CecilLoader loader = new CecilLoader();
loader.InterningProvider = p;
pc = LoadProjects(loader);
PrintStatistics(p); PrintStatistics(p);
loader = null;
p = null; p = null;
long memoryWithInternedPC = GC.GetTotalMemory(true) - startMemory; long memoryWithInternedPC = GC.GetTotalMemory(true) - startMemory;
GC.KeepAlive(pc); GC.KeepAlive(pc);

10
ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs

@ -134,8 +134,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
public void TestClassTypeParameters() public void TestClassTypeParameters()
{ {
var testClass = testCasePC.GetClass(typeof(GenericClass<,>)); var testClass = testCasePC.GetClass(typeof(GenericClass<,>));
Assert.AreSame(testClass, testClass.TypeParameters[0].ParentClass); Assert.AreEqual(EntityType.TypeDefinition, testClass.TypeParameters[0].OwnerType);
Assert.AreSame(testClass, testClass.TypeParameters[1].ParentClass); Assert.AreEqual(EntityType.TypeDefinition, testClass.TypeParameters[1].OwnerType);
Assert.AreSame(testClass.TypeParameters[1], testClass.TypeParameters[0].Constraints[0].Resolve(ctx)); Assert.AreSame(testClass.TypeParameters[1], testClass.TypeParameters[0].Constraints[0].Resolve(ctx));
} }
@ -147,8 +147,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
IMethod m = testClass.Methods.Single(me => me.Name == "TestMethod"); IMethod m = testClass.Methods.Single(me => me.Name == "TestMethod");
Assert.AreEqual("K", m.TypeParameters[0].Name); Assert.AreEqual("K", m.TypeParameters[0].Name);
Assert.AreEqual("V", m.TypeParameters[1].Name); Assert.AreEqual("V", m.TypeParameters[1].Name);
Assert.AreSame(m, m.TypeParameters[0].ParentMethod); Assert.AreEqual(EntityType.Method, m.TypeParameters[0].OwnerType);
Assert.AreSame(m, m.TypeParameters[1].ParentMethod); Assert.AreEqual(EntityType.Method, m.TypeParameters[1].OwnerType);
Assert.AreEqual("System.IComparable`1[[``1]]", m.TypeParameters[0].Constraints[0].Resolve(ctx).ReflectionName); Assert.AreEqual("System.IComparable`1[[``1]]", m.TypeParameters[0].Constraints[0].Resolve(ctx).ReflectionName);
Assert.AreSame(m.TypeParameters[0], m.TypeParameters[1].Constraints[0].Resolve(ctx)); Assert.AreSame(m.TypeParameters[0], m.TypeParameters[1].Constraints[0].Resolve(ctx));
@ -161,7 +161,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
IMethod m = testClass.Methods.Single(me => me.Name == "GetIndex"); IMethod m = testClass.Methods.Single(me => me.Name == "GetIndex");
Assert.AreEqual("T", m.TypeParameters[0].Name); Assert.AreEqual("T", m.TypeParameters[0].Name);
Assert.AreSame(m, m.TypeParameters[0].ParentMethod); Assert.AreEqual(EntityType.Method, m.TypeParameters[0].OwnerType);
ParameterizedType constraint = (ParameterizedType)m.TypeParameters[0].Constraints[0].Resolve(ctx); ParameterizedType constraint = (ParameterizedType)m.TypeParameters[0].Constraints[0].Resolve(ctx);
Assert.AreEqual("IEquatable", constraint.Name); Assert.AreEqual("IEquatable", constraint.Name);

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

@ -31,11 +31,9 @@ using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using ICSharpCode.NRefactory.CSharp.PatternMatching;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public abstract class AstNode public abstract class AstNode : PatternMatching.INode
{ {
#region Null #region Null
public static readonly AstNode Null = new NullAstNode (); public static readonly AstNode Null = new NullAstNode ();
@ -66,6 +64,42 @@ namespace ICSharpCode.NRefactory.CSharp
} }
#endregion #endregion
#region PatternPlaceholder
public static implicit operator AstNode(PatternMatching.Pattern pattern)
{
return pattern != null ? new PatternPlaceholder(pattern) : null;
}
sealed class PatternPlaceholder : AstNode, PatternMatching.INode
{
readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
}
}
#endregion
AstNode parent; AstNode parent;
AstNode prevSibling; AstNode prevSibling;
AstNode nextSibling; AstNode nextSibling;
@ -562,38 +596,32 @@ namespace ICSharpCode.NRefactory.CSharp
public abstract S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data); public abstract S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data);
#region Pattern Matching #region Pattern Matching
/// <summary>
/// Performs a pattern matching operation.
/// <c>this</c> is the pattern, <paramref name="other"/> is the AST that is being matched.
/// </summary>
/// <returns>
/// If successful, a match object containing the matched groups.
/// If the match failed, returns <c>null</c>.
/// </returns>
/// <remarks>
/// Patterns are ASTs that contain special pattern nodes (from the PatternMatching namespace).
/// However, it is also possible to match two ASTs without any pattern nodes - doing so will produce an empty match object
/// if the two ASTs are structurally identical; or will return <c>null</c> if the ASTs are not identical.
/// </remarks>
public Match Match(AstNode other)
{
Match match = new Match();
if (DoMatch(other, match))
return match;
else
return null;
}
protected static bool MatchString(string name1, string name2) protected static bool MatchString(string name1, string name2)
{ {
return string.IsNullOrEmpty(name1) || name1 == name2; return string.IsNullOrEmpty(name1) || name1 == name2;
} }
protected internal abstract bool DoMatch(AstNode other, Match match); protected internal abstract bool DoMatch(AstNode other, PatternMatching.Match match);
internal virtual bool DoMatchCollection (Role role, AstNode pos, Match match, Stack<Pattern.PossibleMatch> backtrackingStack) bool PatternMatching.INode.DoMatch(PatternMatching.INode other, PatternMatching.Match match)
{ {
return DoMatch (pos, match); AstNode o = other as AstNode;
// try matching if other is null, or if other is an AstNode
return (other == null || o != null) && DoMatch(o, match);
}
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
AstNode o = pos as AstNode;
return (pos == null || o != null) && DoMatch (o, match);
}
PatternMatching.INode PatternMatching.INode.NextSibling {
get { return nextSibling; }
}
PatternMatching.INode PatternMatching.INode.FirstChild {
get { return firstChild; }
} }
#endregion #endregion

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

@ -6,7 +6,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.CSharp.PatternMatching; using ICSharpCode.NRefactory.PatternMatching;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
@ -159,39 +159,7 @@ namespace ICSharpCode.NRefactory.CSharp
internal bool DoMatch(AstNodeCollection<T> other, Match match) internal bool DoMatch(AstNodeCollection<T> other, Match match)
{ {
Stack<AstNode> patternStack = new Stack<AstNode>(); return Pattern.DoMatchCollection(role, node.FirstChild, other.node.FirstChild, match);
Stack<Pattern.PossibleMatch> stack = new Stack<Pattern.PossibleMatch>();
patternStack.Push(this.node.FirstChild);
stack.Push(new Pattern.PossibleMatch(other.node.FirstChild, match.CheckPoint()));
while (stack.Count > 0) {
AstNode cur1 = patternStack.Pop();
AstNode cur2 = stack.Peek().NextOther;
match.RestoreCheckPoint(stack.Pop().Checkpoint);
bool success = true;
while (cur1 != null && success) {
while (cur1 != null && cur1.Role != role)
cur1 = cur1.NextSibling;
while (cur2 != null && cur2.Role != role)
cur2 = cur2.NextSibling;
if (cur1 == null)
break;
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;
}
while (cur2 != null && cur2.Role != role)
cur2 = cur2.NextSibling;
if (success && cur2 == null)
return true;
}
return false;
} }
public void InsertAfter(T existingItem, T newItem) public void InsertAfter(T existingItem, T newItem)

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

@ -31,20 +31,78 @@ namespace ICSharpCode.NRefactory.CSharp
} }
#endregion #endregion
#region PatternPlaceholder
public static implicit operator AstType(PatternMatching.Pattern pattern)
{
return pattern != null ? new PatternPlaceholder(pattern) : null;
}
sealed class PatternPlaceholder : AstType, PatternMatching.INode
{
readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
}
}
#endregion
public override NodeType NodeType { public override NodeType NodeType {
get { return NodeType.TypeReference; } get { return NodeType.TypeReference; }
} }
public new AstType Clone()
{
return (AstType)base.Clone();
}
/// <summary>
/// Creates a pointer type from this type by nesting it in a <see cref="ComposedType"/>.
/// If this type already is a pointer type, this method just increases the PointerRank of the existing pointer type.
/// </summary>
public virtual AstType MakePointerType() public virtual AstType MakePointerType()
{ {
return new ComposedType { BaseType = this }.MakePointerType(); return new ComposedType { BaseType = this }.MakePointerType();
} }
/// <summary>
/// Creates an array type from this type by nesting it in a <see cref="ComposedType"/>.
/// If this type already is an array type, the additional rank is prepended to the existing array specifier list.
/// Thus, <c>new SimpleType("T").MakeArrayType(1).MakeArrayType(2)</c> will result in "T[,][]".
/// </summary>
public virtual AstType MakeArrayType(int rank = 1) public virtual AstType MakeArrayType(int rank = 1)
{ {
return new ComposedType { BaseType = this }.MakeArrayType(rank); return new ComposedType { BaseType = this }.MakeArrayType(rank);
} }
/// <summary>
/// Creates a nullable type from this type by nesting it in a <see cref="ComposedType"/>.
/// </summary>
public AstType MakeNullableType()
{
return new ComposedType { BaseType = this, HasNullableSpecifier = true };
}
/// <summary> /// <summary>
/// Builds an expression that can be used to access a static member on this type. /// Builds an expression that can be used to access a static member on this type.
/// </summary> /// </summary>

14
ICSharpCode.NRefactory/CSharp/Ast/DepthFirstAstVisitor.cs

@ -440,6 +440,11 @@ namespace ICSharpCode.NRefactory.CSharp
return VisitChildren (objectCreateExpression, data); return VisitChildren (objectCreateExpression, data);
} }
public virtual S VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression, T data)
{
return VisitChildren (anonymousTypeCreateExpression, data);
}
public virtual S VisitArrayCreateExpression (ArrayCreateExpression arrayObjectCreateExpression, T data) public virtual S VisitArrayCreateExpression (ArrayCreateExpression arrayObjectCreateExpression, T data)
{ {
return VisitChildren (arrayObjectCreateExpression, data); return VisitChildren (arrayObjectCreateExpression, data);
@ -560,9 +565,9 @@ namespace ICSharpCode.NRefactory.CSharp
return VisitChildren (defaultValueExpression, data); return VisitChildren (defaultValueExpression, data);
} }
public virtual S VisitArgListExpression (ArgListExpression argListExpression, T data) public virtual S VisitUndocumentedExpression (UndocumentedExpression undocumentedExpression, T data)
{ {
return VisitChildren (argListExpression, data); return VisitChildren (undocumentedExpression, data);
} }
public virtual S VisitArrayInitializerExpression (ArrayInitializerExpression arrayInitializerExpression, T data) public virtual S VisitArrayInitializerExpression (ArrayInitializerExpression arrayInitializerExpression, T data)
@ -584,5 +589,10 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
return VisitChildren (emptyExpression, data); return VisitChildren (emptyExpression, data);
} }
public virtual S VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern, T data)
{
return VisitChildren (placeholder, data);
}
} }
} }

18
ICSharpCode.NRefactory/CSharp/Ast/Expressions/AnonymousMethodExpression.cs

@ -60,6 +60,24 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (Roles.Body, value); } set { SetChildByRole (Roles.Body, value); }
} }
public AnonymousMethodExpression ()
{
}
public AnonymousMethodExpression (BlockStatement body, IEnumerable<ParameterDeclaration> parameters = null)
{
if (parameters != null) {
foreach (var parameter in parameters) {
AddChild (parameter, Roles.Parameter);
}
}
AddChild (body, Roles.Body);
}
public AnonymousMethodExpression (BlockStatement body, params ParameterDeclaration[] parameters) : this (body, (IEnumerable<ParameterDeclaration>)parameters)
{
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitAnonymousMethodExpression (this, data); return visitor.VisitAnonymousMethodExpression (this, data);

79
ICSharpCode.NRefactory/CSharp/Ast/Expressions/AnonymousTypeCreateExpression.cs

@ -0,0 +1,79 @@
//
// AnonymousTypeCreateExpression.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp
{
/// <summary>
/// new { [ExpressionList] }
/// </summary>
public class AnonymousTypeCreateExpression : Expression
{
public CSharpTokenNode NewToken {
get { return GetChildByRole (Roles.Keyword); }
}
public CSharpTokenNode LParToken {
get { return GetChildByRole (Roles.LPar); }
}
public AstNodeCollection<Expression> Initializer {
get { return GetChildrenByRole (Roles.Expression); }
}
public CSharpTokenNode RParToken {
get { return GetChildByRole (Roles.RPar); }
}
public AnonymousTypeCreateExpression ()
{
}
public AnonymousTypeCreateExpression (IEnumerable<Expression> initializer)
{
foreach (var ini in initializer) {
AddChild (ini, Roles.Expression);
}
}
public AnonymousTypeCreateExpression (params Expression[] initializer) : this ((IEnumerable<Expression>)initializer)
{
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitAnonymousTypeCreateExpression (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
var o = other as AnonymousTypeCreateExpression;
return o != null && this.Initializer.DoMatch(o.Initializer, match);
}
}
}

10
ICSharpCode.NRefactory/CSharp/Ast/Expressions/AsExpression.cs

@ -45,6 +45,16 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole(Roles.Type, value); } set { SetChildByRole(Roles.Type, value); }
} }
public AsExpression ()
{
}
public AsExpression (Expression expression, AstType type)
{
AddChild (expression, Roles.Expression);
AddChild (type, Roles.Type);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitAsExpression (this, data); return visitor.VisitAsExpression (this, data);

7
ICSharpCode.NRefactory/CSharp/Ast/Expressions/AssignmentExpression.cs

@ -48,6 +48,13 @@ namespace ICSharpCode.NRefactory.CSharp
this.Right = right; this.Right = right;
} }
public AssignmentExpression(Expression left, AssignmentOperatorType op, Expression right)
{
this.Left = left;
this.Operator = op;
this.Right = right;
}
public AssignmentOperatorType Operator { public AssignmentOperatorType Operator {
get; get;
set; set;

10
ICSharpCode.NRefactory/CSharp/Ast/Expressions/CastExpression.cs

@ -49,6 +49,16 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (Roles.Expression, value); } set { SetChildByRole (Roles.Expression, value); }
} }
public CastExpression ()
{
}
public CastExpression (AstType castToType, Expression expression)
{
AddChild (castToType, Roles.Type);
AddChild (expression, Roles.Expression);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitCastExpression (this, data); return visitor.VisitCastExpression (this, data);

9
ICSharpCode.NRefactory/CSharp/Ast/Expressions/CheckedExpression.cs

@ -48,6 +48,15 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RPar); } get { return GetChildByRole (Roles.RPar); }
} }
public CheckedExpression ()
{
}
public CheckedExpression (Expression expression)
{
AddChild (expression, Roles.Expression);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitCheckedExpression (this, data); return visitor.VisitCheckedExpression (this, data);

11
ICSharpCode.NRefactory/CSharp/Ast/Expressions/ConditionalExpression.cs

@ -60,6 +60,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole(FalseRole, value); } set { SetChildByRole(FalseRole, value); }
} }
public ConditionalExpression ()
{
}
public ConditionalExpression (Expression condition, Expression trueExpression, Expression falseExpression)
{
AddChild (condition, ConditionRole);
AddChild (trueExpression, TrueRole);
AddChild (falseExpression, FalseRole);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitConditionalExpression (this, data); return visitor.VisitConditionalExpression (this, data);

9
ICSharpCode.NRefactory/CSharp/Ast/Expressions/DefaultValueExpression.cs

@ -48,6 +48,15 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RPar); } get { return GetChildByRole (Roles.RPar); }
} }
public DefaultValueExpression ()
{
}
public DefaultValueExpression (AstType type)
{
AddChild (type, Roles.Type);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitDefaultValueExpression (this, data); return visitor.VisitDefaultValueExpression (this, data);

10
ICSharpCode.NRefactory/CSharp/Ast/Expressions/DirectionExpression.cs

@ -52,6 +52,16 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (Roles.Expression, value); } set { SetChildByRole (Roles.Expression, value); }
} }
public DirectionExpression ()
{
}
public DirectionExpression (FieldDirection direction, Expression expression)
{
this.FieldDirection = direction;
AddChild (expression, Roles.Expression);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitDirectionExpression (this, data); return visitor.VisitDirectionExpression (this, data);

38
ICSharpCode.NRefactory/CSharp/Ast/Expressions/Expression.cs

@ -40,6 +40,42 @@ namespace ICSharpCode.NRefactory.CSharp
} }
#endregion #endregion
#region PatternPlaceholder
public static implicit operator Expression(PatternMatching.Pattern pattern)
{
return pattern != null ? new PatternPlaceholder(pattern) : null;
}
sealed class PatternPlaceholder : Expression, PatternMatching.INode
{
readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
}
}
#endregion
public override NodeType NodeType { public override NodeType NodeType {
get { get {
return NodeType.Expression; return NodeType.Expression;
@ -57,7 +93,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (IsNull) if (IsNull)
return "Null"; return "Null";
StringWriter w = new StringWriter(); StringWriter w = new StringWriter();
AcceptVisitor(new OutputVisitor(w, new CSharpFormattingPolicy()), null); AcceptVisitor(new OutputVisitor(w, new CSharpFormattingOptions()), null);
return w.ToString(); return w.ToString();
} }

18
ICSharpCode.NRefactory/CSharp/Ast/Expressions/IndexerExpression.cs

@ -50,6 +50,24 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RBracket); } get { return GetChildByRole (Roles.RBracket); }
} }
public IndexerExpression ()
{
}
public IndexerExpression (Expression target, IEnumerable<Expression> arguments)
{
AddChild (target, Roles.TargetExpression);
if (arguments != null) {
foreach (var arg in arguments) {
AddChild (arg, Roles.Argument);
}
}
}
public IndexerExpression (Expression target, params Expression[] arguments) : this (target, (IEnumerable<Expression>)arguments)
{
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitIndexerExpression (this, data); return visitor.VisitIndexerExpression (this, data);

18
ICSharpCode.NRefactory/CSharp/Ast/Expressions/InvocationExpression.cs

@ -55,6 +55,24 @@ namespace ICSharpCode.NRefactory.CSharp
return visitor.VisitInvocationExpression (this, data); return visitor.VisitInvocationExpression (this, data);
} }
public InvocationExpression ()
{
}
public InvocationExpression (Expression target, IEnumerable<Expression> arguments)
{
AddChild (target, Roles.TargetExpression);
if (arguments != null) {
foreach (var arg in arguments) {
AddChild (arg, Roles.Argument);
}
}
}
public InvocationExpression (Expression target, params Expression[] arguments) : this (target, (IEnumerable<Expression>)arguments)
{
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{ {
InvocationExpression o = other as InvocationExpression; InvocationExpression o = other as InvocationExpression;

19
ICSharpCode.NRefactory/CSharp/Ast/Expressions/MemberReferenceExpression.cs

@ -59,6 +59,25 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RChevron); } get { return GetChildByRole (Roles.RChevron); }
} }
public MemberReferenceExpression ()
{
}
public MemberReferenceExpression (Expression target, string memberName, IEnumerable<AstType> arguments = null)
{
AddChild (target, Roles.TargetExpression);
MemberName = memberName;
if (arguments != null) {
foreach (var arg in arguments) {
AddChild (arg, Roles.TypeArgument);
}
}
}
public MemberReferenceExpression (Expression target, string memberName, params AstType[] arguments) : this (target, memberName, (IEnumerable<AstType>)arguments)
{
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitMemberReferenceExpression (this, data); return visitor.VisitMemberReferenceExpression (this, data);

4
ICSharpCode.NRefactory/CSharp/Ast/Expressions/NamedArgumentExpression.cs

@ -19,6 +19,10 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
public CSharpTokenNode AssignToken {
get { return GetChildByRole (Roles.Assign); }
}
public Expression Expression { public Expression Expression {
get { return GetChildByRole (Roles.Expression); } get { return GetChildByRole (Roles.Expression); }
set { SetChildByRole (Roles.Expression, value); } set { SetChildByRole (Roles.Expression, value); }

22
ICSharpCode.NRefactory/CSharp/Ast/Expressions/NullReferenceExpression.cs

@ -31,6 +31,28 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary> /// </summary>
public class NullReferenceExpression : Expression public class NullReferenceExpression : Expression
{ {
AstLocation location;
public override AstLocation StartLocation {
get {
return location;
}
}
public override AstLocation EndLocation {
get {
return new AstLocation (location.Line, location.Column + "null".Length);
}
}
public NullReferenceExpression ()
{
}
public NullReferenceExpression (AstLocation location)
{
this.location = location;
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitNullReferenceExpression (this, data); return visitor.VisitNullReferenceExpression (this, data);

18
ICSharpCode.NRefactory/CSharp/Ast/Expressions/ObjectCreateExpression.cs

@ -61,6 +61,24 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (InitializerRole, value); } set { SetChildByRole (InitializerRole, value); }
} }
public ObjectCreateExpression ()
{
}
public ObjectCreateExpression (AstType type, IEnumerable<Expression> arguments = null)
{
AddChild (type, Roles.Type);
if (arguments != null) {
foreach (var arg in arguments) {
AddChild (arg, Roles.Argument);
}
}
}
public ObjectCreateExpression (AstType type, params Expression[] arguments) : this (type, (IEnumerable<Expression>)arguments)
{
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitObjectCreateExpression (this, data); return visitor.VisitObjectCreateExpression (this, data);

9
ICSharpCode.NRefactory/CSharp/Ast/Expressions/ParenthesizedExpression.cs

@ -44,6 +44,15 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RPar); } get { return GetChildByRole (Roles.RPar); }
} }
public ParenthesizedExpression()
{
}
public ParenthesizedExpression(Expression expr)
{
Expression = expr;
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitParenthesizedExpression (this, data); return visitor.VisitParenthesizedExpression (this, data);

9
ICSharpCode.NRefactory/CSharp/Ast/Expressions/SizeOfExpression.cs

@ -48,6 +48,15 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RPar); } get { return GetChildByRole (Roles.RPar); }
} }
public SizeOfExpression ()
{
}
public SizeOfExpression (AstType type)
{
AddChild (type, Roles.Type);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitSizeOfExpression (this, data); return visitor.VisitSizeOfExpression (this, data);

9
ICSharpCode.NRefactory/CSharp/Ast/Expressions/TypeOfExpression.cs

@ -49,6 +49,15 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RPar); } get { return GetChildByRole (Roles.RPar); }
} }
public TypeOfExpression ()
{
}
public TypeOfExpression (AstType type)
{
AddChild (type, Roles.Type);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitTypeOfExpression (this, data); return visitor.VisitTypeOfExpression (this, data);

9
ICSharpCode.NRefactory/CSharp/Ast/Expressions/TypeReferenceExpression.cs

@ -21,6 +21,15 @@ namespace ICSharpCode.NRefactory.CSharp
return visitor.VisitTypeReferenceExpression(this, data); return visitor.VisitTypeReferenceExpression(this, data);
} }
public TypeReferenceExpression ()
{
}
public TypeReferenceExpression (AstType type)
{
AddChild (type, Roles.Type);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{ {
TypeReferenceExpression o = other as TypeReferenceExpression; TypeReferenceExpression o = other as TypeReferenceExpression;

9
ICSharpCode.NRefactory/CSharp/Ast/Expressions/UncheckedExpression.cs

@ -48,6 +48,15 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RPar); } get { return GetChildByRole (Roles.RPar); }
} }
public UncheckedExpression ()
{
}
public UncheckedExpression (Expression expression)
{
AddChild (expression, Roles.Expression);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitUncheckedExpression (this, data); return visitor.VisitUncheckedExpression (this, data);

25
ICSharpCode.NRefactory/CSharp/Ast/Expressions/ArgListExpression.cs → ICSharpCode.NRefactory/CSharp/Ast/Expressions/UndocumentedExpression.cs

@ -1,5 +1,5 @@
// //
// ArgListExpression.cs // UndocumentedExpression.cs
// //
// Author: // Author:
// Mike Krüger <mkrueger@novell.com> // Mike Krüger <mkrueger@novell.com>
@ -28,16 +28,25 @@ using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public enum UndocumentedExpressionType
{
ArgListAccess, // __arglist
ArgList, // __arglist (a1, a2, ..., an)
RefValue, // __refvalue (expr , type)
RefType, // __reftype (expr)
MakeRef // __makeref (expr)
}
/// <summary> /// <summary>
/// Represents the undocumented __arglist keyword. /// Represents undocumented expressions.
/// </summary> /// </summary>
public class ArgListExpression : Expression public class UndocumentedExpression : Expression
{ {
public bool IsAccess { // access is __arglist, otherwise it's __arglist (a1, a2, ..., an) public UndocumentedExpressionType UndocumentedExpressionType {
get; set; get; set;
} }
public CSharpTokenNode ArgListToken { public CSharpTokenNode UndocumentedToken {
get { return GetChildByRole (Roles.Keyword); } get { return GetChildByRole (Roles.Keyword); }
} }
@ -55,13 +64,13 @@ namespace ICSharpCode.NRefactory.CSharp
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitArgListExpression (this, data); return visitor.VisitUndocumentedExpression (this, data);
} }
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{ {
ArgListExpression o = other as ArgListExpression; UndocumentedExpression o = other as UndocumentedExpression;
return o != null && this.IsAccess == o.IsAccess && this.Arguments.DoMatch(o.Arguments, match); return o != null && this.UndocumentedExpressionType == o.UndocumentedExpressionType && this.Arguments.DoMatch(o.Arguments, match);
} }
} }
} }

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

@ -35,6 +35,42 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary> /// </summary>
public class AttributeSection : AstNode public class AttributeSection : AstNode
{ {
#region PatternPlaceholder
public static implicit operator AttributeSection(PatternMatching.Pattern pattern)
{
return pattern != null ? new PatternPlaceholder(pattern) : null;
}
sealed class PatternPlaceholder : AttributeSection, PatternMatching.INode
{
readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
}
}
#endregion
public static readonly Role<Attribute> AttributeRole = new Role<Attribute>("Attribute"); public static readonly Role<Attribute> AttributeRole = new Role<Attribute>("Attribute");
public static readonly Role<CSharpTokenNode> TargetRole = new Role<CSharpTokenNode>("Target", CSharpTokenNode.Null); public static readonly Role<CSharpTokenNode> TargetRole = new Role<CSharpTokenNode>("Target", CSharpTokenNode.Null);
@ -44,7 +80,11 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
public AttributeTarget AttributeTarget { public CSharpTokenNode LBracketToken {
get { return GetChildByRole (Roles.LBracket); }
}
public string AttributeTarget {
get; get;
set; set;
} }
@ -53,6 +93,10 @@ namespace ICSharpCode.NRefactory.CSharp
get { return base.GetChildrenByRole (AttributeRole); } get { return base.GetChildrenByRole (AttributeRole); }
} }
public CSharpTokenNode RBracketToken {
get { return GetChildByRole (Roles.RBracket); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitAttributeSection (this, data); return visitor.VisitAttributeSection (this, data);
@ -73,29 +117,29 @@ namespace ICSharpCode.NRefactory.CSharp
this.Attributes.Add(attr); this.Attributes.Add(attr);
} }
public static string GetAttributeTargetName(AttributeTarget attributeTarget) // public static string GetAttributeTargetName(AttributeTarget attributeTarget)
{ // {
switch (attributeTarget) { // switch (attributeTarget) {
case AttributeTarget.None: // case AttributeTarget.None:
return null; // return null;
case AttributeTarget.Assembly: // case AttributeTarget.Assembly:
return "assembly"; // return "assembly";
case AttributeTarget.Module: // case AttributeTarget.Module:
return "module"; // return "module";
case AttributeTarget.Type: // case AttributeTarget.Type:
return "type"; // return "type";
case AttributeTarget.Param: // case AttributeTarget.Param:
return "param"; // return "param";
case AttributeTarget.Field: // case AttributeTarget.Field:
return "field"; // return "field";
case AttributeTarget.Return: // case AttributeTarget.Return:
return "return"; // return "return";
case AttributeTarget.Method: // case AttributeTarget.Method:
return "method"; // return "method";
default: // default:
throw new NotSupportedException("Invalid value for AttributeTarget"); // throw new NotSupportedException("Invalid value for AttributeTarget");
} // }
} // }
} }
public enum AttributeTarget { public enum AttributeTarget {

13
ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/NamespaceDeclaration.cs

@ -86,6 +86,15 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RBrace); } get { return GetChildByRole (Roles.RBrace); }
} }
public NamespaceDeclaration ()
{
}
public NamespaceDeclaration (string name)
{
this.Name = name;
}
public static string BuildQualifiedName (string name1, string name2) public static string BuildQualifiedName (string name1, string name2)
{ {
if (string.IsNullOrEmpty (name1)) if (string.IsNullOrEmpty (name1))
@ -95,6 +104,10 @@ namespace ICSharpCode.NRefactory.CSharp
return name1 + "." + name2; return name1 + "." + name2;
} }
public void AddMember (AstNode child)
{
AddChild (child, MemberRole);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {

16
ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/UsingAliasDeclaration.cs

@ -66,6 +66,22 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.Semicolon); } get { return GetChildByRole (Roles.Semicolon); }
} }
public UsingAliasDeclaration ()
{
}
public UsingAliasDeclaration (string alias, string nameSpace)
{
AddChild (new Identifier (alias, AstLocation.Empty), AliasRole);
AddChild (new SimpleType (nameSpace), ImportRole);
}
public UsingAliasDeclaration (string alias, AstType import)
{
AddChild (new Identifier (alias, AstLocation.Empty), AliasRole);
AddChild (import, ImportRole);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitUsingAliasDeclaration (this, data); return visitor.VisitUsingAliasDeclaration (this, data);

14
ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/UsingDeclaration.cs

@ -60,6 +60,20 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.Semicolon); } get { return GetChildByRole (Roles.Semicolon); }
} }
public UsingDeclaration ()
{
}
public UsingDeclaration (string nameSpace)
{
AddChild (new SimpleType (nameSpace), ImportRole);
}
public UsingDeclaration (AstType import)
{
AddChild (import, ImportRole);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitUsingDeclaration (this, data); return visitor.VisitUsingDeclaration (this, data);

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

@ -11,7 +11,7 @@ namespace ICSharpCode.NRefactory.CSharp
public interface IAstVisitor<in T, out S> public interface IAstVisitor<in T, out S>
{ {
S VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, T data); S VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, T data);
S VisitArgListExpression(ArgListExpression argListExpression, T data); S VisitUndocumentedExpression(UndocumentedExpression undocumentedExpression, T data);
S VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, T data); S VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, T data);
S VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, T data); S VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, T data);
S VisitAsExpression(AsExpression asExpression, T data); S VisitAsExpression(AsExpression asExpression, T data);
@ -32,6 +32,7 @@ namespace ICSharpCode.NRefactory.CSharp
S VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, T data); S VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, T data);
S VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, T data); S VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, T data);
S VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, T data); S VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, T data);
S VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression, T data);
S VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, T data); S VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, T data);
S VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, T data); S VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, T data);
S VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, T data); S VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, T data);
@ -124,5 +125,7 @@ namespace ICSharpCode.NRefactory.CSharp
S VisitConstraint(Constraint constraint, T data); S VisitConstraint(Constraint constraint, T data);
S VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode, T data); S VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode, T data);
S VisitIdentifier(Identifier identifier, T data); S VisitIdentifier(Identifier identifier, T data);
S VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern, T data);
} }
} }

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

@ -66,6 +66,11 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
public bool IsQuoted {
get;
set;
}
AstLocation startLocation; AstLocation startLocation;
public override AstLocation StartLocation { public override AstLocation StartLocation {
get { get {
@ -75,7 +80,7 @@ namespace ICSharpCode.NRefactory.CSharp
public override AstLocation EndLocation { public override AstLocation EndLocation {
get { get {
return new AstLocation (StartLocation.Line, StartLocation.Column + (Name ?? "").Length); return new AstLocation (StartLocation.Line, StartLocation.Column + (Name ?? "").Length + (IsQuoted ? 1 : 0));
} }
} }
@ -88,7 +93,8 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
if (name == null) if (name == null)
throw new ArgumentNullException("name"); throw new ArgumentNullException("name");
this.Name = name; IsQuoted = name.StartsWith ("@");
this.Name = IsQuoted ? name.Substring (1) : name;
this.startLocation = location; this.startLocation = location;
} }

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

@ -44,8 +44,9 @@ namespace ICSharpCode.NRefactory.CSharp
Expression, Expression,
Token, Token,
QueryClause, QueryClause,
Pattern, /// <summary>
Placeholder /// Placeholder for a pattern
/// </summary>
Pattern
} }
} }

54
ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Choice.cs

@ -1,54 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp.PatternMatching
{
/// <summary>
/// Matches one of several alternatives.
/// </summary>
public class Choice : Pattern, IEnumerable<AstNode>
{
public static readonly Role<AstNode> AlternativeRole = new Role<AstNode>("Alternative", AstNode.Null);
public void Add(string name, AstNode alternative)
{
AddChild(new NamedNode(name, alternative), AlternativeRole);
}
public void Add(AstNode alternative)
{
AddChild(alternative, AlternativeRole);
}
protected internal override bool DoMatch(AstNode other, Match match)
{
var checkPoint = match.CheckPoint();
foreach (AstNode alt in GetChildrenByRole(AlternativeRole)) {
if (alt.DoMatch(other, match))
return true;
else
match.RestoreCheckPoint(checkPoint);
}
return false;
}
IEnumerator<AstNode> IEnumerable<AstNode>.GetEnumerator()
{
return GetChildrenByRole(AlternativeRole).GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetChildrenByRole(AlternativeRole).GetEnumerator();
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return ((IPatternAstVisitor<T, S>)visitor).VisitChoice(this, data);
}
}
}

42
ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/OptionalNode.cs

@ -1,42 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace ICSharpCode.NRefactory.CSharp.PatternMatching
{
public class OptionalNode : Pattern
{
public static readonly Role<AstNode> ElementRole = new Role<AstNode>("Element", AstNode.Null);
public OptionalNode(AstNode childNode)
{
AddChild(childNode, ElementRole);
}
public OptionalNode(string groupName, AstNode childNode) : this(new NamedNode(groupName, childNode))
{
}
internal override bool DoMatchCollection(Role role, AstNode pos, Match match, Stack<Pattern.PossibleMatch> backtrackingStack)
{
backtrackingStack.Push(new PossibleMatch(pos, match.CheckPoint()));
return GetChildByRole(ElementRole).DoMatch(pos, match);
}
protected internal override bool DoMatch(AstNode other, Match match)
{
if (other == null || other.IsNull)
return true;
else
return GetChildByRole(ElementRole).DoMatch(other, match);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return ((IPatternAstVisitor<T, S>)visitor).VisitOptionalNode(this, data);
}
}
}

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

@ -1,95 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
namespace ICSharpCode.NRefactory.CSharp.PatternMatching
{
/// <summary>
/// Base class for all patterns.
/// </summary>
public abstract class Pattern : AstNode
{
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
internal struct PossibleMatch
{
public readonly AstNode NextOther; // next node after the last matched node
public readonly int Checkpoint; // checkpoint
public PossibleMatch(AstNode nextOther, int checkpoint)
{
this.NextOther = nextOther;
this.Checkpoint = checkpoint;
}
}
public static implicit operator AstType(Pattern p)
{
return p != null ? new TypePlaceholder(p) : null;
}
public AstType ToType()
{
return new TypePlaceholder(this);
}
public static implicit operator Expression(Pattern p)
{
return p != null ? new ExpressionPlaceholder(p) : null;
}
public Expression ToExpression()
{
return new ExpressionPlaceholder(this);
}
public static implicit operator Statement(Pattern p)
{
return p != null ? new StatementPlaceholder(p) : null;
}
public Statement ToStatement()
{
return new StatementPlaceholder(this);
}
public static implicit operator BlockStatement(Pattern p)
{
return p != null ? new BlockStatementPlaceholder(p) : null;
}
public static implicit operator VariableInitializer(Pattern p)
{
return p != null ? new VariablePlaceholder(p) : null;
}
public static implicit operator AttributeSection(Pattern p)
{
return p != null ? new AttributeSectionPlaceholder(p) : null;
}
public static implicit operator SwitchSection(Pattern p)
{
return p != null ? new SwitchSectionPlaceholder(p) : null;
}
public static implicit operator CatchClause(Pattern p)
{
return p != null ? new CatchClausePlaceholder(p) : null;
}
// Make debugging easier by giving Patterns a ToString() implementation
public override string ToString()
{
StringWriter w = new StringWriter();
AcceptVisitor(new OutputVisitor(w, new CSharpFormattingPolicy()), null);
return w.ToString();
}
}
}

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

@ -1,242 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// 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
{
readonly AstNode child;
public TypePlaceholder(AstNode child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Placeholder; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, Match 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)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Placeholder; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, Match 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)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Placeholder; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, Match 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)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Placeholder; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, Match 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)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Placeholder; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, Match 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 AttributeSectionPlaceholder : AttributeSection
{
readonly AstNode child;
public AttributeSectionPlaceholder(AstNode child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Placeholder; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, Match 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 SwitchSectionPlaceholder : SwitchSection
{
readonly AstNode child;
public SwitchSectionPlaceholder(AstNode child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Placeholder; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, Match 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 CatchClausePlaceholder : CatchClause
{
readonly AstNode child;
public CatchClausePlaceholder(AstNode child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Placeholder; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, Match 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);
}
}
}

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

@ -57,6 +57,42 @@ namespace ICSharpCode.NRefactory.CSharp
} }
#endregion #endregion
#region PatternPlaceholder
public static implicit operator BlockStatement(PatternMatching.Pattern pattern)
{
return pattern != null ? new PatternPlaceholder(pattern) : null;
}
sealed class PatternPlaceholder : BlockStatement, PatternMatching.INode
{
readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
}
}
#endregion
public CSharpTokenNode LBraceToken { public CSharpTokenNode LBraceToken {
get { return GetChildByRole (Roles.LBrace); } get { return GetChildByRole (Roles.LBrace); }
} }

11
ICSharpCode.NRefactory/CSharp/Ast/Statements/CheckedStatement.cs

@ -27,7 +27,7 @@
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
/// <summary> /// <summary>
/// checked { Body } /// checked BodyBlock
/// </summary> /// </summary>
public class CheckedStatement : Statement public class CheckedStatement : Statement
{ {
@ -40,6 +40,15 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (Roles.Body, value); } set { SetChildByRole (Roles.Body, value); }
} }
public CheckedStatement ()
{
}
public CheckedStatement (BlockStatement body)
{
AddChild (body, Roles.Body);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitCheckedStatement (this, data); return visitor.VisitCheckedStatement (this, data);

9
ICSharpCode.NRefactory/CSharp/Ast/Statements/ReturnStatement.cs

@ -44,6 +44,15 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.Semicolon); } get { return GetChildByRole (Roles.Semicolon); }
} }
public ReturnStatement ()
{
}
public ReturnStatement (Expression returnExpression)
{
AddChild (returnExpression, Roles.Expression);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitReturnStatement (this, data); return visitor.VisitReturnStatement (this, data);

60
ICSharpCode.NRefactory/CSharp/Ast/Statements/Statement.cs

@ -38,37 +38,41 @@ namespace ICSharpCode.NRefactory.CSharp
} }
#endregion #endregion
/// <summary> #region PatternPlaceholder
/// Gets the previous statement within the current block. public static implicit operator Statement(PatternMatching.Pattern pattern)
/// This is usually equivalent to <see cref="PrevSibling"/>, but will skip any non-statements (e.g. comments) {
/// </summary> return pattern != null ? new PatternPlaceholder(pattern) : null;
public Statement PreviousStatement {
get {
AstNode node = this;
while ((node = node.PrevSibling) != null) {
Statement stmt = node as Statement;
if (stmt != null)
return stmt;
}
return null;
}
} }
/// <summary> sealed class PatternPlaceholder : Statement, PatternMatching.INode
/// Gets the next statement within the current block. {
/// This is usually equivalent to <see cref="NextSibling"/>, but will skip any non-statements (e.g. comments) readonly PatternMatching.Pattern child;
/// </summary>
public Statement NextStatement { public PatternPlaceholder(PatternMatching.Pattern child)
get { {
AstNode node = this; this.child = child;
while ((node = node.NextSibling) != null) { }
Statement stmt = node as Statement;
if (stmt != null) public override NodeType NodeType {
return stmt; get { return NodeType.Pattern; }
} }
return null;
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
} }
} }
#endregion
public new Statement Clone() public new Statement Clone()
{ {
@ -92,7 +96,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (IsNull) if (IsNull)
return "Null"; return "Null";
StringWriter w = new StringWriter(); StringWriter w = new StringWriter();
AcceptVisitor(new OutputVisitor(w, new CSharpFormattingPolicy()), null); AcceptVisitor(new OutputVisitor(w, new CSharpFormattingOptions()), null);
string text = w.ToString().TrimEnd().Replace("\t", "").Replace(w.NewLine, " "); string text = w.ToString().TrimEnd().Replace("\t", "").Replace(w.NewLine, " ");
if (text.Length > 100) if (text.Length > 100)
return text.Substring(0, 97) + "..."; return text.Substring(0, 97) + "...";

36
ICSharpCode.NRefactory/CSharp/Ast/Statements/SwitchStatement.cs

@ -79,6 +79,42 @@ namespace ICSharpCode.NRefactory.CSharp
public class SwitchSection : AstNode public class SwitchSection : AstNode
{ {
#region PatternPlaceholder
public static implicit operator SwitchSection(PatternMatching.Pattern pattern)
{
return pattern != null ? new PatternPlaceholder(pattern) : null;
}
sealed class PatternPlaceholder : SwitchSection, PatternMatching.INode
{
readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
}
}
#endregion
public static readonly Role<CaseLabel> CaseLabelRole = new Role<CaseLabel>("CaseLabel"); public static readonly Role<CaseLabel> CaseLabelRole = new Role<CaseLabel>("CaseLabel");
public override NodeType NodeType { public override NodeType NodeType {

9
ICSharpCode.NRefactory/CSharp/Ast/Statements/ThrowStatement.cs

@ -44,6 +44,15 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.Semicolon); } get { return GetChildByRole (Roles.Semicolon); }
} }
public ThrowStatement ()
{
}
public ThrowStatement (Expression expression)
{
AddChild (expression, Roles.Expression);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitThrowStatement (this, data); return visitor.VisitThrowStatement (this, data);

36
ICSharpCode.NRefactory/CSharp/Ast/Statements/TryCatchStatement.cs

@ -79,6 +79,42 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary> /// </summary>
public class CatchClause : AstNode public class CatchClause : AstNode
{ {
#region PatternPlaceholder
public static implicit operator CatchClause(PatternMatching.Pattern pattern)
{
return pattern != null ? new PatternPlaceholder(pattern) : null;
}
sealed class PatternPlaceholder : CatchClause, PatternMatching.INode
{
readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
}
}
#endregion
public override NodeType NodeType { public override NodeType NodeType {
get { get {
return NodeType.Unknown; return NodeType.Unknown;

11
ICSharpCode.NRefactory/CSharp/Ast/Statements/UncheckedStatement.cs

@ -27,7 +27,7 @@
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
/// <summary> /// <summary>
/// unchecked { Body } /// unchecked BodyBlock
/// </summary> /// </summary>
public class UncheckedStatement : Statement public class UncheckedStatement : Statement
{ {
@ -40,6 +40,15 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (Roles.Body, value); } set { SetChildByRole (Roles.Body, value); }
} }
public UncheckedStatement ()
{
}
public UncheckedStatement (BlockStatement body)
{
AddChild (body, Roles.Body);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitUncheckedStatement (this, data); return visitor.VisitUncheckedStatement (this, data);

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

@ -123,10 +123,18 @@ namespace ICSharpCode.NRefactory.CSharp
set; set;
} }
public CSharpTokenNode LParToken {
get { return GetChildByRole (Roles.LPar); }
}
public AstNodeCollection<Expression> Arguments { public AstNodeCollection<Expression> Arguments {
get { return GetChildrenByRole (Roles.Argument); } get { return GetChildrenByRole (Roles.Argument); }
} }
public CSharpTokenNode RParToken {
get { return GetChildByRole (Roles.RPar); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitConstructorInitializer (this, data); return visitor.VisitConstructorInitializer (this, data);

12
ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/FixedVariableInitializer.cs

@ -1,4 +1,4 @@
// //
// FixedFieldDeclaration.cs // FixedFieldDeclaration.cs
// //
// Author: // Author:
@ -29,7 +29,7 @@ using System;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
/// <summary> /// <summary>
/// name [ <expression> ] /// Name [ CountExpression ]
/// </summary> /// </summary>
public class FixedVariableInitializer : AstNode public class FixedVariableInitializer : AstNode
{ {
@ -46,7 +46,7 @@ namespace ICSharpCode.NRefactory.CSharp
public FixedVariableInitializer (string name, Expression initializer = null) public FixedVariableInitializer (string name, Expression initializer = null)
{ {
this.Name = name; this.Name = name;
this.Initializer = initializer; this.CountExpression = initializer;
} }
public string Name { public string Name {
@ -62,7 +62,7 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.LBracket); } get { return GetChildByRole (Roles.LBracket); }
} }
public Expression Initializer { public Expression CountExpression {
get { return GetChildByRole (Roles.Expression); } get { return GetChildByRole (Roles.Expression); }
set { SetChildByRole (Roles.Expression, value); } set { SetChildByRole (Roles.Expression, value); }
} }
@ -76,10 +76,10 @@ namespace ICSharpCode.NRefactory.CSharp
return visitor.VisitFixedVariableInitializer (this, data); return visitor.VisitFixedVariableInitializer (this, data);
} }
protected internal override bool DoMatch (AstNode other, ICSharpCode.NRefactory.CSharp.PatternMatching.Match match) protected internal override bool DoMatch (AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
{ {
var o = other as FixedVariableInitializer; var o = other as FixedVariableInitializer;
return o != null && MatchString (this.Name, o.Name) && this.Initializer.DoMatch (o.Initializer, match); return o != null && MatchString (this.Name, o.Name) && this.CountExpression.DoMatch (o.CountExpression, match);
} }
} }
} }

38
ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/VariableInitializer.cs

@ -28,6 +28,42 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
public class VariableInitializer : AstNode public class VariableInitializer : AstNode
{ {
#region PatternPlaceholder
public static implicit operator VariableInitializer(PatternMatching.Pattern pattern)
{
return pattern != null ? new PatternPlaceholder(pattern) : null;
}
sealed class PatternPlaceholder : VariableInitializer, PatternMatching.INode
{
readonly PatternMatching.Pattern child;
public PatternPlaceholder(PatternMatching.Pattern child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
}
}
#endregion
public override NodeType NodeType { public override NodeType NodeType {
get { get {
return NodeType.Unknown; return NodeType.Unknown;
@ -67,7 +103,7 @@ namespace ICSharpCode.NRefactory.CSharp
return visitor.VisitVariableInitializer (this, data); return visitor.VisitVariableInitializer (this, data);
} }
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.CSharp.PatternMatching.Match match) protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{ {
VariableInitializer o = other as VariableInitializer; VariableInitializer o = other as VariableInitializer;
return o != null && MatchString(this.Name, o.Name) && this.Initializer.DoMatch(o.Initializer, match); return o != null && MatchString(this.Name, o.Name) && this.Initializer.DoMatch(o.Initializer, match);

18
ICSharpCode.NRefactory/CSharp/Formatter/AstFormattingVisitor.cs

@ -33,7 +33,7 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
public class AstFormattingVisitor : DepthFirstAstVisitor<object, object> public class AstFormattingVisitor : DepthFirstAstVisitor<object, object>
{ {
CSharpFormattingPolicy policy; CSharpFormattingOptions policy;
ITextEditorAdapter data; ITextEditorAdapter data;
List<Change> changes = new List<Change> (); List<Change> changes = new List<Change> ();
Indent curIndent = new Indent (); Indent curIndent = new Indent ();
@ -66,7 +66,7 @@ namespace ICSharpCode.NRefactory.CSharp
set; set;
} }
public AstFormattingVisitor (CSharpFormattingPolicy policy, ITextEditorAdapter data) public AstFormattingVisitor (CSharpFormattingOptions policy, ITextEditorAdapter data)
{ {
this.policy = policy; this.policy = policy;
this.data = data; this.data = data;
@ -521,13 +521,25 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
FixIndentationForceNewLine (fieldDeclaration.StartLocation); FixIndentationForceNewLine (fieldDeclaration.StartLocation);
FormatCommas (fieldDeclaration, policy.SpaceBeforeFieldDeclarationComma, policy.SpaceAfterFieldDeclarationComma); FormatCommas (fieldDeclaration, policy.SpaceBeforeFieldDeclarationComma, policy.SpaceAfterFieldDeclarationComma);
if (fieldDeclaration.NextSibling is FieldDeclaration) { if (fieldDeclaration.NextSibling is FieldDeclaration || fieldDeclaration.NextSibling is FixedFieldDeclaration) {
EnsureBlankLinesAfter (fieldDeclaration, policy.BlankLinesBetweenFields); EnsureBlankLinesAfter (fieldDeclaration, policy.BlankLinesBetweenFields);
} else if (IsMember (fieldDeclaration.NextSibling)) { } else if (IsMember (fieldDeclaration.NextSibling)) {
EnsureBlankLinesAfter (fieldDeclaration, policy.BlankLinesBetweenMembers); EnsureBlankLinesAfter (fieldDeclaration, policy.BlankLinesBetweenMembers);
} }
return base.VisitFieldDeclaration (fieldDeclaration, data); return base.VisitFieldDeclaration (fieldDeclaration, data);
} }
public override object VisitFixedFieldDeclaration (FixedFieldDeclaration fixedFieldDeclaration, object data)
{
FixIndentationForceNewLine (fixedFieldDeclaration.StartLocation);
FormatCommas (fixedFieldDeclaration, policy.SpaceBeforeFieldDeclarationComma, policy.SpaceAfterFieldDeclarationComma);
if (fixedFieldDeclaration.NextSibling is FieldDeclaration || fixedFieldDeclaration.NextSibling is FixedFieldDeclaration ) {
EnsureBlankLinesAfter (fixedFieldDeclaration, policy.BlankLinesBetweenFields);
} else if (IsMember (fixedFieldDeclaration.NextSibling)) {
EnsureBlankLinesAfter (fixedFieldDeclaration, policy.BlankLinesBetweenMembers);
}
return base.VisitFixedFieldDeclaration (fixedFieldDeclaration, data);
}
public override object VisitEnumMemberDeclaration (EnumMemberDeclaration enumMemberDeclaration, object data) public override object VisitEnumMemberDeclaration (EnumMemberDeclaration enumMemberDeclaration, object data)
{ {

24
ICSharpCode.NRefactory/CSharp/Formatter/CSharpFormattingPolicy.cs → ICSharpCode.NRefactory/CSharp/Formatter/CSharpFormattingOptions.cs

@ -1,5 +1,5 @@
// //
// CSharpFormattingPolicy.cs // CSharpFormattingOptions.cs
// //
// Author: // Author:
// Mike Krüger <mkrueger@novell.com> // Mike Krüger <mkrueger@novell.com>
@ -60,7 +60,7 @@ namespace ICSharpCode.NRefactory.CSharp
ForceNewLine ForceNewLine
} }
public class CSharpFormattingPolicy public class CSharpFormattingOptions
{ {
public string Name { public string Name {
get; get;
@ -72,9 +72,9 @@ namespace ICSharpCode.NRefactory.CSharp
set; set;
} }
public CSharpFormattingPolicy Clone () public CSharpFormattingOptions Clone ()
{ {
return (CSharpFormattingPolicy)MemberwiseClone (); return (CSharpFormattingOptions)MemberwiseClone ();
} }
#region Indentation #region Indentation
@ -766,7 +766,7 @@ namespace ICSharpCode.NRefactory.CSharp
#endregion #endregion
public CSharpFormattingPolicy () public CSharpFormattingOptions ()
{ {
IndentNamespaceBody = true; IndentNamespaceBody = true;
IndentClassBody = IndentInterfaceBody = IndentStructBody = IndentEnumBody = true; IndentClassBody = IndentInterfaceBody = IndentStructBody = IndentEnumBody = true;
@ -880,22 +880,22 @@ namespace ICSharpCode.NRefactory.CSharp
BlankLinesBetweenMembers = 1; BlankLinesBetweenMembers = 1;
} }
/*public static CSharpFormattingPolicy Load (FilePath selectedFile) /*public static CSharpFormattingOptions Load (FilePath selectedFile)
{ {
using (var stream = System.IO.File.OpenRead (selectedFile)) { using (var stream = System.IO.File.OpenRead (selectedFile)) {
return Load (stream); return Load (stream);
} }
} }
public static CSharpFormattingPolicy Load (System.IO.Stream input) public static CSharpFormattingOptions Load (System.IO.Stream input)
{ {
CSharpFormattingPolicy result = new CSharpFormattingPolicy (); CSharpFormattingOptions result = new CSharpFormattingOptions ();
result.Name = "noname"; result.Name = "noname";
using (XmlTextReader reader = new XmlTextReader (input)) { using (XmlTextReader reader = new XmlTextReader (input)) {
while (reader.Read ()) { while (reader.Read ()) {
if (reader.NodeType == XmlNodeType.Element) { if (reader.NodeType == XmlNodeType.Element) {
if (reader.LocalName == "Property") { if (reader.LocalName == "Property") {
var info = typeof(CSharpFormattingPolicy).GetProperty (reader.GetAttribute ("name")); var info = typeof(CSharpFormattingOptions).GetProperty (reader.GetAttribute ("name"));
string valString = reader.GetAttribute ("value"); string valString = reader.GetAttribute ("value");
object value; object value;
if (info.PropertyType == typeof(bool)) { if (info.PropertyType == typeof(bool)) {
@ -926,7 +926,7 @@ namespace ICSharpCode.NRefactory.CSharp
writer.IndentChar = '\t'; writer.IndentChar = '\t';
writer.WriteStartElement ("FormattingProfile"); writer.WriteStartElement ("FormattingProfile");
writer.WriteAttributeString ("name", Name); writer.WriteAttributeString ("name", Name);
foreach (PropertyInfo info in typeof (CSharpFormattingPolicy).GetProperties ()) { foreach (PropertyInfo info in typeof (CSharpFormattingOptions).GetProperties ()) {
if (info.GetCustomAttributes (false).Any (o => o.GetType () == typeof(ItemPropertyAttribute))) { if (info.GetCustomAttributes (false).Any (o => o.GetType () == typeof(ItemPropertyAttribute))) {
writer.WriteStartElement ("Property"); writer.WriteStartElement ("Property");
writer.WriteAttributeString ("name", info.Name); writer.WriteAttributeString ("name", info.Name);
@ -938,9 +938,9 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
public bool Equals (CSharpFormattingPolicy other) public bool Equals (CSharpFormattingOptions other)
{ {
foreach (PropertyInfo info in typeof (CSharpFormattingPolicy).GetProperties ()) { foreach (PropertyInfo info in typeof (CSharpFormattingOptions).GetProperties ()) {
if (info.GetCustomAttributes (false).Any (o => o.GetType () == typeof(ItemPropertyAttribute))) { if (info.GetCustomAttributes (false).Any (o => o.GetType () == typeof(ItemPropertyAttribute))) {
object val = info.GetValue (this, null); object val = info.GetValue (this, null);
object otherVal = info.GetValue (other, null); object otherVal = info.GetValue (other, null);

125
ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs

@ -9,7 +9,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using ICSharpCode.NRefactory.CSharp.PatternMatching; using ICSharpCode.NRefactory.PatternMatching;
using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
@ -17,10 +17,10 @@ namespace ICSharpCode.NRefactory.CSharp
/// <summary> /// <summary>
/// Outputs the AST. /// Outputs the AST.
/// </summary> /// </summary>
public class OutputVisitor : IPatternAstVisitor<object, object> public class OutputVisitor : IAstVisitor<object, object>, IPatternAstVisitor<object, object>
{ {
readonly IOutputFormatter formatter; readonly IOutputFormatter formatter;
readonly CSharpFormattingPolicy policy; readonly CSharpFormattingOptions policy;
readonly Stack<AstNode> containerStack = new Stack<AstNode>(); readonly Stack<AstNode> containerStack = new Stack<AstNode>();
readonly Stack<AstNode> positionStack = new Stack<AstNode>(); readonly Stack<AstNode> positionStack = new Stack<AstNode>();
@ -42,7 +42,7 @@ namespace ICSharpCode.NRefactory.CSharp
Division Division
} }
public OutputVisitor(TextWriter textWriter, CSharpFormattingPolicy formattingPolicy) public OutputVisitor(TextWriter textWriter, CSharpFormattingOptions formattingPolicy)
{ {
if (textWriter == null) if (textWriter == null)
throw new ArgumentNullException("textWriter"); throw new ArgumentNullException("textWriter");
@ -52,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp
this.policy = formattingPolicy; this.policy = formattingPolicy;
} }
public OutputVisitor(IOutputFormatter formatter, CSharpFormattingPolicy formattingPolicy) public OutputVisitor(IOutputFormatter formatter, CSharpFormattingOptions formattingPolicy)
{ {
if (formatter == null) if (formatter == null)
throw new ArgumentNullException("formatter"); throw new ArgumentNullException("formatter");
@ -67,7 +67,7 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
// Ensure that nodes are visited in the proper nested order. // Ensure that nodes are visited in the proper nested order.
// Jumps to different subtrees are allowed only for the child of a placeholder node. // 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); Debug.Assert(containerStack.Count == 0 || node.Parent == containerStack.Peek() || containerStack.Peek().NodeType == NodeType.Pattern);
if (positionStack.Count > 0) if (positionStack.Count > 0)
WriteSpecialsUpToNode(node); WriteSpecialsUpToNode(node);
containerStack.Push(node); containerStack.Push(node);
@ -468,15 +468,29 @@ namespace ICSharpCode.NRefactory.CSharp
return EndNode(anonymousMethodExpression); return EndNode(anonymousMethodExpression);
} }
public object VisitArgListExpression(ArgListExpression argListExpression, object data) public object VisitUndocumentedExpression(UndocumentedExpression undocumentedExpression, object data)
{ {
StartNode(argListExpression); StartNode(undocumentedExpression);
WriteKeyword("__arglist"); switch (undocumentedExpression.UndocumentedExpressionType) {
if (!argListExpression.IsAccess) { case UndocumentedExpressionType.ArgList:
case UndocumentedExpressionType.ArgListAccess:
WriteKeyword("__arglist");
break;
case UndocumentedExpressionType.MakeRef:
WriteKeyword("__makeref");
break;
case UndocumentedExpressionType.RefType:
WriteKeyword("__reftype");
break;
case UndocumentedExpressionType.RefValue:
WriteKeyword("__refvalue");
break;
}
if (undocumentedExpression.Arguments.Count > 0) {
Space(policy.SpaceBeforeMethodCallParentheses); Space(policy.SpaceBeforeMethodCallParentheses);
WriteCommaSeparatedListInParenthesis(argListExpression.Arguments, policy.SpaceWithinMethodCallParentheses); WriteCommaSeparatedListInParenthesis(undocumentedExpression.Arguments, policy.SpaceWithinMethodCallParentheses);
} }
return EndNode(argListExpression); return EndNode(undocumentedExpression);
} }
public object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data) public object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data)
@ -501,7 +515,7 @@ namespace ICSharpCode.NRefactory.CSharp
style = BraceStyle.EndOfLine; style = BraceStyle.EndOfLine;
OpenBrace(style); OpenBrace(style);
bool isFirst = true; bool isFirst = true;
foreach (AstNode node in arrayInitializerExpression.Children) { foreach (AstNode node in arrayInitializerExpression.Elements) {
if (isFirst) { if (isFirst) {
isFirst = false; isFirst = false;
} else { } else {
@ -771,6 +785,25 @@ namespace ICSharpCode.NRefactory.CSharp
return EndNode(objectCreateExpression); return EndNode(objectCreateExpression);
} }
public object VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression, object data)
{
StartNode(anonymousTypeCreateExpression);
WriteKeyword("new");
Space();
LPar();
RPar();
Space();
OpenBrace(policy.AnonymousMethodBraceStyle);
foreach (AstNode node in anonymousTypeCreateExpression.Initializer) {
node.AcceptVisitor(this, null);
if (node.NextSibling != null)
Comma(node);
NewLine ();
}
CloseBrace(policy.AnonymousMethodBraceStyle);
return EndNode(anonymousTypeCreateExpression);
}
public object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data) public object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data)
{ {
StartNode(parenthesizedExpression); StartNode(parenthesizedExpression);
@ -1026,7 +1059,8 @@ namespace ICSharpCode.NRefactory.CSharp
if (first) { if (first) {
first = false; first = false;
} else { } else {
NewLine(); if (!(clause is QueryContinuationClause))
NewLine();
} }
clause.AcceptVisitor(this, data); clause.AcceptVisitor(this, data);
} }
@ -1169,8 +1203,8 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
StartNode(attributeSection); StartNode(attributeSection);
WriteToken("[", AstNode.Roles.LBracket); WriteToken("[", AstNode.Roles.LBracket);
if (attributeSection.AttributeTarget != AttributeTarget.None) { if (!string.IsNullOrEmpty (attributeSection.AttributeTarget)) {
WriteToken(AttributeSection.GetAttributeTargetName(attributeSection.AttributeTarget), AttributeSection.TargetRole); WriteToken(attributeSection.AttributeTarget, AttributeSection.TargetRole);
WriteToken(":", AttributeSection.Roles.Colon); WriteToken(":", AttributeSection.Roles.Colon);
Space(); Space();
} }
@ -1847,7 +1881,6 @@ namespace ICSharpCode.NRefactory.CSharp
StartNode(fixedFieldDeclaration); StartNode(fixedFieldDeclaration);
WriteAttributes(fixedFieldDeclaration.Attributes); WriteAttributes(fixedFieldDeclaration.Attributes);
WriteModifiers(fixedFieldDeclaration.ModifierTokens); WriteModifiers(fixedFieldDeclaration.ModifierTokens);
Space();
WriteKeyword("fixed"); WriteKeyword("fixed");
Space(); Space();
fixedFieldDeclaration.ReturnType.AcceptVisitor (this, data); fixedFieldDeclaration.ReturnType.AcceptVisitor (this, data);
@ -1861,10 +1894,10 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
StartNode(fixedVariableInitializer); StartNode(fixedVariableInitializer);
WriteIdentifier(fixedVariableInitializer.Name); WriteIdentifier(fixedVariableInitializer.Name);
if (!fixedVariableInitializer.Initializer.IsNull) { if (!fixedVariableInitializer.CountExpression.IsNull) {
WriteToken("[", AstNode.Roles.LBracket); WriteToken("[", AstNode.Roles.LBracket);
Space(policy.SpacesWithinBrackets); Space(policy.SpacesWithinBrackets);
fixedVariableInitializer.Initializer.AcceptVisitor(this, data); fixedVariableInitializer.CountExpression.AcceptVisitor(this, data);
Space(policy.SpacesWithinBrackets); Space(policy.SpacesWithinBrackets);
WriteToken("]", AstNode.Roles.RBracket); WriteToken("]", AstNode.Roles.RBracket);
} }
@ -2140,77 +2173,71 @@ namespace ICSharpCode.NRefactory.CSharp
#endregion #endregion
#region Pattern Nodes #region Pattern Nodes
object IPatternAstVisitor<object, object>.VisitPlaceholder(AstNode placeholder, AstNode child, object data) public object VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern, object data)
{ {
StartNode(placeholder); StartNode(placeholder);
child.AcceptVisitor(this, data); pattern.AcceptVisitor(this, data);
return EndNode(placeholder); return EndNode(placeholder);
} }
object IPatternAstVisitor<object, object>.VisitAnyNode(AnyNode anyNode, object data) object IPatternAstVisitor<object, object>.VisitAnyNode(AnyNode anyNode, object data)
{ {
StartNode(anyNode);
if (!string.IsNullOrEmpty(anyNode.GroupName)) { if (!string.IsNullOrEmpty(anyNode.GroupName)) {
WriteIdentifier(anyNode.GroupName); WriteIdentifier(anyNode.GroupName);
WriteToken(":", AstNode.Roles.Colon); WriteToken(":", AstNode.Roles.Colon);
} }
WriteKeyword("anyNode"); WriteKeyword("anyNode");
return EndNode(anyNode); return null;
} }
object IPatternAstVisitor<object, object>.VisitBackreference(Backreference backreference, object data) object IPatternAstVisitor<object, object>.VisitBackreference(Backreference backreference, object data)
{ {
StartNode(backreference);
WriteKeyword("backreference"); WriteKeyword("backreference");
LPar(); LPar();
WriteIdentifier(backreference.ReferencedGroupName); WriteIdentifier(backreference.ReferencedGroupName);
RPar(); RPar();
return EndNode(backreference); return null;
} }
object IPatternAstVisitor<object, object>.VisitIdentifierExpressionBackreference(IdentifierExpressionBackreference identifierExpressionBackreference, object data) object IPatternAstVisitor<object, object>.VisitIdentifierExpressionBackreference(IdentifierExpressionBackreference identifierExpressionBackreference, object data)
{ {
StartNode(identifierExpressionBackreference);
WriteKeyword("identifierBackreference"); WriteKeyword("identifierBackreference");
LPar(); LPar();
WriteIdentifier(identifierExpressionBackreference.ReferencedGroupName); WriteIdentifier(identifierExpressionBackreference.ReferencedGroupName);
RPar(); RPar();
return EndNode(identifierExpressionBackreference); return null;
} }
object IPatternAstVisitor<object, object>.VisitChoice(Choice choice, object data) object IPatternAstVisitor<object, object>.VisitChoice(Choice choice, object data)
{ {
StartNode(choice);
WriteKeyword("choice"); WriteKeyword("choice");
Space(); Space();
LPar(); LPar();
NewLine(); NewLine();
formatter.Indent(); formatter.Indent();
foreach (AstNode alternative in choice) { foreach (INode alternative in choice) {
alternative.AcceptVisitor(this, data); VisitNodeInPattern(alternative, data);
if (alternative != choice.LastChild) if (alternative != choice.Last())
WriteToken(",", AstNode.Roles.Comma); WriteToken(",", AstNode.Roles.Comma);
NewLine(); NewLine();
} }
formatter.Unindent(); formatter.Unindent();
RPar(); RPar();
return EndNode(choice); return null;
} }
object IPatternAstVisitor<object, object>.VisitNamedNode(NamedNode namedNode, object data) object IPatternAstVisitor<object, object>.VisitNamedNode(NamedNode namedNode, object data)
{ {
StartNode(namedNode);
if (!string.IsNullOrEmpty(namedNode.GroupName)) { if (!string.IsNullOrEmpty(namedNode.GroupName)) {
WriteIdentifier(namedNode.GroupName); WriteIdentifier(namedNode.GroupName);
WriteToken(":", AstNode.Roles.Colon); WriteToken(":", AstNode.Roles.Colon);
} }
namedNode.GetChildByRole(NamedNode.ElementRole).AcceptVisitor(this, data); VisitNodeInPattern(namedNode.ChildNode, data);
return EndNode(namedNode); return null;
} }
object IPatternAstVisitor<object, object>.VisitRepeat(Repeat repeat, object data) object IPatternAstVisitor<object, object>.VisitRepeat(Repeat repeat, object data)
{ {
StartNode(repeat);
WriteKeyword("repeat"); WriteKeyword("repeat");
LPar(); LPar();
if (repeat.MinCount != 0 || repeat.MaxCount != int.MaxValue) { if (repeat.MinCount != 0 || repeat.MaxCount != int.MaxValue) {
@ -2219,19 +2246,33 @@ namespace ICSharpCode.NRefactory.CSharp
WriteIdentifier(repeat.MaxCount.ToString()); WriteIdentifier(repeat.MaxCount.ToString());
WriteToken(",", AstNode.Roles.Comma); WriteToken(",", AstNode.Roles.Comma);
} }
repeat.GetChildByRole(Repeat.ElementRole).AcceptVisitor(this, data); VisitNodeInPattern(repeat.ChildNode, data);
RPar(); RPar();
return EndNode(repeat); return null;
} }
object IPatternAstVisitor<object, object>.VisitOptionalNode(OptionalNode optionalNode, object data) object IPatternAstVisitor<object, object>.VisitOptionalNode(OptionalNode optionalNode, object data)
{ {
StartNode(optionalNode);
WriteKeyword("optional"); WriteKeyword("optional");
LPar(); LPar();
optionalNode.GetChildByRole(OptionalNode.ElementRole).AcceptVisitor(this, data); VisitNodeInPattern(optionalNode.ChildNode, data);
RPar(); RPar();
return EndNode(optionalNode); return null;
}
void VisitNodeInPattern(INode childNode, object data)
{
AstNode astNode = childNode as AstNode;
if (astNode != null) {
astNode.AcceptVisitor(this, data);
} else {
Pattern pattern = childNode as Pattern;
if (pattern != null) {
pattern.AcceptVisitor(this, data);
} else {
throw new InvalidOperationException("Unknown node type in pattern");
}
}
} }
#endregion #endregion
} }

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

File diff suppressed because it is too large Load Diff

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

@ -308,8 +308,8 @@ namespace ICSharpCode.NRefactory.CSharp
ConvertTypeParameters(m.TypeParameters, methodDeclaration.TypeParameters, methodDeclaration.Constraints); ConvertTypeParameters(m.TypeParameters, methodDeclaration.TypeParameters, methodDeclaration.Constraints);
m.ReturnType = ConvertType(methodDeclaration.ReturnType); m.ReturnType = ConvertType(methodDeclaration.ReturnType);
ConvertAttributes(m.Attributes, methodDeclaration.Attributes.Where(s => s.AttributeTarget != AttributeTarget.Return)); ConvertAttributes(m.Attributes, methodDeclaration.Attributes.Where(s => s.AttributeTarget != "return"));
ConvertAttributes(m.ReturnTypeAttributes, methodDeclaration.Attributes.Where(s => s.AttributeTarget == AttributeTarget.Return)); ConvertAttributes(m.ReturnTypeAttributes, methodDeclaration.Attributes.Where(s => s.AttributeTarget == "return"));
ApplyModifiers(m, methodDeclaration.Modifiers); ApplyModifiers(m, methodDeclaration.Modifiers);
m.IsExtensionMethod = methodDeclaration.IsExtensionMethod; m.IsExtensionMethod = methodDeclaration.IsExtensionMethod;
@ -346,8 +346,8 @@ namespace ICSharpCode.NRefactory.CSharp
m.BodyRegion = MakeRegion(operatorDeclaration.Body); m.BodyRegion = MakeRegion(operatorDeclaration.Body);
m.ReturnType = ConvertType(operatorDeclaration.ReturnType); m.ReturnType = ConvertType(operatorDeclaration.ReturnType);
ConvertAttributes(m.Attributes, operatorDeclaration.Attributes.Where(s => s.AttributeTarget != AttributeTarget.Return)); ConvertAttributes(m.Attributes, operatorDeclaration.Attributes.Where(s => s.AttributeTarget != "return"));
ConvertAttributes(m.ReturnTypeAttributes, operatorDeclaration.Attributes.Where(s => s.AttributeTarget == AttributeTarget.Return)); ConvertAttributes(m.ReturnTypeAttributes, operatorDeclaration.Attributes.Where(s => s.AttributeTarget == "return"));
ApplyModifiers(m, operatorDeclaration.Modifiers); ApplyModifiers(m, operatorDeclaration.Modifiers);

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

Loading…
Cancel
Save