Browse Source

Update NRefactory to 5.3.0-5-g33c882d

newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
f902088e38
  1. 48
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Analysis/ControlFlow.cs
  2. 4
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/ComposedType.cs
  3. 15
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/AttributeSection.cs
  4. 4
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/MemberType.cs
  5. 2
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/SyntaxTree.cs
  6. 20
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  7. 12
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/UsingHelper.cs
  8. 1
      src/Libraries/NRefactory/ICSharpCode.NRefactory.ConsistencyCheck/CSharpFile.cs
  9. 1
      src/Libraries/NRefactory/ICSharpCode.NRefactory.ConsistencyCheck/ICSharpCode.NRefactory.ConsistencyCheck.csproj
  10. 66
      src/Libraries/NRefactory/ICSharpCode.NRefactory.ConsistencyCheck/PatternMatchingTest.cs
  11. 1
      src/Libraries/NRefactory/ICSharpCode.NRefactory.ConsistencyCheck/Program.cs
  12. 3
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddAnotherAccessorTests.cs
  13. 11
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddUsing/AddUsingActionAlphabeticalTests.cs
  14. 6
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddUsing/AddUsingActionInsideNamespaceTests.cs
  15. 4
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddUsing/AddUsingActionTests.cs
  16. 6
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddUsing/AddUsingRunActionTests.cs
  17. 49
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/ConvertToInitializer/ConvertToInitializerTests.cs
  18. 2
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateMethodDeclarationTests.cs
  19. 4
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/IdentifierExpressionTests.cs
  20. 2
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/TypeOfExpressionTests.cs
  21. 2
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/UnaryOperatorExpressionTests.cs
  22. 2
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/AttributeSectionTests.cs
  23. 8
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/IndexerDeclarationTests.cs
  24. 82
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/MethodDeclarationTests.cs
  25. 2
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/OperatorDeclarationTests.cs
  26. 2
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/ObjectCreationTests.cs
  27. 4
      src/Libraries/NRefactory/ICSharpCode.NRefactory/Properties/GlobalAssemblyInfo.cs
  28. 4
      src/Libraries/NRefactory/Packages/ICSharpCode.NRefactory.nuspec
  29. 4
      src/Libraries/NRefactory/README
  30. 10
      src/Libraries/NRefactory/doc/TODO

48
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Analysis/ControlFlow.cs

@ -249,6 +249,8 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis @@ -249,6 +249,8 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis
#region Create*Node
ControlFlowNode CreateStartNode(Statement statement)
{
if (statement.IsNull)
return null;
ControlFlowNode node = CreateNode(null, statement, ControlFlowNodeType.StartNode);
nodes.Add(node);
return node;
@ -295,6 +297,8 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis @@ -295,6 +297,8 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis
/// <returns>The constant value of the expression; or null if the expression is not a constant.</returns>
ResolveResult EvaluateConstant(Expression expr)
{
if (expr.IsNull)
return null;
if (EvaluateOnlyPrimitiveConstants) {
if (!(expr is PrimitiveExpression || expr is NullReferenceExpression))
return null;
@ -337,6 +341,8 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis @@ -337,6 +341,8 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis
internal ControlFlowEdge Connect(ControlFlowNode from, ControlFlowNode to, ControlFlowEdgeType type = ControlFlowEdgeType.Normal)
{
if (from == null || to == null)
return null;
ControlFlowEdge edge = builder.CreateEdge(from, to, type);
from.Outgoing.Add(edge);
to.Incoming.Add(edge);
@ -406,30 +412,21 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis @@ -406,30 +412,21 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis
public override ControlFlowNode VisitIfElseStatement(IfElseStatement ifElseStatement, ControlFlowNode data)
{
bool? cond = ifElseStatement.Condition.IsNull ? true : builder.EvaluateCondition(ifElseStatement.Condition);
if (ifElseStatement.TrueStatement.IsNull)
return data;
ControlFlowNode trueBegin;
if (ifElseStatement.TrueStatement.IsNull) {
trueBegin = null;
} else {
trueBegin = builder.CreateStartNode(ifElseStatement.TrueStatement);
}
if (cond != false && trueBegin != null)
bool? cond = builder.EvaluateCondition(ifElseStatement.Condition);
ControlFlowNode trueBegin = builder.CreateStartNode(ifElseStatement.TrueStatement);
if (cond != false)
Connect(data, trueBegin, ControlFlowEdgeType.ConditionTrue);
ControlFlowNode trueEnd = trueBegin != null ? ifElseStatement.TrueStatement.AcceptVisitor(this, trueBegin) : null;
ControlFlowNode falseEnd;
if (ifElseStatement.FalseStatement.IsNull) {
falseEnd = null;
} else {
ControlFlowNode falseBegin = builder.CreateStartNode(ifElseStatement.FalseStatement);
if (cond != true)
Connect(data, falseBegin, ControlFlowEdgeType.ConditionFalse);
falseEnd = ifElseStatement.FalseStatement.AcceptVisitor(this, falseBegin);
}
ControlFlowNode trueEnd = ifElseStatement.TrueStatement.AcceptVisitor(this, trueBegin);
ControlFlowNode falseBegin = builder.CreateStartNode(ifElseStatement.FalseStatement);
if (cond != true)
Connect(data, falseBegin, ControlFlowEdgeType.ConditionFalse);
ControlFlowNode falseEnd = ifElseStatement.FalseStatement.AcceptVisitor(this, falseBegin);
// (if no else statement exists, both falseBegin and falseEnd will be null)
ControlFlowNode end = builder.CreateEndNode(ifElseStatement);
if (trueEnd != null)
Connect(trueEnd, end);
Connect(trueEnd, end);
if (falseEnd != null) {
Connect(falseEnd, end);
} else if (cond != true) {
@ -543,7 +540,7 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis @@ -543,7 +540,7 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis
Connect(data, conditionNode);
bool? cond = whileStatement.Condition.IsNull ? true : builder.EvaluateCondition(whileStatement.Condition);
bool? cond = builder.EvaluateCondition(whileStatement.Condition);
ControlFlowNode bodyStart = builder.CreateStartNode(whileStatement.EmbeddedStatement);
if (cond != false)
Connect(conditionNode, bodyStart, ControlFlowEdgeType.ConditionTrue);
@ -571,7 +568,7 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis @@ -571,7 +568,7 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis
ControlFlowNode bodyEnd = doWhileStatement.EmbeddedStatement.AcceptVisitor(this, bodyStart);
Connect(bodyEnd, conditionNode);
bool? cond = doWhileStatement.Condition.IsNull ? true : builder.EvaluateCondition(doWhileStatement.Condition);
bool? cond = builder.EvaluateCondition(doWhileStatement.Condition);
if (cond != false)
Connect(conditionNode, bodyStart, ControlFlowEdgeType.ConditionTrue);
if (cond != true)
@ -607,8 +604,7 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis @@ -607,8 +604,7 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis
ControlFlowNode bodyStart = builder.CreateStartNode(forStatement.EmbeddedStatement);
ControlFlowNode bodyEnd = forStatement.EmbeddedStatement.AcceptVisitor(this, bodyStart);
if (bodyEnd != null)
Connect(bodyEnd, iteratorStart);
Connect(bodyEnd, iteratorStart);
breakTargets.Pop();
continueTargets.Pop();

4
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/ComposedType.cs

@ -92,7 +92,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -92,7 +92,9 @@ namespace ICSharpCode.NRefactory.CSharp
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
ComposedType o = other as ComposedType;
return o != null && this.HasNullableSpecifier == o.HasNullableSpecifier && this.PointerRank == o.PointerRank && this.ArraySpecifiers.DoMatch(o.ArraySpecifiers, match);
return o != null && this.HasNullableSpecifier == o.HasNullableSpecifier && this.PointerRank == o.PointerRank
&& this.BaseType.DoMatch(o.BaseType, match)
&& this.ArraySpecifiers.DoMatch(o.ArraySpecifiers, match);
}
public override string ToString()

15
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/AttributeSection.cs

@ -135,7 +135,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -135,7 +135,7 @@ namespace ICSharpCode.NRefactory.CSharp
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
AttributeSection o = other as AttributeSection;
return o != null && this.AttributeTarget == o.AttributeTarget && this.Attributes.DoMatch(o.Attributes, match);
return o != null && MatchString(this.AttributeTarget, o.AttributeTarget) && this.Attributes.DoMatch(o.Attributes, match);
}
public AttributeSection()
@ -171,17 +171,4 @@ namespace ICSharpCode.NRefactory.CSharp @@ -171,17 +171,4 @@ namespace ICSharpCode.NRefactory.CSharp
// }
// }
}
public enum AttributeTarget {
None,
Assembly,
Module,
Type,
Param,
Field,
Return,
Method,
Unknown
}
}

4
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/MemberType.cs

@ -115,7 +115,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -115,7 +115,9 @@ namespace ICSharpCode.NRefactory.CSharp
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
MemberType o = other as MemberType;
return o != null && this.IsDoubleColon == o.IsDoubleColon && MatchString(this.MemberName, o.MemberName) && this.Target.DoMatch(o.Target, match);
return o != null && this.IsDoubleColon == o.IsDoubleColon
&& MatchString(this.MemberName, o.MemberName) && this.Target.DoMatch(o.Target, match)
&& this.TypeArguments.DoMatch(o.TypeArguments, match);
}
public override string ToString()

2
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Ast/SyntaxTree.cs

@ -132,7 +132,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -132,7 +132,7 @@ namespace ICSharpCode.NRefactory.CSharp
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
SyntaxTree o = other as SyntaxTree;
return o != null && GetChildrenByRole(MemberRole).DoMatch(o.GetChildrenByRole(MemberRole), match);
return o != null && this.Members.DoMatch(o.Members, match);
}
public override void AcceptVisitor (IAstVisitor visitor)

20
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs

@ -101,7 +101,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -101,7 +101,11 @@ namespace ICSharpCode.NRefactory.CSharp
if (first) {
first = false;
AddAttributeSection(Unit, mc);
if (mc.OptAttributes != null) {
foreach (var attr in mc.OptAttributes.Sections) {
unit.AddChild (ConvertAttributeSection (attr), SyntaxTree.MemberRole);
}
}
}
if (nspace.Containers != null) {
@ -934,12 +938,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -934,12 +938,12 @@ namespace ICSharpCode.NRefactory.CSharp
AddAttributeSection (parent, a.OptAttributes);
}
public void AddAttributeSection (AstNode parent, Attributes attrs, Role role)
public void AddAttributeSection (AstNode parent, Attributes attrs, Role<AttributeSection> role)
{
if (attrs == null)
return;
foreach (var attr in attrs.Sections) {
parent.AddChild (ConvertAttributeSection (attr), EntityDeclaration.AttributeRole);
parent.AddChild (ConvertAttributeSection (attr), role);
}
}
@ -957,7 +961,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -957,7 +961,7 @@ namespace ICSharpCode.NRefactory.CSharp
newIndexer.AddChild (ConvertToType (indexer.TypeExpression), Roles.Type);
AddExplicitInterface (newIndexer, indexer.MemberName);
var name = indexer.MemberName;
newIndexer.AddChild (Identifier.Create ("this", Convert (name.Location)), Roles.Identifier);
newIndexer.AddChild (new CSharpTokenNode(Convert (name.Location), IndexerDeclaration.ThisKeywordRole), IndexerDeclaration.ThisKeywordRole);
if (location != null && location.Count > 0)
newIndexer.AddChild (new CSharpTokenNode (Convert (location [0]), Roles.LBracket), Roles.LBracket);
@ -2594,7 +2598,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -2594,7 +2598,7 @@ namespace ICSharpCode.NRefactory.CSharp
{
if (d == null)
return;
for (int i = d.Count - 1; i >= 0; i--) {
for (int i = 0; i < d.Count; i++) {
var typeParameter = d [i];
if (typeParameter == null)
continue;
@ -2617,7 +2621,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -2617,7 +2621,11 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
parent.AddChild (constraint, Roles.Constraint);
// We need to sort the constraints by position; as they might be in a different order than the type parameters
AstNode prevSibling = parent.LastChild;
while (prevSibling.StartLocation > constraint.StartLocation && prevSibling.PrevSibling != null)
prevSibling = prevSibling.PrevSibling;
parent.InsertChildAfter (prevSibling, constraint, Roles.Constraint);
}
}

12
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/UsingHelper.cs

@ -64,6 +64,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -64,6 +64,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
// Find the main block of using declarations in the chosen scope:
AstNode blockStart = usingParent.Children.FirstOrDefault(IsUsingDeclaration);
AstNode insertionPoint;
bool insertAfter = false;
if (blockStart == null) {
// no using declarations in the file
Debug.Assert(SyntaxTree.MemberRole == NamespaceDeclaration.MemberRole);
@ -72,9 +73,18 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -72,9 +73,18 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
insertionPoint = blockStart;
while (IsUsingDeclaration(insertionPoint) && newUsingInfo.CompareTo(new UsingInfo(insertionPoint, context)) > 0)
insertionPoint = insertionPoint.NextSibling;
if (!IsUsingDeclaration(insertionPoint)) {
// Insert after last using instead of before next node
// This affects where empty lines get placed.
insertionPoint = insertionPoint.PrevSibling;
insertAfter = true;
}
}
if (insertionPoint != null) {
script.InsertBefore(insertionPoint, newUsing);
if (insertAfter)
script.InsertAfter(insertionPoint, newUsing);
else
script.InsertBefore(insertionPoint, newUsing);
}
}

1
src/Libraries/NRefactory/ICSharpCode.NRefactory.ConsistencyCheck/CSharpFile.cs

@ -50,6 +50,7 @@ namespace ICSharpCode.NRefactory.ConsistencyCheck @@ -50,6 +50,7 @@ namespace ICSharpCode.NRefactory.ConsistencyCheck
// Keep the original text around; we might use it for a refactoring later
this.OriginalText = File.ReadAllText(fileName);
this.SyntaxTree = p.Parse(this.OriginalText, fileName);
this.SyntaxTree.Freeze(); // the various tests shouldn't modify the AST shared by all tests
if (p.HasErrors) {
Console.WriteLine("Error parsing " + fileName + ":");

1
src/Libraries/NRefactory/ICSharpCode.NRefactory.ConsistencyCheck/ICSharpCode.NRefactory.ConsistencyCheck.csproj

@ -74,6 +74,7 @@ @@ -74,6 +74,7 @@
<Compile Include="CSharpFile.cs" />
<Compile Include="CSharpProject.cs" />
<Compile Include="FindReferencesConsistencyCheck.cs" />
<Compile Include="PatternMatchingTest.cs" />
<Compile Include="TypeSystemTests.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

66
src/Libraries/NRefactory/ICSharpCode.NRefactory.ConsistencyCheck/PatternMatchingTest.cs

@ -0,0 +1,66 @@ @@ -0,0 +1,66 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
//
// 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.Linq;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.PatternMatching;
namespace ICSharpCode.NRefactory.ConsistencyCheck
{
/// <summary>
/// Validates pattern matching:
/// Every compilation must match its clone;
/// and mutations to the cloned compilation must prevent the match.
/// </summary>
/// <remarks>
/// This test is SLOW! (due to O(n^2) algorithm).
/// Expect it to take a whole hour!
/// </remarks>
public class PatternMatchingTest
{
public static void RunTest(CSharpFile file)
{
AstNode copy = file.SyntaxTree.Clone();
if (!copy.IsMatch(file.SyntaxTree))
throw new InvalidOperationException("Clone must match the compilation itself; in " + file.FileName);
// Mutate identifiers:
foreach (var id in copy.Descendants.OfType<Identifier>()) {
if (id.Parent is ConstructorDeclaration || id.Parent is DestructorDeclaration)
continue; // identifier in ctor/dtor isn't relevant for matches
string oldName = id.Name;
id.Name = "mutatedName";
if (copy.IsMatch(file.SyntaxTree))
throw new InvalidOperationException("Mutation in " + id.StartLocation + " did not prevent the match; in " + file.FileName);
id.Name = oldName;
//if (!copy.IsMatch(file.SyntaxTree))
// throw new InvalidOperationException("Clone must match the compilation itself after resetting the mutation");
}
// Mutate primitive values:
foreach (var pe in copy.Descendants.OfType<PrimitiveExpression>()) {
object oldVal = pe.Value;
pe.Value = "Mutated " + "Value";
if (copy.IsMatch(file.SyntaxTree))
throw new InvalidOperationException("Mutation in " + pe.StartLocation + " did not prevent the match; in " + file.FileName);
pe.Value = oldVal;
}
Console.Write('.');
}
}
}

1
src/Libraries/NRefactory/ICSharpCode.NRefactory.ConsistencyCheck/Program.cs

@ -66,6 +66,7 @@ namespace ICSharpCode.NRefactory.ConsistencyCheck @@ -66,6 +66,7 @@ namespace ICSharpCode.NRefactory.ConsistencyCheck
RunTestOnAllFiles("Resolver test (no parsed file)", ResolverTest.RunTestWithoutUnresolvedFile);
RunTestOnAllFiles("Resolver test (randomized order)", RandomizedOrderResolverTest.RunTest);
new FindReferencesConsistencyCheck(solution).Run();
RunTestOnAllFiles("Pattern Matching test", PatternMatchingTest.RunTest);
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);

3
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddAnotherAccessorTests.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// AddAnotherAccessorTests.cs
//
// Author:
@ -33,7 +33,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions @@ -33,7 +33,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions
[TestFixture]
public class AddAnotherAccessorTests : ContextActionTestBase
{
[Ignore("Broken")]
[Test()]
public void TestAddSet ()
{

11
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddUsing/AddUsingActionAlphabeticalTests.cs

@ -1,14 +1,12 @@ @@ -1,14 +1,12 @@
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp.CodeIssues;
using System.Linq;
using ICSharpCode.NRefactory.CSharp.Refactoring;
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp.CodeActions;
using ICSharpCode.NRefactory.CSharp;
using System.Linq;
namespace ICSharpCode.NRefactory.CSharp.CodeIssues.UnresolvedType
namespace ICSharpCode.NRefactory.CSharp.CodeActions.AddUsing
{
[TestFixture]
public class UnresolvedTypeActionAlphabeticalTests : ContextActionTestBase
public class AddUsingActionAlphabeticalTests : ContextActionTestBase
{
[Test]
public void ShouldAddUsingAtStartIfItIsTheFirstAlphabetically()
@ -71,7 +69,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues.UnresolvedType @@ -71,7 +69,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues.UnresolvedType
}
[Test]
[Ignore("Add using does not honor the blank line setting yet")]
public void ShouldInsertUsingAfterExistingUsings()
{
string testCode =

6
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddUsing/AddUsingActionInsideNamespaceTests.cs

@ -4,10 +4,10 @@ using ICSharpCode.NRefactory.CSharp.CodeActions; @@ -4,10 +4,10 @@ using ICSharpCode.NRefactory.CSharp.CodeActions;
using ICSharpCode.NRefactory.CSharp.Refactoring;
using System.Linq;
namespace ICSharpCode.NRefactory.CSharp.CodeIssues.UnresolvedType
namespace ICSharpCode.NRefactory.CSharp.CodeActions.AddUsing
{
[TestFixture]
public class UnresolvedTypeActionInsideNamespaceTests : ContextActionTestBase
public class AddUsingActionInsideNamespaceTests : ContextActionTestBase
{
[Test]
public void ShouldInsertUsingStatement()
@ -98,7 +98,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues.UnresolvedType @@ -98,7 +98,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues.UnresolvedType
}
[Test]
[Ignore("Something is wrong with the blank lines")]
public void ShouldAddUsingAfterExistingUsings()
{
string testCode =
@ -163,7 +162,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues.UnresolvedType @@ -163,7 +162,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues.UnresolvedType
}
[Test]
[Ignore("Something is wrong with the blank lines")]
public void ShouldAddUsingAfterExistingUsingsInMostNestedNamespace()
{
string testCode =

4
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddUsing/AddUsingActionTests.cs

@ -4,10 +4,10 @@ using ICSharpCode.NRefactory.CSharp.CodeActions; @@ -4,10 +4,10 @@ using ICSharpCode.NRefactory.CSharp.CodeActions;
using ICSharpCode.NRefactory.CSharp.Refactoring;
using System.Linq;
namespace ICSharpCode.NRefactory.CSharp.CodeIssues.UnresolvedType
namespace ICSharpCode.NRefactory.CSharp.CodeActions.AddUsing
{
[TestFixture]
public class UnresolvedTypeIssueTests : ContextActionTestBase
public class AddUsingActionTests : ContextActionTestBase
{
void UnresolvedTypeName(string code, string typeName, params string[] namespaces)
{

6
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddUsing/AddUsingRunActionTests.cs

@ -4,10 +4,10 @@ using ICSharpCode.NRefactory.CSharp.CodeActions; @@ -4,10 +4,10 @@ using ICSharpCode.NRefactory.CSharp.CodeActions;
using ICSharpCode.NRefactory.CSharp.Refactoring;
using System.Linq;
namespace ICSharpCode.NRefactory.CSharp.CodeIssues.UnresolvedType
namespace ICSharpCode.NRefactory.CSharp.CodeActions.AddUsing
{
[TestFixture]
public class UnresolvedTypeActionTests : ContextActionTestBase
public class AddUsingRunActionTests : ContextActionTestBase
{
[Test]
[Ignore("Add using does not honor the blank line setting yet")]
@ -125,7 +125,6 @@ namespace TestNamespace @@ -125,7 +125,6 @@ namespace TestNamespace
}
[Test]
[Ignore("Something else is broken regarding blank lines as well")]
public void ShouldNotAddBlankLinesAfterIfTheyAreAlreadyThere()
{
string testCode =
@ -155,7 +154,6 @@ namespace TestNamespace @@ -155,7 +154,6 @@ namespace TestNamespace
}
[Test]
[Ignore("Something else is broken regarding blank lines as well")]
public void ShouldLeaveAdditionalBlankLinesThatAlreadyExist()
{
string testCode =

49
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/ConvertToInitializer/ConvertToInitializerTests.cs

@ -33,7 +33,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions @@ -33,7 +33,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions
[TestFixture]
public class ConvertToInitializerTests : ContextActionTestBase
{
// TODO: Remove this when the formatter handles object and collection initializers
// This tests the expected code vs the actual code based on their ASTs instead of the text they produce.
public new void Test<T>(string input, string output, int action = 0, bool expectErrors = false)
@ -113,7 +112,7 @@ class TestClass @@ -113,7 +112,7 @@ class TestClass
}
}", baseText + @"
var tc0 = new TestClass();
var collection = new System.Collections.Generic.Dictionary<string> () {
var collection = new System.Collections.Generic.Dictionary<string, TestClass> () {
{""string1"", new TestClass() { Property = ""tc1"" }},
{""string2"", new TestClass() { Property = ""tc2"" }}
};
@ -138,12 +137,12 @@ class TestClass @@ -138,12 +137,12 @@ class TestClass
}
}", baseText + @"
var collection = new System.Collections.Generic.List<string> () {
new TestClass() {
new TestClass () {
Property = ""Value1""
},
new TestClass() {
new TestClass () {
Property = ""Value2"",
Nested = new TestClass() {
Nested = new TestClass () {
Property = ""Value3""
}
}
@ -163,7 +162,7 @@ class TestClass @@ -163,7 +162,7 @@ class TestClass
}
}", baseText + @"
var collection = new System.Collections.Generic.List<string> ();
var item = new TestClass() {
var item = new TestClass () {
Property = ""Value1""
};
collection.Add(item);
@ -186,12 +185,12 @@ class TestClass @@ -186,12 +185,12 @@ class TestClass
public System.Collections.Generic.IList<TestClass> Children;
}", baseText + @"
var variable = new TestClass() {
var variable = new TestClass () {
Property = ""Value1"",
Children = new System.Collections.Generic.List<TestClass>() {
new TestClass(),
new TestClass(),
new TestClass()
Children = new System.Collections.Generic.List<TestClass> () {
new TestClass (),
new TestClass (),
new TestClass ()
}
};
}
@ -306,9 +305,9 @@ class TestClass @@ -306,9 +305,9 @@ class TestClass
}", baseText + @"
var variable = new TestClass () {
Property = ""Value"",
Nested = new TestClass() {
Nested = new TestClass () {
Property = ""NestedValue"",
Nested = new TestClass() {
Nested = new TestClass () {
Property = ""NestedNestedValue""
}
}
@ -330,7 +329,7 @@ class TestClass @@ -330,7 +329,7 @@ class TestClass
var variable = new TestClass () {
Property = ""Value"",
Nested = {
Nested = new TestClass() {
Nested = new TestClass () {
Property = ""NestedNestedValue""
}
}
@ -393,7 +392,7 @@ class TestClass @@ -393,7 +392,7 @@ class TestClass
}", baseText + @"
var variable = new TestClass () {
Property = ""Value"",
Nested = new TestClass()
Nested = new TestClass ()
};
System.Console.WriteLine("""");
variable.Nested.Property = ""NestedValue"";
@ -413,7 +412,7 @@ class TestClass @@ -413,7 +412,7 @@ class TestClass
}", baseText + @"
var variable = new TestClass () {
Property = ""Value"",
Nested = new TestClass()
Nested = new TestClass ()
};
variable.Nested.Property = variable.ToString();
}
@ -454,9 +453,9 @@ class TestClass @@ -454,9 +453,9 @@ class TestClass
}", baseText + @"
var tc = new TestClass();
tc.Property = ""1"";
var tc2 = new TestClass() {
var tc2 = new TestClass () {
Property = ""2"",
Nested = new TestClass() {
Nested = new TestClass () {
Property = ""3""
}
};
@ -479,7 +478,7 @@ class TestClass @@ -479,7 +478,7 @@ class TestClass
}", baseText + @"
var tc = new TestClass();
tc.Property = ""1"";
var tc2 = new TestClass() {
var tc2 = new TestClass () {
Property = ""2"",
Nested = tc
};
@ -499,7 +498,7 @@ class TestClass @@ -499,7 +498,7 @@ class TestClass
}
}", baseText + @"
var variable = new TestClass () {
Nested = new TestClass()
Nested = new TestClass ()
};
}
}");
@ -534,7 +533,7 @@ class TestClass @@ -534,7 +533,7 @@ class TestClass
var tc = new TestClass () {
Property = ""Value""
};
var _variable = new Test$Class ();
var _variable = new TestClass ();
var variable = _variable;
}
}");
@ -552,7 +551,7 @@ class TestClass @@ -552,7 +551,7 @@ class TestClass
}
}", baseText + @"
Nested = new TestClass () {
Nested = new TestClass(),
Nested = new TestClass (),
Property = ""Value""
};
Nested.Nested.Property = Nested.Property;
@ -579,12 +578,12 @@ class TestClass @@ -579,12 +578,12 @@ class TestClass
}
}", baseText + @"
var collection = new System.Collections.Generic.List<string> () {
new TestClass() {
new TestClass () {
Property = ""Value1""
},
new TestClass() {
new TestClass () {
Property = ""Value2"",
Nested = new TestClass() {
Nested = new TestClass () {
Property = ""Value3""
}
}

2
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateMethodDeclarationTests.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// CreateMethodDeclarationTests.cs
//
// Author:

4
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/IdentifierExpressionTests.cs

@ -55,7 +55,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -55,7 +55,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
CheckIdentifier(@"l\U00000065xer", "lexer");
}
[Test, Ignore("The @ should not be part of IdentifierExpression.Identifier")]
[Test]
public void TestKeyWordAsIdentifier()
{
CheckIdentifier("@int", "int");
@ -67,7 +67,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -67,7 +67,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
CheckIdentifier(@"i\u006et", "int");
}
[Test, Ignore("The @ should not be part of IdentifierExpression.Identifier")]
[Test]
public void TestKeyWordAsIdentifierStartingWithUnderscore()
{
CheckIdentifier("@_int", "_int");

2
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/TypeOfExpressionTests.cs

@ -118,7 +118,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -118,7 +118,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
"typeof(MyStruct?)",
new TypeOfExpression {
Type = new ComposedType {
BaseType = new SimpleType("MyType"),
BaseType = new SimpleType("MyStruct"),
HasNullableSpecifier = true
}});
}

2
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/UnaryOperatorExpressionTests.cs

@ -82,7 +82,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -82,7 +82,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
TestUnaryOperatorExpressionTest("a--", UnaryOperatorType.PostDecrement);
}
[Test, Ignore("Incorrect start position")]
[Test]
public void Dereference()
{
TestUnaryOperatorExpressionTest("*a", UnaryOperatorType.Dereference);

2
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/AttributeSectionTests.cs

@ -51,6 +51,7 @@ public class Form1 { @@ -51,6 +51,7 @@ public class Form1 {
AttributeSection decl = ParseUtilCSharp.ParseGlobal<AttributeSection>(program);
Assert.AreEqual(new TextLocation(1, 1), decl.StartLocation);
Assert.AreEqual("assembly", decl.AttributeTarget);
Assert.AreEqual(SyntaxTree.MemberRole, decl.Role);
}
[Test]
@ -60,6 +61,7 @@ public class Form1 { @@ -60,6 +61,7 @@ public class Form1 {
AttributeSection decl = ParseUtilCSharp.ParseGlobal<AttributeSection>(program);
Assert.AreEqual(new TextLocation(1, 1), decl.StartLocation);
Assert.AreEqual("module", decl.AttributeTarget);
Assert.AreEqual(SyntaxTree.MemberRole, decl.Role);
}
[Test]

8
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/IndexerDeclarationTests.cs

@ -38,6 +38,14 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -38,6 +38,14 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
Assert.AreEqual("Item", id.Name);
}
[Test]
public void ThisTokenPosition()
{
IndexerDeclaration id = ParseUtilCSharp.ParseTypeMember<IndexerDeclaration>("public int this[int a] { get { } protected set { } }");
CSharpTokenNode thisKeyword = id.GetChildByRole(IndexerDeclaration.ThisKeywordRole);
Assert.AreEqual(12, thisKeyword.StartLocation.Column);
}
[Test]
public void IndexerImplementingInterfaceTest()
{

82
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/MethodDeclarationTests.cs

@ -157,6 +157,64 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -157,6 +157,64 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
});
}
[Test]
public void GenericMethodWithTwoConstraints()
{
ParseUtilCSharp.AssertTypeMember(
"void MyMethod<A, B>() where A : IA where B : IB {} ",
new MethodDeclaration {
ReturnType = new PrimitiveType("void"),
Name = "MyMethod",
TypeParameters = {
new TypeParameterDeclaration { Name = "A" },
new TypeParameterDeclaration { Name = "B" }
},
Constraints = {
new Constraint {
TypeParameter = new SimpleType("A"),
BaseTypes = { new SimpleType("IA") }
},
new Constraint {
TypeParameter = new SimpleType("B"),
BaseTypes = { new SimpleType("IB") }
}
},
Body = new BlockStatement()
});
}
[Test]
public void GenericMethodDeclarationWithThreeConstraintsTest()
{
ParseUtilCSharp.AssertTypeMember(
"A MyMethod<A, B, C>() where B : BB where A : BA, IA where C : class {} ",
new MethodDeclaration {
ReturnType = new SimpleType("A"),
Name = "MyMethod",
TypeParameters = {
new TypeParameterDeclaration { Name = "A" },
new TypeParameterDeclaration { Name = "B" },
new TypeParameterDeclaration { Name = "C" }
},
Constraints = {
new Constraint {
TypeParameter = new SimpleType ("B"),
BaseTypes = { new SimpleType("BB") }
},
new Constraint {
TypeParameter = new SimpleType ("A"),
BaseTypes = { new SimpleType("BA"), new SimpleType("IA") }
},
new Constraint {
TypeParameter = new SimpleType ("C"),
BaseTypes = { new PrimitiveType("class") }
}
},
Body = new BlockStatement()
});
}
[Test]
public void GenericMethodInInterface()
{
@ -281,30 +339,6 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -281,30 +339,6 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
});
}
[Test, Ignore("Parser bug: constraints added in wrong order")]
public void GenericMethodWithMultipleConstraints()
{
ParseUtilCSharp.AssertTypeMember(
"void MyMethod<A, B>() where A : IA where B : IB {} ",
new MethodDeclaration {
ReturnType = new PrimitiveType("void"),
Name = "MyMethod",
TypeParameters = {
new TypeParameterDeclaration { Name = "A" },
new TypeParameterDeclaration { Name = "B" }
},
Constraints = {
new Constraint {
TypeParameter = new SimpleType("A"),
BaseTypes = { new SimpleType("IA") }
},
new Constraint {
TypeParameter = new SimpleType("B"),
BaseTypes = { new SimpleType("IB") }
}
}});
}
[Test]
public void IncompleteConstraintsTest()
{

2
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/OperatorDeclarationTests.cs

@ -65,7 +65,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -65,7 +65,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
Assert.AreEqual("op_UnaryPlus", od.Name);
}
[Test, Ignore("Parser crash")]
[Test]
public void InvalidOperatorTrueDeclaration()
{
ParseUtilCSharp.ParseTypeMember<OperatorDeclaration>("public static implicit operator true(MyBool b) {}", expectErrors: true);

2
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Resolver/ObjectCreationTests.cs

@ -174,7 +174,6 @@ class B { @@ -174,7 +174,6 @@ class B {
Assert.AreEqual("Point.X", result.Member.FullName);
}
[Ignore("Broken")]
[Test]
public void CollectionInitializerTest()
{
@ -188,7 +187,6 @@ class B { @@ -188,7 +187,6 @@ class B {
Assert.AreEqual("System.Collections.Generic.List.Add", result.Member.FullName);
}
[Ignore("Broken on mcs/mac os x")]
[Test]
public void DictionaryInitializerTest()
{

4
src/Libraries/NRefactory/ICSharpCode.NRefactory/Properties/GlobalAssemblyInfo.cs

@ -11,7 +11,7 @@ using System.Runtime.InteropServices; @@ -11,7 +11,7 @@ using System.Runtime.InteropServices;
// associated with an assembly.
[assembly: AssemblyCompany("ICSharpCode")]
[assembly: AssemblyProduct("SharpDevelop/MonoDevelop")]
[assembly: AssemblyCopyright("Copyright 2010-2012 AlphaSierraPapa")]
[assembly: AssemblyCopyright("Copyright 2010-2013 AlphaSierraPapa")]
// This sets the default COM visibility of types in the assembly to invisible.
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
@ -23,4 +23,4 @@ using System.Runtime.InteropServices; @@ -23,4 +23,4 @@ using System.Runtime.InteropServices;
// [AssemblyFileVersion] is the version of the NuGet package,
// should follow http://semver.org/ rules
[assembly: AssemblyFileVersion("5.2.0")]
[assembly: AssemblyFileVersion("5.3.0")]

4
src/Libraries/NRefactory/Packages/ICSharpCode.NRefactory.nuspec

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>ICSharpCode.NRefactory</id>
<version>5.2.0</version>
<version>5.3.0</version>
<title>NRefactory</title>
<authors>Daniel Grunwald, Mike Krüger, Erik Källén</authors>
<owners>Daniel Grunwald</owners>
@ -12,7 +12,7 @@ @@ -12,7 +12,7 @@
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>NRefactory supports analysis of C# source code: it includes a parser, abstract syntax tree, type system, semantic analysis (resolver), code completion, and several refactorings.</description>
<!--<releaseNotes></releaseNotes>-->
<copyright>Copyright 2010-2012 AlphaSierraPapa</copyright>
<copyright>Copyright 2010-2013 AlphaSierraPapa</copyright>
<tags>C# Parser Semantic Analysis SharpDevelop</tags>
<dependencies>
<dependency id="Mono.Cecil" version="0.9.5.2" />

4
src/Libraries/NRefactory/README

@ -23,7 +23,7 @@ Features: @@ -23,7 +23,7 @@ Features:
Non-Features:
- VB support is not implemented yet.
- NRefactory cannot generate IL code
- NRefactory cannot generate IL code -- it's a compiler frontend, not a full compiler
Dependencies:
.NET 4.0
@ -206,7 +206,7 @@ A: This question is a bit difficult to answer. @@ -206,7 +206,7 @@ A: This question is a bit difficult to answer.
-> this is being worked on; for the time being, NRefactory uses a global lock during parsing;
so it's thread-safe but slow.
Some instance methods may use hidden instance state, so it is not safe to e.g use an instance
Some instance methods may use hidden instance state, so it is not safe to e.g. use an instance
of the CSharp.Resolver.TypeInference class concurrently.
Instead, you need to create an instance on every thread.

10
src/Libraries/NRefactory/doc/TODO

@ -1,8 +1,7 @@ @@ -1,8 +1,7 @@

Parser:
- put newlines into the AST
- add API to report errors
- allow multithreaded parsing
- eliminate the global lock
Type System:
- Reduce memory usage
@ -12,10 +11,3 @@ Resolver: @@ -12,10 +11,3 @@ Resolver:
- Port all #D resolver unit tests to NR
- Port all MD resolver unit tests to NR
Features:
- Code Completion
- Extract Method refactoring
For integration into SharpDevelop:
- Review NR and DOM changes done in the timeframe

Loading…
Cancel
Save