Browse Source

Moved more roles to the Roles class/Changed TypeDeclaration

representation (saves some memory and class type is now always
defined).
newNRvisualizers
Mike Krüger 14 years ago
parent
commit
4ea7ebc517
  1. 13
      ICSharpCode.NRefactory.CSharp/Ast/CompilationUnit.cs
  2. 6
      ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/DelegateDeclaration.cs
  3. 7
      ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/ExternAliasDeclaration.cs
  4. 4
      ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/NamespaceDeclaration.cs
  5. 108
      ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/TypeDeclaration.cs
  6. 15
      ICSharpCode.NRefactory.CSharp/Ast/Roles.cs
  7. 4
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs
  8. 24
      ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpOutputVisitor.cs
  9. 69
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  10. 8
      ICSharpCode.NRefactory.CSharp/Refactoring/TypeSystemAstBuilder.cs
  11. 5
      ICSharpCode.NRefactory.Tests/CSharp/AstStructureTests.cs
  12. 5
      ICSharpCode.NRefactory.Tests/CSharp/CSharpOutputVisitorTests.cs
  13. 11
      ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/AttributeSectionTests.cs
  14. 8
      ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/PreprocessorDirectiveTests.cs
  15. 36
      ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/TypeDeclarationTests.cs
  16. 13
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/MethodDeclarationTests.cs
  17. 4
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/PropertyDeclarationTests.cs

13
ICSharpCode.NRefactory.CSharp/Ast/CompilationUnit.cs

@ -1,4 +1,4 @@
// //
// CompilationUnit.cs // CompilationUnit.cs
// //
// Author: // Author:
@ -72,17 +72,18 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
} }
public IEnumerable<TypeDeclaration> GetTypes (bool includeInnerTypes = false) public IEnumerable<TypeDeclaration> GetTypes(bool includeInnerTypes = false)
{ {
Stack<AstNode> nodeStack = new Stack<AstNode> (); Stack<AstNode> nodeStack = new Stack<AstNode> ();
nodeStack.Push (this); nodeStack.Push(this);
while (nodeStack.Count > 0) { while (nodeStack.Count > 0) {
var curNode = nodeStack.Pop (); var curNode = nodeStack.Pop();
if (curNode is TypeDeclaration) if (curNode is TypeDeclaration) {
yield return (TypeDeclaration)curNode; yield return (TypeDeclaration)curNode;
}
foreach (var child in curNode.Children) { foreach (var child in curNode.Children) {
if (!(child is Statement || child is Expression) && if (!(child is Statement || child is Expression) &&
(child.Role != TypeDeclaration.MemberRole || (child is TypeDeclaration && includeInnerTypes))) (child.Role != Roles.TypeMemberRole || (child is TypeDeclaration && includeInnerTypes)))
nodeStack.Push (child); nodeStack.Push (child);
} }
} }

6
ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/DelegateDeclaration.cs

@ -33,8 +33,6 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary> /// </summary>
public class DelegateDeclaration : EntityDeclaration public class DelegateDeclaration : EntityDeclaration
{ {
public readonly static TokenRole DelegateKeywordRole = new TokenRole ("delegate");
public override NodeType NodeType { public override NodeType NodeType {
get { return NodeType.TypeDeclaration; } get { return NodeType.TypeDeclaration; }
} }
@ -44,9 +42,9 @@ namespace ICSharpCode.NRefactory.CSharp
} }
public CSharpTokenNode DelegateToken { public CSharpTokenNode DelegateToken {
get { return GetChildByRole (DelegateKeywordRole); } get { return GetChildByRole(Roles.DelegateKeyword); }
} }
public AstNodeCollection<TypeParameterDeclaration> TypeParameters { public AstNodeCollection<TypeParameterDeclaration> TypeParameters {
get { return GetChildrenByRole (Roles.TypeParameter); } get { return GetChildrenByRole (Roles.TypeParameter); }
} }

7
ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/ExternAliasDeclaration.cs

@ -31,9 +31,6 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary> /// </summary>
public class ExternAliasDeclaration : AstNode public class ExternAliasDeclaration : AstNode
{ {
public static readonly TokenRole ExternKeywordRole = new TokenRole ("extern");
public static readonly TokenRole AliasKeywordRole = new TokenRole ("alias");
public override NodeType NodeType { public override NodeType NodeType {
get { get {
return NodeType.Unknown; return NodeType.Unknown;
@ -41,11 +38,11 @@ namespace ICSharpCode.NRefactory.CSharp
} }
public CSharpTokenNode ExternToken { public CSharpTokenNode ExternToken {
get { return GetChildByRole (ExternKeywordRole); } get { return GetChildByRole (Roles.ExternKeyword); }
} }
public CSharpTokenNode AliasToken { public CSharpTokenNode AliasToken {
get { return GetChildByRole (AliasKeywordRole); } get { return GetChildByRole (Roles.AliasKeyword); }
} }
public string Name { public string Name {

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

@ -35,8 +35,6 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary> /// </summary>
public class NamespaceDeclaration : AstNode public class NamespaceDeclaration : AstNode
{ {
public static readonly TokenRole NamespaceKeywordRole = new TokenRole ("namespace");
public static readonly Role<AstNode> MemberRole = CompilationUnit.MemberRole; public static readonly Role<AstNode> MemberRole = CompilationUnit.MemberRole;
public override NodeType NodeType { public override NodeType NodeType {
@ -46,7 +44,7 @@ namespace ICSharpCode.NRefactory.CSharp
} }
public CSharpTokenNode NamespaceToken { public CSharpTokenNode NamespaceToken {
get { return GetChildByRole (NamespaceKeywordRole); } get { return GetChildByRole (Roles.NamespaceKeyword); }
} }
public string Name { public string Name {

108
ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/TypeDeclaration.cs

@ -41,15 +41,8 @@ namespace ICSharpCode.NRefactory.CSharp
/// <summary> /// <summary>
/// class Name&lt;TypeParameters&gt; : BaseTypes where Constraints; /// class Name&lt;TypeParameters&gt; : BaseTypes where Constraints;
/// </summary> /// </summary>
public class TypeDeclaration : EntityDeclaration public abstract class TypeDeclaration : EntityDeclaration
{ {
public static readonly TokenRole EnumKeywordRole = new TokenRole ("enum");
public static readonly TokenRole InterfaceKeywordRole = new TokenRole ("interface");
public static readonly TokenRole StructKeywordRole = new TokenRole ("struct");
public static readonly TokenRole ClassKeywordRole = new TokenRole ("class");
public readonly static Role<EntityDeclaration> MemberRole = new Role<EntityDeclaration>("Member");
public override NodeType NodeType { public override NodeType NodeType {
get { return NodeType.TypeDeclaration; } get { return NodeType.TypeDeclaration; }
} }
@ -58,22 +51,25 @@ namespace ICSharpCode.NRefactory.CSharp
get { return EntityType.TypeDefinition; } get { return EntityType.TypeDefinition; }
} }
public ClassType ClassType {
public abstract CSharpTokenNode TypeKeyword {
get; get;
set;
} }
public abstract ClassType ClassType {
get;
}
public AstNodeCollection<TypeParameterDeclaration> TypeParameters { public AstNodeCollection<TypeParameterDeclaration> TypeParameters {
get { return GetChildrenByRole (Roles.TypeParameter); } get { return GetChildrenByRole (Roles.TypeParameter); }
} }
public AstNodeCollection<AstType> BaseTypes { public AstNodeCollection<AstType> BaseTypes {
get { get { return GetChildrenByRole(Roles.BaseType); }
return GetChildrenByRole(Roles.BaseType); }
} }
public AstNodeCollection<Constraint> Constraints { public AstNodeCollection<Constraint> Constraints {
get { return GetChildrenByRole (Roles.Constraint); } get { return GetChildrenByRole(Roles.Constraint); }
} }
public CSharpTokenNode LBraceToken { public CSharpTokenNode LBraceToken {
@ -81,7 +77,7 @@ namespace ICSharpCode.NRefactory.CSharp
} }
public AstNodeCollection<EntityDeclaration> Members { public AstNodeCollection<EntityDeclaration> Members {
get { return GetChildrenByRole (MemberRole); } get { return GetChildrenByRole (Roles.TypeMemberRole); }
} }
public CSharpTokenNode RBraceToken { public CSharpTokenNode RBraceToken {
@ -111,5 +107,87 @@ namespace ICSharpCode.NRefactory.CSharp
&& this.BaseTypes.DoMatch(o.BaseTypes, match) && this.Constraints.DoMatch(o.Constraints, match) && this.BaseTypes.DoMatch(o.BaseTypes, match) && this.Constraints.DoMatch(o.Constraints, match)
&& this.Members.DoMatch(o.Members, match); && this.Members.DoMatch(o.Members, match);
} }
protected TypeDeclaration ()
{
}
public static TypeDeclaration Create(ClassType type)
{
switch (type) {
case ICSharpCode.NRefactory.CSharp.ClassType.Class:
return new Class ();
case ICSharpCode.NRefactory.CSharp.ClassType.Struct:
return new Struct ();
case ICSharpCode.NRefactory.CSharp.ClassType.Interface:
return new Interface ();
case ICSharpCode.NRefactory.CSharp.ClassType.Enum:
return new Enum ();
default:
throw new System.ArgumentOutOfRangeException();
}
}
#region Concrete Types
public class Class : TypeDeclaration
{
public override ClassType ClassType {
get {
return ClassType.Class;
}
}
public override CSharpTokenNode TypeKeyword {
get {
return GetChildByRole(Roles.ClassKeyword);
}
}
}
public class Struct : TypeDeclaration
{
public override ClassType ClassType {
get {
return ClassType.Struct;
}
}
public override CSharpTokenNode TypeKeyword {
get {
return GetChildByRole(Roles.StructKeyword);
}
}
}
public class Interface : TypeDeclaration
{
public override ClassType ClassType {
get {
return ClassType.Interface;
}
}
public override CSharpTokenNode TypeKeyword {
get {
return GetChildByRole(Roles.InterfaceKeyword);
}
}
}
public class Enum : TypeDeclaration
{
public override ClassType ClassType {
get {
return ClassType.Enum;
}
}
public override CSharpTokenNode TypeKeyword {
get {
return GetChildByRole(Roles.EnumKeyword);
}
}
}
#endregion
} }
} }

15
ICSharpCode.NRefactory.CSharp/Ast/Roles.cs

@ -49,7 +49,10 @@ namespace ICSharpCode.NRefactory.CSharp
public readonly static Role<Constraint> Constraint = new Role<Constraint> ("Constraint"); public readonly static Role<Constraint> Constraint = new Role<Constraint> ("Constraint");
public static readonly Role<VariableInitializer> Variable = new Role<VariableInitializer> ("Variable", VariableInitializer.Null); public static readonly Role<VariableInitializer> Variable = new Role<VariableInitializer> ("Variable", VariableInitializer.Null);
public static readonly Role<Statement> EmbeddedStatement = new Role<Statement> ("EmbeddedStatement", CSharp.Statement.Null); public static readonly Role<Statement> EmbeddedStatement = new Role<Statement> ("EmbeddedStatement", CSharp.Statement.Null);
// public static readonly TokenRole Keyword = new TokenRole ("Keyword", CSharpTokenNode.Null); public readonly static Role<EntityDeclaration> TypeMemberRole = new Role<EntityDeclaration> ("TypeMember");
// public static readonly TokenRole Keyword = new TokenRole ("Keyword", CSharpTokenNode.Null);
// public static readonly TokenRole InKeyword = new TokenRole ("InKeyword", CSharpTokenNode.Null); // public static readonly TokenRole InKeyword = new TokenRole ("InKeyword", CSharpTokenNode.Null);
// some pre defined constants for most used punctuation // some pre defined constants for most used punctuation
@ -78,6 +81,16 @@ namespace ICSharpCode.NRefactory.CSharp
public readonly static TokenRole WhereKeyword = new TokenRole ("where"); public readonly static TokenRole WhereKeyword = new TokenRole ("where");
public readonly static Role<SimpleType> ConstraintTypeParameter = new Role<SimpleType> ("TypeParameter", SimpleType.Null); public readonly static Role<SimpleType> ConstraintTypeParameter = new Role<SimpleType> ("TypeParameter", SimpleType.Null);
public readonly static TokenRole DelegateKeyword = new TokenRole ("delegate");
public static readonly TokenRole ExternKeyword = new TokenRole ("extern");
public static readonly TokenRole AliasKeyword = new TokenRole ("alias");
public static readonly TokenRole NamespaceKeyword = new TokenRole ("namespace");
public static readonly TokenRole EnumKeyword = new TokenRole ("enum");
public static readonly TokenRole InterfaceKeyword = new TokenRole ("interface");
public static readonly TokenRole StructKeyword = new TokenRole ("struct");
public static readonly TokenRole ClassKeyword = new TokenRole ("class");
} }
} }

4
ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs

@ -1,4 +1,4 @@
// //
// CSharpCompletionEngine.cs // CSharpCompletionEngine.cs
// //
// Author: // Author:
@ -2238,7 +2238,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
member2.Remove (); member2.Remove ();
if (member is TypeDeclaration) { if (member is TypeDeclaration) {
member.AddChild (member2, TypeDeclaration.MemberRole); member.AddChild (member2, Roles.TypeMemberRole);
} else { } else {
member.ReplaceWith (member2); member.ReplaceWith (member2);
} }

24
ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpOutputVisitor.cs

@ -1382,7 +1382,7 @@ namespace ICSharpCode.NRefactory.CSharp
StartNode (delegateDeclaration); StartNode (delegateDeclaration);
WriteAttributes (delegateDeclaration.Attributes); WriteAttributes (delegateDeclaration.Attributes);
WriteModifiers (delegateDeclaration.ModifierTokens); WriteModifiers (delegateDeclaration.ModifierTokens);
WriteKeyword (DelegateDeclaration.DelegateKeywordRole); WriteKeyword (Roles.DelegateKeyword);
delegateDeclaration.ReturnType.AcceptVisitor (this); delegateDeclaration.ReturnType.AcceptVisitor (this);
Space (); Space ();
WriteIdentifier (delegateDeclaration.Name); WriteIdentifier (delegateDeclaration.Name);
@ -1396,10 +1396,10 @@ namespace ICSharpCode.NRefactory.CSharp
EndNode (delegateDeclaration); EndNode (delegateDeclaration);
} }
public void VisitNamespaceDeclaration (NamespaceDeclaration namespaceDeclaration) public void VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration)
{ {
StartNode (namespaceDeclaration); StartNode(namespaceDeclaration);
WriteKeyword (NamespaceDeclaration.NamespaceKeywordRole); WriteKeyword(Roles.NamespaceKeyword);
WriteQualifiedIdentifier (namespaceDeclaration.Identifiers); WriteQualifiedIdentifier (namespaceDeclaration.Identifiers);
OpenBrace (policy.NamespaceBraceStyle); OpenBrace (policy.NamespaceBraceStyle);
foreach (var member in namespaceDeclaration.Members) foreach (var member in namespaceDeclaration.Members)
@ -1418,19 +1418,19 @@ namespace ICSharpCode.NRefactory.CSharp
BraceStyle braceStyle; BraceStyle braceStyle;
switch (typeDeclaration.ClassType) { switch (typeDeclaration.ClassType) {
case ClassType.Enum: case ClassType.Enum:
WriteKeyword(TypeDeclaration.EnumKeywordRole); WriteKeyword(Roles.EnumKeyword);
braceStyle = policy.EnumBraceStyle; braceStyle = policy.EnumBraceStyle;
break; break;
case ClassType.Interface: case ClassType.Interface:
WriteKeyword(TypeDeclaration.InterfaceKeywordRole); WriteKeyword(Roles.InterfaceKeyword);
braceStyle = policy.InterfaceBraceStyle; braceStyle = policy.InterfaceBraceStyle;
break; break;
case ClassType.Struct: case ClassType.Struct:
WriteKeyword(TypeDeclaration.StructKeywordRole); WriteKeyword(Roles.StructKeyword);
braceStyle = policy.StructBraceStyle; braceStyle = policy.StructBraceStyle;
break; break;
default: default:
WriteKeyword(TypeDeclaration.ClassKeywordRole); WriteKeyword(Roles.ClassKeyword);
braceStyle = policy.ClassBraceStyle; braceStyle = policy.ClassBraceStyle;
break; break;
} }
@ -1492,12 +1492,12 @@ namespace ICSharpCode.NRefactory.CSharp
EndNode (usingDeclaration); EndNode (usingDeclaration);
} }
public void VisitExternAliasDeclaration (ExternAliasDeclaration externAliasDeclaration) public void VisitExternAliasDeclaration(ExternAliasDeclaration externAliasDeclaration)
{ {
StartNode (externAliasDeclaration); StartNode(externAliasDeclaration);
WriteKeyword (ExternAliasDeclaration.ExternKeywordRole); WriteKeyword(Roles.ExternKeyword);
Space (); Space ();
WriteKeyword (ExternAliasDeclaration.AliasKeywordRole); WriteKeyword (Roles.AliasKeyword);
Space (); Space ();
externAliasDeclaration.NameToken.AcceptVisitor (this); externAliasDeclaration.NameToken.AcceptVisitor (this);
Semicolon (); Semicolon ();

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

@ -81,7 +81,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (nspace.NS != null && !string.IsNullOrEmpty (nspace.NS.Name)) { if (nspace.NS != null && !string.IsNullOrEmpty (nspace.NS.Name)) {
nDecl = new NamespaceDeclaration (); nDecl = new NamespaceDeclaration ();
if (loc != null) if (loc != null)
nDecl.AddChild (new CSharpTokenNode (Convert (loc [0])), NamespaceDeclaration.NamespaceKeywordRole); nDecl.AddChild (new CSharpTokenNode (Convert (loc [0])), Roles.NamespaceKeyword);
ConvertNamespaceName (nspace.RealMemberName, nDecl); ConvertNamespaceName (nspace.RealMemberName, nDecl);
if (loc != null && loc.Count > 1) if (loc != null && loc.Count > 1)
nDecl.AddChild (new CSharpTokenNode (Convert (loc [1])), Roles.LBrace); nDecl.AddChild (new CSharpTokenNode (Convert (loc [1])), Roles.LBrace);
@ -352,7 +352,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (nspace.NS != null && !string.IsNullOrEmpty (nspace.NS.Name)) { if (nspace.NS != null && !string.IsNullOrEmpty (nspace.NS.Name)) {
nDecl = new NamespaceDeclaration (); nDecl = new NamespaceDeclaration ();
if (loc != null) if (loc != null)
nDecl.AddChild (new CSharpTokenNode (Convert (loc [0])), NamespaceDeclaration.NamespaceKeywordRole); nDecl.AddChild (new CSharpTokenNode (Convert (loc [0])), Roles.NamespaceKeyword);
ConvertNamespaceName (nspace.RealMemberName, nDecl); ConvertNamespaceName (nspace.RealMemberName, nDecl);
if (loc != null && loc.Count > 1) if (loc != null && loc.Count > 1)
nDecl.AddChild (new CSharpTokenNode (Convert (loc [1])), Roles.LBrace); nDecl.AddChild (new CSharpTokenNode (Convert (loc [1])), Roles.LBrace);
@ -442,9 +442,9 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
var ud = new ExternAliasDeclaration (); var ud = new ExternAliasDeclaration ();
var loc = LocationsBag.GetLocations (uea); var loc = LocationsBag.GetLocations (uea);
ud.AddChild (new CSharpTokenNode (Convert (uea.Location)), ExternAliasDeclaration.ExternKeywordRole); ud.AddChild (new CSharpTokenNode (Convert (uea.Location)), Roles.ExternKeyword);
if (loc != null) if (loc != null)
ud.AddChild (new CSharpTokenNode (Convert (loc [0])), ExternAliasDeclaration.AliasKeywordRole); ud.AddChild (new CSharpTokenNode (Convert (loc [0])), Roles.AliasKeyword);
ud.AddChild (Identifier.Create (uea.Alias.Value, Convert (uea.Alias.Location)), Roles.Identifier); ud.AddChild (Identifier.Create (uea.Alias.Value, Convert (uea.Alias.Location)), Roles.Identifier);
if (loc != null && loc.Count > 1) if (loc != null && loc.Count > 1)
ud.AddChild (new CSharpTokenNode (Convert (loc [1])), Roles.Semicolon); ud.AddChild (new CSharpTokenNode (Convert (loc [1])), Roles.Semicolon);
@ -483,15 +483,14 @@ namespace ICSharpCode.NRefactory.CSharp
public override void Visit(Class c) public override void Visit(Class c)
{ {
TypeDeclaration newType = new TypeDeclaration (); var newType = new TypeDeclaration.Class ();
newType.ClassType = ClassType.Class;
AddAttributeSection(newType, c); AddAttributeSection(newType, c);
var location = LocationsBag.GetMemberLocation(c); var location = LocationsBag.GetMemberLocation(c);
AddModifiers(newType, location); AddModifiers(newType, location);
int curLoc = 0; int curLoc = 0;
if (location != null) if (location != null)
newType.AddChild (new CSharpTokenNode (Convert (location [curLoc++])), TypeDeclaration.ClassKeywordRole); newType.AddChild (new CSharpTokenNode (Convert (location [curLoc++])), Roles.ClassKeyword);
newType.AddChild (Identifier.Create (c.MemberName.Name, Convert (c.MemberName.Location)), Roles.Identifier); newType.AddChild (Identifier.Create (c.MemberName.Name, Convert (c.MemberName.Location)), Roles.Identifier);
AddTypeParameters (newType, c.MemberName); AddTypeParameters (newType, c.MemberName);
@ -534,14 +533,13 @@ namespace ICSharpCode.NRefactory.CSharp
public override void Visit(Struct s) public override void Visit(Struct s)
{ {
TypeDeclaration newType = new TypeDeclaration (); var newType = new TypeDeclaration.Struct();
newType.ClassType = ClassType.Struct;
AddAttributeSection(newType, s); AddAttributeSection(newType, s);
var location = LocationsBag.GetMemberLocation(s); var location = LocationsBag.GetMemberLocation(s);
AddModifiers(newType, location); AddModifiers(newType, location);
int curLoc = 0; int curLoc = 0;
if (location != null) if (location != null)
newType.AddChild (new CSharpTokenNode (Convert (location [curLoc++])), TypeDeclaration.StructKeywordRole); newType.AddChild (new CSharpTokenNode (Convert (location [curLoc++])), Roles.StructKeyword);
newType.AddChild (Identifier.Create (s.MemberName.Name, Convert (s.MemberName.Location)), Roles.Identifier); newType.AddChild (Identifier.Create (s.MemberName.Name, Convert (s.MemberName.Location)), Roles.Identifier);
AddTypeParameters (newType, s.MemberName); AddTypeParameters (newType, s.MemberName);
@ -579,14 +577,13 @@ namespace ICSharpCode.NRefactory.CSharp
public override void Visit(Interface i) public override void Visit(Interface i)
{ {
TypeDeclaration newType = new TypeDeclaration (); var newType = new TypeDeclaration.Interface ();
newType.ClassType = ClassType.Interface;
AddAttributeSection(newType, i); AddAttributeSection(newType, i);
var location = LocationsBag.GetMemberLocation(i); var location = LocationsBag.GetMemberLocation(i);
AddModifiers(newType, location); AddModifiers(newType, location);
int curLoc = 0; int curLoc = 0;
if (location != null) if (location != null)
newType.AddChild (new CSharpTokenNode (Convert (location [curLoc++])), TypeDeclaration.InterfaceKeywordRole); newType.AddChild (new CSharpTokenNode (Convert (location [curLoc++])), Roles.InterfaceKeyword);
newType.AddChild (Identifier.Create (i.MemberName.Name, Convert (i.MemberName.Location)), Roles.Identifier); newType.AddChild (Identifier.Create (i.MemberName.Name, Convert (i.MemberName.Location)), Roles.Identifier);
AddTypeParameters (newType, i.MemberName); AddTypeParameters (newType, i.MemberName);
@ -622,14 +619,15 @@ namespace ICSharpCode.NRefactory.CSharp
AddType (newType); AddType (newType);
} }
public override void Visit (Mono.CSharp.Delegate d) public override void Visit(Mono.CSharp.Delegate d)
{ {
DelegateDeclaration newDelegate = new DelegateDeclaration (); DelegateDeclaration newDelegate = new DelegateDeclaration ();
var location = LocationsBag.GetMemberLocation (d); var location = LocationsBag.GetMemberLocation(d);
AddAttributeSection (newDelegate, d); AddAttributeSection(newDelegate, d);
AddModifiers (newDelegate, location); AddModifiers(newDelegate, location);
if (location != null) if (location != null) {
newDelegate.AddChild (new CSharpTokenNode (Convert (location [0])), DelegateDeclaration.DelegateKeywordRole); newDelegate.AddChild(new CSharpTokenNode (Convert(location [0])), Roles.DelegateKeyword);
}
newDelegate.AddChild (ConvertToType (d.ReturnType), Roles.Type); newDelegate.AddChild (ConvertToType (d.ReturnType), Roles.Type);
newDelegate.AddChild (Identifier.Create (d.MemberName.Name, Convert (d.MemberName.Location)), Roles.Identifier); newDelegate.AddChild (Identifier.Create (d.MemberName.Name, Convert (d.MemberName.Location)), Roles.Identifier);
AddTypeParameters (newDelegate, d.MemberName); AddTypeParameters (newDelegate, d.MemberName);
@ -651,7 +649,7 @@ namespace ICSharpCode.NRefactory.CSharp
void AddType (EntityDeclaration child) void AddType (EntityDeclaration child)
{ {
if (typeStack.Count > 0) { if (typeStack.Count > 0) {
typeStack.Peek ().AddChild (child, TypeDeclaration.MemberRole); typeStack.Peek ().AddChild (child, Roles.TypeMemberRole);
} else { } else {
AddToNamespace (child); AddToNamespace (child);
} }
@ -668,15 +666,14 @@ namespace ICSharpCode.NRefactory.CSharp
public override void Visit(Mono.CSharp.Enum e) public override void Visit(Mono.CSharp.Enum e)
{ {
TypeDeclaration newType = new TypeDeclaration (); var newType = new TypeDeclaration.Enum ();
AddAttributeSection(newType, e); AddAttributeSection(newType, e);
newType.ClassType = ClassType.Enum;
var location = LocationsBag.GetMemberLocation(e); var location = LocationsBag.GetMemberLocation(e);
AddModifiers(newType, location); AddModifiers(newType, location);
int curLoc = 0; int curLoc = 0;
if (location != null) if (location != null)
newType.AddChild (new CSharpTokenNode (Convert (location [curLoc++])), TypeDeclaration.EnumKeywordRole); newType.AddChild (new CSharpTokenNode (Convert (location [curLoc++])), Roles.EnumKeyword);
newType.AddChild (Identifier.Create (e.MemberName.Name, Convert (e.MemberName.Location)), Roles.Identifier); newType.AddChild (Identifier.Create (e.MemberName.Name, Convert (e.MemberName.Location)), Roles.Identifier);
if (e.BaseTypeExpression != null) { if (e.BaseTypeExpression != null) {
@ -719,7 +716,7 @@ namespace ICSharpCode.NRefactory.CSharp
} }
//Console.WriteLine (newField.StartLocation +"-" + newField.EndLocation); //Console.WriteLine (newField.StartLocation +"-" + newField.EndLocation);
typeStack.Peek ().AddChild (newField, TypeDeclaration.MemberRole); typeStack.Peek ().AddChild (newField, Roles.TypeMemberRole);
} }
#endregion #endregion
@ -771,7 +768,7 @@ namespace ICSharpCode.NRefactory.CSharp
} }
if (location != null) if (location != null)
newField.AddChild (new CSharpTokenNode (Convert (location [1])), Roles.Semicolon); newField.AddChild (new CSharpTokenNode (Convert (location [1])), Roles.Semicolon);
typeStack.Peek ().AddChild (newField, TypeDeclaration.MemberRole); typeStack.Peek ().AddChild (newField, Roles.TypeMemberRole);
} }
@ -812,7 +809,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null) if (location != null)
newField.AddChild (new CSharpTokenNode (Convert (location [location.Count - 1])), Roles.Semicolon); newField.AddChild (new CSharpTokenNode (Convert (location [location.Count - 1])), Roles.Semicolon);
typeStack.Peek ().AddChild (newField, TypeDeclaration.MemberRole); typeStack.Peek ().AddChild (newField, Roles.TypeMemberRole);
} }
public override void Visit (Const f) public override void Visit (Const f)
@ -852,7 +849,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null) if (location != null)
newField.AddChild (new CSharpTokenNode (Convert (location [1])), Roles.Semicolon); newField.AddChild (new CSharpTokenNode (Convert (location [1])), Roles.Semicolon);
typeStack.Peek ().AddChild (newField, TypeDeclaration.MemberRole); typeStack.Peek ().AddChild (newField, Roles.TypeMemberRole);
} }
@ -902,7 +899,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null && location.Count >= 5) if (location != null && location.Count >= 5)
newOperator.AddChild (new CSharpTokenNode (Convert (location [4])), Roles.Semicolon); newOperator.AddChild (new CSharpTokenNode (Convert (location [4])), Roles.Semicolon);
} }
typeStack.Peek ().AddChild (newOperator, TypeDeclaration.MemberRole); typeStack.Peek ().AddChild (newOperator, Roles.TypeMemberRole);
} }
public void AddAttributeSection (AstNode parent, Attributable a) public void AddAttributeSection (AstNode parent, Attributable a)
@ -985,7 +982,7 @@ namespace ICSharpCode.NRefactory.CSharp
// parser error, set end node to max value. // parser error, set end node to max value.
newIndexer.AddChild (new ErrorNode (), Roles.Error); newIndexer.AddChild (new ErrorNode (), Roles.Error);
} }
typeStack.Peek ().AddChild (newIndexer, TypeDeclaration.MemberRole); typeStack.Peek ().AddChild (newIndexer, Roles.TypeMemberRole);
} }
public override void Visit (Method m) public override void Visit (Method m)
@ -1024,7 +1021,7 @@ namespace ICSharpCode.NRefactory.CSharp
newMethod.AddChild (new CSharpTokenNode (Convert (location [2])), Roles.Semicolon); newMethod.AddChild (new CSharpTokenNode (Convert (location [2])), Roles.Semicolon);
} }
} }
typeStack.Peek ().AddChild (newMethod, TypeDeclaration.MemberRole); typeStack.Peek ().AddChild (newMethod, Roles.TypeMemberRole);
} }
static Dictionary<Mono.CSharp.Modifiers, ICSharpCode.NRefactory.CSharp.Modifiers> modifierTable = new Dictionary<Mono.CSharp.Modifiers, ICSharpCode.NRefactory.CSharp.Modifiers> (); static Dictionary<Mono.CSharp.Modifiers, ICSharpCode.NRefactory.CSharp.Modifiers> modifierTable = new Dictionary<Mono.CSharp.Modifiers, ICSharpCode.NRefactory.CSharp.Modifiers> ();
@ -1151,7 +1148,7 @@ namespace ICSharpCode.NRefactory.CSharp
newProperty.AddChild (new ErrorNode (), Roles.Error); newProperty.AddChild (new ErrorNode (), Roles.Error);
} }
typeStack.Peek ().AddChild (newProperty, TypeDeclaration.MemberRole); typeStack.Peek ().AddChild (newProperty, Roles.TypeMemberRole);
} }
public override void Visit (Constructor c) public override void Visit (Constructor c)
@ -1188,7 +1185,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (c.Block != null) if (c.Block != null)
newConstructor.AddChild ((BlockStatement)c.Block.Accept (this), Roles.Body); newConstructor.AddChild ((BlockStatement)c.Block.Accept (this), Roles.Body);
typeStack.Peek ().AddChild (newConstructor, TypeDeclaration.MemberRole); typeStack.Peek ().AddChild (newConstructor, Roles.TypeMemberRole);
} }
public override void Visit (Destructor d) public override void Visit (Destructor d)
@ -1211,7 +1208,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (d.Block != null) if (d.Block != null)
newDestructor.AddChild ((BlockStatement)d.Block.Accept (this), Roles.Body); newDestructor.AddChild ((BlockStatement)d.Block.Accept (this), Roles.Body);
typeStack.Peek ().AddChild (newDestructor, TypeDeclaration.MemberRole); typeStack.Peek ().AddChild (newDestructor, Roles.TypeMemberRole);
} }
public override void Visit (EventField e) public override void Visit (EventField e)
@ -1255,9 +1252,9 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null && location.Count > 1) if (location != null && location.Count > 1)
newEvent.AddChild (new CSharpTokenNode (Convert (location [1])), Roles.Semicolon); newEvent.AddChild (new CSharpTokenNode (Convert (location [1])), Roles.Semicolon);
typeStack.Peek ().AddChild (newEvent, TypeDeclaration.MemberRole); typeStack.Peek ().AddChild (newEvent, Roles.TypeMemberRole);
} }
void AddExplicitInterface (AstNode parent, MemberName memberName) void AddExplicitInterface (AstNode parent, MemberName memberName)
{ {
if (memberName == null || memberName.ExplicitInterface == null) if (memberName == null || memberName.ExplicitInterface == null)
@ -1316,7 +1313,7 @@ namespace ICSharpCode.NRefactory.CSharp
newEvent.AddChild (new ErrorNode (), Roles.Error); newEvent.AddChild (new ErrorNode (), Roles.Error);
} }
typeStack.Peek ().AddChild (newEvent, TypeDeclaration.MemberRole); typeStack.Peek ().AddChild (newEvent, Roles.TypeMemberRole);
} }
#endregion #endregion

8
ICSharpCode.NRefactory.CSharp/Refactoring/TypeSystemAstBuilder.cs

@ -466,18 +466,18 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
break; break;
case TypeKind.Delegate: case TypeKind.Delegate:
IMethod invoke = typeDefinition.GetDelegateInvokeMethod(); IMethod invoke = typeDefinition.GetDelegateInvokeMethod();
if (invoke != null) if (invoke != null) {
return ConvertDelegate(invoke, modifiers); return ConvertDelegate(invoke, modifiers);
else } else {
goto default; goto default;
}
default: default:
classType = ClassType.Class; classType = ClassType.Class;
break; break;
} }
TypeDeclaration decl = new TypeDeclaration(); var decl = TypeDeclaration.Create(classType);
decl.Modifiers = modifiers; decl.Modifiers = modifiers;
decl.ClassType = classType;
decl.Name = typeDefinition.Name; decl.Name = typeDefinition.Name;
int outerTypeParameterCount = (typeDefinition.DeclaringTypeDefinition == null) ? 0 : typeDefinition.DeclaringTypeDefinition.TypeParameterCount; int outerTypeParameterCount = (typeDefinition.DeclaringTypeDefinition == null) ? 0 : typeDefinition.DeclaringTypeDefinition.TypeParameterCount;

5
ICSharpCode.NRefactory.Tests/CSharp/AstStructureTests.cs

@ -26,11 +26,12 @@ namespace ICSharpCode.NRefactory.CSharp
public class AstStructureTests public class AstStructureTests
{ {
[Test] [Test]
public void RolesAreStaticReadOnly() public void RolesAreStaticReadOnly ()
{ {
foreach (Type type in typeof(AstNode).Assembly.GetExportedTypes()) { foreach (Type type in typeof(AstNode).Assembly.GetExportedTypes()) {
if (type.IsSubclassOf(typeof(AstNode))) { if (type.IsSubclassOf (typeof(AstNode))) {
foreach (FieldInfo field in type.GetFields()) { foreach (FieldInfo field in type.GetFields()) {
Console.WriteLine (field);
if (field.FieldType.IsSubclassOf(typeof(Role))) { if (field.FieldType.IsSubclassOf(typeof(Role))) {
Assert.IsTrue(field.IsPublic); Assert.IsTrue(field.IsPublic);
Assert.IsTrue(field.IsStatic); Assert.IsTrue(field.IsStatic);

5
ICSharpCode.NRefactory.Tests/CSharp/CSharpOutputVisitorTests.cs

@ -51,10 +51,9 @@ namespace ICSharpCode.NRefactory.CSharp
} }
[Test] [Test]
public void EnumDeclarationWithInitializers() public void EnumDeclarationWithInitializers ()
{ {
TypeDeclaration type = new TypeDeclaration { TypeDeclaration type = new TypeDeclaration.Enum {
ClassType = ClassType.Enum,
Name = "DisplayFlags", Name = "DisplayFlags",
Members = { Members = {
new EnumMemberDeclaration { new EnumMemberDeclaration {

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

@ -97,7 +97,7 @@ public class Form1 {
{ {
ParseUtilCSharp.AssertGlobal( ParseUtilCSharp.AssertGlobal(
@"[A, B] class Test {}", @"[A, B] class Test {}",
new TypeDeclaration { new TypeDeclaration.Class {
Name = "Test", Name = "Test",
Attributes = { Attributes = {
new AttributeSection { new AttributeSection {
@ -113,8 +113,7 @@ public class Form1 {
{ {
ParseUtilCSharp.AssertGlobal( ParseUtilCSharp.AssertGlobal(
"class Test<[A,B]C> {}", "class Test<[A,B]C> {}",
new TypeDeclaration { new TypeDeclaration.Class {
ClassType = ClassType.Class,
Name = "Test", Name = "Test",
TypeParameters = { TypeParameters = {
new TypeParameterDeclaration { new TypeParameterDeclaration {
@ -169,11 +168,11 @@ public class Form1 {
// TODO: Tests for other contexts where attributes can appear // TODO: Tests for other contexts where attributes can appear
[Test] [Test]
public void AttributeWithNamedArguments() public void AttributeWithNamedArguments ()
{ {
ParseUtilCSharp.AssertTypeMember( ParseUtilCSharp.AssertTypeMember (
@"[A(0, a:1, b=2)] class Test {}", @"[A(0, a:1, b=2)] class Test {}",
new TypeDeclaration { new TypeDeclaration.Class {
Name = "Test", Name = "Test",
Attributes = { Attributes = {
new AttributeSection { new AttributeSection {

8
ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/PreprocessorDirectiveTests.cs

@ -1,4 +1,4 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team // Copyright (c) AlphaSierraPapa for the SharpDevelop Team
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy of this // 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 // software and associated documentation files (the "Software"), to deal in the Software
@ -37,7 +37,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
Assert.AreEqual(0, ns.Members.Count); Assert.AreEqual(0, ns.Members.Count);
Assert.AreEqual(new Role[] { Assert.AreEqual(new Role[] {
NamespaceDeclaration.NamespaceKeywordRole, Roles.NamespaceKeyword,
Roles.Identifier, Roles.Identifier,
Roles.LBrace, Roles.LBrace,
Roles.PreProcessorDirective, Roles.PreProcessorDirective,
@ -83,7 +83,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
Assert.AreEqual(0, ns.Members.Count); Assert.AreEqual(0, ns.Members.Count);
Assert.AreEqual(new Role[] { Assert.AreEqual(new Role[] {
NamespaceDeclaration.NamespaceKeywordRole, Roles.NamespaceKeyword,
Roles.Identifier, Roles.Identifier,
Roles.LBrace, Roles.LBrace,
Roles.PreProcessorDirective, Roles.PreProcessorDirective,
@ -110,7 +110,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
Assert.AreEqual(0, ns.Members.Count); Assert.AreEqual(0, ns.Members.Count);
Assert.AreEqual(new Role[] { Assert.AreEqual(new Role[] {
NamespaceDeclaration.NamespaceKeywordRole, Roles.NamespaceKeyword,
Roles.Identifier, Roles.Identifier,
Roles.LBrace, Roles.LBrace,
Roles.PreProcessorDirective, Roles.PreProcessorDirective,

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

@ -1,4 +1,4 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team // Copyright (c) AlphaSierraPapa for the SharpDevelop Team
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy of this // 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 // software and associated documentation files (the "Software"), to deal in the Software
@ -89,9 +89,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
{ {
ParseUtilCSharp.AssertGlobal( ParseUtilCSharp.AssertGlobal(
"public class G<T> {}", "public class G<T> {}",
new TypeDeclaration { new TypeDeclaration.Class {
Modifiers = Modifiers.Public, Modifiers = Modifiers.Public,
ClassType = ClassType.Class,
Name = "G", Name = "G",
TypeParameters = { new TypeParameterDeclaration { Name = "T" } } TypeParameters = { new TypeParameterDeclaration { Name = "T" } }
}); });
@ -102,9 +101,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
{ {
ParseUtilCSharp.AssertGlobal( ParseUtilCSharp.AssertGlobal(
@"public class Test<T> where T : IMyInterface { }", @"public class Test<T> where T : IMyInterface { }",
new TypeDeclaration { new TypeDeclaration.Class {
Modifiers = Modifiers.Public, Modifiers = Modifiers.Public,
ClassType = ClassType.Class,
Name = "Test", Name = "Test",
TypeParameters = { new TypeParameterDeclaration { Name = "T" } }, TypeParameters = { new TypeParameterDeclaration { Name = "T" } },
Constraints = { Constraints = {
@ -120,9 +118,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
{ {
ParseUtilCSharp.AssertGlobal( ParseUtilCSharp.AssertGlobal(
"public interface Generic<in T, out S> : System.IComparable where S : G<T[]>, new() where T : MyNamespace.IMyInterface {}", "public interface Generic<in T, out S> : System.IComparable where S : G<T[]>, new() where T : MyNamespace.IMyInterface {}",
new TypeDeclaration { new TypeDeclaration.Interface {
Modifiers = Modifiers.Public, Modifiers = Modifiers.Public,
ClassType = ClassType.Interface,
Name = "Generic", Name = "Generic",
TypeParameters = { TypeParameters = {
new TypeParameterDeclaration { Variance = VarianceModifier.Contravariant, Name = "T" }, new TypeParameterDeclaration { Variance = VarianceModifier.Contravariant, Name = "T" },
@ -167,7 +164,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
public abstract class MyClass : MyBase, Interface1, My.Test.Interface2 public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
{ {
}", }",
new TypeDeclaration { new TypeDeclaration.Class {
Attributes = { Attributes = {
new AttributeSection { new AttributeSection {
Attributes = { Attributes = {
@ -176,7 +173,6 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
} }
}, },
Modifiers = Modifiers.Public | Modifiers.Abstract, Modifiers = Modifiers.Public | Modifiers.Abstract,
ClassType = ClassType.Class,
Name = "MyClass", Name = "MyClass",
BaseTypes = { BaseTypes = {
new SimpleType("MyBase"), new SimpleType("MyBase"),
@ -223,9 +219,8 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
{ {
ParseUtilCSharp.AssertGlobal( ParseUtilCSharp.AssertGlobal(
"partial class partial<[partial: where] where> where where : partial<where> { }", "partial class partial<[partial: where] where> where where : partial<where> { }",
new TypeDeclaration { new TypeDeclaration.Class {
Modifiers = Modifiers.Partial, Modifiers = Modifiers.Partial,
ClassType = ClassType.Class,
Name = "partial", Name = "partial",
TypeParameters = { TypeParameters = {
new TypeParameterDeclaration { new TypeParameterDeclaration {
@ -305,12 +300,11 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
} }
[Test, Ignore("Mono parser crash")] [Test, Ignore("Mono parser crash")]
public void EnumWithIncorrectNewlineAfterIntegerLiteral() public void EnumWithIncorrectNewlineAfterIntegerLiteral ()
{ {
ParseUtilCSharp.AssertGlobal( ParseUtilCSharp.AssertGlobal (
"enum DisplayFlags { D = 4\r\r\n}", "enum DisplayFlags { D = 4\r\r\n}",
new TypeDeclaration { new TypeDeclaration.Enum {
ClassType = ClassType.Enum,
Name = "DisplayFlags", Name = "DisplayFlags",
Members = { Members = {
new EnumMemberDeclaration { new EnumMemberDeclaration {
@ -326,10 +320,10 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("enum MyEnum { A, }"); TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("enum MyEnum { A, }");
Assert.AreEqual( Assert.AreEqual(
new Role[] { new Role[] {
TypeDeclaration.EnumKeywordRole, Roles.EnumKeyword,
Roles.Identifier, Roles.Identifier,
Roles.LBrace, Roles.LBrace,
TypeDeclaration.MemberRole, Roles.TypeMemberRole,
Roles.Comma, Roles.Comma,
Roles.RBrace Roles.RBrace
}, td.Children.Select(c => c.Role).ToArray()); }, td.Children.Select(c => c.Role).ToArray());
@ -341,10 +335,10 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("enum MyEnum { A, };"); TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("enum MyEnum { A, };");
Assert.AreEqual( Assert.AreEqual(
new Role[] { new Role[] {
TypeDeclaration.EnumKeywordRole, Roles.EnumKeyword,
Roles.Identifier, Roles.Identifier,
Roles.LBrace, Roles.LBrace,
TypeDeclaration.MemberRole, Roles.TypeMemberRole,
Roles.Comma, Roles.Comma,
Roles.RBrace, Roles.RBrace,
Roles.Semicolon Roles.Semicolon
@ -357,10 +351,10 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("enum MyEnum { A };"); TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("enum MyEnum { A };");
Assert.AreEqual( Assert.AreEqual(
new Role[] { new Role[] {
TypeDeclaration.EnumKeywordRole, Roles.EnumKeyword,
Roles.Identifier, Roles.Identifier,
Roles.LBrace, Roles.LBrace,
TypeDeclaration.MemberRole, Roles.TypeMemberRole,
Roles.RBrace, Roles.RBrace,
Roles.Semicolon Roles.Semicolon
}, td.Children.Select(c => c.Role).ToArray()); }, td.Children.Select(c => c.Role).ToArray());

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

@ -165,8 +165,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
T MyMethod<T>(T a) where T : ISomeInterface; T MyMethod<T>(T a) where T : ISomeInterface;
} }
", ",
new TypeDeclaration { new TypeDeclaration.Interface {
ClassType = ClassType.Interface,
Name = "MyInterface", Name = "MyInterface",
Members = { Members = {
new MethodDeclaration { new MethodDeclaration {
@ -191,8 +190,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
void MyMethod<T>(T a) where T : ISomeInterface; void MyMethod<T>(T a) where T : ISomeInterface;
} }
", ",
new TypeDeclaration { new TypeDeclaration.Interface {
ClassType = ClassType.Interface,
Name = "MyInterface", Name = "MyInterface",
Members = { Members = {
new MethodDeclaration { new MethodDeclaration {
@ -210,15 +208,14 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
} }
[Test] [Test]
public void ShadowingMethodInInterface() public void ShadowingMethodInInterface ()
{ {
ParseUtilCSharp.AssertGlobal( ParseUtilCSharp.AssertGlobal (
@"interface MyInterface : IDisposable { @"interface MyInterface : IDisposable {
new void Dispose(); new void Dispose();
} }
", ",
new TypeDeclaration { new TypeDeclaration.Interface {
ClassType = ClassType.Interface,
Name = "MyInterface", Name = "MyInterface",
BaseTypes = { new SimpleType("IDisposable") }, BaseTypes = { new SimpleType("IDisposable") },
Members = { Members = {

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

@ -1,4 +1,4 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team // Copyright (c) AlphaSierraPapa for the SharpDevelop Team
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy of this // 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 // software and associated documentation files (the "Software"), to deal in the Software
@ -73,7 +73,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
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");
PropertyDeclaration pd = (PropertyDeclaration)cu.Children.Single().GetChildByRole(TypeDeclaration.MemberRole); PropertyDeclaration pd = (PropertyDeclaration)cu.Children.Single().GetChildByRole(Roles.TypeMemberRole);
Assert.AreEqual(new TextLocation(2, code.IndexOf("{\n\t\tget") - line2Pos + 1), pd.GetChildByRole(Roles.LBrace).StartLocation); Assert.AreEqual(new TextLocation(2, code.IndexOf("{\n\t\tget") - line2Pos + 1), pd.GetChildByRole(Roles.LBrace).StartLocation);
Assert.AreEqual(new TextLocation(5, 3), pd.EndLocation); Assert.AreEqual(new TextLocation(5, 3), pd.EndLocation);
Assert.AreEqual(new TextLocation(3, code.IndexOf("{ return") - line3Pos + 1), pd.Getter.Body.StartLocation); Assert.AreEqual(new TextLocation(3, code.IndexOf("{ return") - line3Pos + 1), pd.Getter.Body.StartLocation);

Loading…
Cancel
Save