Skip to content

Commit caa8915

Browse files
Transition PrimaryMethod annotation to property
1 parent 9ac3b01 commit caa8915

File tree

6 files changed

+12
-36
lines changed

6 files changed

+12
-36
lines changed

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DocumentClassifierPassBaseTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public void Execute_AddsPrimaryAnnotations()
234234
Assert.True(@class.IsPrimaryClass);
235235

236236
var method = SingleChild<MethodDeclarationIntermediateNode>(@class);
237-
AnnotationEquals(method, CommonAnnotations.PrimaryMethod);
237+
Assert.True(method.IsPrimaryMethod);
238238
}
239239

240240
private class TestDocumentClassifierPass : DocumentClassifierPassBase

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Intermediate/DocumentIntermediateNodeExtensionsTest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ public void FindPrimaryMethod_FindsMethodWithAnnotation()
3434
{
3535
// Arrange
3636
var document = new DocumentIntermediateNode();
37-
var method = new MethodDeclarationIntermediateNode();
38-
method.Annotations[CommonAnnotations.PrimaryMethod] = CommonAnnotations.PrimaryMethod;
37+
var method = new MethodDeclarationIntermediateNode
38+
{
39+
IsPrimaryMethod = true
40+
};
3941

4042
var builder = IntermediateNodeBuilder.Create(document);
4143
builder.Add(method);

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DocumentClassifierPassBase.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ private void Rewrite(RazorCodeDocument codeDocument, DocumentIntermediateNode do
6363
IsPrimaryClass = true
6464
};
6565

66-
var method = new MethodDeclarationIntermediateNode();
67-
method.Annotations[CommonAnnotations.PrimaryMethod] = CommonAnnotations.PrimaryMethod;
66+
var method = new MethodDeclarationIntermediateNode
67+
{
68+
IsPrimaryMethod = true
69+
};
6870

6971
var documentBuilder = IntermediateNodeBuilder.Create(documentNode);
7072

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/CommonAnnotations.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/DocumentIntermediateNodeExtensions.cs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static MethodDeclarationIntermediateNode FindPrimaryMethod(this DocumentI
2727
throw new ArgumentNullException(nameof(node));
2828
}
2929

30-
return FindWithAnnotation<MethodDeclarationIntermediateNode>(node, CommonAnnotations.PrimaryMethod);
30+
return FindNode<MethodDeclarationIntermediateNode>(node, static n => n.IsPrimaryMethod);
3131
}
3232

3333
public static NamespaceDeclarationIntermediateNode FindPrimaryNamespace(this DocumentIntermediateNode node)
@@ -91,25 +91,6 @@ private static T FindNode<T>(IntermediateNode node, Func<T, bool> predicate)
9191
return null;
9292
}
9393

94-
private static T FindWithAnnotation<T>(IntermediateNode node, object annotation) where T : IntermediateNode
95-
{
96-
if (node is T target && object.ReferenceEquals(target.Annotations[annotation], annotation))
97-
{
98-
return target;
99-
}
100-
101-
for (var i = 0; i < node.Children.Count; i++)
102-
{
103-
var result = FindWithAnnotation<T>(node.Children[i], annotation);
104-
if (result != null)
105-
{
106-
return result;
107-
}
108-
}
109-
110-
return null;
111-
}
112-
11394
private class DirectiveVisitor : IntermediateNodeWalker
11495
{
11596
private readonly DirectiveDescriptor _directive;

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/MethodDeclarationIntermediateNode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public sealed class MethodDeclarationIntermediateNode : MemberDeclarationInterme
2222

2323
public string ReturnType { get; set; }
2424

25+
public bool IsPrimaryMethod { get; set; }
26+
2527
public override void Accept(IntermediateNodeVisitor visitor)
2628
{
2729
if (visitor == null)

0 commit comments

Comments
 (0)