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. 14
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  3. 3
      ICSharpCode.NRefactory.CSharp/TypeSystem/CSharpAttribute.cs

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

@ -25,6 +25,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -25,6 +25,7 @@ namespace ICSharpCode.NRefactory.CSharp
public abstract class AttributedNode : AstNode
{
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 AstNodeCollection<AttributeSection> Attributes {

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

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

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

@ -156,7 +156,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -156,7 +156,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
} else {
namedArgs = new List<KeyValuePair<IMember, ResolveResult>>();
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) {
ResolveResult val = pair.Value.Resolve(context);
namedArgs.Add(new KeyValuePair<IMember, ResolveResult>(member, val));
@ -258,4 +258,3 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -258,4 +258,3 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
}
*/
}
MarshalByRefObject ^äp
Loading…
Cancel
Save