From d54c9d53306312b3562ddd1bcd824480e67b1682 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 15 Jul 2011 13:34:03 +0200 Subject: [PATCH] implement conversion of attribute targets --- .../Ast/General/Attribute.cs | 7 +++++-- .../OutputVisitor/OutputVisitor.cs | 18 +++++++++++++++--- .../Visitors/CSharpToVBConverterVisitor.cs | 6 +++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/NRefactory/ICSharpCode.NRefactory.VB/Ast/General/Attribute.cs b/NRefactory/ICSharpCode.NRefactory.VB/Ast/General/Attribute.cs index a46e27549..3ad468609 100644 --- a/NRefactory/ICSharpCode.NRefactory.VB/Ast/General/Attribute.cs +++ b/NRefactory/ICSharpCode.NRefactory.VB/Ast/General/Attribute.cs @@ -42,7 +42,9 @@ namespace ICSharpCode.NRefactory.VB.Ast public static readonly Role AttributeRole = new Role("Attribute"); public static readonly Role TargetRole = new Role("Target", VBTokenNode.Null); - public VBTokenNode Target { + public AttributeTarget Target { get; set; } + + public VBTokenNode TargetKeyword { get { return GetChildByRole(TargetRole); } set { SetChildByRole(TargetRole, value); } } @@ -81,12 +83,13 @@ namespace ICSharpCode.NRefactory.VB.Ast protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) { var node = other as Attribute; - return node != null && node.Target.DoMatch(this.Target, match) && node.Type.DoMatch(this.Type, match) && node.Arguments.DoMatch(this.Arguments, match); + return node != null && node.Target == Target && node.TargetKeyword.DoMatch(this.TargetKeyword, match) && node.Type.DoMatch(this.Type, match) && node.Arguments.DoMatch(this.Arguments, match); } } public enum AttributeTarget { + None, Assembly, Module } diff --git a/NRefactory/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/NRefactory/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 925f7168a..0cbf43514 100644 --- a/NRefactory/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/NRefactory/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -148,9 +148,21 @@ namespace ICSharpCode.NRefactory.VB { StartNode(attribute); - if (!attribute.Target.IsNull) { - attribute.Target.AcceptVisitor(this, data); - WriteToken(":", VB.Ast.Attribute.TargetRole); + if (attribute.Target != AttributeTarget.None) { + switch (attribute.Target) { + case AttributeTarget.None: + break; + case AttributeTarget.Assembly: + WriteKeyword("Assembly"); + break; + case AttributeTarget.Module: + WriteKeyword("Module"); + break; + default: + throw new Exception("Invalid value for AttributeTarget"); + } + WriteToken(":", Ast.Attribute.Roles.Colon); + Space(); } attribute.Type.AcceptVisitor(this, data); WriteCommaSeparatedListInParenthesis(attribute.Arguments, false); diff --git a/NRefactory/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/NRefactory/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 683ae235a..5dde5328e 100644 --- a/NRefactory/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/NRefactory/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -714,9 +714,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors public AstNode VisitAttribute(CSharp.Attribute attribute, object data) { var attr = new VB.Ast.Attribute(); - - // TODO : attribute targets - + AttributeTarget target; + Enum.TryParse(((CSharp.AttributeSection)attribute.Parent).AttributeTarget, true, out target); + attr.Target = target; attr.Type = (AstType)attribute.Type.AcceptVisitor(this, data); ConvertNodes(attribute.Arguments, attr.Arguments);