Browse Source

Added unattached attributes to the AST.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
6054ed469a
  1. 1
      ICSharpCode.NRefactory.CSharp/Ast/TypeMembers/AttributedNode.cs
  2. 16
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  3. 5
      ICSharpCode.NRefactory.CSharp/TypeSystem/CSharpAttribute.cs

1
ICSharpCode.NRefactory.CSharp/Ast/TypeMembers/AttributedNode.cs

@ -25,6 +25,7 @@ namespace ICSharpCode.NRefactory.CSharp
public abstract class AttributedNode : AstNode public abstract class AttributedNode : AstNode
{ {
public static readonly Role<AttributeSection> AttributeRole = new Role<AttributeSection>("Attribute"); public static readonly Role<AttributeSection> AttributeRole = new Role<AttributeSection>("Attribute");
public static readonly Role<AttributeSection> UnattachedAttributeRole = new Role<AttributeSection>("UnattachedAttribute");
public static readonly Role<CSharpModifierToken> ModifierRole = new Role<CSharpModifierToken>("Modifier"); public static readonly Role<CSharpModifierToken> ModifierRole = new Role<CSharpModifierToken>("Modifier");
public AstNodeCollection<AttributeSection> Attributes { public AstNodeCollection<AttributeSection> Attributes {

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

@ -106,7 +106,9 @@ namespace ICSharpCode.NRefactory.CSharp
subContainer.Accept (this); subContainer.Accept (this);
} }
} }
if (nspace.UnattachedAttributes != null && nspace.UnattachedAttributes.Length > 0)
AddToNamespace (ConvertAttributeSection (nspace.UnattachedAttributes));
if (nDecl != null) { if (nDecl != null) {
if (loc != null && loc.Count > 2) if (loc != null && loc.Count > 2)
nDecl.AddChild (new CSharpTokenNode (Convert (loc[2]), 1), NamespaceDeclaration.Roles.RBrace); nDecl.AddChild (new CSharpTokenNode (Convert (loc[2]), 1), NamespaceDeclaration.Roles.RBrace);
@ -251,7 +253,7 @@ namespace ICSharpCode.NRefactory.CSharp
return new SimpleType ("unknown"); return new SimpleType ("unknown");
} }
IEnumerable<Attribute> GetAttributes (List<Mono.CSharp.Attribute> optAttributes) IEnumerable<Attribute> GetAttributes (IEnumerable<Mono.CSharp.Attribute> optAttributes)
{ {
if (optAttributes == null) if (optAttributes == null)
yield break; yield break;
@ -307,7 +309,7 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
AttributeSection ConvertAttributeSection (List<Mono.CSharp.Attribute> optAttributes) AttributeSection ConvertAttributeSection (IEnumerable<Mono.CSharp.Attribute> optAttributes)
{ {
if (optAttributes == null) if (optAttributes == null)
return null; return null;
@ -356,6 +358,7 @@ namespace ICSharpCode.NRefactory.CSharp
AddToNamespace (nDecl); AddToNamespace (nDecl);
namespaceStack.Push (nDecl); namespaceStack.Push (nDecl);
} }
if (nspace.Usings != null) { if (nspace.Usings != null) {
foreach (var us in nspace.Usings) { foreach (var us in nspace.Usings) {
us.Accept (this); us.Accept (this);
@ -368,6 +371,9 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
if (nspace.UnattachedAttributes != null && nspace.UnattachedAttributes.Length > 0)
AddToNamespace (ConvertAttributeSection (nspace.UnattachedAttributes));
if (nDecl != null) { if (nDecl != null) {
if (loc != null && loc.Count > 2) if (loc != null && loc.Count > 2)
nDecl.AddChild (new CSharpTokenNode (Convert (loc[2]), 1), NamespaceDeclaration.Roles.RBrace); nDecl.AddChild (new CSharpTokenNode (Convert (loc[2]), 1), NamespaceDeclaration.Roles.RBrace);
@ -510,6 +516,10 @@ namespace ICSharpCode.NRefactory.CSharp
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.LBrace); newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.LBrace);
typeStack.Push (newType); typeStack.Push (newType);
base.Visit (c); base.Visit (c);
if (c.UnattachedAttributes != null && c.UnattachedAttributes.Length > 0)
newType.AddChild (ConvertAttributeSection (c.UnattachedAttributes), TypeDeclaration.UnattachedAttributeRole);
if (location != null && curLoc < location.Count) { if (location != null && curLoc < location.Count) {
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.RBrace); newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.RBrace);

5
ICSharpCode.NRefactory.CSharp/TypeSystem/CSharpAttribute.cs

@ -156,7 +156,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
} else { } else {
namedArgs = new List<KeyValuePair<IMember, ResolveResult>>(); namedArgs = new List<KeyValuePair<IMember, ResolveResult>>();
foreach (var pair in unresolved.namedArguments) { foreach (var pair in unresolved.namedArguments) {
IMember member = attributeType.GetMembers(m => (m.EntityType == EntityType.Fidyj.keld || m.EntityType == EntityType.Property) && m.Name == pair.Key).FirstOrDefault(); IMember member = attributeType.GetMembers(m => (m.EntityType == EntityType.Field || m.EntityType == EntityType.Property) && m.Name == pair.Key).FirstOrDefault();
if (member != null) { if (member != null) {
ResolveResult val = pair.Value.Resolve(context); ResolveResult val = pair.Value.Resolve(context);
namedArgs.Add(new KeyValuePair<IMember, ResolveResult>(member, val)); namedArgs.Add(new KeyValuePair<IMember, ResolveResult>(member, val));
@ -257,5 +257,4 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
} }
} }
*/ */
} }
MarshalByRefObject ^äp
Loading…
Cancel
Save