Browse Source

Merge remote-tracking branch 'upstream/master' into mansheng

newNRvisualizers
Mansheng Yang 14 years ago
parent
commit
aa59c76669
  1. 2
      ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs
  2. 3
      ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj
  3. 17
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  4. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreatePropertyAction.cs
  5. 93
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ExtractFieldAction.cs
  6. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/UseExplicitTypeAction.cs
  7. 43
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/InconsistentNamingIssue/DefaultRules.cs
  8. 2
      ICSharpCode.NRefactory.ConsistencyCheck/CSharpProject.cs
  9. 2
      ICSharpCode.NRefactory.Demo/CSDemo.cs
  10. 149
      ICSharpCode.NRefactory.Tests/CSharp/CodeActions/ExtractFieldTests.cs
  11. 6
      ICSharpCode.NRefactory.Tests/CSharp/CodeActions/TestRefactoringContext.cs
  12. 106
      ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/InconsistentNamingTests.cs
  13. 20
      ICSharpCode.NRefactory.Tests/CSharp/Parser/ParseUtil.cs
  14. 34
      ICSharpCode.NRefactory.Tests/FormattingTests/TestWrapping.cs
  15. 3
      ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj
  16. 1
      ICSharpCode.NRefactory.Tests/TypeSystem/CecilLoaderTests.cs

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

@ -1822,7 +1822,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (methodCallArgumentWrapping == Wrapping.DoNotWrap) { if (methodCallArgumentWrapping == Wrapping.DoNotWrap) {
ForceSpacesBeforeRemoveNewLines(rParToken, spaceWithinMethodCallParentheses); ForceSpacesBeforeRemoveNewLines(rParToken, spaceWithinMethodCallParentheses);
} else { } else {
bool sameLine = rParToken.GetPrevNode().StartLocation.Line == rParToken.StartLocation.Line; bool sameLine = rParToken.GetPrevNode().EndLocation.Line == rParToken.StartLocation.Line;
if (sameLine) { if (sameLine) {
ForceSpacesBeforeRemoveNewLines(rParToken, spaceWithinMethodCallParentheses); ForceSpacesBeforeRemoveNewLines(rParToken, spaceWithinMethodCallParentheses);
} else { } else {

3
ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup> <PropertyGroup>
<ProjectGuid>{53DCA265-3C3C-42F9-B647-F72BA678122B}</ProjectGuid> <ProjectGuid>{53DCA265-3C3C-42F9-B647-F72BA678122B}</ProjectGuid>
@ -387,6 +387,7 @@
<Compile Include="Refactoring\CodeActions\ImplementInterfaceAction.cs" /> <Compile Include="Refactoring\CodeActions\ImplementInterfaceAction.cs" />
<Compile Include="Refactoring\CodeActions\ImplementInterfaceExplicitAction.cs" /> <Compile Include="Refactoring\CodeActions\ImplementInterfaceExplicitAction.cs" />
<Compile Include="Refactoring\CodeActions\ImplementAbstractMembersAction.cs" /> <Compile Include="Refactoring\CodeActions\ImplementAbstractMembersAction.cs" />
<Compile Include="Refactoring\CodeActions\ExtractFieldAction.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj"> <ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">

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

@ -3598,6 +3598,7 @@ namespace ICSharpCode.NRefactory.CSharp
} }
ErrorReportPrinter errorReportPrinter = new ErrorReportPrinter (null); ErrorReportPrinter errorReportPrinter = new ErrorReportPrinter (null);
[Obsolete("Use the Errors/Warnings/ErrorsAndWarnings properties instead")]
public ErrorReportPrinter ErrorPrinter { public ErrorReportPrinter ErrorPrinter {
get { get {
return errorReportPrinter; return errorReportPrinter;
@ -3616,6 +3617,22 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
public IEnumerable<Error> Errors {
get {
return errorReportPrinter.Errors.Where(e => e.ErrorType == ErrorType.Error);
}
}
public IEnumerable<Error> Warnings {
get {
return errorReportPrinter.Errors.Where(e => e.ErrorType == ErrorType.Warning);
}
}
public IEnumerable<Error> ErrorsAndWarnings {
get { return errorReportPrinter.Errors; }
}
public CompilationUnit Parse (ITextSource textSource, string fileName, int lineModifier = 0) public CompilationUnit Parse (ITextSource textSource, string fileName, int lineModifier = 0)
{ {
return Parse (textSource.CreateReader (), fileName, lineModifier); return Parse (textSource.CreateReader (), fileName, lineModifier);

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreatePropertyAction.cs

@ -63,6 +63,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
ResolveResult targetResolveResult = null; ResolveResult targetResolveResult = null;
if (identifier is MemberReferenceExpression) { if (identifier is MemberReferenceExpression) {
targetResolveResult = context.Resolve(((MemberReferenceExpression)identifier).Target); targetResolveResult = context.Resolve(((MemberReferenceExpression)identifier).Target);
if (targetResolveResult.Type.GetDefinition() == null || targetResolveResult.Type.GetDefinition().Region.IsEmpty)
yield break;
createInOtherType = !state.CurrentTypeDefinition.Equals(targetResolveResult.Type.GetDefinition()); createInOtherType = !state.CurrentTypeDefinition.Equals(targetResolveResult.Type.GetDefinition());
} }

93
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ExtractFieldAction.cs

@ -0,0 +1,93 @@
//
// ExtractFieldAction.cs
//
// Author:
// Nieve <>
//
// Copyright (c) 2012 Nieve
//
// 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;
using System.Linq;
using ICSharpCode.NRefactory.PatternMatching;
using Mono.CSharp;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
[ContextAction("Extract field", Description = "Extracts a field from a local variable declaration.")]
public class ExtractFieldAction : ICodeActionProvider
{
public IEnumerable<CodeAction> GetActions(RefactoringContext context)
{
//TODO: implement variable assignment & ctor param
var varInit = context.GetNode<VariableInitializer>();
if (varInit != null) {
AstType type = varInit.GetPrevNode() as AstType;
if (type == null) yield break;
if (varInit.Parent is FieldDeclaration) yield break;
if (CannotExtractField(varInit)) yield break;
yield return new CodeAction("Extract field", s=>{
var name = varInit.Name;
FieldDeclaration field = new FieldDeclaration(){
ReturnType = type.Clone(),
Variables = { new VariableInitializer(name) }
};
AstNode nodeToRemove = RemoveDeclaration(varInit) ? varInit.Parent : type;
s.Remove(nodeToRemove, true);
s.InsertWithCursor(context.TranslateString("Extract field"),Script.InsertPosition.Before,field);
s.FormatText(varInit.Parent);
});
}
var idntf = context.GetNode<Identifier>();
if (idntf == null) yield break;
var paramDec = idntf.Parent as ParameterDeclaration;
if (paramDec != null) {
var ctor = paramDec.Parent as ConstructorDeclaration;
if (ctor == null) yield break;
MemberReferenceExpression thisField = new MemberReferenceExpression(new ThisReferenceExpression(), idntf.Name, new AstType[]{});
var assign = new AssignmentExpression(thisField, AssignmentOperatorType.Assign, new IdentifierExpression(idntf.Name));
var statement = new ExpressionStatement(assign);
var type = (idntf.GetPrevNode() as AstType).Clone();
FieldDeclaration field = new FieldDeclaration(){
ReturnType = type.Clone(),
Variables = { new VariableInitializer(idntf.Name) }
};
yield return new CodeAction("Extract field", s=>{
s.InsertWithCursor(context.TranslateString("Extract field"),Script.InsertPosition.Before,field);
s.AddTo(ctor.Body, statement);
});
}
}
static bool RemoveDeclaration (VariableInitializer varInit){
var result = varInit.Parent as VariableDeclarationStatement;
return result.Variables.First ().Initializer.IsNull;
}
static bool CannotExtractField (VariableInitializer varInit)
{
var result = varInit.Parent as VariableDeclarationStatement;
return result == null || result.Variables.Count != 1;
}
}
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/UseExplicitTypeAction.cs

@ -52,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
if (!(!type.Equals(SpecialType.NullType) && !type.Equals(SpecialType.UnknownType))) { if (!(!type.Equals(SpecialType.NullType) && !type.Equals(SpecialType.UnknownType))) {
yield break; yield break;
} }
yield return new CodeAction (context.TranslateString("Use expcicit type"), script => { yield return new CodeAction (context.TranslateString("Use explicit type"), script => {
if (varDecl != null) { if (varDecl != null) {
script.Replace (varDecl.Type, context.CreateShortType (type)); script.Replace (varDecl.Type, context.CreateShortType (type));
} else { } else {

43
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/InconsistentNamingIssue/DefaultRules.cs

@ -39,24 +39,28 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
yield return new NamingRule(AffectedEntity.Class | AffectedEntity.Struct | AffectedEntity.Enum | AffectedEntity.Delegate) { yield return new NamingRule(AffectedEntity.Class | AffectedEntity.Struct | AffectedEntity.Enum | AffectedEntity.Delegate) {
Name = "Types", Name = "Types",
VisibilityMask = Modifiers.Public,
NamingStyle = NamingStyle.PascalCase NamingStyle = NamingStyle.PascalCase
}; };
yield return new NamingRule(AffectedEntity.Interface) { yield return new NamingRule(AffectedEntity.Interface) {
Name = "Interfaces", Name = "Interfaces",
NamingStyle = NamingStyle.PascalCase, NamingStyle = NamingStyle.PascalCase,
VisibilityMask = Modifiers.Public,
RequiredPrefixes = new [] { "I" } RequiredPrefixes = new [] { "I" }
}; };
yield return new NamingRule(AffectedEntity.CustomAttributes) { yield return new NamingRule(AffectedEntity.CustomAttributes) {
Name = "Attributes", Name = "Attributes",
NamingStyle = NamingStyle.PascalCase, NamingStyle = NamingStyle.PascalCase,
VisibilityMask = Modifiers.Public,
RequiredSuffixes = new [] { "Attribute" } RequiredSuffixes = new [] { "Attribute" }
}; };
yield return new NamingRule(AffectedEntity.CustomEventArgs) { yield return new NamingRule(AffectedEntity.CustomEventArgs) {
Name = "Event Arguments", Name = "Event Arguments",
NamingStyle = NamingStyle.PascalCase, NamingStyle = NamingStyle.PascalCase,
VisibilityMask = Modifiers.Public,
RequiredSuffixes = new [] { "EventArgs" } RequiredSuffixes = new [] { "EventArgs" }
}; };
@ -68,66 +72,45 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
yield return new NamingRule(AffectedEntity.Methods) { yield return new NamingRule(AffectedEntity.Methods) {
Name = "Methods", Name = "Methods",
VisibilityMask = Modifiers.Public | Modifiers.Protected,
NamingStyle = NamingStyle.PascalCase NamingStyle = NamingStyle.PascalCase
}; };
yield return new NamingRule(AffectedEntity.ReadonlyField) { yield return new NamingRule(AffectedEntity.ReadonlyField) {
Name = "Static Readonly Fields", Name = "Static Readonly Fields",
VisibilityMask = Modifiers.Public | Modifiers.Protected | Modifiers.Internal, VisibilityMask = Modifiers.Public | Modifiers.Protected,
NamingStyle = NamingStyle.PascalCase, NamingStyle = NamingStyle.PascalCase,
IncludeInstanceMembers = false IncludeInstanceMembers = false
}; };
yield return new NamingRule(AffectedEntity.Field) { yield return new NamingRule(AffectedEntity.Field) {
Name = "Fields (Non Private)", Name = "Fields",
NamingStyle = NamingStyle.PascalCase, NamingStyle = NamingStyle.PascalCase,
VisibilityMask = Modifiers.Public | Modifiers.Protected | Modifiers.Internal VisibilityMask = Modifiers.Public | Modifiers.Protected
}; };
yield return new NamingRule(AffectedEntity.ReadonlyField) { yield return new NamingRule(AffectedEntity.ReadonlyField) {
Name = "ReadOnly Fields (Non Private)", Name = "ReadOnly Fields",
NamingStyle = NamingStyle.PascalCase, NamingStyle = NamingStyle.PascalCase,
VisibilityMask = Modifiers.Public | Modifiers.Protected | Modifiers.Internal, VisibilityMask = Modifiers.Public | Modifiers.Protected,
IncludeStaticEntities = false
};
yield return new NamingRule(AffectedEntity.Field | AffectedEntity.ReadonlyField) {
Name = "Fields (Private)",
NamingStyle = NamingStyle.CamelCase,
AllowedPrefixes = new [] { "_", "m_" },
VisibilityMask = Modifiers.Private,
IncludeStaticEntities = false
};
yield return new NamingRule(AffectedEntity.Field) {
Name = "Static Fields (Private)",
NamingStyle = NamingStyle.CamelCase,
VisibilityMask = Modifiers.Private,
IncludeStaticEntities = true,
IncludeInstanceMembers = false
};
yield return new NamingRule(AffectedEntity.ReadonlyField) {
Name = "ReadOnly Fields (Private)",
NamingStyle = NamingStyle.CamelCase,
VisibilityMask = Modifiers.Private,
AllowedPrefixes = new [] { "_", "m_" },
IncludeStaticEntities = false IncludeStaticEntities = false
}; };
yield return new NamingRule(AffectedEntity.ConstantField) { yield return new NamingRule(AffectedEntity.ConstantField) {
Name = "Constant Fields", Name = "Constant Fields",
NamingStyle = NamingStyle.PascalCase, NamingStyle = NamingStyle.PascalCase,
VisibilityMask = Modifiers.Public | Modifiers.Protected | Modifiers.Internal | Modifiers.Private VisibilityMask = Modifiers.Public | Modifiers.Protected
}; };
yield return new NamingRule(AffectedEntity.Property) { yield return new NamingRule(AffectedEntity.Property) {
Name = "Properties", Name = "Properties",
VisibilityMask = Modifiers.Public | Modifiers.Protected,
NamingStyle = NamingStyle.PascalCase NamingStyle = NamingStyle.PascalCase
}; };
yield return new NamingRule(AffectedEntity.Event) { yield return new NamingRule(AffectedEntity.Event) {
Name = "Events", Name = "Events",
VisibilityMask = Modifiers.Public | Modifiers.Protected,
NamingStyle = NamingStyle.PascalCase NamingStyle = NamingStyle.PascalCase
}; };

2
ICSharpCode.NRefactory.ConsistencyCheck/CSharpProject.cs

@ -180,7 +180,7 @@ namespace ICSharpCode.NRefactory.ConsistencyCheck
this.CompilationUnit = p.Parse(Content.CreateReader(), fileName); this.CompilationUnit = p.Parse(Content.CreateReader(), fileName);
if (p.HasErrors) { if (p.HasErrors) {
Console.WriteLine("Error parsing " + fileName + ":"); Console.WriteLine("Error parsing " + fileName + ":");
foreach (var error in p.ErrorPrinter.Errors) { foreach (var error in p.ErrorsAndWarnings) {
Console.WriteLine(" " + error.Region + " " + error.Message); Console.WriteLine(" " + error.Region + " " + error.Message);
} }
} }

2
ICSharpCode.NRefactory.Demo/CSDemo.cs

@ -94,7 +94,7 @@ namespace ICSharpCode.NRefactory.Demo
b.Append(node.GetType().Name); b.Append(node.GetType().Name);
bool hasProperties = false; bool hasProperties = false;
foreach (PropertyInfo p in node.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) { foreach (PropertyInfo p in node.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) {
if (p.Name == "NodeType" || p.Name == "IsNull") if (p.Name == "NodeType" || p.Name == "IsNull" || p.Name == "IsFrozen" || p.Name == "HasChildren")
continue; continue;
if (p.PropertyType == typeof(string) || p.PropertyType.IsEnum || p.PropertyType == typeof(bool)) { if (p.PropertyType == typeof(string) || p.PropertyType.IsEnum || p.PropertyType == typeof(bool)) {
if (!hasProperties) { if (!hasProperties) {

149
ICSharpCode.NRefactory.Tests/CSharp/CodeActions/ExtractFieldTests.cs

@ -0,0 +1,149 @@
//
// CreateFieldTests.cs
//
// Author:
// Nieve Goor
//
// 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 NUnit.Framework;
using ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp.CodeActions
{
[TestFixture]
public class ExtractFieldTests : ContextActionTestBase
{
[Test]
public void TestWrongContext1 ()
{
TestWrongContext<ExtractFieldAction> (
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" $foo = 2;" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
}
[Test]
public void TestWrongContext2 ()
{
TestWrongContext<ExtractFieldAction> (
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" int foo;" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" $foo = 2;" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
}
[Test]
public void TestLocalInitializer()
{
string result = RunContextAction (
new ExtractFieldAction (),
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" int $foo = 5;" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Console.WriteLine (result);
Assert.AreEqual (
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" int foo;" + Environment.NewLine +
"" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" foo = 5;" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
[Test]
public void TestLocalDeclaration()
{
string result = RunContextAction (
new ExtractFieldAction (),
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" int $foo;" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Console.WriteLine (result);
Assert.AreEqual (
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" int foo;" + Environment.NewLine +
"" + Environment.NewLine +
" void Test ()" + Environment.NewLine +
" {" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
[Test]
public void TestCtorParam ()
{
string result = RunContextAction (
new ExtractFieldAction (),
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" TestClass (int $foo)" + Environment.NewLine +
" {" + Environment.NewLine +
" " + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
Assert.AreEqual (
"using System;" + Environment.NewLine +
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" int foo;" + Environment.NewLine +
"" + Environment.NewLine +
" TestClass (int foo)" + Environment.NewLine +
" {" + Environment.NewLine +
" this.foo = foo;" + Environment.NewLine +
" " + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);
}
}
}

6
ICSharpCode.NRefactory.Tests/CSharp/CodeActions/TestRefactoringContext.cs

@ -1,4 +1,4 @@
// //
// TestRefactoringContext.cs // TestRefactoringContext.cs
// //
// Author: // Author:
@ -246,8 +246,8 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions
var doc = new StringBuilderDocument (content); var doc = new StringBuilderDocument (content);
var parser = new CSharpParser (); var parser = new CSharpParser ();
var unit = parser.Parse (content, "program.cs"); var unit = parser.Parse (content, "program.cs");
if (parser.HasErrors) foreach (var error in parser.Errors)
parser.ErrorPrinter.Errors.ForEach (e => Console.WriteLine (e.Message)); Console.WriteLine (error.Message);
Assert.IsFalse (parser.HasErrors, "File contains parsing errors."); Assert.IsFalse (parser.HasErrors, "File contains parsing errors.");
unit.Freeze (); unit.Freeze ();
var parsedFile = unit.ToTypeSystem (); var parsedFile = unit.ToTypeSystem ();

106
ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/InconsistentNamingTests.cs

@ -57,24 +57,24 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues
[Test] [Test]
public void TestClassName () public void TestClassName ()
{ {
var input = @"class anIssue {}"; var input = @"public class anIssue {}";
var output = @"class AnIssue {}"; var output = @"public class AnIssue {}";
CheckNaming (input, output); CheckNaming (input, output);
} }
[Test] [Test]
public void TestAttributeName () public void TestAttributeName ()
{ {
var input = @"class test : System.Attribute {}"; var input = @"public class test : System.Attribute {}";
var output = @"class TestAttribute : System.Attribute {}"; var output = @"public class TestAttribute : System.Attribute {}";
CheckNaming (input, output); CheckNaming (input, output);
} }
[Test] [Test]
public void TestEventArgsName () public void TestEventArgsName ()
{ {
var input = @"class test : System.EventArgs {}"; var input = @"public class test : System.EventArgs {}";
var output = @"class TestEventArgs : System.EventArgs {}"; var output = @"public class TestEventArgs : System.EventArgs {}";
CheckNaming (input, output); CheckNaming (input, output);
} }
@ -89,50 +89,50 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues
[Test] [Test]
public void TestStructName () public void TestStructName ()
{ {
var input = @"struct anIssue {}"; var input = @"public struct anIssue {}";
var output = @"struct AnIssue {}"; var output = @"public struct AnIssue {}";
CheckNaming (input, output); CheckNaming (input, output);
} }
[Test] [Test]
public void TestInterfaceName () public void TestInterfaceName ()
{ {
var input = @"interface anIssue {}"; var input = @"public interface anIssue {}";
var output = @"interface IAnIssue {}"; var output = @"public interface IAnIssue {}";
CheckNaming (input, output); CheckNaming (input, output);
} }
[Test] [Test]
public void TestEnumName () public void TestEnumName ()
{ {
var input = @"enum anIssue {}"; var input = @"public enum anIssue {}";
var output = @"enum AnIssue {}"; var output = @"public enum AnIssue {}";
CheckNaming (input, output); CheckNaming (input, output);
} }
[Test] [Test]
public void TestDelegateName () public void TestDelegateName ()
{ {
var input = @"delegate void anIssue ();"; var input = @"public delegate void anIssue ();";
var output = @"delegate void AnIssue ();"; var output = @"public delegate void AnIssue ();";
CheckNaming (input, output); CheckNaming (input, output);
} }
[Test] // [Test]
public void TestPrivateFieldName () // public void TestPrivateFieldName ()
{ // {
var input = @"class AClass { int Field; }"; // var input = @"class AClass { int Field; }";
var output = @"class AClass { int field; }"; // var output = @"class AClass { int field; }";
CheckNaming (input, output); // CheckNaming (input, output);
} // }
[Test] // [Test]
public void TestUnderscoreFieldName () // public void TestUnderscoreFieldName ()
{ // {
var input = @"class AClass { int _Field; }"; // var input = @"class AClass { int _Field; }";
var output = @"class AClass { int _field; }"; // var output = @"class AClass { int _field; }";
CheckNaming (input, output); // CheckNaming (input, output);
} // }
[Test] [Test]
public void TestPublicFieldName () public void TestPublicFieldName ()
@ -142,13 +142,13 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues
CheckNaming (input, output); CheckNaming (input, output);
} }
[Test] // [Test]
public void TestPrivateConstantFieldName () // public void TestPrivateConstantFieldName ()
{ // {
var input = @"class AClass { const int field = 5; }"; // var input = @"class AClass { const int field = 5; }";
var output = @"class AClass { const int Field = 5; }"; // var output = @"class AClass { const int Field = 5; }";
CheckNaming (input, output); // CheckNaming (input, output);
} // }
[Test] [Test]
public void TestPublicReadOnlyFieldName () public void TestPublicReadOnlyFieldName ()
@ -174,13 +174,13 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues
CheckNaming (input, output, true); CheckNaming (input, output, true);
} }
[Test] // [Test]
public void TestPrivateStaticFieldName () // public void TestPrivateStaticFieldName ()
{ // {
var input = @"class AClass { static int Field; }"; // var input = @"class AClass { static int Field; }";
var output = @"class AClass { static int field; }"; // var output = @"class AClass { static int field; }";
CheckNaming (input, output); // CheckNaming (input, output);
} // }
[Test] [Test]
public void TestPublicStaticReadOnlyFieldName () public void TestPublicStaticReadOnlyFieldName ()
@ -190,13 +190,13 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues
CheckNaming (input, output); CheckNaming (input, output);
} }
[Test] // [Test]
public void TestPrivateReadOnlyFieldName () // public void TestPrivateReadOnlyFieldName ()
{ // {
var input = @"class AClass { readonly int Field; }"; // var input = @"class AClass { readonly int Field; }";
var output = @"class AClass { readonly int field; }"; // var output = @"class AClass { readonly int field; }";
CheckNaming (input, output); // CheckNaming (input, output);
} // }
[Test] [Test]
public void TestPublicConstantFieldName () public void TestPublicConstantFieldName ()
@ -209,16 +209,16 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues
[Test] [Test]
public void TestMethodName () public void TestMethodName ()
{ {
var input = @"class AClass { int method () {} }"; var input = @"class AClass { public int method () {} }";
var output = @"class AClass { int Method () {} }"; var output = @"class AClass { public int Method () {} }";
CheckNaming (input, output); CheckNaming (input, output);
} }
[Test] [Test]
public void TestPropertyName () public void TestPropertyName ()
{ {
var input = @"class AClass { int property { get; set; } }"; var input = @"class AClass { public int property { get; set; } }";
var output = @"class AClass { int Property { get; set; } }"; var output = @"class AClass { public int Property { get; set; } }";
CheckNaming (input, output); CheckNaming (input, output);
} }

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

@ -35,8 +35,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
CSharpParser parser = new CSharpParser(); CSharpParser parser = new CSharpParser();
CompilationUnit cu = parser.Parse(new StringReader(code), "parsed.cs"); CompilationUnit cu = parser.Parse(new StringReader(code), "parsed.cs");
if (parser.HasErrors) foreach (var error in parser.Errors)
parser.ErrorPrinter.Errors.ForEach (err => Console.WriteLine (err.Message)); Console.WriteLine (error.Message);
Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors"); Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors");
AstNode node = cu.Children.Single(); AstNode node = cu.Children.Single();
@ -58,8 +58,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
CSharpParser parser = new CSharpParser(); CSharpParser parser = new CSharpParser();
var statements = parser.ParseStatements(new StringReader(stmt)); var statements = parser.ParseStatements(new StringReader(stmt));
if (parser.HasErrors) foreach (var error in parser.Errors)
parser.ErrorPrinter.Errors.ForEach (err => Console.WriteLine (err.Message)); Console.WriteLine (error.Message);
Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors"); Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors");
AstNode statement = statements.Single(); AstNode statement = statements.Single();
@ -81,8 +81,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
CSharpParser parser = new CSharpParser(); CSharpParser parser = new CSharpParser();
AstNode parsedExpression = parser.ParseExpression(new StringReader(expr)); AstNode parsedExpression = parser.ParseExpression(new StringReader(expr));
if (parser.HasErrors) foreach (var error in parser.Errors)
parser.ErrorPrinter.Errors.ForEach (err => Console.WriteLine (err.Message)); Console.WriteLine (error.Message);
Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors"); Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors");
if (expectErrors && parsedExpression == null) if (expectErrors && parsedExpression == null)
return default (T); return default (T);
@ -103,8 +103,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
{ {
CSharpParser parser = new CSharpParser(); CSharpParser parser = new CSharpParser();
var members = parser.ParseTypeMembers(new StringReader(expr)); var members = parser.ParseTypeMembers(new StringReader(expr));
if (parser.HasErrors) foreach (var error in parser.Errors)
parser.ErrorPrinter.Errors.ForEach (err => Console.WriteLine (err.Message)); Console.WriteLine (error.Message);
Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors"); Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors");
EntityDeclaration m = members.Single(); EntityDeclaration m = members.Single();
Type type = typeof(T); Type type = typeof(T);
@ -125,8 +125,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
CSharpParser parser = new CSharpParser(); CSharpParser parser = new CSharpParser();
var parsedExpression = parser.ParseDocumentationReference(cref); var parsedExpression = parser.ParseDocumentationReference(cref);
if (parser.HasErrors) foreach (var error in parser.Errors)
parser.ErrorPrinter.Errors.ForEach (err => Console.WriteLine (err.Message)); Console.WriteLine (error.Message);
Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors"); Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors");
if (expectErrors && parsedExpression == null) if (expectErrors && parsedExpression == null)
return null; return null;

34
ICSharpCode.NRefactory.Tests/FormattingTests/TestWrapping.cs

@ -580,5 +580,39 @@ namespace ICSharpCode.NRefactory.CSharp.FormattingTests
}"); }");
} }
[Test()]
public void TestNoBlankLinesBetweenEndBraceAndEndParenthesis ()
{
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono ();
policy.BlankLinesBetweenMembers = 1;
var adapter = Test (policy, @"class Test
{
int Foo (int i, double d, Action a)
{
a ();
}
void Bar ()
{
Foo (1, 2, () => {
});
}
}",
@"class Test
{
int Foo (int i, double d, Action a)
{
a ();
}
void Bar ()
{
Foo (1, 2, () => {
});
}
}", FormattingMode.Intrusive);
}
} }
} }

3
ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup> <PropertyGroup>
<ProjectGuid>{63D3B27A-D966-4902-90B3-30290E1692F1}</ProjectGuid> <ProjectGuid>{63D3B27A-D966-4902-90B3-30290E1692F1}</ProjectGuid>
@ -283,6 +283,7 @@
<Compile Include="CSharp\CodeActions\ImplementInterfaceTests.cs" /> <Compile Include="CSharp\CodeActions\ImplementInterfaceTests.cs" />
<Compile Include="CSharp\CodeActions\ImplementInterfaceExplicitTests.cs" /> <Compile Include="CSharp\CodeActions\ImplementInterfaceExplicitTests.cs" />
<Compile Include="CSharp\CodeActions\ImplementAbstractMembersTest.cs" /> <Compile Include="CSharp\CodeActions\ImplementAbstractMembersTest.cs" />
<Compile Include="CSharp\CodeActions\ExtractFieldTests.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Mono.Cecil\Mono.Cecil.csproj"> <ProjectReference Include="..\..\Mono.Cecil\Mono.Cecil.csproj">

1
ICSharpCode.NRefactory.Tests/TypeSystem/CecilLoaderTests.cs

@ -145,7 +145,6 @@ namespace ICSharpCode.NRefactory.TypeSystem
Assert.AreEqual(0, c.GetProperties().Count()); Assert.AreEqual(0, c.GetProperties().Count());
Assert.AreEqual(0, c.GetEvents().Count()); Assert.AreEqual(0, c.GetEvents().Count());
Assert.AreEqual(0, c.GetFields().Count()); Assert.AreEqual(0, c.GetFields().Count());
Assert.AreEqual(3, c.Attributes.Count);
} }
[Test] [Test]

Loading…
Cancel
Save