mirror of https://github.com/icsharpcode/ILSpy.git
Browse Source
56fde51 Use "Role" suffix for the fixed field variable role. e8d8ff8 Merge NRefactory changes from ILSpy. d022808 Fixed parsing of enum member declarations. f030426 Added extern alias node. d8e26ed Added fixed field ast node. I thought about this a bit - it's a better solution to invent a new node for this construct even if it's reallly close to fields. Really close != same. 836e178 Fixed bug in formatting unit tests. c01ba21 Converted the unit tests. Some of them are failing - I expect it has to do with the adapter. 9b1913e Track API changes. 2bee26a Added AST formatting visitor. 749f5a8 Updated parser & mcs. 605a56a merged changes related to lambdas and expression finding from old NRefactory 8c36dd8 renamed VB.Dom to VB.Ast bf96506 DefiniteAssignmentAnalysis bugfix 4e1140d Fixed definite assignment analysis bug. ebc34e6 Add NextStatement/PreviousStatement properties. 6f2e9c2 Order the control flow nodes lexically, and allow restricting definite assignment analysis to a specific lexical range. 3cc6fab Allow performing definite assignment analysis without providing an ITypeResolveContext. 5660677 Add InsertAfter/InsertBefore to AstNodeCollection. ccfd4ea Evaluate constant expressions in definite assignment analysis. 3a4fdf2 Add support for non-custom attributes to CecilLoader. f68a49b Improve spacing in fixed statement output. 9974734 Use a property to return the list of annotations. 735cb85 Fix issues in definite assignment analysis. 65bf46a Set NRefactory back to .NET 4.0 (we're not going to port ILSpy to .NET 3.5) 76dfccc Add definite assignment analysis. a79d43d Add control flow analysis for the NRefactory C# AST. c33f33e Enable using patterns in place of catch clauses. 3ad453d Add OptionalNode for pattern matching. cfccfca AstNode: add Invoke() methods to AstType (builds InvocationExpression for static methods) 60b3164 NRefactory AstNode: add DescendantsAndSelf property. c6a8a1f Add support for Modifiers.Any (for pattern-matching) and for AttributeSection patterns. 73350e7 small code reformatting fdf1dac Indexer decompilation support. cafda5f Generate switch default case. Closes #26 0c9dec1 Fix output of float/double literals that are infinite or NaN. 0c9b5cb Remove "Attribute" suffix and add support for attributes on type parameters. 35d0426 Adjust ILSpy to NRefactory changes. c997b75 Merge commit '39fcd7d72f73d386455d00d63446601c99eafb83' bc195b8 Merge branch 'WithNUnit' of git://github.com/arturek/ILSpy f4f554d more attribute targets implemented. 74fd14a attributed parameter declaration. a07f545 Printing initializers of enum members. 20ceef1 Merge branch 'master' of git://github.com/icsharpcode/ILSpy into cust-attr 07c8c0c Use newlines in array initializers. 1cb5642 Merge commit '7ac091e93d8112b369425cceab64829c094e401c' f2c8607 Print a custom attribute's positional arguments. 212d39b Fix duplicate reference to Mono.Cecil. 5dfed88 Removed redundant int base type of enum. 8bd4e5d Basic output of custom attributes attached to types and methods. 9a1d759 Modifications of solution and project files made by VS2010. git-subtree-dir: NRefactory git-subtree-split: 56fde51b698e6c7b8ea23ebbc5caf0cd10bc4682pull/129/head
247 changed files with 25315 additions and 20588 deletions
@ -0,0 +1,201 @@
@@ -0,0 +1,201 @@
|
||||
// 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.Linq; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Analysis |
||||
{ |
||||
[TestFixture] |
||||
public class DefiniteAssignmentTests |
||||
{ |
||||
[Test] |
||||
public void TryFinally() |
||||
{ |
||||
BlockStatement block = new BlockStatement { |
||||
new TryCatchStatement { |
||||
TryBlock = new BlockStatement { |
||||
new GotoStatement("LABEL"), |
||||
new AssignmentExpression(new IdentifierExpression("i"), new PrimitiveExpression(1)) |
||||
}, |
||||
CatchClauses = { |
||||
new CatchClause { |
||||
Body = new BlockStatement { |
||||
new AssignmentExpression(new IdentifierExpression("i"), new PrimitiveExpression(3)) |
||||
} |
||||
} |
||||
}, |
||||
FinallyBlock = new BlockStatement { |
||||
new AssignmentExpression(new IdentifierExpression("j"), new PrimitiveExpression(5)) |
||||
} |
||||
}, |
||||
new LabelStatement { Label = "LABEL" }, |
||||
new EmptyStatement() |
||||
}; |
||||
TryCatchStatement tryCatchStatement = (TryCatchStatement)block.Statements.First(); |
||||
Statement stmt1 = tryCatchStatement.TryBlock.Statements.ElementAt(1); |
||||
Statement stmt3 = tryCatchStatement.CatchClauses.Single().Body.Statements.Single(); |
||||
Statement stmt5 = tryCatchStatement.FinallyBlock.Statements.Single(); |
||||
LabelStatement label = (LabelStatement)block.Statements.ElementAt(1); |
||||
|
||||
DefiniteAssignmentAnalysis da = new DefiniteAssignmentAnalysis(block, CecilLoaderTests.Mscorlib); |
||||
da.Analyze("i"); |
||||
Assert.AreEqual(0, da.UnassignedVariableUses.Count); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusBefore(tryCatchStatement)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.CodeUnreachable, da.GetStatusBefore(stmt1)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.CodeUnreachable, da.GetStatusAfter(stmt1)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusBefore(stmt3)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusAfter(stmt3)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusBefore(stmt5)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusAfter(stmt5)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusAfter(tryCatchStatement)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusBefore(label)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusAfter(label)); |
||||
|
||||
da.Analyze("j"); |
||||
Assert.AreEqual(0, da.UnassignedVariableUses.Count); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusBefore(tryCatchStatement)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.CodeUnreachable, da.GetStatusBefore(stmt1)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.CodeUnreachable, da.GetStatusAfter(stmt1)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusBefore(stmt3)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusAfter(stmt3)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusBefore(stmt5)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusAfter(stmt5)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusAfter(tryCatchStatement)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusBefore(label)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusAfter(label)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ConditionalAnd() |
||||
{ |
||||
IfElseStatement ifStmt = new IfElseStatement { |
||||
Condition = new BinaryOperatorExpression { |
||||
Left = new BinaryOperatorExpression(new IdentifierExpression("x"), BinaryOperatorType.GreaterThan, new PrimitiveExpression(0)), |
||||
Operator = BinaryOperatorType.ConditionalAnd, |
||||
Right = new BinaryOperatorExpression { |
||||
Left = new ParenthesizedExpression { |
||||
Expression = new AssignmentExpression { |
||||
Left = new IdentifierExpression("i"), |
||||
Operator = AssignmentOperatorType.Assign, |
||||
Right = new IdentifierExpression("y") |
||||
} |
||||
}, |
||||
Operator = BinaryOperatorType.GreaterThanOrEqual, |
||||
Right = new PrimitiveExpression(0) |
||||
} |
||||
}, |
||||
TrueStatement = new BlockStatement(), |
||||
FalseStatement = new BlockStatement() |
||||
}; |
||||
DefiniteAssignmentAnalysis da = new DefiniteAssignmentAnalysis(ifStmt, CecilLoaderTests.Mscorlib); |
||||
da.Analyze("i"); |
||||
Assert.AreEqual(0, da.UnassignedVariableUses.Count); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusBefore(ifStmt)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusBefore(ifStmt.TrueStatement)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusBefore(ifStmt.FalseStatement)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusAfter(ifStmt)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ConditionalOr() |
||||
{ |
||||
IfElseStatement ifStmt = new IfElseStatement { |
||||
Condition = new BinaryOperatorExpression { |
||||
Left = new BinaryOperatorExpression(new IdentifierExpression("x"), BinaryOperatorType.GreaterThan, new PrimitiveExpression(0)), |
||||
Operator = BinaryOperatorType.ConditionalOr, |
||||
Right = new BinaryOperatorExpression { |
||||
Left = new ParenthesizedExpression { |
||||
Expression = new AssignmentExpression { |
||||
Left = new IdentifierExpression("i"), |
||||
Operator = AssignmentOperatorType.Assign, |
||||
Right = new IdentifierExpression("y") |
||||
} |
||||
}, |
||||
Operator = BinaryOperatorType.GreaterThanOrEqual, |
||||
Right = new PrimitiveExpression(0) |
||||
} |
||||
}, |
||||
TrueStatement = new BlockStatement(), |
||||
FalseStatement = new BlockStatement() |
||||
}; |
||||
DefiniteAssignmentAnalysis da = new DefiniteAssignmentAnalysis(ifStmt, CecilLoaderTests.Mscorlib); |
||||
da.Analyze("i"); |
||||
Assert.AreEqual(0, da.UnassignedVariableUses.Count); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusBefore(ifStmt)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusBefore(ifStmt.TrueStatement)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusBefore(ifStmt.FalseStatement)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusAfter(ifStmt)); |
||||
} |
||||
|
||||
[Test] |
||||
public void WhileTrue() |
||||
{ |
||||
WhileStatement loop = new WhileStatement { |
||||
Condition = new PrimitiveExpression(true), |
||||
EmbeddedStatement = new BlockStatement { |
||||
new AssignmentExpression(new IdentifierExpression("i"), new PrimitiveExpression(0)), |
||||
new BreakStatement() |
||||
} |
||||
}; |
||||
DefiniteAssignmentAnalysis da = new DefiniteAssignmentAnalysis(loop, CecilLoaderTests.Mscorlib); |
||||
da.Analyze("i"); |
||||
Assert.AreEqual(0, da.UnassignedVariableUses.Count); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusBefore(loop)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusBefore(loop.EmbeddedStatement)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.CodeUnreachable, da.GetStatusAfter(loop.EmbeddedStatement)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusAfter(loop)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ForLoop() |
||||
{ |
||||
ForStatement loop = new ForStatement { |
||||
Initializers = { |
||||
new ExpressionStatement( |
||||
new AssignmentExpression(new IdentifierExpression("i"), new PrimitiveExpression(0)) |
||||
) |
||||
}, |
||||
Condition = new BinaryOperatorExpression(new IdentifierExpression("i"), BinaryOperatorType.LessThan, new PrimitiveExpression(1000)), |
||||
Iterators = { |
||||
new ExpressionStatement( |
||||
new AssignmentExpression { |
||||
Left = new IdentifierExpression("i"), |
||||
Operator = AssignmentOperatorType.Add, |
||||
Right = new IdentifierExpression("j") |
||||
} |
||||
) |
||||
}, |
||||
EmbeddedStatement = new ExpressionStatement( |
||||
new AssignmentExpression(new IdentifierExpression("j"), new IdentifierExpression("i")) |
||||
)}; |
||||
|
||||
DefiniteAssignmentAnalysis da = new DefiniteAssignmentAnalysis(loop, CecilLoaderTests.Mscorlib); |
||||
da.Analyze("i"); |
||||
Assert.AreEqual(0, da.UnassignedVariableUses.Count); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusBefore(loop)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusBefore(loop.Initializers.Single())); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusAfter(loop.Initializers.Single())); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusBeforeLoopCondition(loop)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusBefore(loop.EmbeddedStatement)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusAfter(loop.EmbeddedStatement)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusBefore(loop.Iterators.Single())); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusAfter(loop.Iterators.Single())); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusAfter(loop)); |
||||
|
||||
da.Analyze("j"); |
||||
Assert.AreEqual(0, da.UnassignedVariableUses.Count); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusBefore(loop)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusBefore(loop.Initializers.Single())); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusAfter(loop.Initializers.Single())); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusBeforeLoopCondition(loop)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusBefore(loop.EmbeddedStatement)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusAfter(loop.EmbeddedStatement)); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusBefore(loop.Iterators.Single())); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusAfter(loop.Iterators.Single())); |
||||
Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusAfter(loop)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,285 @@
@@ -0,0 +1,285 @@
|
||||
//
|
||||
// TastBlankLineFormatting.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2010 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.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.CSharp; |
||||
|
||||
namespace ICSharpCode.NRefactory.FormattingTests |
||||
{ |
||||
[TestFixture()] |
||||
public class TestBlankLineFormatting : TestBase |
||||
{ |
||||
[Test()] |
||||
public void TestBlankLinesAfterUsings () |
||||
{ |
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.BlankLinesAfterUsings = 2; |
||||
|
||||
var adapter = Test (policy, @"using System;
|
||||
using System.Text; |
||||
namespace Test |
||||
{ |
||||
}",
|
||||
@"using System;
|
||||
using System.Text; |
||||
|
||||
|
||||
namespace Test |
||||
{ |
||||
}");
|
||||
|
||||
policy.BlankLinesAfterUsings = 0; |
||||
Continue (policy, adapter, |
||||
@"using System;
|
||||
using System.Text; |
||||
namespace Test |
||||
{ |
||||
}");
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestBlankLinesBeforeUsings () |
||||
{ |
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.BlankLinesAfterUsings = 0; |
||||
policy.BlankLinesBeforeUsings = 2; |
||||
|
||||
var adapter = Test (policy, @"using System;
|
||||
using System.Text; |
||||
namespace Test |
||||
{ |
||||
}",
|
||||
@"
|
||||
|
||||
using System; |
||||
using System.Text; |
||||
namespace Test |
||||
{ |
||||
}");
|
||||
|
||||
policy.BlankLinesBeforeUsings = 0; |
||||
Continue (policy, adapter, |
||||
@"using System;
|
||||
using System.Text; |
||||
namespace Test |
||||
{ |
||||
}");
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestBlankLinesBeforeFirstDeclaration () |
||||
{ |
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.BlankLinesBeforeFirstDeclaration = 2; |
||||
|
||||
var adapter = Test (policy, @"namespace Test
|
||||
{ |
||||
class Test |
||||
{ |
||||
} |
||||
}",
|
||||
@"namespace Test
|
||||
{ |
||||
|
||||
|
||||
class Test |
||||
{ |
||||
} |
||||
}");
|
||||
|
||||
policy.BlankLinesBeforeFirstDeclaration = 0; |
||||
Continue (policy, adapter, |
||||
@"namespace Test
|
||||
{ |
||||
class Test |
||||
{ |
||||
} |
||||
}");
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestBlankLinesBetweenTypes () |
||||
{ |
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.BlankLinesBetweenTypes = 1; |
||||
|
||||
var adapter = Test (policy, @"namespace Test
|
||||
{ |
||||
class Test1 |
||||
{ |
||||
} |
||||
class Test2 |
||||
{ |
||||
} |
||||
class Test3 |
||||
{ |
||||
} |
||||
}",
|
||||
@"namespace Test
|
||||
{ |
||||
class Test1 |
||||
{ |
||||
} |
||||
|
||||
class Test2 |
||||
{ |
||||
} |
||||
|
||||
class Test3 |
||||
{ |
||||
} |
||||
}");
|
||||
|
||||
policy.BlankLinesBetweenTypes = 0; |
||||
Continue (policy, adapter, @"namespace Test
|
||||
{ |
||||
class Test1 |
||||
{ |
||||
} |
||||
class Test2 |
||||
{ |
||||
} |
||||
class Test3 |
||||
{ |
||||
} |
||||
}");
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestBlankLinesBetweenFields () |
||||
{ |
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.BlankLinesBetweenFields = 1; |
||||
|
||||
var adapter = Test (policy, @"class Test
|
||||
{ |
||||
int a; |
||||
int b; |
||||
int c; |
||||
}",
|
||||
@"class Test
|
||||
{ |
||||
int a; |
||||
|
||||
int b; |
||||
|
||||
int c; |
||||
}");
|
||||
|
||||
policy.BlankLinesBetweenFields = 0; |
||||
Continue (policy, adapter, @"class Test
|
||||
{ |
||||
int a; |
||||
int b; |
||||
int c; |
||||
}");
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestBlankLinesBetweenEventFields () |
||||
{ |
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.BlankLinesBetweenEventFields = 1; |
||||
|
||||
var adapter = Test (policy, @"class Test
|
||||
{ |
||||
public event EventHandler a; |
||||
public event EventHandler b; |
||||
public event EventHandler c; |
||||
}",
|
||||
@"class Test
|
||||
{ |
||||
public event EventHandler a; |
||||
|
||||
public event EventHandler b; |
||||
|
||||
public event EventHandler c; |
||||
}");
|
||||
|
||||
policy.BlankLinesBetweenEventFields = 0; |
||||
Continue (policy, adapter, |
||||
@"class Test
|
||||
{ |
||||
public event EventHandler a; |
||||
public event EventHandler b; |
||||
public event EventHandler c; |
||||
}");
|
||||
} |
||||
|
||||
[Test()] |
||||
public void TestBlankLinesBetweenMembers () |
||||
{ |
||||
CSharpFormattingPolicy policy = new CSharpFormattingPolicy (); |
||||
policy.BlankLinesBetweenMembers = 1; |
||||
|
||||
var adapter = Test (policy,@"class Test
|
||||
{ |
||||
void AMethod () |
||||
{ |
||||
} |
||||
void BMethod () |
||||
{ |
||||
} |
||||
void CMethod () |
||||
{ |
||||
} |
||||
}", @"class Test |
||||
{ |
||||
void AMethod () |
||||
{ |
||||
} |
||||
|
||||
void BMethod () |
||||
{ |
||||
} |
||||
|
||||
void CMethod () |
||||
{ |
||||
} |
||||
}");
|
||||
|
||||
policy.BlankLinesBetweenMembers = 0; |
||||
Continue (policy, adapter, @"class Test
|
||||
{ |
||||
void AMethod () |
||||
{ |
||||
} |
||||
void BMethod () |
||||
{ |
||||
} |
||||
void CMethod () |
||||
{ |
||||
} |
||||
}");
|
||||
} |
||||
|
||||
|
||||
|
||||
} |
||||
} |
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,261 @@
@@ -0,0 +1,261 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.CSharp; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.FormattingTests |
||||
{ |
||||
/// <summary>
|
||||
/// Text editor test adapter. Only implemented for testing purposes. Don't use in production code.
|
||||
/// </summary>
|
||||
class TextEditorTestAdapter : ITextEditorAdapter |
||||
{ |
||||
string text; |
||||
|
||||
public string Text { |
||||
get { |
||||
return this.text; |
||||
} |
||||
} |
||||
|
||||
List<Delimiter> delimiters; |
||||
|
||||
struct Delimiter |
||||
{ |
||||
public readonly int Offset; |
||||
public readonly int Length; |
||||
|
||||
public int EndOffset { |
||||
get { return Offset + Length; } |
||||
} |
||||
|
||||
public Delimiter (int offset, int length) |
||||
{ |
||||
Offset = offset; |
||||
Length = length; |
||||
} |
||||
|
||||
public override string ToString () |
||||
{ |
||||
return string.Format ("[Delimiter: Offset={0}, Length={1}]", Offset, Length); |
||||
} |
||||
} |
||||
|
||||
static IEnumerable<Delimiter> FindDelimiter (string text) |
||||
{ |
||||
for (int i = 0; i < text.Length; i++) { |
||||
switch (text [i]) { |
||||
case '\r': |
||||
if (i + 1 < text.Length && text [i + 1] == '\n') { |
||||
yield return new Delimiter (i, 2); |
||||
i++; |
||||
} else { |
||||
yield return new Delimiter (i, 1); |
||||
} |
||||
break; |
||||
case '\n': |
||||
yield return new Delimiter (i, 1); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public TextEditorTestAdapter (string text) |
||||
{ |
||||
this.text = text; |
||||
delimiters = new List<Delimiter> (FindDelimiter (text)); |
||||
} |
||||
|
||||
class Segment |
||||
{ |
||||
public readonly int Offset; |
||||
public readonly int Length; |
||||
public readonly int DelimiterLength; |
||||
|
||||
public Segment (int offset, int length, int delimiterLength) |
||||
{ |
||||
this.Offset = offset; |
||||
this.Length = length; |
||||
this.DelimiterLength = delimiterLength; |
||||
} |
||||
|
||||
public override string ToString () |
||||
{ |
||||
return string.Format ("[Segment: Offset={0}, Length={1}, DelimiterLength={2}]", Offset, Length, DelimiterLength); |
||||
} |
||||
} |
||||
|
||||
Segment Get (int number) |
||||
{ |
||||
number--; |
||||
if (number < 0 || number - 1 >= delimiters.Count) |
||||
return null; |
||||
int startOffset = number > 0 ? delimiters [number - 1].EndOffset : 0; |
||||
int endOffset; |
||||
int delimiterLength; |
||||
if (number < delimiters.Count) { |
||||
endOffset = delimiters [number].EndOffset; |
||||
delimiterLength = delimiters [number].Length; |
||||
} else { |
||||
endOffset = text.Length; |
||||
delimiterLength = 0; |
||||
} |
||||
return new Segment (startOffset, endOffset - startOffset, delimiterLength); |
||||
} |
||||
|
||||
public void ApplyChanges (List<Change> changes) |
||||
{ |
||||
changes.Sort ((x, y) => x.Offset.CompareTo (y.Offset)); |
||||
changes.Reverse (); |
||||
foreach (var change in changes) { |
||||
text = text.Substring (0, change.Offset) + change.InsertedText + text.Substring (change.Offset + change.RemovedChars); |
||||
} |
||||
delimiters = new List<Delimiter> (FindDelimiter (text)); |
||||
} |
||||
|
||||
#region ITextEditorAdapter implementation
|
||||
public int LocationToOffset (int line, int col) |
||||
{ |
||||
Segment seg = Get (line); |
||||
if (seg == null) |
||||
return 0; |
||||
return seg.Offset + col - 1; |
||||
} |
||||
|
||||
public char GetCharAt (int offset) |
||||
{ |
||||
if (offset < 0 || offset >= text.Length) |
||||
return '\0'; |
||||
return text [offset]; |
||||
} |
||||
|
||||
public string GetTextAt (int offset, int length) |
||||
{ |
||||
if (offset < 0 || offset + length >= text.Length) |
||||
return ""; |
||||
if (length <= 0) |
||||
return ""; |
||||
|
||||
return text.Substring (offset, length); |
||||
} |
||||
|
||||
public int GetEditableLength (int lineNumber) |
||||
{ |
||||
var seg = Get (lineNumber); |
||||
if (seg == null) |
||||
return 0; |
||||
return seg.Length - seg.DelimiterLength; |
||||
} |
||||
|
||||
public string GetIndentation (int lineNumber) |
||||
{ |
||||
var seg = Get (lineNumber); |
||||
if (seg == null) |
||||
return ""; |
||||
int start = seg.Offset; |
||||
int end = seg.Offset; |
||||
int endOffset = seg.Offset + seg.Length - seg.DelimiterLength; |
||||
|
||||
while (end < endOffset && (text[end] == ' ' || text[end] == '\t')) |
||||
end++; |
||||
|
||||
return start < end ? text.Substring (start, end - start) : ""; |
||||
} |
||||
|
||||
public int GetLineOffset (int lineNumber) |
||||
{ |
||||
var seg = Get (lineNumber); |
||||
if (seg == null) |
||||
return 0; |
||||
return seg.Offset; |
||||
} |
||||
|
||||
public int GetLineLength (int lineNumber) |
||||
{ |
||||
var seg = Get (lineNumber); |
||||
if (seg == null) |
||||
return 0; |
||||
return seg.Length; |
||||
} |
||||
|
||||
public int GetLineEndOffset (int lineNumber) |
||||
{ |
||||
var seg = Get (lineNumber); |
||||
if (seg == null) |
||||
return 0; |
||||
return seg.Offset + seg.Length; |
||||
} |
||||
|
||||
public bool TabsToSpaces { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public int TabSize { |
||||
get { |
||||
return 4; |
||||
} |
||||
} |
||||
|
||||
public string EolMarker { |
||||
get { |
||||
return Environment.NewLine; |
||||
} |
||||
} |
||||
|
||||
public int Length { |
||||
get { |
||||
return text.Length; |
||||
} |
||||
} |
||||
|
||||
public int LineCount { |
||||
get { |
||||
return delimiters.Count + 1; |
||||
} |
||||
} |
||||
#endregion
|
||||
} |
||||
|
||||
public abstract class TestBase |
||||
{ |
||||
protected static ITextEditorAdapter GetResult (CSharpFormattingPolicy policy, string input) |
||||
{ |
||||
var adapter = new TextEditorTestAdapter (input); |
||||
var visitior = new AstFormattingVisitor (policy, adapter); |
||||
|
||||
var compilationUnit = new CSharpParser ().Parse (new StringReader (adapter.Text)); |
||||
compilationUnit.AcceptVisitor (visitior, null); |
||||
adapter.ApplyChanges (visitior.Changes); |
||||
|
||||
return adapter; |
||||
} |
||||
|
||||
protected static ITextEditorAdapter Test (CSharpFormattingPolicy policy, string input, string expectedOutput) |
||||
{ |
||||
var adapter = new TextEditorTestAdapter (input); |
||||
var visitior = new AstFormattingVisitor (policy, adapter); |
||||
|
||||
var compilationUnit = new CSharpParser ().Parse (new StringReader (adapter.Text)); |
||||
compilationUnit.AcceptVisitor (visitior, null); |
||||
adapter.ApplyChanges (visitior.Changes); |
||||
Assert.AreEqual (expectedOutput, adapter.Text); |
||||
return adapter; |
||||
} |
||||
|
||||
protected static void Continue (CSharpFormattingPolicy policy, ITextEditorAdapter adapter, string expectedOutput) |
||||
{ |
||||
var visitior = new AstFormattingVisitor (policy, adapter); |
||||
|
||||
var compilationUnit = new CSharpParser ().Parse (new StringReader (adapter.Text)); |
||||
compilationUnit.AcceptVisitor (visitior, null); |
||||
((TextEditorTestAdapter)adapter).ApplyChanges (visitior.Changes); |
||||
Assert.AreEqual (expectedOutput, adapter.Text); |
||||
} |
||||
|
||||
|
||||
} |
||||
} |
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue