File tree Expand file tree Collapse file tree 4 files changed +18
-15
lines changed
Expand file tree Collapse file tree 4 files changed +18
-15
lines changed Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ public override void Populate(TextWriter trapFile)
7070
7171 Overrides ( trapFile ) ;
7272
73- if ( Symbol . FromSource ( ) && Block is null )
73+ if ( Symbol . FromSource ( ) && ! HasBody )
7474 {
7575 trapFile . compiler_generated ( this ) ;
7676 }
Original file line number Diff line number Diff line change @@ -89,29 +89,32 @@ protected void BindComments()
8989
9090 protected virtual T BodyDeclaringSymbol => Symbol ;
9191
92- public BlockSyntax ? Block
92+ private static BlockSyntax ? GetBlock ( T symbol )
9393 {
94- get
95- {
96- return BodyDeclaringSymbol . DeclaringSyntaxReferences
94+ return symbol . DeclaringSyntaxReferences
9795 . SelectMany ( r => r . GetSyntax ( ) . ChildNodes ( ) )
9896 . OfType < BlockSyntax > ( )
9997 . FirstOrDefault ( ) ;
100- }
10198 }
10299
103- public ExpressionSyntax ? ExpressionBody
100+ private static ExpressionSyntax ? GetExpressionBody ( T symbol )
104101 {
105- get
106- {
107- return BodyDeclaringSymbol . DeclaringSyntaxReferences
102+ return symbol . DeclaringSyntaxReferences
108103 . SelectMany ( r => r . GetSyntax ( ) . ChildNodes ( ) )
109104 . OfType < ArrowExpressionClauseSyntax > ( )
110105 . Select ( arrow => arrow . Expression )
111106 . FirstOrDefault ( ) ;
112- }
113107 }
114108
109+ private BlockSyntax ? vBlock ;
110+ public BlockSyntax ? Block => vBlock ??= GetBlock ( BodyDeclaringSymbol ) ;
111+
112+ private ExpressionSyntax ? vExpressionBody ;
113+ public ExpressionSyntax ? ExpressionBody => vExpressionBody ??= GetExpressionBody ( BodyDeclaringSymbol ) ;
114+
115+ private bool ? vHasBody ;
116+ public bool HasBody => vHasBody ??= Block is not null || ExpressionBody is not null ;
117+
115118 public virtual bool IsSourceDeclaration => Symbol . IsSourceDeclaration ( ) ;
116119
117120 public override bool NeedsPopulation => Context . Defines ( Symbol ) ;
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ public override void Populate(TextWriter trapFile)
4242 return ;
4343 }
4444
45- if ( MakeSynthetic )
45+ if ( MakeSyntheticBody )
4646 {
4747 // Create a synthetic empty body for primary and default constructors.
4848 Statements . SyntheticEmptyBlock . Create ( Context , this , 0 , Location ) ;
@@ -60,7 +60,7 @@ protected override void ExtractInitializers(TextWriter trapFile)
6060 // Do not extract initializers for constructed types.
6161 // Extract initializers for constructors with a body, primary constructors
6262 // and default constructors for classes and structs declared in source code.
63- if ( Block is null && ExpressionBody is null && ! MakeSynthetic || Context . OnlyScaffold )
63+ if ( ! HasBody && ! MakeSyntheticBody || Context . OnlyScaffold )
6464 {
6565 return ;
6666 }
@@ -211,7 +211,7 @@ Symbol.ContainingType.TypeKind is TypeKind.Class or TypeKind.Struct &&
211211 /// </summary>
212212 private bool IsBestSourceLocation => ReportingLocation is not null && Context . IsLocationInContext ( ReportingLocation ) ;
213213
214- private bool MakeSynthetic => ( IsPrimary || ( IsDefault && IsBestSourceLocation ) ) && ! Context . OnlyScaffold ;
214+ private bool MakeSyntheticBody => ( IsPrimary || ( IsDefault && IsBestSourceLocation ) ) && ! Context . OnlyScaffold ;
215215
216216 [ return : NotNullIfNotNull ( nameof ( constructor ) ) ]
217217 public static new Constructor ? Create ( Context cx , IMethodSymbol ? constructor )
Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ public override void Populate(TextWriter trapFile)
5959
6060 Overrides ( trapFile ) ;
6161
62- if ( Symbol . FromSource ( ) && Block is null )
62+ if ( Symbol . FromSource ( ) && ! HasBody )
6363 {
6464 trapFile . compiler_generated ( this ) ;
6565 }
You can’t perform that action at this time.
0 commit comments