From 9a1d759f9797e6b5d1a7a4ec2e7b1d7baab03fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Zgodzi=F1ski?= Date: Tue, 22 Feb 2011 21:14:33 +0100 Subject: [PATCH 1/7] Modifications of solution and project files made by VS2010. --- .../ICSharpCode.NRefactory.Demo.csproj | 16 ++++++++++++---- .../ICSharpCode.NRefactory.csproj | 6 ------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ICSharpCode.NRefactory.Demo/ICSharpCode.NRefactory.Demo.csproj b/ICSharpCode.NRefactory.Demo/ICSharpCode.NRefactory.Demo.csproj index 36ea620c69..906a947738 100644 --- a/ICSharpCode.NRefactory.Demo/ICSharpCode.NRefactory.Demo.csproj +++ b/ICSharpCode.NRefactory.Demo/ICSharpCode.NRefactory.Demo.csproj @@ -40,21 +40,29 @@ - + + Form + VBEditDialog.cs - + + UserControl + VBDomView.cs - + + Form + MainForm.cs - + + UserControl + VBDemo.cs diff --git a/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj b/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj index 6fdcd0c9f1..68821f9531 100644 --- a/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj +++ b/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj @@ -350,11 +350,5 @@ Mono.Cecil - - - {D68133BD-1E63-496E-9EDE-4FBDBF77B486} - Mono.Cecil - - \ No newline at end of file From 8bd4e5dad02fd76903d8a33898ef8ae3da9292ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Zgodzi=F1ski?= Date: Tue, 22 Feb 2011 23:56:47 +0100 Subject: [PATCH 2/7] Basic output of custom attributes attached to types and methods. --- .../CSharp/OutputVisitor/OutputVisitor.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs index cf880653e6..933a7f9a18 100644 --- a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs @@ -1083,7 +1083,8 @@ namespace ICSharpCode.NRefactory.CSharp StartNode(attribute); attribute.Type.AcceptVisitor(this, data); Space(policy.BeforeMethodCallParentheses); - WriteCommaSeparatedListInParenthesis(attribute.Arguments, policy.WithinMethodCallParentheses); + if (attribute.Arguments.Count != 0) + WriteCommaSeparatedListInParenthesis(attribute.Arguments, policy.WithinMethodCallParentheses); return EndNode(attribute); } @@ -1879,8 +1880,14 @@ namespace ICSharpCode.NRefactory.CSharp public object VisitSimpleType(SimpleType simpleType, object data) { + bool inAttribute = currentContainerNode is Attribute; StartNode(simpleType); - WriteIdentifier(simpleType.Identifier); + + var identifier = simpleType.Identifier; + if (inAttribute && identifier.EndsWith("Attribute")) + identifier = identifier.Substring(0, identifier.Length - 9); + WriteIdentifier(identifier); + WriteTypeArguments(simpleType.TypeArguments); return EndNode(simpleType); } From 5dfed88da703125a15f57b1ab12591fae5eb7b2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Zgodzi=F1ski?= Date: Wed, 23 Feb 2011 09:40:26 +0100 Subject: [PATCH 3/7] Removed redundant int base type of enum. --- .../CSharp/OutputVisitor/OutputVisitor.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs index 933a7f9a18..8c5911e706 100644 --- a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs @@ -1161,7 +1161,7 @@ namespace ICSharpCode.NRefactory.CSharp } WriteIdentifier(typeDeclaration.Name); WriteTypeParameters(typeDeclaration.TypeParameters); - if (typeDeclaration.BaseTypes.Any()) { + if (typeDeclaration.BaseTypes.Any() && !IsStandardEnum(typeDeclaration)) { Space(); WriteToken(":", TypeDeclaration.ColonRole); Space(); @@ -1192,6 +1192,22 @@ namespace ICSharpCode.NRefactory.CSharp NewLine(); return EndNode(typeDeclaration); } + + private static bool IsStandardEnum(TypeDeclaration typeDeclaration) + { + if (typeDeclaration.ClassType != ClassType.Enum) + { + return false; + } + + if (typeDeclaration.BaseTypes.Count != 1) // is is possible? + { + return false; + } + + var baseType = typeDeclaration.BaseTypes.First() as PrimitiveType; + return baseType != null && baseType.Keyword == "int"; + } public object VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration, object data) { From f2c860704e6aab86e8e43b6f62cfdab0a2470044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Zgodzi=F1ski?= Date: Wed, 23 Feb 2011 17:42:36 +0100 Subject: [PATCH 4/7] Print a custom attribute's positional arguments. --- ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Attribute.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Attribute.cs b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Attribute.cs index 877771736a..b5a44275b7 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Attribute.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Attribute.cs @@ -25,12 +25,14 @@ // THE SOFTWARE. using System.Collections.Generic; +using System.Diagnostics; namespace ICSharpCode.NRefactory.CSharp { /// /// Attribute(Arguments) /// + [DebuggerDisplay("Attribute {Type}")] public class Attribute : AstNode { public override NodeType NodeType { From a07f54537799513226c40f073db5282bb55b5162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Zgodzi=F1ski?= Date: Thu, 24 Feb 2011 22:28:37 +0100 Subject: [PATCH 5/7] Printing initializers of enum members. --- .../CSharp/OutputVisitor/OutputVisitor.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs index 4e3111458a..ec0ad4b929 100644 --- a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs @@ -146,13 +146,14 @@ namespace ICSharpCode.NRefactory.CSharp /// Writes a comma. /// /// The next node after the comma. - void Comma(AstNode nextNode) + /// When set prevents printing a space after comma. + void Comma(AstNode nextNode, bool noSpacesAfterComma = false) { WriteSpecialsUpToRole(AstNode.Roles.Comma, nextNode); Space(policy.SpacesBeforeComma); formatter.WriteToken(","); lastWritten = LastWritten.Other; - Space(policy.SpacesAfterComma); + Space(!noSpacesAfterComma && policy.SpacesAfterComma); } void WriteCommaSeparatedList(IEnumerable list) @@ -1187,7 +1188,7 @@ namespace ICSharpCode.NRefactory.CSharp if (first) { first = false; } else { - Comma(member); + Comma(member, noSpacesAfterComma: true); NewLine(); } member.AcceptVisitor(this, data); From 74fd14a2f56a048df588ce352ebe25058dad501f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Zgodzi=F1ski?= Date: Sat, 26 Feb 2011 08:50:05 +0100 Subject: [PATCH 6/7] attributed parameter declaration. --- .../CSharp/Ast/TypeMembers/ParameterDeclaration.cs | 2 +- ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs index 0334d2a3fb..05bd3140e0 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ParameterDeclaration.cs @@ -38,7 +38,7 @@ namespace ICSharpCode.NRefactory.CSharp This } - public class ParameterDeclaration : AstNode + public class ParameterDeclaration : AttributedNode { public static readonly Role AttributeRole = AttributedNode.AttributeRole; public static readonly Role ModifierRole = new Role("Modifier", CSharpTokenNode.Null); diff --git a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs index ec0ad4b929..1a7f0e4989 100644 --- a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs @@ -1110,7 +1110,8 @@ namespace ICSharpCode.NRefactory.CSharp } WriteCommaSeparatedList(attributeSection.Attributes); WriteToken("]", AstNode.Roles.RBracket); - NewLine(); + if (!(attributeSection.Parent is ParameterDeclaration)) + NewLine(); return EndNode(attributeSection); } From f4f554d5ace0d6c17283d55a1f85442b0cdc44ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Zgodzi=F1ski?= Date: Sat, 26 Feb 2011 13:12:19 +0100 Subject: [PATCH 7/7] more attribute targets implemented. --- ICSharpCode.NRefactory/CSharp/Ast/CompilationUnit.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/CompilationUnit.cs b/ICSharpCode.NRefactory/CSharp/Ast/CompilationUnit.cs index 9a50477191..1b97a4cd05 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/CompilationUnit.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/CompilationUnit.cs @@ -28,7 +28,7 @@ using System.Collections.Generic; namespace ICSharpCode.NRefactory.CSharp { - public class CompilationUnit : AstNode + public class CompilationUnit : AttributedNode { public static readonly Role MemberRole = new Role("Member", AstNode.Null);