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
public static readonly Role<Attribute> AttributeRole = new Role<Attribute>("Attribute"); public static readonly Role<Attribute> AttributeRole = new Role<Attribute>("Attribute");
public static readonly Role<VBTokenNode> TargetRole = new Role<VBTokenNode>("Target", VBTokenNode.Null); 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); } get { return GetChildByRole(TargetRole); }
set { SetChildByRole(TargetRole, value); } 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) protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
{ {
var node = other as Attribute; 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 public enum AttributeTarget
{ {
None,
Assembly, Assembly,
Module Module
} }

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

@ -148,9 +148,21 @@ namespace ICSharpCode.NRefactory.VB
{ {
StartNode(attribute); StartNode(attribute);
if (!attribute.Target.IsNull) { if (attribute.Target != AttributeTarget.None) {
attribute.Target.AcceptVisitor(this, data); switch (attribute.Target) {
WriteToken(":", VB.Ast.Attribute.TargetRole); 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); attribute.Type.AcceptVisitor(this, data);
WriteCommaSeparatedListInParenthesis(attribute.Arguments, false); WriteCommaSeparatedListInParenthesis(attribute.Arguments, false);

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

@ -714,9 +714,9 @@ namespace ICSharpCode.NRefactory.VB.Visitors
public AstNode VisitAttribute(CSharp.Attribute attribute, object data) public AstNode VisitAttribute(CSharp.Attribute attribute, object data)
{ {
var attr = new VB.Ast.Attribute(); var attr = new VB.Ast.Attribute();
AttributeTarget target;
// TODO : attribute targets Enum.TryParse(((CSharp.AttributeSection)attribute.Parent).AttributeTarget, true, out target);
attr.Target = target;
attr.Type = (AstType)attribute.Type.AcceptVisitor(this, data); attr.Type = (AstType)attribute.Type.AcceptVisitor(this, data);
ConvertNodes(attribute.Arguments, attr.Arguments); ConvertNodes(attribute.Arguments, attr.Arguments);

Loading…
Cancel
Save