Browse Source

implement conversion of attribute targets

pull/254/head
Siegfried Pammer 14 years ago
parent
commit
d54c9d5330
  1. 7
      NRefactory/ICSharpCode.NRefactory.VB/Ast/General/Attribute.cs
  2. 18
      NRefactory/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs
  3. 6
      NRefactory/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs

7
NRefactory/ICSharpCode.NRefactory.VB/Ast/General/Attribute.cs

@ -42,7 +42,9 @@ namespace ICSharpCode.NRefactory.VB.Ast @@ -42,7 +42,9 @@ namespace ICSharpCode.NRefactory.VB.Ast
public static readonly Role<Attribute> AttributeRole = new Role<Attribute>("Attribute");
public static readonly Role<VBTokenNode> TargetRole = new Role<VBTokenNode>("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 @@ -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
}

18
NRefactory/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs

@ -148,9 +148,21 @@ namespace ICSharpCode.NRefactory.VB @@ -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);

6
NRefactory/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs

@ -714,9 +714,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors @@ -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);

Loading…
Cancel
Save