Browse Source

Merge branch 'master' of git://github.com/icsharpcode/ILSpy into Debugger

pull/191/merge
Eusebiu Marcu 14 years ago
parent
commit
446f8423b7
  1. 2
      Debugger/Debugger.Core/NRefactory/Ast/ExpressionExtensionMethods.cs
  2. 65
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  3. 18
      ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  4. 2
      ICSharpCode.Decompiler/Ast/CommentStatement.cs
  5. 25
      ICSharpCode.Decompiler/Ast/NRefactoryExtensions.cs
  6. 6
      ICSharpCode.Decompiler/Ast/Transforms/AddCheckedBlocks.cs
  7. 6
      ICSharpCode.Decompiler/Ast/Transforms/CombineQueryExpressions.cs
  8. 12
      ICSharpCode.Decompiler/Ast/Transforms/ConvertConstructorCallIntoInitializer.cs
  9. 2
      ICSharpCode.Decompiler/Ast/Transforms/DeclareVariables.cs
  10. 12
      ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs
  11. 58
      ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs
  12. 6
      ICSharpCode.Decompiler/Ast/Transforms/PushNegation.cs
  13. 6
      ICSharpCode.Decompiler/Ast/Transforms/ReplaceMethodCallsWithOperators.cs
  14. 4
      ICSharpCode.Decompiler/Tests/Helpers/RemoveCompilerAttribute.cs
  15. 33
      ILSpy/CSharpLanguage.cs
  16. 7
      ILSpy/ILSpy.csproj
  17. 14
      ILSpy/Language.cs
  18. 2
      ILSpy/MainWindow.xaml.cs
  19. 103
      ILSpy/TextView/DecompilerTextView.cs
  20. 9
      ILSpy/XmlDoc/XmlDocKeyProvider.cs
  21. 117
      ILSpy/XmlDoc/XmlDocLoader.cs
  22. 122
      ILSpy/XmlDoc/XmlDocRenderer.cs
  23. 4
      NRefactory/ICSharpCode.NRefactory.Demo/MainForm.cs
  24. 4
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/InsertParenthesesVisitorTests.cs
  25. 11
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/AliasReferenceExpressionTests.cs
  26. 6
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/AnonymousMethodTests.cs
  27. 4
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ArrayObjectCreateExpressionTests.cs
  28. 4
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/CastExpressionTests.cs
  29. 2
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ConditionalExpressionTests.cs
  30. 2
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/DefaultValueExpressionTests.cs
  31. 11
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/IdentifierExpressionTests.cs
  32. 2
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/InvocationExpressionTests.cs
  33. 10
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/LambdaExpressionTests.cs
  34. 20
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/MemberReferenceExpressionTests.cs
  35. 4
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/PointerReferenceExpressionTests.cs
  36. 77
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/QueryExpressionTests.cs
  37. 14
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/TypeOfExpressionTests.cs
  38. 48
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/TypeReferenceExpressionTests.cs
  39. 57
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/AttributeSectionTests.cs
  40. 2
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/DelegateDeclarationTests.cs
  41. 17
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/TypeDeclarationTests.cs
  42. 3
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/UsingDeclarationTests.cs
  43. 21
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/ParseUtil.cs
  44. 5
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/BlockStatementTests.cs
  45. 30
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/FixedStatementTests.cs
  46. 4
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/ForStatementTests.cs
  47. 2
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/GotoStatementTests.cs
  48. 5
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/TryCatchStatementTests.cs
  49. 18
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/UsingStatementTests.cs
  50. 191
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/VariableDeclarationStatementTests.cs
  51. 4
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/ConstructorDeclarationTests.cs
  52. 4
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/EventDeclarationTests.cs
  53. 15
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/FieldDeclarationTests.cs
  54. 4
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/IndexerDeclarationTests.cs
  55. 21
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/MethodDeclarationTests.cs
  56. 7
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/PropertyDeclarationTests.cs
  57. 14
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/LambdaTests.cs
  58. 8
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/OverloadResolutionTests.cs
  59. 14
      NRefactory/ICSharpCode.NRefactory.Tests/FormattingTests/TestBlankLineFormatting.cs
  60. 32
      NRefactory/ICSharpCode.NRefactory.Tests/FormattingTests/TestBraceStlye.cs
  61. 16
      NRefactory/ICSharpCode.NRefactory.Tests/FormattingTests/TestFormattingBugs.cs
  62. 168
      NRefactory/ICSharpCode.NRefactory.Tests/FormattingTests/TestSpacingVisitor.cs
  63. 120
      NRefactory/ICSharpCode.NRefactory.Tests/FormattingTests/TestStatementIndentation.cs
  64. 40
      NRefactory/ICSharpCode.NRefactory.Tests/FormattingTests/TestTypeLevelIndentation.cs
  65. 6
      NRefactory/ICSharpCode.NRefactory.Tests/FormattingTests/TextEditorTestAdapter.cs
  66. 8
      NRefactory/ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj
  67. 2
      NRefactory/ICSharpCode.NRefactory.Tests/TypeSystem/GetAllBaseTypesTest.cs
  68. 25
      NRefactory/ICSharpCode.NRefactory.Tests/TypeSystem/TestInterningProvider.cs
  69. 10
      NRefactory/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs
  70. 84
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs
  71. 36
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/AstNodeCollection.cs
  72. 58
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/AstType.cs
  73. 14
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/DepthFirstAstVisitor.cs
  74. 18
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AnonymousMethodExpression.cs
  75. 79
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AnonymousTypeCreateExpression.cs
  76. 10
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AsExpression.cs
  77. 7
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AssignmentExpression.cs
  78. 10
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/CastExpression.cs
  79. 9
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/CheckedExpression.cs
  80. 11
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ConditionalExpression.cs
  81. 9
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/DefaultValueExpression.cs
  82. 10
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/DirectionExpression.cs
  83. 38
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/Expression.cs
  84. 18
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/IndexerExpression.cs
  85. 18
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/InvocationExpression.cs
  86. 19
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/MemberReferenceExpression.cs
  87. 4
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/NamedArgumentExpression.cs
  88. 22
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/NullReferenceExpression.cs
  89. 18
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ObjectCreateExpression.cs
  90. 9
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/ParenthesizedExpression.cs
  91. 9
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/SizeOfExpression.cs
  92. 9
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/TypeOfExpression.cs
  93. 9
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/TypeReferenceExpression.cs
  94. 9
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/UncheckedExpression.cs
  95. 25
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/UndocumentedExpression.cs
  96. 92
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/AttributeSection.cs
  97. 13
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/NamespaceDeclaration.cs
  98. 16
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/UsingAliasDeclaration.cs
  99. 14
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/UsingDeclaration.cs
  100. 5
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/IAstVisitor.cs
  101. Some files were not shown because too many files have changed in this diff Show More

2
Debugger/Debugger.Core/NRefactory/Ast/ExpressionExtensionMethods.cs

@ -159,7 +159,7 @@ namespace ICSharpCode.NRefactory.Ast @@ -159,7 +159,7 @@ namespace ICSharpCode.NRefactory.Ast
using (var sw = new StringWriter())
{
OutputVisitor csOutVisitor = new OutputVisitor(sw, new CSharpFormattingPolicy());
OutputVisitor csOutVisitor = new OutputVisitor(sw, new CSharpFormattingOptions());
code.AcceptVisitor(csOutVisitor, null);
return sw.ToString();
}

65
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -41,6 +41,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -41,6 +41,7 @@ namespace ICSharpCode.Decompiler.Ast
if (context == null)
throw new ArgumentNullException("context");
this.context = context;
this.DecompileMethodBodies = true;
}
public static bool MemberIsHidden(MemberReference member, DecompilerSettings settings)
@ -109,7 +110,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -109,7 +110,7 @@ namespace ICSharpCode.Decompiler.Ast
astCompileUnit.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }, null);
var outputFormatter = new TextOutputFormatter(output);
var formattingPolicy = new CSharpFormattingPolicy();
var formattingPolicy = new CSharpFormattingOptions();
// disable whitespace in front of parentheses:
formattingPolicy.SpaceBeforeMethodCallParentheses = false;
formattingPolicy.SpaceBeforeMethodDeclarationParentheses = false;
@ -120,8 +121,8 @@ namespace ICSharpCode.Decompiler.Ast @@ -120,8 +121,8 @@ namespace ICSharpCode.Decompiler.Ast
public void AddAssembly(AssemblyDefinition assemblyDefinition, bool onlyAssemblyLevel = false)
{
ConvertCustomAttributes(astCompileUnit, assemblyDefinition, AttributeTarget.Assembly);
ConvertCustomAttributes(astCompileUnit, assemblyDefinition.MainModule, AttributeTarget.Module);
ConvertCustomAttributes(astCompileUnit, assemblyDefinition, "assembly");
ConvertCustomAttributes(astCompileUnit, assemblyDefinition.MainModule, "module");
if (!onlyAssemblyLevel) {
foreach (TypeDefinition typeDef in assemblyDefinition.MainModule.Types) {
@ -640,7 +641,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -640,7 +641,7 @@ namespace ICSharpCode.Decompiler.Ast
}
} else
astMethod.PrivateImplementationType = ConvertType(methodDef.Overrides.First().DeclaringType);
astMethod.Body = AstMethodBodyBuilder.CreateMethodBody(methodDef, context, astMethod.Parameters);
astMethod.Body = CreateMethodBody(methodDef, astMethod.Parameters);
}
ConvertAttributes(astMethod, methodDef);
if (methodDef.HasCustomAttributes && astMethod.Parameters.Count > 0) {
@ -722,7 +723,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -722,7 +723,7 @@ namespace ICSharpCode.Decompiler.Ast
}
astMethod.Name = CleanName(methodDef.DeclaringType.Name);
astMethod.Parameters.AddRange(MakeParameters(methodDef));
astMethod.Body = AstMethodBodyBuilder.CreateMethodBody(methodDef, context, astMethod.Parameters);
astMethod.Body = CreateMethodBody(methodDef, astMethod.Parameters);
ConvertAttributes(astMethod, methodDef);
astMethod.WithAnnotation(methodMapping);
return astMethod;
@ -773,10 +774,9 @@ namespace ICSharpCode.Decompiler.Ast @@ -773,10 +774,9 @@ namespace ICSharpCode.Decompiler.Ast
// Create mapping - used in debugger
MemberMapping methodMapping = propDef.GetMethod.CreateCodeMapping(CSharpCodeMapping.SourceCodeMappings);
astProp.Getter = new Accessor {
Body = AstMethodBodyBuilder.CreateMethodBody(propDef.GetMethod, context)
}.WithAnnotation(propDef.GetMethod);
astProp.Getter = new Accessor();
astProp.Getter.Body = CreateMethodBody(propDef.GetMethod);
astProp.AddAnnotation(propDef.GetMethod);
ConvertAttributes(astProp.Getter, propDef.GetMethod);
if ((getterModifiers & Modifiers.VisibilityMask) != (astProp.Modifiers & Modifiers.VisibilityMask))
@ -788,12 +788,11 @@ namespace ICSharpCode.Decompiler.Ast @@ -788,12 +788,11 @@ namespace ICSharpCode.Decompiler.Ast
// Create mapping - used in debugger
MemberMapping methodMapping = propDef.SetMethod.CreateCodeMapping(CSharpCodeMapping.SourceCodeMappings);
astProp.Setter = new Accessor {
Body = AstMethodBodyBuilder.CreateMethodBody(propDef.SetMethod, context)
}.WithAnnotation(propDef.SetMethod);
astProp.Setter = new Accessor();
astProp.Setter.Body = CreateMethodBody(propDef.SetMethod);
astProp.Setter.AddAnnotation(propDef.SetMethod);
ConvertAttributes(astProp.Setter, propDef.SetMethod);
ConvertCustomAttributes(astProp.Setter, propDef.SetMethod.Parameters.Last(), AttributeTarget.Param);
ConvertCustomAttributes(astProp.Setter, propDef.SetMethod.Parameters.Last(), "param");
if ((setterModifiers & Modifiers.VisibilityMask) != (astProp.Modifiers & Modifiers.VisibilityMask))
astProp.Setter.Modifiers = setterModifiers & Modifiers.VisibilityMask;
@ -850,7 +849,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -850,7 +849,7 @@ namespace ICSharpCode.Decompiler.Ast
MemberMapping methodMapping = eventDef.AddMethod.CreateCodeMapping(CSharpCodeMapping.SourceCodeMappings);
astEvent.AddAccessor = new Accessor {
Body = AstMethodBodyBuilder.CreateMethodBody(eventDef.AddMethod, context)
Body = CreateMethodBody(eventDef.AddMethod)
}.WithAnnotation(eventDef.AddMethod);
ConvertAttributes(astEvent.AddAccessor, eventDef.AddMethod);
@ -861,7 +860,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -861,7 +860,7 @@ namespace ICSharpCode.Decompiler.Ast
MemberMapping methodMapping = eventDef.RemoveMethod.CreateCodeMapping(CSharpCodeMapping.SourceCodeMappings);
astEvent.RemoveAccessor = new Accessor {
Body = AstMethodBodyBuilder.CreateMethodBody(eventDef.RemoveMethod, context)
Body = CreateMethodBody(eventDef.RemoveMethod)
}.WithAnnotation(eventDef.RemoveMethod);
ConvertAttributes(astEvent.RemoveAccessor, eventDef.RemoveMethod);
@ -870,6 +869,16 @@ namespace ICSharpCode.Decompiler.Ast @@ -870,6 +869,16 @@ namespace ICSharpCode.Decompiler.Ast
return astEvent;
}
}
public bool DecompileMethodBodies { get; set; }
BlockStatement CreateMethodBody(MethodDefinition method, IEnumerable<ParameterDeclaration> parameters = null)
{
if (DecompileMethodBodies)
return AstMethodBodyBuilder.CreateMethodBody(method, context, parameters);
else
return null;
}
FieldDeclaration CreateField(FieldDefinition fieldDef)
{
@ -884,7 +893,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -884,7 +893,7 @@ namespace ICSharpCode.Decompiler.Ast
initializer.Initializer = new NullReferenceExpression();
} else {
TypeCode c = Type.GetTypeCode(fieldDef.Constant.GetType());
if (c >= TypeCode.SByte && c <= TypeCode.UInt64) {
if (c >= TypeCode.SByte && c <= TypeCode.UInt64 && !fieldDef.DeclaringType.IsEnum) {
initializer.Initializer = MakePrimitive((long)CSharpPrimitiveCast.Cast(TypeCode.Int64, fieldDef.Constant, false), fieldDef.FieldType);
} else {
initializer.Initializer = new PrimitiveExpression(fieldDef.Constant);
@ -899,7 +908,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -899,7 +908,7 @@ namespace ICSharpCode.Decompiler.Ast
{
var parameters = MakeParameters(method.Parameters, isLambda);
if (method.CallingConvention == MethodCallingConvention.VarArg) {
return parameters.Concat(new[] { new ParameterDeclaration { Name = "__arglist" } });
return parameters.Concat(new[] { new ParameterDeclaration { Type = new PrimitiveType("__arglist") } });
} else {
return parameters;
}
@ -1089,14 +1098,14 @@ namespace ICSharpCode.Decompiler.Ast @@ -1089,14 +1098,14 @@ namespace ICSharpCode.Decompiler.Ast
}
#endregion
ConvertCustomAttributes(attributedNode, methodDefinition.MethodReturnType, AttributeTarget.Return);
ConvertCustomAttributes(attributedNode, methodDefinition.MethodReturnType, "return");
if (methodDefinition.MethodReturnType.HasMarshalInfo) {
var marshalInfo = ConvertMarshalInfo(methodDefinition.MethodReturnType, methodDefinition.Module);
attributedNode.Attributes.Add(new AttributeSection(marshalInfo) { AttributeTarget = AttributeTarget.Return });
attributedNode.Attributes.Add(new AttributeSection(marshalInfo) { AttributeTarget = "return" });
}
}
internal static void ConvertAttributes(AttributedNode attributedNode, FieldDefinition fieldDefinition, AttributeTarget target = AttributeTarget.None)
internal static void ConvertAttributes(AttributedNode attributedNode, FieldDefinition fieldDefinition, string attributeTarget = null)
{
ConvertCustomAttributes(attributedNode, fieldDefinition);
@ -1104,19 +1113,19 @@ namespace ICSharpCode.Decompiler.Ast @@ -1104,19 +1113,19 @@ namespace ICSharpCode.Decompiler.Ast
if (fieldDefinition.HasLayoutInfo) {
Ast.Attribute fieldOffset = CreateNonCustomAttribute(typeof(FieldOffsetAttribute), fieldDefinition.Module);
fieldOffset.Arguments.Add(new PrimitiveExpression(fieldDefinition.Offset));
attributedNode.Attributes.Add(new AttributeSection(fieldOffset) { AttributeTarget = target });
attributedNode.Attributes.Add(new AttributeSection(fieldOffset) { AttributeTarget = attributeTarget });
}
#endregion
#region NonSerializedAttribute
if (fieldDefinition.IsNotSerialized) {
Ast.Attribute nonSerialized = CreateNonCustomAttribute(typeof(NonSerializedAttribute), fieldDefinition.Module);
attributedNode.Attributes.Add(new AttributeSection(nonSerialized) { AttributeTarget = target });
attributedNode.Attributes.Add(new AttributeSection(nonSerialized) { AttributeTarget = attributeTarget });
}
#endregion
if (fieldDefinition.HasMarshalInfo) {
attributedNode.Attributes.Add(new AttributeSection(ConvertMarshalInfo(fieldDefinition, fieldDefinition.Module)) { AttributeTarget = target });
attributedNode.Attributes.Add(new AttributeSection(ConvertMarshalInfo(fieldDefinition, fieldDefinition.Module)) { AttributeTarget = attributeTarget });
}
}
@ -1147,7 +1156,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -1147,7 +1156,7 @@ namespace ICSharpCode.Decompiler.Ast
return attr;
}
static void ConvertCustomAttributes(AstNode attributedNode, ICustomAttributeProvider customAttributeProvider, AttributeTarget target = AttributeTarget.None)
static void ConvertCustomAttributes(AstNode attributedNode, ICustomAttributeProvider customAttributeProvider, string attributeTarget = null)
{
if (customAttributeProvider.HasCustomAttributes) {
var attributes = new List<ICSharpCode.NRefactory.CSharp.Attribute>();
@ -1198,18 +1207,18 @@ namespace ICSharpCode.Decompiler.Ast @@ -1198,18 +1207,18 @@ namespace ICSharpCode.Decompiler.Ast
}
}
if (target == AttributeTarget.Module || target == AttributeTarget.Assembly) {
if (attributeTarget == "module" || attributeTarget == "assembly") {
// use separate section for each attribute
foreach (var attribute in attributes) {
var section = new AttributeSection();
section.AttributeTarget = target;
section.AttributeTarget = attributeTarget;
section.Attributes.Add(attribute);
attributedNode.AddChild(section, AttributedNode.AttributeRole);
}
} else if (attributes.Count > 0) {
// use single section for all attributes
var section = new AttributeSection();
section.AttributeTarget = target;
section.AttributeTarget = attributeTarget;
section.Attributes.AddRange(attributes);
attributedNode.AddChild(section, AttributedNode.AttributeRole);
}

18
ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

@ -4,9 +4,11 @@ using System.Collections.Generic; @@ -4,9 +4,11 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using ICSharpCode.Decompiler.Ast.Transforms;
using ICSharpCode.Decompiler.ILAst;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.PatternMatching;
using ICSharpCode.NRefactory.Utils;
using Mono.Cecil;
using Mono.Cecil.Cil;
@ -492,7 +494,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -492,7 +494,7 @@ namespace ICSharpCode.Decompiler.Ast
return new AssignmentExpression(new UnaryOperatorExpression(UnaryOperatorType.Dereference, arg1), arg2);
#endregion
case ILCode.Arglist:
return new ArgListExpression { IsAccess = true };
return new UndocumentedExpression { UndocumentedExpressionType = UndocumentedExpressionType.ArgListAccess };
case ILCode.Break: return InlineAssembly(byteCode, args);
case ILCode.Call:
case ILCode.CallGetter:
@ -612,10 +614,14 @@ namespace ICSharpCode.Decompiler.Ast @@ -612,10 +614,14 @@ namespace ICSharpCode.Decompiler.Ast
case ILCode.Mkrefany:
{
DirectionExpression dir = arg1 as DirectionExpression;
if (dir != null)
return new IdentifierExpression("__makeref").Invoke(dir.Expression.Detach());
else
if (dir != null) {
return new UndocumentedExpression {
UndocumentedExpressionType = UndocumentedExpressionType.MakeRef,
Arguments = { dir.Expression.Detach() }
};
} else {
return InlineAssembly(byteCode, args);
}
}
case ILCode.Newobj: {
Cecil.TypeReference declaringType = ((MethodReference)operand).DeclaringType;
@ -729,10 +735,10 @@ namespace ICSharpCode.Decompiler.Ast @@ -729,10 +735,10 @@ namespace ICSharpCode.Decompiler.Ast
}
BinaryOperatorExpression boe = expr as BinaryOperatorExpression;
if (boe != null && boe.Operator == BinaryOperatorType.Multiply && sizeOfExpression.Match(boe.Right) != null)
if (boe != null && boe.Operator == BinaryOperatorType.Multiply && sizeOfExpression.IsMatch(boe.Right))
return boe.Left.Detach();
if (sizeOfExpression.Match(expr) != null)
if (sizeOfExpression.IsMatch(expr))
return new PrimitiveExpression(1);
return new BinaryOperatorExpression(expr, BinaryOperatorType.Divide, sizeOfExpression);

2
ICSharpCode.Decompiler/Ast/CommentStatement.cs

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.PatternMatching;
using ICSharpCode.NRefactory.PatternMatching;
namespace ICSharpCode.Decompiler.Ast
{

25
ICSharpCode.Decompiler/Ast/NRefactoryExtensions.cs

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
using System;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.PatternMatching;
using ICSharpCode.NRefactory.PatternMatching;
namespace ICSharpCode.Decompiler.Ast
{
@ -44,5 +44,28 @@ namespace ICSharpCode.Decompiler.Ast @@ -44,5 +44,28 @@ namespace ICSharpCode.Decompiler.Ast
{
attribute.Arguments.Add(new AssignmentExpression(new IdentifierExpression(name), argument));
}
public static AstType ToType(this Pattern pattern)
{
return pattern;
}
public static Expression ToExpression(this Pattern pattern)
{
return pattern;
}
public static Statement ToStatement(this Pattern pattern)
{
return pattern;
}
public static Statement GetNextStatement(this Statement statement)
{
AstNode next = statement.NextSibling;
while (next != null && !(next is Statement))
next = next.NextSibling;
return (Statement)next;
}
}
}

6
ICSharpCode.Decompiler/Ast/Transforms/AddCheckedBlocks.cs

@ -180,8 +180,8 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -180,8 +180,8 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
BlockStatement newBlock = new BlockStatement();
// Move all statements except for the first
Statement next;
for (Statement stmt = firstStatement.NextStatement; stmt != lastStatement; stmt = next) {
next = stmt.NextStatement;
for (Statement stmt = firstStatement.GetNextStatement(); stmt != lastStatement; stmt = next) {
next = stmt.GetNextStatement();
newBlock.Add(stmt.Detach());
}
// Replace the first statement with the new (un)checked block
@ -276,7 +276,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -276,7 +276,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
costUncheckedContextCheckedBlockOpen += stmtResult.CostInCheckedContext;
nodesUncheckedContextCheckedBlockOpen += stmtResult.NodesToInsertInCheckedContext;
statement = statement.NextStatement;
statement = statement.GetNextStatement();
}
return new Result {

6
ICSharpCode.Decompiler/Ast/Transforms/CombineQueryExpressions.cs

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.PatternMatching;
using ICSharpCode.NRefactory.PatternMatching;
namespace ICSharpCode.Decompiler.Ast.Transforms
{
@ -54,7 +54,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -54,7 +54,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
}
} else {
Match m = castPattern.Match(fromClause.Expression);
if (m != null) {
if (m.Success) {
fromClause.Type = m.Get<AstType>("targetType").Single().Detach();
fromClause.Expression = m.Get<Expression>("inExpr").Single().Detach();
}
@ -82,7 +82,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -82,7 +82,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
if (!IsTransparentIdentifier(fromClause.Identifier))
return false;
Match match = selectTransparentIdentifierPattern.Match(innerQuery.Clauses.Last());
if (match == null)
if (!match.Success)
return false;
QuerySelectClause selectClause = (QuerySelectClause)innerQuery.Clauses.Last();
NamedArgumentExpression nae1 = match.Get<NamedArgumentExpression>("nae1").Single();

12
ICSharpCode.Decompiler/Ast/Transforms/ConvertConstructorCallIntoInitializer.cs

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.PatternMatching;
using ICSharpCode.NRefactory.PatternMatching;
using Mono.Cecil;
namespace ICSharpCode.Decompiler.Ast.Transforms
@ -55,17 +55,17 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -55,17 +55,17 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{
var instanceCtors = typeDeclaration.Members.OfType<ConstructorDeclaration>().Where(c => (c.Modifiers & Modifiers.Static) == 0).ToArray();
var instanceCtorsNotChainingWithThis = instanceCtors.Where(ctor => thisCallPattern.Match(ctor.Body.Statements.FirstOrDefault()) == null).ToArray();
var instanceCtorsNotChainingWithThis = instanceCtors.Where(ctor => !thisCallPattern.IsMatch(ctor.Body.Statements.FirstOrDefault())).ToArray();
if (instanceCtorsNotChainingWithThis.Length > 0 && typeDeclaration.ClassType == NRefactory.TypeSystem.ClassType.Class) {
// Recognize field initializers:
// Convert first statement in all ctors (if all ctors have the same statement) into a field initializer.
bool allSame;
do {
Match m = fieldInitializerPattern.Match(instanceCtorsNotChainingWithThis[0].Body.FirstOrDefault());
if (m == null)
if (!m.Success)
break;
FieldDefinition fieldDef = m.Get("fieldAccess").Single().Annotation<FieldReference>().ResolveWithinSameModule();
FieldDefinition fieldDef = m.Get<AstNode>("fieldAccess").Single().Annotation<FieldReference>().ResolveWithinSameModule();
if (fieldDef == null)
break;
AttributedNode fieldOrEventDecl = typeDeclaration.Members.FirstOrDefault(f => f.Annotation<FieldDefinition>() == fieldDef);
@ -74,7 +74,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -74,7 +74,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
allSame = true;
for (int i = 1; i < instanceCtorsNotChainingWithThis.Length; i++) {
if (instanceCtors[0].Body.First().Match(instanceCtorsNotChainingWithThis[i].Body.FirstOrDefault()) == null)
if (!instanceCtors[0].Body.First().IsMatch(instanceCtorsNotChainingWithThis[i].Body.FirstOrDefault()))
allSame = false;
}
if (allSame) {
@ -93,7 +93,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -93,7 +93,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
ConstructorDeclaration emptyCtor = new ConstructorDeclaration();
emptyCtor.Modifiers = ((typeDeclaration.Modifiers & Modifiers.Abstract) == Modifiers.Abstract ? Modifiers.Protected : Modifiers.Public);
emptyCtor.Body = new BlockStatement();
if (emptyCtor.Match(instanceCtors[0]) != null)
if (emptyCtor.IsMatch(instanceCtors[0]))
instanceCtors[0].Remove();
}

2
ICSharpCode.Decompiler/Ast/Transforms/DeclareVariables.cs

@ -200,7 +200,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -200,7 +200,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
}
// If we can move the variable into the sub-block, we need to ensure that the remaining code
// does not use the value that was assigned by the first sub-block
Statement nextStatement = stmt.NextStatement;
Statement nextStatement = stmt.GetNextStatement();
if (nextStatement != null) {
// Analyze the range from the next statement to the end of the block
daa.SetAnalyzedRange(nextStatement, block);

12
ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs

@ -9,7 +9,7 @@ using System.Threading; @@ -9,7 +9,7 @@ using System.Threading;
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.ILAst;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.PatternMatching;
using ICSharpCode.NRefactory.PatternMatching;
using Mono.Cecil;
namespace ICSharpCode.Decompiler.Ast.Transforms
@ -270,16 +270,16 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -270,16 +270,16 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
base.VisitBlockStatement(blockStatement, data);
foreach (ExpressionStatement stmt in blockStatement.Statements.OfType<ExpressionStatement>().ToArray()) {
Match displayClassAssignmentMatch = displayClassAssignmentPattern.Match(stmt);
if (displayClassAssignmentMatch == null)
if (!displayClassAssignmentMatch.Success)
continue;
ILVariable variable = displayClassAssignmentMatch.Get("variable").Single().Annotation<ILVariable>();
ILVariable variable = displayClassAssignmentMatch.Get<AstNode>("variable").Single().Annotation<ILVariable>();
if (variable == null)
continue;
TypeDefinition type = variable.Type.ResolveWithinSameModule();
if (!IsPotentialClosure(context, type))
continue;
if (displayClassAssignmentMatch.Get("type").Single().Annotation<TypeReference>().ResolveWithinSameModule() != type)
if (displayClassAssignmentMatch.Get<AstType>("type").Single().Annotation<TypeReference>().ResolveWithinSameModule() != type)
continue;
// Looks like we found a display class creation. Now let's verify that the variable is used only for field accesses:
@ -320,9 +320,9 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -320,9 +320,9 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
)
);
Match m = closureFieldAssignmentPattern.Match(cur);
if (m != null) {
if (m.Success) {
FieldDefinition fieldDef = m.Get<MemberReferenceExpression>("left").Single().Annotation<FieldReference>().ResolveWithinSameModule();
AstNode right = m.Get("right").Single();
AstNode right = m.Get<AstNode>("right").Single();
bool isParameter = false;
bool isDisplayClassParentPointerAssignment = false;
if (right is ThisReferenceExpression) {

58
ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs

@ -5,10 +5,11 @@ using System; @@ -5,10 +5,11 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ICSharpCode.Decompiler.ILAst;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.Analysis;
using ICSharpCode.NRefactory.CSharp.PatternMatching;
using ICSharpCode.NRefactory.PatternMatching;
using Mono.Cecil;
namespace ICSharpCode.Decompiler.Ast.Transforms
@ -160,15 +161,15 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -160,15 +161,15 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
public UsingStatement TransformUsings(ExpressionStatement node)
{
Match m1 = variableAssignPattern.Match(node);
if (m1 == null) return null;
if (!m1.Success) return null;
AstNode tryCatch = node.NextSibling;
Match m2 = usingTryCatchPattern.Match(tryCatch);
if (m2 == null) return null;
if (!m2.Success) return null;
string variableName = m1.Get<IdentifierExpression>("variable").Single().Identifier;
if (variableName == m2.Get<IdentifierExpression>("ident").Single().Identifier) {
if (m2.Has("valueType")) {
// if there's no if(x!=null), then it must be a value type
ILVariable v = m1.Get("variable").Single().Annotation<ILVariable>();
ILVariable v = m1.Get<AstNode>("variable").Single().Annotation<ILVariable>();
if (v == null || v.Type == null || !v.Type.IsValueType)
return null;
}
@ -270,7 +271,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -270,7 +271,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
public ForeachStatement TransformForeach(UsingStatement node)
{
Match m = foreachPattern.Match(node);
if (m == null)
if (!m.Success)
return null;
if (!(node.Parent is BlockStatement) && m.Has("variablesOutsideLoop")) {
// if there are variables outside the loop, we need to put those into the parent block, and that won't work if the direct parent isn't a block
@ -341,10 +342,10 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -341,10 +342,10 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
public ForStatement TransformFor(ExpressionStatement node)
{
Match m1 = variableAssignPattern.Match(node);
if (m1 == null) return null;
if (!m1.Success) return null;
AstNode next = node.NextSibling;
Match m2 = forPattern.Match(next);
if (m2 == null) return null;
if (!m2.Success) return null;
// ensure the variable in the for pattern is the same as in the declaration
if (m1.Get<IdentifierExpression>("variable").Single().Identifier != m2.Get<IdentifierExpression>("ident").Single().Identifier)
return null;
@ -379,7 +380,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -379,7 +380,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
public DoWhileStatement TransformDoWhile(WhileStatement whileLoop)
{
Match m = doWhilePattern.Match(whileLoop);
if (m != null) {
if (m.Success) {
DoWhileStatement doLoop = new DoWhileStatement();
doLoop.Condition = new UnaryOperatorExpression(UnaryOperatorType.Not, m.Get<Expression>("condition").Single().Detach());
doLoop.Condition.AcceptVisitor(new PushNegation(), null);
@ -439,19 +440,19 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -439,19 +440,19 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
public LockStatement TransformLock(ExpressionStatement node)
{
Match m1 = lockFlagInitPattern.Match(node);
if (m1 == null) return null;
if (!m1.Success) return null;
AstNode tryCatch = node.NextSibling;
Match m2 = lockTryCatchPattern.Match(tryCatch);
if (m2 == null) return null;
if (!m2.Success) return null;
if (m1.Get<IdentifierExpression>("variable").Single().Identifier == m2.Get<IdentifierExpression>("flag").Single().Identifier) {
Expression enter = m2.Get<Expression>("enter").Single();
IdentifierExpression exit = m2.Get<IdentifierExpression>("exit").Single();
if (exit.Match(enter) == null) {
if (!exit.IsMatch(enter)) {
// If exit and enter are not the same, then enter must be "exit = ..."
AssignmentExpression assign = enter as AssignmentExpression;
if (assign == null)
return null;
if (exit.Match(assign.Left) == null)
if (!exit.IsMatch(assign.Left))
return null;
enter = assign.Right;
// TODO: verify that 'obj' variable can be removed
@ -512,17 +513,17 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -512,17 +513,17 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
public SwitchStatement TransformSwitchOnString(IfElseStatement node)
{
Match m = switchOnStringPattern.Match(node);
if (m == null)
if (!m.Success)
return null;
if (m.Has("nonNullDefaultStmt") && !m.Has("nullStmt"))
return null;
// switchVar must be the same as switchExpr; or switchExpr must be an assignment and switchVar the left side of that assignment
if (m.Get("switchVar").Single().Match(m.Get("switchExpr").Single()) == null) {
if (!m.Get("switchVar").Single().IsMatch(m.Get("switchExpr").Single())) {
AssignmentExpression assign = m.Get("switchExpr").Single() as AssignmentExpression;
if (m.Get("switchVar").Single().Match(assign.Left) == null)
if (!m.Get("switchVar").Single().IsMatch(assign.Left))
return null;
}
FieldReference cachedDictField = m.Get("cachedDict").Single().Annotation<FieldReference>();
FieldReference cachedDictField = m.Get<AstNode>("cachedDict").Single().Annotation<FieldReference>();
if (cachedDictField == null || !cachedDictField.DeclaringType.Name.StartsWith("<PrivateImplementationDetails>", StringComparison.Ordinal))
return null;
List<Statement> dictCreation = m.Get<BlockStatement>("dictCreation").Single().Statements.ToList();
@ -616,8 +617,8 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -616,8 +617,8 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
if (!(cecilProperty.GetMethod.IsCompilerGenerated() && cecilProperty.SetMethod.IsCompilerGenerated()))
return null;
Match m = automaticPropertyPattern.Match(property);
if (m != null) {
FieldDefinition field = m.Get("fieldReference").Single().Annotation<FieldReference>().ResolveWithinSameModule();
if (m.Success) {
FieldDefinition field = m.Get<AstNode>("fieldReference").Single().Annotation<FieldReference>().ResolveWithinSameModule();
if (field.IsCompilerGenerated() && field.DeclaringType == cecilProperty.DeclaringType) {
RemoveCompilerGeneratedAttribute(property.Getter.Attributes);
RemoveCompilerGeneratedAttribute(property.Setter.Attributes);
@ -691,13 +692,13 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -691,13 +692,13 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
bool CheckAutomaticEventV4Match(Match m, CustomEventDeclaration ev, bool isAddAccessor)
{
if (m == null)
if (!m.Success)
return false;
if (m.Get<MemberReferenceExpression>("field").Single().MemberName != ev.Name)
return false; // field name must match event name
if (ev.ReturnType.Match(m.Get("type").Single()) == null)
if (!ev.ReturnType.IsMatch(m.Get("type").Single()))
return false; // variable types must match event type
var combineMethod = m.Get("delegateCombine").Single().Parent.Annotation<MethodReference>();
var combineMethod = m.Get<AstNode>("delegateCombine").Single().Parent.Annotation<MethodReference>();
if (combineMethod == null || combineMethod.Name != (isAddAccessor ? "Combine" : "Remove"))
return false;
return combineMethod.DeclaringType.FullName == "System.Delegate";
@ -723,7 +724,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -723,7 +724,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
FieldDefinition field = eventDef.DeclaringType.Fields.FirstOrDefault(f => f.Name == ev.Name);
if (field != null) {
ed.AddAnnotation(field);
AstBuilder.ConvertAttributes(ed, field, AttributeTarget.Field);
AstBuilder.ConvertAttributes(ed, field, "field");
}
}
@ -751,7 +752,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -751,7 +752,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
DestructorDeclaration TransformDestructor(MethodDeclaration methodDef)
{
Match m = destructorPattern.Match(methodDef);
if (m != null) {
if (m.Success) {
DestructorDeclaration dd = new DestructorDeclaration();
methodDef.Attributes.MoveTo(dd.Attributes);
dd.Modifiers = methodDef.Modifiers & ~(Modifiers.Protected | Modifiers.Override);
@ -781,7 +782,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -781,7 +782,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
/// </summary>
TryCatchStatement TransformTryCatchFinally(TryCatchStatement tryFinally)
{
if (tryCatchFinallyPattern.Match(tryFinally) != null) {
if (tryCatchFinallyPattern.IsMatch(tryFinally)) {
TryCatchStatement tryCatch = (TryCatchStatement)tryFinally.TryBlock.Statements.Single();
tryFinally.TryBlock = tryCatch.TryBlock.Detach();
tryCatch.CatchClauses.MoveTo(tryFinally.CatchClauses);
@ -803,15 +804,16 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -803,15 +804,16 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
this.name = type.Name;
}
protected override bool DoMatch(AstNode other, Match match)
public override bool DoMatch(INode other, Match match)
{
if (other == null)
AstNode o = other as AstNode;
if (o == null)
return false;
TypeReference tr = other.Annotation<TypeReference>();
TypeReference tr = o.Annotation<TypeReference>();
return tr != null && tr.Namespace == ns && tr.Name == name;
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
public override S AcceptVisitor<T, S>(IPatternAstVisitor<T, S> visitor, T data)
{
throw new NotImplementedException();
}

6
ICSharpCode.Decompiler/Ast/Transforms/PushNegation.cs

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.PatternMatching;
using ICSharpCode.NRefactory.PatternMatching;
namespace ICSharpCode.Decompiler.Ast.Transforms
{
@ -109,11 +109,11 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -109,11 +109,11 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
} else {
bool negate = false;
Match m = asCastIsNotNullPattern.Match(binaryOperatorExpression);
if (m == null) {
if (!m.Success) {
m = asCastIsNullPattern.Match(binaryOperatorExpression);
negate = true;
}
if (m != null) {
if (m.Success) {
Expression expr = m.Get<Expression>("expr").Single().Detach().IsType(m.Get<AstType>("type").Single().Detach());
if (negate)
expr = new UnaryOperatorExpression(UnaryOperatorType.Not, expr);

6
ICSharpCode.Decompiler/Ast/Transforms/ReplaceMethodCallsWithOperators.cs

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.NRefactory.CSharp.PatternMatching;
using ICSharpCode.NRefactory.PatternMatching;
using Mono.Cecil;
using Ast = ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp;
@ -176,7 +176,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -176,7 +176,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
// Combine "x = x op y" into "x op= y"
BinaryOperatorExpression binary = assignment.Right as BinaryOperatorExpression;
if (binary != null && assignment.Operator == AssignmentOperatorType.Assign) {
if (CanConvertToCompoundAssignment(assignment.Left) && assignment.Left.Match(binary.Left) != null) {
if (CanConvertToCompoundAssignment(assignment.Left) && assignment.Left.IsMatch(binary.Left)) {
assignment.Operator = GetAssignmentOperatorForBinaryOperator(binary.Operator);
if (assignment.Operator != AssignmentOperatorType.Assign) {
// If we found a shorter operator, get rid of the BinaryOperatorExpression:
@ -188,7 +188,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -188,7 +188,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
}
if (assignment.Operator == AssignmentOperatorType.Add || assignment.Operator == AssignmentOperatorType.Subtract) {
// detect increment/decrement
if (assignment.Right.Match(new PrimitiveExpression(1)) != null) {
if (assignment.Right.IsMatch(new PrimitiveExpression(1))) {
// only if it's not a custom operator
if (assignment.Annotation<MethodReference>() == null) {
UnaryOperatorType type;

4
ICSharpCode.Decompiler/Tests/Helpers/RemoveCompilerAttribute.cs

@ -14,14 +14,14 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -14,14 +14,14 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
{
var section = (AttributeSection)attribute.Parent;
SimpleType type = attribute.Type as SimpleType;
if (section.AttributeTarget == AttributeTarget.Assembly &&
if (section.AttributeTarget == "assembly" &&
(type.Identifier == "CompilationRelaxations" || type.Identifier == "RuntimeCompatibility"))
{
attribute.Remove();
if (section.Attributes.Count == 0)
section.Remove();
}
if (section.AttributeTarget == AttributeTarget.Module && type.Identifier == "UnverifiableCode")
if (section.AttributeTarget == "module" && type.Identifier == "UnverifiableCode")
{
attribute.Remove();
if (section.Attributes.Count == 0)

33
ILSpy/CSharpLanguage.cs

@ -23,6 +23,8 @@ using System.ComponentModel.Composition; @@ -23,6 +23,8 @@ using System.ComponentModel.Composition;
using System.IO;
using System.Linq;
using System.Resources;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xaml;
using System.Xml;
@ -423,7 +425,7 @@ namespace ICSharpCode.ILSpy @@ -423,7 +425,7 @@ namespace ICSharpCode.ILSpy
((ComposedType)astType).PointerRank--;
}
astType.AcceptVisitor(new OutputVisitor(w, new CSharpFormattingPolicy()), null);
astType.AcceptVisitor(new OutputVisitor(w, new CSharpFormattingOptions()), null);
return w.ToString();
}
@ -462,5 +464,34 @@ namespace ICSharpCode.ILSpy @@ -462,5 +464,34 @@ namespace ICSharpCode.ILSpy
{
return showAllMembers || !AstBuilder.MemberIsHidden(member, new DecompilationOptions().DecompilerSettings);
}
public override string GetTooltip(MemberReference member)
{
MethodDefinition md = member as MethodDefinition;
PropertyDefinition pd = member as PropertyDefinition;
EventDefinition ed = member as EventDefinition;
FieldDefinition fd = member as FieldDefinition;
if (md != null || pd != null || ed != null || fd != null) {
AstBuilder b = new AstBuilder(new DecompilerContext(member.Module) { Settings = new DecompilerSettings { UsingDeclarations = false } });
b.DecompileMethodBodies = false;
if (md != null)
b.AddMethod(md);
else if (pd != null)
b.AddProperty(pd);
else if (ed != null)
b.AddEvent(ed);
else
b.AddField(fd);
b.RunTransformations();
foreach (var attribute in b.CompilationUnit.Descendants.OfType<AttributeSection>())
attribute.Remove();
StringWriter w = new StringWriter();
b.GenerateCode(new PlainTextOutput(w));
return Regex.Replace(w.ToString(), @"\s+", " ").TrimEnd();
}
return base.GetTooltip(member);
}
}
}

7
ILSpy/ILSpy.csproj

@ -138,10 +138,12 @@ @@ -138,10 +138,12 @@
<Compile Include="TreeNodes\Analyzer\AnalyzeContextMenuEntry.cs" />
<Compile Include="TreeNodes\IMemberTreeNode.cs" />
<Compile Include="TreeNodes\XamlResourceNode.cs" />
<Compile Include="XmlDocKeyProvider.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedPropertyAccessorsTreeNode.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedPropertyOverridesTreeNode.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedPropertyTreeNode.cs" />
<Compile Include="XmlDoc\XmlDocKeyProvider.cs" />
<Compile Include="XmlDoc\XmlDocLoader.cs" />
<Compile Include="XmlDoc\XmlDocRenderer.cs" />
<EmbeddedResource Include="..\README.txt">
<Link>README.txt</Link>
</EmbeddedResource>
@ -278,6 +280,9 @@ @@ -278,6 +280,9 @@
<Name>ICSharpCode.TreeView</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="XmlDoc" />
</ItemGroup>
<ItemGroup>
<Folder Include="Options" />
</ItemGroup>

14
ILSpy/Language.cs

@ -105,7 +105,19 @@ namespace ICSharpCode.ILSpy @@ -105,7 +105,19 @@ namespace ICSharpCode.ILSpy
else
return type.Name;
}
/// <summary>
/// Converts a member signature to a string.
/// This is used for displaying the tooltip on a member reference.
/// </summary>
public virtual string GetTooltip(MemberReference member)
{
if (member is TypeReference)
return TypeToString((TypeReference)member, true);
else
return member.ToString();
}
public virtual string FormatPropertyName(PropertyDefinition property, bool? isIndexer = null)
{
if (property == null)

2
ILSpy/MainWindow.xaml.cs

@ -32,10 +32,12 @@ using System.Windows.Interop; @@ -32,10 +32,12 @@ using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using ICSharpCode.Decompiler;
using ICSharpCode.ILSpy.TextView;
using ICSharpCode.ILSpy.TreeNodes;
using ICSharpCode.ILSpy.TreeNodes.Analyzer;
using ICSharpCode.ILSpy.XmlDoc;
using ICSharpCode.TreeView;
using ICSharpCode.ILSpy.Debugger;
using ICSharpCode.ILSpy.Debugger.Services;

103
ILSpy/TextView/DecompilerTextView.cs

@ -45,8 +45,11 @@ using ICSharpCode.ILSpy.Debugger.AvalonEdit; @@ -45,8 +45,11 @@ using ICSharpCode.ILSpy.Debugger.AvalonEdit;
using ICSharpCode.ILSpy.Debugger.Bookmarks;
using ICSharpCode.ILSpy.Debugger.Tooltips;
using ICSharpCode.ILSpy.TreeNodes;
using ICSharpCode.ILSpy.XmlDoc;
using ICSharpCode.NRefactory.Documentation;
using ICSharpCode.NRefactory.TypeSystem;
using Microsoft.Win32;
using Mono.Cecil;
using TextEditorWeakEventManager = ICSharpCode.ILSpy.Debugger.AvalonEdit.TextEditorWeakEventManager;
namespace ICSharpCode.ILSpy.TextView
@ -146,85 +149,39 @@ namespace ICSharpCode.ILSpy.TextView @@ -146,85 +149,39 @@ namespace ICSharpCode.ILSpy.TextView
Mono.Cecil.Cil.OpCode code = (Mono.Cecil.Cil.OpCode)segment.Reference;
string encodedName = code.Code.ToString();
string opCodeHex = code.Size > 1 ? string.Format("0x{0:x2}{1:x2}", code.Op1, code.Op2) : string.Format("0x{0:x2}", code.Op2);
string documentationFile = FindDocumentation("mscorlib.xml");
string text = "";
if (documentationFile != null){
XmlDocumentationProvider provider = new XmlDocumentationProvider(documentationFile);
string documentation = provider.GetDocumentation("F:System.Reflection.Emit.OpCodes." + encodedName);
if (documentation != null)
text = StripXml(documentation);
XmlDocumentationProvider docProvider = XmlDocLoader.MscorlibDocumentation;
if (docProvider != null){
string documentation = docProvider.GetDocumentation("F:System.Reflection.Emit.OpCodes." + encodedName);
if (documentation != null) {
XmlDocRenderer renderer = new XmlDocRenderer();
renderer.AppendText(string.Format("{0} ({1}) - ", code.Name, opCodeHex));
renderer.AddXmlDocumentation(documentation);
return renderer.CreateTextBlock();
}
}
return string.Format("{0} ({1}): {2}", code.Name, opCodeHex, text);
}
return null;
}
string StripXml(string xmlText)
{
try {
using (XmlTextReader xml = new XmlTextReader(new StringReader(xmlText))) {
StringBuilder ret = new StringBuilder();
while (xml.Read()) {
if (xml.NodeType == XmlNodeType.Element) {
string elname = xml.Name.ToLowerInvariant();
switch (elname) {
case "summary":
break;
case "br":
case "para":
ret.AppendLine();
break;
default:
xml.Skip();
break;
}
} else if (xml.NodeType == XmlNodeType.Text) {
ret.Append(Regex.Replace(xml.Value, @"\s+", " "));
}
return string.Format("{0} ({1})", code.Name, opCodeHex);
} else if (segment.Reference is MemberReference) {
MemberReference mr = (MemberReference)segment.Reference;
// if possible, resolve the reference
if (mr is TypeReference) {
mr = ((TypeReference)mr).Resolve() ?? mr;
} else if (mr is MethodReference) {
mr = ((MethodReference)mr).Resolve() ?? mr;
}
XmlDocumentationProvider docProvider = XmlDocLoader.LoadDocumentation(mr.Module);
if (docProvider != null) {
XmlDocRenderer renderer = new XmlDocRenderer();
renderer.AppendText(MainWindow.Instance.CurrentLanguage.GetTooltip(mr));
string documentation = docProvider.GetDocumentation(XmlDocKeyProvider.GetKey(mr));
if (documentation != null) {
renderer.AppendText(Environment.NewLine);
renderer.AddXmlDocumentation(documentation);
}
return ret.ToString();
return renderer.CreateTextBlock();
}
} catch (XmlException) {
return null; // invalid XML docu
}
}
string FindDocumentation(string fileName)
{
string path = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
List<string> names = new List<string>();
EnumerateCultures(CultureInfo.CurrentCulture, names);
names.Add("en");
names.Add("en-US");
names.Add("en-GB");
foreach (string name in names) {
string location = Path.Combine(path, name, fileName);
if (File.Exists(location))
return location;
}
path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), @"Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0");
string loc = Path.Combine(path, fileName);
if (File.Exists(loc)) {
return loc;
}
return null;
}
void EnumerateCultures(CultureInfo info, List<string> names)
{
while (info != null) {
names.Add(info.Name);
info = info.Parent;
if (info == info.Parent)
return;
}
}
#endregion
#region RunWithCancellation

9
ILSpy/XmlDocKeyProvider.cs → ILSpy/XmlDoc/XmlDocKeyProvider.cs

@ -8,12 +8,12 @@ using System.Linq; @@ -8,12 +8,12 @@ using System.Linq;
using System.Text;
using Mono.Cecil;
namespace ICSharpCode.ILSpy
namespace ICSharpCode.ILSpy.XmlDoc
{
/// <summary>
/// Provides XML documentation tags.
/// </summary>
sealed class XmlDocKeyProvider
public sealed class XmlDocKeyProvider
{
#region GetKey
public static string GetKey(MemberReference member)
@ -33,7 +33,10 @@ namespace ICSharpCode.ILSpy @@ -33,7 +33,10 @@ namespace ICSharpCode.ILSpy
b.Append("M:");
AppendTypeName(b, member.DeclaringType);
b.Append('.');
b.Append(member.Name);
if (member.Name == ".ctor")
b.Append("#ctor");
else
b.Append(member.Name);
IList<ParameterDefinition> parameters;
if (member is PropertyDefinition) {
parameters = ((PropertyDefinition)member).Parameters;

117
ILSpy/XmlDoc/XmlDocLoader.cs

@ -0,0 +1,117 @@ @@ -0,0 +1,117 @@
// 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.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using ICSharpCode.NRefactory.Documentation;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.XmlDoc
{
/// <summary>
/// Helps finding and loading .xml documentation.
/// </summary>
public static class XmlDocLoader
{
static readonly Lazy<XmlDocumentationProvider> mscorlibDocumentation = new Lazy<XmlDocumentationProvider>(LoadMscorlibDocumentation);
static readonly ConditionalWeakTable<ModuleDefinition, XmlDocumentationProvider> cache = new ConditionalWeakTable<ModuleDefinition, XmlDocumentationProvider>();
static XmlDocumentationProvider LoadMscorlibDocumentation()
{
string xmlDocFile = FindXmlDocumentation("mscorlib.dll", TargetRuntime.Net_4_0)
?? FindXmlDocumentation("mscorlib.dll", TargetRuntime.Net_2_0);
if (xmlDocFile != null)
return new XmlDocumentationProvider(xmlDocFile);
else
return null;
}
public static XmlDocumentationProvider MscorlibDocumentation {
get { return mscorlibDocumentation.Value; }
}
public static XmlDocumentationProvider LoadDocumentation(ModuleDefinition module)
{
if (module == null)
throw new ArgumentNullException("module");
lock (cache) {
XmlDocumentationProvider xmlDoc;
if (!cache.TryGetValue(module, out xmlDoc)) {
string xmlDocFile = LookupLocalizedXmlDoc(module.FullyQualifiedName);
if (xmlDocFile == null) {
xmlDocFile = FindXmlDocumentation(Path.GetFileName(module.FullyQualifiedName), module.Runtime);
}
if (xmlDocFile != null) {
xmlDoc = new XmlDocumentationProvider(xmlDocFile);
cache.Add(module, xmlDoc);
} else {
xmlDoc = null;
}
}
return xmlDoc;
}
}
static readonly string referenceAssembliesPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), @"Reference Assemblies\Microsoft\\Framework");
static readonly string frameworkPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"Microsoft.NET\Framework");
static string FindXmlDocumentation(string assemblyFileName, TargetRuntime runtime)
{
string fileName;
switch (runtime) {
case TargetRuntime.Net_1_0:
fileName = LookupLocalizedXmlDoc(Path.Combine(frameworkPath, "v1.0.3705", assemblyFileName));
break;
case TargetRuntime.Net_1_1:
fileName = LookupLocalizedXmlDoc(Path.Combine(frameworkPath, "v1.1.4322", assemblyFileName));
break;
case TargetRuntime.Net_2_0:
fileName = LookupLocalizedXmlDoc(Path.Combine(frameworkPath, "v2.0.50727", assemblyFileName))
?? LookupLocalizedXmlDoc(Path.Combine(referenceAssembliesPath, "v3.5"))
?? LookupLocalizedXmlDoc(Path.Combine(referenceAssembliesPath, "v3.0"))
?? LookupLocalizedXmlDoc(Path.Combine(referenceAssembliesPath, @".NETFramework\v3.5\Profile\Client"));
break;
case TargetRuntime.Net_4_0:
default:
fileName = LookupLocalizedXmlDoc(Path.Combine(referenceAssembliesPath, @".NETFramework\v4.0", assemblyFileName))
?? LookupLocalizedXmlDoc(Path.Combine(frameworkPath, "v4.0.30319", assemblyFileName));
break;
}
return fileName;
}
static string LookupLocalizedXmlDoc(string fileName)
{
string xmlFileName = Path.ChangeExtension(fileName, ".xml");
string currentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
string localizedXmlDocFile = GetLocalizedName(xmlFileName, currentCulture);
Debug.WriteLine("Try find XMLDoc @" + localizedXmlDocFile);
if (File.Exists(localizedXmlDocFile)) {
return localizedXmlDocFile;
}
Debug.WriteLine("Try find XMLDoc @" + xmlFileName);
if (File.Exists(xmlFileName)) {
return xmlFileName;
}
if (currentCulture != "en") {
string englishXmlDocFile = GetLocalizedName(xmlFileName, "en");
Debug.WriteLine("Try find XMLDoc @" + englishXmlDocFile);
if (File.Exists(englishXmlDocFile)) {
return englishXmlDocFile;
}
}
return null;
}
static string GetLocalizedName(string fileName, string language)
{
string localizedXmlDocFile = Path.GetDirectoryName(fileName);
localizedXmlDocFile = Path.Combine(localizedXmlDocFile, language);
localizedXmlDocFile = Path.Combine(localizedXmlDocFile, Path.GetFileName(fileName));
return localizedXmlDocFile;
}
}
}

122
ILSpy/XmlDoc/XmlDocRenderer.cs

@ -0,0 +1,122 @@ @@ -0,0 +1,122 @@
// 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.Diagnostics;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Controls;
using System.Xml;
namespace ICSharpCode.ILSpy.XmlDoc
{
/// <summary>
/// Renders XML documentation into a WPF <see cref="TextBlock"/>.
/// </summary>
public class XmlDocRenderer
{
StringBuilder ret = new StringBuilder();
public void AppendText(string text)
{
ret.Append(text);
}
public void AddXmlDocumentation(string xmlDocumentation)
{
if (xmlDocumentation == null)
return;
Debug.WriteLine(xmlDocumentation);
try {
XmlTextReader r = new XmlTextReader(new StringReader("<docroot>" + xmlDocumentation + "</docroot>"));
r.XmlResolver = null;
AddXmlDocumentation(r);
} catch (XmlException) {
}
}
static readonly Regex whitespace = new Regex(@"\s+");
public void AddXmlDocumentation(XmlReader xml)
{
while (xml.Read()) {
if (xml.NodeType == XmlNodeType.Element) {
string elname = xml.Name.ToLowerInvariant();
switch (elname) {
case "filterpriority":
case "remarks":
xml.Skip();
break;
case "example":
ret.Append(Environment.NewLine);
ret.Append("Example:");
ret.Append(Environment.NewLine);
break;
case "exception":
ret.Append(Environment.NewLine);
ret.Append(GetCref(xml["cref"]));
ret.Append(": ");
break;
case "returns":
ret.Append(Environment.NewLine);
ret.Append("Returns: ");
break;
case "see":
ret.Append(GetCref(xml["cref"]));
ret.Append(xml["langword"]);
break;
case "seealso":
ret.Append(Environment.NewLine);
ret.Append("See also: ");
ret.Append(GetCref(xml["cref"]));
break;
case "paramref":
ret.Append(xml["name"]);
break;
case "param":
ret.Append(Environment.NewLine);
ret.Append(whitespace.Replace(xml["name"].Trim()," "));
ret.Append(": ");
break;
case "typeparam":
ret.Append(Environment.NewLine);
ret.Append(whitespace.Replace(xml["name"].Trim()," "));
ret.Append(": ");
break;
case "value":
ret.Append(Environment.NewLine);
ret.Append("Value: ");
ret.Append(Environment.NewLine);
break;
case "br":
case "para":
ret.Append(Environment.NewLine);
break;
}
} else if (xml.NodeType == XmlNodeType.Text) {
ret.Append(whitespace.Replace(xml.Value, " "));
}
}
}
static string GetCref(string cref)
{
if (cref == null || cref.Trim().Length==0) {
return "";
}
if (cref.Length < 2) {
return cref;
}
if (cref.Substring(1, 1) == ":") {
return cref.Substring(2, cref.Length - 2);
}
return cref;
}
public TextBlock CreateTextBlock()
{
return new TextBlock { Text = ret.ToString() };
}
}
}

4
NRefactory/ICSharpCode.NRefactory.Demo/MainForm.cs

@ -1,4 +1,4 @@ @@ -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)
using System;
@ -126,7 +126,7 @@ namespace ICSharpCode.NRefactory.Demo @@ -126,7 +126,7 @@ namespace ICSharpCode.NRefactory.Demo
void CSharpGenerateCodeButtonClick(object sender, EventArgs e)
{
StringWriter w = new StringWriter();
OutputVisitor output = new OutputVisitor(w, new CSharpFormattingPolicy());
OutputVisitor output = new OutputVisitor(w, new CSharpFormattingOptions());
compilationUnit.AcceptVisitor(output, null);
csharpCodeTextBox.Text = w.ToString();
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -6,7 +6,7 @@ using NUnit.Framework; @@ -6,7 +6,7 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
{
[TestFixture, Ignore("Query expressions not yet implemented")]
[TestFixture]
public class QueryExpressionTests
{
[Test]
@ -125,19 +125,17 @@ select new { c.Name, o.OrderID, o.Total }", @@ -125,19 +125,17 @@ select new { c.Name, o.OrderID, o.Total }",
},
new QueryWhereClause {
Condition = new BinaryOperatorExpression {
Left = new IdentifierExpression("c").Member("OrderDate").Member("Year"),
Left = new IdentifierExpression("o").Member("OrderDate").Member("Year"),
Operator = BinaryOperatorType.Equality,
Right = new PrimitiveExpression(2005)
}
},
new QuerySelectClause {
Expression = new ObjectCreateExpression {
Initializer = new ArrayInitializerExpression {
Elements = {
new IdentifierExpression("c").Member("Name"),
new IdentifierExpression("o").Member("OrderID"),
new IdentifierExpression("o").Member("Total")
}
Expression = new AnonymousTypeCreateExpression {
Initializer = {
new IdentifierExpression("c").Member("Name"),
new IdentifierExpression("o").Member("OrderID"),
new IdentifierExpression("o").Member("Total")
}
}
}
@ -221,5 +219,66 @@ select new { c.Name, o.OrderID, o.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
NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/TypeOfExpressionTests.cs

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

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

@ -3,44 +3,60 @@ @@ -3,44 +3,60 @@
using System;
using NUnit.Framework;
using ICSharpCode.NRefactory.PatternMatching;
namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
{
[TestFixture, Ignore]
[TestFixture]
public class TypeReferenceExpressionTests
{
[Test]
public void GlobalTypeReferenceExpression()
{
/*TypeReferenceExpression tr = ParseUtilCSharp.ParseExpression<TypeReferenceExpression>("global::System");
Assert.AreEqual("System", tr.TypeReference.Type);
Assert.IsTrue(tr.TypeReference.IsGlobal);*/
throw new NotImplementedException();
TypeReferenceExpression tr = ParseUtilCSharp.ParseExpression<TypeReferenceExpression>("global::System");
Assert.IsTrue (tr.IsMatch (new TypeReferenceExpression () {
Type = new MemberType () {
Target = new SimpleType ("global"),
IsDoubleColon = true,
MemberName = "System"
}
}));
}
/* TODO
[Test]
[Test, Ignore ("Doesn't work")]
public void GlobalTypeReferenceExpressionWithoutTypeName()
{
TypeReferenceExpression tr = ParseUtilCSharp.ParseExpression<TypeReferenceExpression>("global::", true);
Assert.AreEqual("?", tr.TypeReference.Type);
Assert.IsTrue(tr.TypeReference.IsGlobal);
Assert.IsTrue (tr.IsMatch (new TypeReferenceExpression () {
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()
{
MemberReferenceExpression fre = ParseUtilCSharp.ParseExpression<MemberReferenceExpression>("int.MaxValue");
Assert.AreEqual("MaxValue", fre.MemberName);
Assert.AreEqual("System.Int32", ((TypeReferenceExpression)fre.TargetObject).TypeReference.Type);
Assert.IsTrue (fre.IsMatch (new MemberReferenceExpression () {
Target = new TypeReferenceExpression () {
Type = new PrimitiveType("int")
},
MemberName = "MaxValue"
}));
}
[Test]
/* [Test]
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");
Assert.AreEqual("System.Int32", tre.TypeReference.Type);
}
*/
Assert.IsNotNull (tre.Match (new TypeReferenceExpression () {
Type = new SimpleType ("int")
}));
}*/
}
}

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

@ -3,28 +3,31 @@ @@ -3,28 +3,31 @@
using System;
using System.Linq;
using System.Text.RegularExpressions;
using ICSharpCode.NRefactory.PatternMatching;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
{
[TestFixture, Ignore]
[TestFixture]
public class AttributeSectionTests
{
[Test, Ignore]
[Test, Ignore("Parser crash")]
public void GlobalAttributeCSharp()
{
string program = @"[global::Microsoft.VisualBasic.CompilerServices.DesignerGenerated()]
[someprefix::DesignerGenerated()]
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);
//Assert.AreEqual("Microsoft.VisualBasic.CompilerServices.DesignerGenerated", decl.Attributes.First().Attributes.Single().Name);
//Assert.AreEqual("someprefix.DesignerGenerated", decl.Attributes.Last().Attributes.Single().Name);
TypeDeclaration decl = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program);
Assert.AreEqual(2, decl.Attributes.Count);
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()
{
string program = @"[assembly: System.Attribute()]";
@ -33,7 +36,7 @@ public class Form1 { @@ -33,7 +36,7 @@ public class Form1 {
Assert.AreEqual("assembly", decl.AttributeTarget);
}
[Test]
[Test, Ignore("assembly/module attributes are broken")]
public void AssemblyAttributeCSharpWithNamedArguments()
{
string program = @"[assembly: Foo(1, namedArg: 2, prop = 3)]";
@ -43,16 +46,25 @@ public class Form1 { @@ -43,16 +46,25 @@ public class Form1 {
Assert.AreEqual("Foo", a.Type);
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()
{
string program = @"[module: System.Attribute()]";
AttributeSection decl = ParseUtilCSharp.ParseGlobal<AttributeSection>(program);
Assert.AreEqual(new AstLocation(1, 1), decl.StartLocation);
Assert.AreEqual(AttributeTarget.Module, decl.AttributeTarget);
Assert.AreEqual("module", decl.AttributeTarget);
}
[Test]
@ -62,7 +74,28 @@ public class Form1 { @@ -62,7 +74,28 @@ public class Form1 {
TypeDeclaration type = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program);
AttributeSection decl = type.Attributes.Single();
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
NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/DelegateDeclarationTests.cs

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

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

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

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

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

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

@ -1,9 +1,11 @@ @@ -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)
using System;
using System.IO;
using System.Linq;
using ICSharpCode.NRefactory.PatternMatching;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser
@ -29,7 +31,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser @@ -29,7 +31,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
public static void AssertGlobal(string code, AstNode expectedNode)
{
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));
}
}
@ -50,20 +52,19 @@ namespace ICSharpCode.NRefactory.CSharp.Parser @@ -50,20 +52,19 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
public static void AssertStatement(string code, CSharp.Statement expectedStmt)
{
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));
}
}
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();
AstNode parsedExpression = parser.ParseExpression(new StringReader(expr));
Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors");
if (expectErrors && parsedExpression == null)
return default (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));
return (T)parsedExpression;
@ -72,15 +73,13 @@ namespace ICSharpCode.NRefactory.CSharp.Parser @@ -72,15 +73,13 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
public static void AssertExpression(string code, CSharp.Expression expectedExpr)
{
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));
}
}
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();
var members = parser.ParseTypeMembers(new StringReader(expr));
@ -95,7 +94,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser @@ -95,7 +94,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
public static void AssertTypeMember(string code, CSharp.AttributedNode expectedMember)
{
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));
}
}
@ -103,7 +102,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser @@ -103,7 +102,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
static string ToCSharp(AstNode node)
{
StringWriter w = new StringWriter();
node.AcceptVisitor(new OutputVisitor(w, new CSharpFormattingPolicy()), null);
node.AcceptVisitor(new OutputVisitor(w, new CSharpFormattingOptions()), null);
return w.ToString();
}
}

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

@ -17,7 +17,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements @@ -17,7 +17,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
Assert.AreEqual(0, blockStmt.Statements.Count());
}
[Test, Ignore("position isn't correct when only parsing a block")]
[Test]
public void ComplexBlockStatementPositionTest()
{
string code = @"{
@ -30,7 +30,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements @@ -30,7 +30,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
};
}";
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(2, blockStmt.EndLocation.Column);
Assert.AreEqual(9, blockStmt.EndLocation.Line);

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

@ -6,21 +6,43 @@ using NUnit.Framework; @@ -6,21 +6,43 @@ using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
{
[TestFixture, Ignore("fixed is not implemented")]
[TestFixture]
public class FixedStatementTests
{
[Test]
public void FixedStatementTest()
{
FixedStatement fixedStmt = ParseUtilCSharp.ParseStatement<FixedStatement>("fixed (int* ptr = &myIntArr) { }");
ParseUtilCSharp.AssertStatement(
"fixed (int* ptr = &myIntArr) { }",
"fixed (int* ptr = myIntArr) { }",
new FixedStatement {
Type = new PrimitiveType("int").MakePointerType(),
Variables = {
new VariableInitializer {
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()

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

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

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

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

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

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

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

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Linq;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
@ -9,11 +10,22 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements @@ -9,11 +10,22 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Statements
[TestFixture]
public class UsingStatementTests
{
[Test]
public void UsingStatementTest()
[Test, Ignore("Parser doesn't report the VariableDeclarationStatement")]
public void UsingStatementWithVariableDeclaration()
{
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
NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Statements/VariableDeclarationStatementTests.cs

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

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

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

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

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

@ -9,7 +9,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -9,7 +9,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
[TestFixture]
public class FieldDeclarationTests
{
[Test, Ignore("multidimensional array rank incorrect?")]
[Test]
public void SimpleFieldDeclarationTest()
{
ParseUtilCSharp.AssertTypeMember(
@ -56,12 +56,21 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -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()
{
ParseUtilCSharp.AssertTypeMember(
"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
NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/IndexerDeclarationTests.cs

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

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

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

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

@ -5,6 +5,7 @@ using System; @@ -5,6 +5,7 @@ using System;
using System.IO;
using System.Linq;
using NUnit.Framework;
using ICSharpCode.NRefactory.PatternMatching;
namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
{
@ -66,7 +67,7 @@ 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);
}
[Test, Ignore("explicit interface implementation not yet implemented")]
[Test]
public void PropertyImplementingInterfaceTest()
{
PropertyDeclaration pd = ParseUtilCSharp.ParseTypeMember<PropertyDeclaration>("int MyInterface.MyProperty { get {} } ");
@ -77,7 +78,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -77,7 +78,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
Assert.AreEqual("MyInterface", ((SimpleType)pd.PrivateImplementationType).Identifier);
}
[Test, Ignore("explicit interface implementation not yet implemented")]
[Test]
public void PropertyImplementingGenericInterfaceTest()
{
PropertyDeclaration pd = ParseUtilCSharp.ParseTypeMember<PropertyDeclaration>("int MyInterface<string>.MyProperty { get {} } ");
@ -85,7 +86,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -85,7 +86,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
Assert.IsFalse(pd.Getter.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
NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/LambdaTests.cs

@ -274,5 +274,19 @@ class TestClass { @@ -274,5 +274,19 @@ class TestClass {
var lrr = Resolve<LocalResolveResult>(program);
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
NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/OverloadResolutionTests.cs

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -221,7 +221,7 @@ namespace ICSharpCode.NRefactory.FormattingTests @@ -221,7 +221,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
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 visitior = new AstFormattingVisitor (policy, adapter);
@ -233,7 +233,7 @@ namespace ICSharpCode.NRefactory.FormattingTests @@ -233,7 +233,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
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 visitior = new AstFormattingVisitor (policy, adapter);
@ -245,7 +245,7 @@ namespace ICSharpCode.NRefactory.FormattingTests @@ -245,7 +245,7 @@ namespace ICSharpCode.NRefactory.FormattingTests
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);

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

@ -34,22 +34,24 @@ @@ -34,22 +34,24 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputPath>..\ICSharpCode.NRefactory\bin\Debug\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputPath>..\ICSharpCode.NRefactory\bin\Release\</OutputPath>
</PropertyGroup>
<ItemGroup>
<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.Core">
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
</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>
<Compile Include="CSharp\Analysis\DefiniteAssignmentTests.cs" />

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

@ -84,7 +84,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -84,7 +84,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
{
// class C<X> : C<C<X>> {}
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] }) }));
Assert.AreEqual(new [] { c }, c.GetAllBaseTypes(context).ToArray());
}

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

@ -140,15 +140,36 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -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]
public void PrintStatistics()
{
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;
InterningProvider p = new InterningProvider();
p.InternProject(pc);
CecilLoader loader = new CecilLoader();
loader.InterningProvider = p;
pc = LoadProjects(loader);
PrintStatistics(p);
loader = null;
p = null;
long memoryWithInternedPC = GC.GetTotalMemory(true) - startMemory;
GC.KeepAlive(pc);

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

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

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

@ -31,11 +31,9 @@ using System.Diagnostics; @@ -31,11 +31,9 @@ using System.Diagnostics;
using System.Linq;
using System.Threading;
using ICSharpCode.NRefactory.CSharp.PatternMatching;
namespace ICSharpCode.NRefactory.CSharp
{
public abstract class AstNode
public abstract class AstNode : PatternMatching.INode
{
#region Null
public static readonly AstNode Null = new NullAstNode ();
@ -66,6 +64,42 @@ namespace ICSharpCode.NRefactory.CSharp @@ -66,6 +64,42 @@ namespace ICSharpCode.NRefactory.CSharp
}
#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 prevSibling;
AstNode nextSibling;
@ -562,38 +596,32 @@ namespace ICSharpCode.NRefactory.CSharp @@ -562,38 +596,32 @@ namespace ICSharpCode.NRefactory.CSharp
public abstract S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data);
#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)
{
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

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

@ -6,7 +6,7 @@ using System.Collections; @@ -6,7 +6,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ICSharpCode.NRefactory.CSharp.PatternMatching;
using ICSharpCode.NRefactory.PatternMatching;
namespace ICSharpCode.NRefactory.CSharp
{
@ -159,39 +159,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -159,39 +159,7 @@ namespace ICSharpCode.NRefactory.CSharp
internal bool DoMatch(AstNodeCollection<T> other, Match match)
{
Stack<AstNode> patternStack = new Stack<AstNode>();
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;
return Pattern.DoMatchCollection(role, node.FirstChild, other.node.FirstChild, match);
}
public void InsertAfter(T existingItem, T newItem)

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

@ -31,20 +31,78 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,20 +31,78 @@ namespace ICSharpCode.NRefactory.CSharp
}
#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 {
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()
{
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)
{
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>
/// Builds an expression that can be used to access a static member on this type.
/// </summary>

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

@ -440,6 +440,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -440,6 +440,11 @@ namespace ICSharpCode.NRefactory.CSharp
return VisitChildren (objectCreateExpression, data);
}
public virtual S VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression, T data)
{
return VisitChildren (anonymousTypeCreateExpression, data);
}
public virtual S VisitArrayCreateExpression (ArrayCreateExpression arrayObjectCreateExpression, T data)
{
return VisitChildren (arrayObjectCreateExpression, data);
@ -560,9 +565,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -560,9 +565,9 @@ namespace ICSharpCode.NRefactory.CSharp
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)
@ -584,5 +589,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -584,5 +589,10 @@ namespace ICSharpCode.NRefactory.CSharp
{
return VisitChildren (emptyExpression, data);
}
public virtual S VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern, T data)
{
return VisitChildren (placeholder, data);
}
}
}

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

@ -60,6 +60,24 @@ namespace ICSharpCode.NRefactory.CSharp @@ -60,6 +60,24 @@ namespace ICSharpCode.NRefactory.CSharp
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)
{
return visitor.VisitAnonymousMethodExpression (this, data);

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

@ -0,0 +1,79 @@ @@ -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
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/Expressions/AsExpression.cs

@ -45,6 +45,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -45,6 +45,16 @@ namespace ICSharpCode.NRefactory.CSharp
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)
{
return visitor.VisitAsExpression (this, data);

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

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

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

@ -49,6 +49,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -49,6 +49,16 @@ namespace ICSharpCode.NRefactory.CSharp
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)
{
return visitor.VisitCastExpression (this, data);

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

@ -48,6 +48,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -48,6 +48,15 @@ namespace ICSharpCode.NRefactory.CSharp
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)
{
return visitor.VisitCheckedExpression (this, data);

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

@ -60,6 +60,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -60,6 +60,17 @@ namespace ICSharpCode.NRefactory.CSharp
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)
{
return visitor.VisitConditionalExpression (this, data);

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

@ -48,6 +48,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -48,6 +48,15 @@ namespace ICSharpCode.NRefactory.CSharp
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)
{
return visitor.VisitDefaultValueExpression (this, data);

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

@ -52,6 +52,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -52,6 +52,16 @@ namespace ICSharpCode.NRefactory.CSharp
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)
{
return visitor.VisitDirectionExpression (this, data);

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

@ -40,6 +40,42 @@ namespace ICSharpCode.NRefactory.CSharp @@ -40,6 +40,42 @@ namespace ICSharpCode.NRefactory.CSharp
}
#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 {
get {
return NodeType.Expression;
@ -57,7 +93,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -57,7 +93,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (IsNull)
return "Null";
StringWriter w = new StringWriter();
AcceptVisitor(new OutputVisitor(w, new CSharpFormattingPolicy()), null);
AcceptVisitor(new OutputVisitor(w, new CSharpFormattingOptions()), null);
return w.ToString();
}

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

@ -50,6 +50,24 @@ namespace ICSharpCode.NRefactory.CSharp @@ -50,6 +50,24 @@ namespace ICSharpCode.NRefactory.CSharp
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)
{
return visitor.VisitIndexerExpression (this, data);

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

@ -55,6 +55,24 @@ namespace ICSharpCode.NRefactory.CSharp @@ -55,6 +55,24 @@ namespace ICSharpCode.NRefactory.CSharp
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)
{
InvocationExpression o = other as InvocationExpression;

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

@ -59,6 +59,25 @@ namespace ICSharpCode.NRefactory.CSharp @@ -59,6 +59,25 @@ namespace ICSharpCode.NRefactory.CSharp
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)
{
return visitor.VisitMemberReferenceExpression (this, data);

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

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

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

@ -31,6 +31,28 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,6 +31,28 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
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)
{
return visitor.VisitNullReferenceExpression (this, data);

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

@ -61,6 +61,24 @@ namespace ICSharpCode.NRefactory.CSharp @@ -61,6 +61,24 @@ namespace ICSharpCode.NRefactory.CSharp
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)
{
return visitor.VisitObjectCreateExpression (this, data);

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

@ -44,6 +44,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -44,6 +44,15 @@ namespace ICSharpCode.NRefactory.CSharp
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)
{
return visitor.VisitParenthesizedExpression (this, data);

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

@ -48,6 +48,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -48,6 +48,15 @@ namespace ICSharpCode.NRefactory.CSharp
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)
{
return visitor.VisitSizeOfExpression (this, data);

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

@ -49,6 +49,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -49,6 +49,15 @@ namespace ICSharpCode.NRefactory.CSharp
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)
{
return visitor.VisitTypeOfExpression (this, data);

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

@ -21,6 +21,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -21,6 +21,15 @@ namespace ICSharpCode.NRefactory.CSharp
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)
{
TypeReferenceExpression o = other as TypeReferenceExpression;

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

@ -48,6 +48,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -48,6 +48,15 @@ namespace ICSharpCode.NRefactory.CSharp
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)
{
return visitor.VisitUncheckedExpression (this, data);

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
//
// ArgListExpression.cs
// UndocumentedExpression.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
@ -28,16 +28,25 @@ using System.Collections.Generic; @@ -28,16 +28,25 @@ using System.Collections.Generic;
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>
/// Represents the undocumented __arglist keyword.
/// Represents undocumented expressions.
/// </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;
}
public CSharpTokenNode ArgListToken {
public CSharpTokenNode UndocumentedToken {
get { return GetChildByRole (Roles.Keyword); }
}
@ -55,13 +64,13 @@ namespace ICSharpCode.NRefactory.CSharp @@ -55,13 +64,13 @@ namespace ICSharpCode.NRefactory.CSharp
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)
{
ArgListExpression o = other as ArgListExpression;
return o != null && this.IsAccess == o.IsAccess && this.Arguments.DoMatch(o.Arguments, match);
UndocumentedExpression o = other as UndocumentedExpression;
return o != null && this.UndocumentedExpressionType == o.UndocumentedExpressionType && this.Arguments.DoMatch(o.Arguments, match);
}
}
}

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

@ -35,6 +35,42 @@ namespace ICSharpCode.NRefactory.CSharp @@ -35,6 +35,42 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
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<CSharpTokenNode> TargetRole = new Role<CSharpTokenNode>("Target", CSharpTokenNode.Null);
@ -44,7 +80,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -44,7 +80,11 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public AttributeTarget AttributeTarget {
public CSharpTokenNode LBracketToken {
get { return GetChildByRole (Roles.LBracket); }
}
public string AttributeTarget {
get;
set;
}
@ -53,6 +93,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -53,6 +93,10 @@ namespace ICSharpCode.NRefactory.CSharp
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)
{
return visitor.VisitAttributeSection (this, data);
@ -73,29 +117,29 @@ namespace ICSharpCode.NRefactory.CSharp @@ -73,29 +117,29 @@ namespace ICSharpCode.NRefactory.CSharp
this.Attributes.Add(attr);
}
public static string GetAttributeTargetName(AttributeTarget attributeTarget)
{
switch (attributeTarget) {
case AttributeTarget.None:
return null;
case AttributeTarget.Assembly:
return "assembly";
case AttributeTarget.Module:
return "module";
case AttributeTarget.Type:
return "type";
case AttributeTarget.Param:
return "param";
case AttributeTarget.Field:
return "field";
case AttributeTarget.Return:
return "return";
case AttributeTarget.Method:
return "method";
default:
throw new NotSupportedException("Invalid value for AttributeTarget");
}
}
// public static string GetAttributeTargetName(AttributeTarget attributeTarget)
// {
// switch (attributeTarget) {
// case AttributeTarget.None:
// return null;
// case AttributeTarget.Assembly:
// return "assembly";
// case AttributeTarget.Module:
// return "module";
// case AttributeTarget.Type:
// return "type";
// case AttributeTarget.Param:
// return "param";
// case AttributeTarget.Field:
// return "field";
// case AttributeTarget.Return:
// return "return";
// case AttributeTarget.Method:
// return "method";
// default:
// throw new NotSupportedException("Invalid value for AttributeTarget");
// }
// }
}
public enum AttributeTarget {

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

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

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

@ -66,6 +66,22 @@ namespace ICSharpCode.NRefactory.CSharp @@ -66,6 +66,22 @@ namespace ICSharpCode.NRefactory.CSharp
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)
{
return visitor.VisitUsingAliasDeclaration (this, data);

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

@ -60,6 +60,20 @@ namespace ICSharpCode.NRefactory.CSharp @@ -60,6 +60,20 @@ namespace ICSharpCode.NRefactory.CSharp
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)
{
return visitor.VisitUsingDeclaration (this, data);

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

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

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

Loading…
Cancel
Save