Skip to content

Commit f334e44

Browse files
committed
Added optional visiting of property accessors.
1 parent 0919938 commit f334e44

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/AST/ASTVisitor.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public interface IAstVisited
1313

1414
public interface IAstVisitor<out T> : ITypeVisitor<T>, IDeclVisitor<T>
1515
{
16-
16+
AstVisitorOptions VisitOptions { get; }
1717
}
1818

1919
public class AstVisitorOptions
@@ -23,6 +23,7 @@ public class AstVisitorOptions
2323
public bool VisitClassProperties = true;
2424
public bool VisitClassMethods = true;
2525
public bool VisitClassTemplateSpecializations { get; set; } = true;
26+
public bool VisitPropertyAccessors = false;
2627

2728
public bool VisitNamespaceEnums = true;
2829
public bool VisitNamespaceTemplates = true;
@@ -376,7 +377,16 @@ public virtual bool VisitProperty(Property property)
376377
return false;
377378

378379
if (VisitOptions.VisitFunctionReturnType)
379-
return property.Type.Visit(this);
380+
property.Type.Visit(this);
381+
382+
if (VisitOptions.VisitPropertyAccessors)
383+
{
384+
if (property.GetMethod != null)
385+
property.GetMethod.Visit(this);
386+
387+
if (property.SetMethod != null)
388+
property.SetMethod.Visit(this);
389+
}
380390

381391
return true;
382392
}

src/Generator/Generators/CodeGenerator.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public virtual CommentKind CommentKind
4646

4747
public ISet<object> Visited { get; } = new HashSet<object>();
4848

49+
public AstVisitorOptions VisitOptions { get; } = new AstVisitorOptions();
50+
4951
protected CodeGenerator(BindingContext context, TranslationUnit unit)
5052
: this(context, new List<TranslationUnit> { unit })
5153
{
@@ -331,7 +333,19 @@ public virtual bool VisitEvent(Event @event)
331333

332334
public virtual bool VisitProperty(Property property)
333335
{
334-
throw new NotImplementedException();
336+
if (!VisitDeclaration(property))
337+
return false;
338+
339+
if (VisitOptions.VisitPropertyAccessors)
340+
{
341+
if (property.GetMethod != null)
342+
property.GetMethod.Visit(this);
343+
344+
if (property.SetMethod != null)
345+
property.SetMethod.Visit(this);
346+
}
347+
348+
return true;
335349
}
336350

337351
public virtual bool VisitFriend(Friend friend)

0 commit comments

Comments
 (0)