Skip to content

Commit 538dfca

Browse files
authored
Merge pull request #3470 from rubberduck-vba/next
v2.1.0 ...take 3
2 parents 8e5dfcb + 7ffd582 commit 538dfca

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

Rubberduck.Parsing/Grammar/PartialExtensions/VBAParserPartialExtensions.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,78 @@ public void AddAttributes(Attributes attributes)
424424
#endregion
425425
}
426426

427+
public partial class UdtDeclarationContext : IIdentifierContext, IAnnotatedContext
428+
{
429+
#region IIdentifierContext
430+
public Interval IdentifierTokens
431+
{
432+
get
433+
{
434+
Interval tokenInterval;
435+
Identifier.GetName(this, out tokenInterval);
436+
return tokenInterval;
437+
}
438+
}
439+
#endregion
440+
441+
#region IAnnotatedContext
442+
public Attributes Attributes { get; } = new Attributes();
443+
public int AttributeTokenIndex => Start.TokenIndex - 1;
444+
445+
private readonly List<AnnotationContext> _annotations = new List<AnnotationContext>();
446+
public IEnumerable<AnnotationContext> Annotations => _annotations;
447+
448+
public void Annotate(AnnotationContext annotation)
449+
{
450+
_annotations.Add(annotation);
451+
}
452+
453+
public void AddAttributes(Attributes attributes)
454+
{
455+
foreach (var attribute in attributes)
456+
{
457+
Attributes.Add(new AttributeNode(attribute.Name, attribute.Values));
458+
}
459+
}
460+
#endregion
461+
}
462+
463+
public partial class UdtMemberContext : IIdentifierContext, IAnnotatedContext
464+
{
465+
#region IIdentifierContext
466+
public Interval IdentifierTokens
467+
{
468+
get
469+
{
470+
Interval tokenInterval;
471+
Identifier.GetName(this, out tokenInterval);
472+
return tokenInterval;
473+
}
474+
}
475+
#endregion
476+
477+
#region IAnnotatedContext
478+
public Attributes Attributes { get; } = new Attributes();
479+
public int AttributeTokenIndex => Start.TokenIndex - 1;
480+
481+
private readonly List<AnnotationContext> _annotations = new List<AnnotationContext>();
482+
public IEnumerable<AnnotationContext> Annotations => _annotations;
483+
484+
public void Annotate(AnnotationContext annotation)
485+
{
486+
_annotations.Add(annotation);
487+
}
488+
489+
public void AddAttributes(Attributes attributes)
490+
{
491+
foreach (var attribute in attributes)
492+
{
493+
Attributes.Add(new AttributeNode(attribute.Name, attribute.Values));
494+
}
495+
}
496+
#endregion
497+
}
498+
427499
public partial class IdentifierStatementLabelContext : IIdentifierContext, IAnnotatedContext
428500
{
429501
#region IIdentifierContext

Rubberduck.Parsing/Symbols/Identifier.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,23 @@ public static string GetName(VBAParser.EnumerationStmtContext context)
120120
return GetName(context.identifier());
121121
}
122122

123+
public static string GetName(VBAParser.UdtDeclarationContext context, out Interval tokenInterval)
124+
{
125+
return GetName(context.untypedIdentifier(), out tokenInterval);
126+
}
127+
128+
public static string GetName(VBAParser.UdtMemberContext context, out Interval tokenInterval)
129+
{
130+
var untypedIdentifier = context.untypedNameMemberDeclaration()?.untypedIdentifier();
131+
if (untypedIdentifier != null)
132+
{
133+
return GetName(untypedIdentifier, out tokenInterval);
134+
}
135+
136+
var unrestrictedIdentifier = context.reservedNameMemberDeclaration().unrestrictedIdentifier();
137+
return GetName(unrestrictedIdentifier, out tokenInterval);
138+
}
139+
123140
public static string GetName(VBAParser.EnumerationStmt_ConstantContext context, out Interval tokenInterval)
124141
{
125142
var nameContext = context.identifier();

0 commit comments

Comments
 (0)