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 @@ @@ -1,4 +1,4 @@
//
//
// CompilationUnit.cs
//
// Author:
@ -72,17 +72,18 @@ namespace ICSharpCode.NRefactory.CSharp @@ -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> ();
nodeStack.Push (this);
nodeStack.Push(this);
while (nodeStack.Count > 0) {
var curNode = nodeStack.Pop ();
if (curNode is TypeDeclaration)
var curNode = nodeStack.Pop();
if (curNode is TypeDeclaration) {
yield return (TypeDeclaration)curNode;
}
foreach (var child in curNode.Children) {
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);
}
}

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

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

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

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

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

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

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

@ -41,15 +41,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -41,15 +41,8 @@ namespace ICSharpCode.NRefactory.CSharp
/// <summary>
/// class Name&lt;TypeParameters&gt; : BaseTypes where Constraints;
/// </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 {
get { return NodeType.TypeDeclaration; }
}
@ -58,22 +51,25 @@ namespace ICSharpCode.NRefactory.CSharp @@ -58,22 +51,25 @@ namespace ICSharpCode.NRefactory.CSharp
get { return EntityType.TypeDefinition; }
}
public ClassType ClassType {
public abstract CSharpTokenNode TypeKeyword {
get;
set;
}
public abstract ClassType ClassType {
get;
}
public AstNodeCollection<TypeParameterDeclaration> TypeParameters {
get { return GetChildrenByRole (Roles.TypeParameter); }
}
public AstNodeCollection<AstType> BaseTypes {
get {
return GetChildrenByRole(Roles.BaseType); }
get { return GetChildrenByRole(Roles.BaseType); }
}
public AstNodeCollection<Constraint> Constraints {
get { return GetChildrenByRole (Roles.Constraint); }
get { return GetChildrenByRole(Roles.Constraint); }
}
public CSharpTokenNode LBraceToken {
@ -81,7 +77,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -81,7 +77,7 @@ namespace ICSharpCode.NRefactory.CSharp
}
public AstNodeCollection<EntityDeclaration> Members {
get { return GetChildrenByRole (MemberRole); }
get { return GetChildrenByRole (Roles.TypeMemberRole); }
}
public CSharpTokenNode RBraceToken {
@ -111,5 +107,87 @@ namespace ICSharpCode.NRefactory.CSharp @@ -111,5 +107,87 @@ namespace ICSharpCode.NRefactory.CSharp
&& this.BaseTypes.DoMatch(o.BaseTypes, match) && this.Constraints.DoMatch(o.Constraints, 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 @@ -49,7 +49,10 @@ namespace ICSharpCode.NRefactory.CSharp
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<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);
// some pre defined constants for most used punctuation
@ -78,6 +81,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -78,6 +81,16 @@ namespace ICSharpCode.NRefactory.CSharp
public readonly static TokenRole WhereKeyword = new TokenRole ("where");
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 @@ @@ -1,4 +1,4 @@
//
//
// CSharpCompletionEngine.cs
//
// Author:
@ -2238,7 +2238,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -2238,7 +2238,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
member2.Remove ();
if (member is TypeDeclaration) {
member.AddChild (member2, TypeDeclaration.MemberRole);
member.AddChild (member2, Roles.TypeMemberRole);
} else {
member.ReplaceWith (member2);
}

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

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

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

@ -81,7 +81,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -81,7 +81,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (nspace.NS != null && !string.IsNullOrEmpty (nspace.NS.Name)) {
nDecl = new NamespaceDeclaration ();
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);
if (loc != null && loc.Count > 1)
nDecl.AddChild (new CSharpTokenNode (Convert (loc [1])), Roles.LBrace);
@ -352,7 +352,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -352,7 +352,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (nspace.NS != null && !string.IsNullOrEmpty (nspace.NS.Name)) {
nDecl = new NamespaceDeclaration ();
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);
if (loc != null && loc.Count > 1)
nDecl.AddChild (new CSharpTokenNode (Convert (loc [1])), Roles.LBrace);
@ -442,9 +442,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -442,9 +442,9 @@ namespace ICSharpCode.NRefactory.CSharp
{
var ud = new ExternAliasDeclaration ();
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)
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);
if (loc != null && loc.Count > 1)
ud.AddChild (new CSharpTokenNode (Convert (loc [1])), Roles.Semicolon);
@ -483,15 +483,14 @@ namespace ICSharpCode.NRefactory.CSharp @@ -483,15 +483,14 @@ namespace ICSharpCode.NRefactory.CSharp
public override void Visit(Class c)
{
TypeDeclaration newType = new TypeDeclaration ();
newType.ClassType = ClassType.Class;
var newType = new TypeDeclaration.Class ();
AddAttributeSection(newType, c);
var location = LocationsBag.GetMemberLocation(c);
AddModifiers(newType, location);
int curLoc = 0;
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);
AddTypeParameters (newType, c.MemberName);
@ -534,14 +533,13 @@ namespace ICSharpCode.NRefactory.CSharp @@ -534,14 +533,13 @@ namespace ICSharpCode.NRefactory.CSharp
public override void Visit(Struct s)
{
TypeDeclaration newType = new TypeDeclaration ();
newType.ClassType = ClassType.Struct;
var newType = new TypeDeclaration.Struct();
AddAttributeSection(newType, s);
var location = LocationsBag.GetMemberLocation(s);
AddModifiers(newType, location);
int curLoc = 0;
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);
AddTypeParameters (newType, s.MemberName);
@ -579,14 +577,13 @@ namespace ICSharpCode.NRefactory.CSharp @@ -579,14 +577,13 @@ namespace ICSharpCode.NRefactory.CSharp
public override void Visit(Interface i)
{
TypeDeclaration newType = new TypeDeclaration ();
newType.ClassType = ClassType.Interface;
var newType = new TypeDeclaration.Interface ();
AddAttributeSection(newType, i);
var location = LocationsBag.GetMemberLocation(i);
AddModifiers(newType, location);
int curLoc = 0;
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);
AddTypeParameters (newType, i.MemberName);
@ -622,14 +619,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -622,14 +619,15 @@ namespace ICSharpCode.NRefactory.CSharp
AddType (newType);
}
public override void Visit (Mono.CSharp.Delegate d)
public override void Visit(Mono.CSharp.Delegate d)
{
DelegateDeclaration newDelegate = new DelegateDeclaration ();
var location = LocationsBag.GetMemberLocation (d);
AddAttributeSection (newDelegate, d);
AddModifiers (newDelegate, location);
if (location != null)
newDelegate.AddChild (new CSharpTokenNode (Convert (location [0])), DelegateDeclaration.DelegateKeywordRole);
var location = LocationsBag.GetMemberLocation(d);
AddAttributeSection(newDelegate, d);
AddModifiers(newDelegate, location);
if (location != null) {
newDelegate.AddChild(new CSharpTokenNode (Convert(location [0])), Roles.DelegateKeyword);
}
newDelegate.AddChild (ConvertToType (d.ReturnType), Roles.Type);
newDelegate.AddChild (Identifier.Create (d.MemberName.Name, Convert (d.MemberName.Location)), Roles.Identifier);
AddTypeParameters (newDelegate, d.MemberName);
@ -651,7 +649,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -651,7 +649,7 @@ namespace ICSharpCode.NRefactory.CSharp
void AddType (EntityDeclaration child)
{
if (typeStack.Count > 0) {
typeStack.Peek ().AddChild (child, TypeDeclaration.MemberRole);
typeStack.Peek ().AddChild (child, Roles.TypeMemberRole);
} else {
AddToNamespace (child);
}
@ -668,15 +666,14 @@ namespace ICSharpCode.NRefactory.CSharp @@ -668,15 +666,14 @@ namespace ICSharpCode.NRefactory.CSharp
public override void Visit(Mono.CSharp.Enum e)
{
TypeDeclaration newType = new TypeDeclaration ();
var newType = new TypeDeclaration.Enum ();
AddAttributeSection(newType, e);
newType.ClassType = ClassType.Enum;
var location = LocationsBag.GetMemberLocation(e);
AddModifiers(newType, location);
int curLoc = 0;
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);
if (e.BaseTypeExpression != null) {
@ -719,7 +716,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -719,7 +716,7 @@ namespace ICSharpCode.NRefactory.CSharp
}
//Console.WriteLine (newField.StartLocation +"-" + newField.EndLocation);
typeStack.Peek ().AddChild (newField, TypeDeclaration.MemberRole);
typeStack.Peek ().AddChild (newField, Roles.TypeMemberRole);
}
#endregion
@ -771,7 +768,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -771,7 +768,7 @@ namespace ICSharpCode.NRefactory.CSharp
}
if (location != null)
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 @@ -812,7 +809,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null)
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)
@ -852,7 +849,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -852,7 +849,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null)
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 @@ -902,7 +899,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null && location.Count >= 5)
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)
@ -985,7 +982,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -985,7 +982,7 @@ namespace ICSharpCode.NRefactory.CSharp
// parser error, set end node to max value.
newIndexer.AddChild (new ErrorNode (), Roles.Error);
}
typeStack.Peek ().AddChild (newIndexer, TypeDeclaration.MemberRole);
typeStack.Peek ().AddChild (newIndexer, Roles.TypeMemberRole);
}
public override void Visit (Method m)
@ -1024,7 +1021,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1024,7 +1021,7 @@ namespace ICSharpCode.NRefactory.CSharp
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> ();
@ -1151,7 +1148,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1151,7 +1148,7 @@ namespace ICSharpCode.NRefactory.CSharp
newProperty.AddChild (new ErrorNode (), Roles.Error);
}
typeStack.Peek ().AddChild (newProperty, TypeDeclaration.MemberRole);
typeStack.Peek ().AddChild (newProperty, Roles.TypeMemberRole);
}
public override void Visit (Constructor c)
@ -1188,7 +1185,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1188,7 +1185,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (c.Block != null)
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)
@ -1211,7 +1208,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1211,7 +1208,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (d.Block != null)
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)
@ -1255,9 +1252,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1255,9 +1252,9 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null && location.Count > 1)
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)
{
if (memberName == null || memberName.ExplicitInterface == null)
@ -1316,7 +1313,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1316,7 +1313,7 @@ namespace ICSharpCode.NRefactory.CSharp
newEvent.AddChild (new ErrorNode (), Roles.Error);
}
typeStack.Peek ().AddChild (newEvent, TypeDeclaration.MemberRole);
typeStack.Peek ().AddChild (newEvent, Roles.TypeMemberRole);
}
#endregion

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

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

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

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

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

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

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

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

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

@ -1,4 +1,4 @@ @@ -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
// software and associated documentation files (the "Software"), to deal in the Software
@ -37,7 +37,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope @@ -37,7 +37,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
Assert.AreEqual(0, ns.Members.Count);
Assert.AreEqual(new Role[] {
NamespaceDeclaration.NamespaceKeywordRole,
Roles.NamespaceKeyword,
Roles.Identifier,
Roles.LBrace,
Roles.PreProcessorDirective,
@ -83,7 +83,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope @@ -83,7 +83,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
Assert.AreEqual(0, ns.Members.Count);
Assert.AreEqual(new Role[] {
NamespaceDeclaration.NamespaceKeywordRole,
Roles.NamespaceKeyword,
Roles.Identifier,
Roles.LBrace,
Roles.PreProcessorDirective,
@ -110,7 +110,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope @@ -110,7 +110,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
Assert.AreEqual(0, ns.Members.Count);
Assert.AreEqual(new Role[] {
NamespaceDeclaration.NamespaceKeywordRole,
Roles.NamespaceKeyword,
Roles.Identifier,
Roles.LBrace,
Roles.PreProcessorDirective,

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

@ -1,4 +1,4 @@ @@ -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
// software and associated documentation files (the "Software"), to deal in the Software
@ -89,9 +89,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope @@ -89,9 +89,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
{
ParseUtilCSharp.AssertGlobal(
"public class G<T> {}",
new TypeDeclaration {
new TypeDeclaration.Class {
Modifiers = Modifiers.Public,
ClassType = ClassType.Class,
Name = "G",
TypeParameters = { new TypeParameterDeclaration { Name = "T" } }
});
@ -102,9 +101,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope @@ -102,9 +101,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
{
ParseUtilCSharp.AssertGlobal(
@"public class Test<T> where T : IMyInterface { }",
new TypeDeclaration {
new TypeDeclaration.Class {
Modifiers = Modifiers.Public,
ClassType = ClassType.Class,
Name = "Test",
TypeParameters = { new TypeParameterDeclaration { Name = "T" } },
Constraints = {
@ -120,9 +118,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope @@ -120,9 +118,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
{
ParseUtilCSharp.AssertGlobal(
"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,
ClassType = ClassType.Interface,
Name = "Generic",
TypeParameters = {
new TypeParameterDeclaration { Variance = VarianceModifier.Contravariant, Name = "T" },
@ -167,7 +164,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope @@ -167,7 +164,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
{
}",
new TypeDeclaration {
new TypeDeclaration.Class {
Attributes = {
new AttributeSection {
Attributes = {
@ -176,7 +173,6 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2 @@ -176,7 +173,6 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
}
},
Modifiers = Modifiers.Public | Modifiers.Abstract,
ClassType = ClassType.Class,
Name = "MyClass",
BaseTypes = {
new SimpleType("MyBase"),
@ -223,9 +219,8 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2 @@ -223,9 +219,8 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
{
ParseUtilCSharp.AssertGlobal(
"partial class partial<[partial: where] where> where where : partial<where> { }",
new TypeDeclaration {
new TypeDeclaration.Class {
Modifiers = Modifiers.Partial,
ClassType = ClassType.Class,
Name = "partial",
TypeParameters = {
new TypeParameterDeclaration {
@ -305,12 +300,11 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2 @@ -305,12 +300,11 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
}
[Test, Ignore("Mono parser crash")]
public void EnumWithIncorrectNewlineAfterIntegerLiteral()
public void EnumWithIncorrectNewlineAfterIntegerLiteral ()
{
ParseUtilCSharp.AssertGlobal(
ParseUtilCSharp.AssertGlobal (
"enum DisplayFlags { D = 4\r\r\n}",
new TypeDeclaration {
ClassType = ClassType.Enum,
new TypeDeclaration.Enum {
Name = "DisplayFlags",
Members = {
new EnumMemberDeclaration {
@ -326,10 +320,10 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2 @@ -326,10 +320,10 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("enum MyEnum { A, }");
Assert.AreEqual(
new Role[] {
TypeDeclaration.EnumKeywordRole,
Roles.EnumKeyword,
Roles.Identifier,
Roles.LBrace,
TypeDeclaration.MemberRole,
Roles.TypeMemberRole,
Roles.Comma,
Roles.RBrace
}, td.Children.Select(c => c.Role).ToArray());
@ -341,10 +335,10 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2 @@ -341,10 +335,10 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("enum MyEnum { A, };");
Assert.AreEqual(
new Role[] {
TypeDeclaration.EnumKeywordRole,
Roles.EnumKeyword,
Roles.Identifier,
Roles.LBrace,
TypeDeclaration.MemberRole,
Roles.TypeMemberRole,
Roles.Comma,
Roles.RBrace,
Roles.Semicolon
@ -357,10 +351,10 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2 @@ -357,10 +351,10 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>("enum MyEnum { A };");
Assert.AreEqual(
new Role[] {
TypeDeclaration.EnumKeywordRole,
Roles.EnumKeyword,
Roles.Identifier,
Roles.LBrace,
TypeDeclaration.MemberRole,
Roles.TypeMemberRole,
Roles.RBrace,
Roles.Semicolon
}, 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 @@ -165,8 +165,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
T MyMethod<T>(T a) where T : ISomeInterface;
}
",
new TypeDeclaration {
ClassType = ClassType.Interface,
new TypeDeclaration.Interface {
Name = "MyInterface",
Members = {
new MethodDeclaration {
@ -191,8 +190,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -191,8 +190,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
void MyMethod<T>(T a) where T : ISomeInterface;
}
",
new TypeDeclaration {
ClassType = ClassType.Interface,
new TypeDeclaration.Interface {
Name = "MyInterface",
Members = {
new MethodDeclaration {
@ -210,15 +208,14 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -210,15 +208,14 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
}
[Test]
public void ShadowingMethodInInterface()
public void ShadowingMethodInInterface ()
{
ParseUtilCSharp.AssertGlobal(
ParseUtilCSharp.AssertGlobal (
@"interface MyInterface : IDisposable {
new void Dispose();
}
",
new TypeDeclaration {
ClassType = ClassType.Interface,
new TypeDeclaration.Interface {
Name = "MyInterface",
BaseTypes = { new SimpleType("IDisposable") },
Members = {

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

@ -1,4 +1,4 @@ @@ -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
// software and associated documentation files (the "Software"), to deal in the Software
@ -73,7 +73,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers @@ -73,7 +73,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
CSharpParser parser = new CSharpParser();
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(5, 3), pd.EndLocation);
Assert.AreEqual(new TextLocation(3, code.IndexOf("{ return") - line3Pos + 1), pd.Getter.Body.StartLocation);

Loading…
Cancel
Save