@@ -23,12 +23,8 @@ protected CSharpHeaderFacts()
2323
2424 public override bool IsOnTypeHeader ( SyntaxNode root , int position , bool fullHeader , [ NotNullWhen ( true ) ] out SyntaxNode ? typeDeclaration )
2525 {
26- var node = TryGetAncestorForLocation < BaseTypeDeclarationSyntax > ( root , position ) ;
27- typeDeclaration = node ;
28- if ( node == null )
29- return false ;
30-
31- return IsOnHeader ( root , position , node , GetLastToken ( ) ) ;
26+ var node = TryGetAncestorForLocation < BaseTypeDeclarationSyntax > ( root , position , out typeDeclaration ) ;
27+ return node != null && IsOnHeader ( root , position , node , GetLastToken ( ) ) ;
3228
3329 SyntaxToken GetLastToken ( )
3430 {
@@ -53,107 +49,51 @@ SyntaxToken GetLastToken()
5349
5450 public override bool IsOnPropertyDeclarationHeader ( SyntaxNode root , int position , [ NotNullWhen ( true ) ] out SyntaxNode ? propertyDeclaration )
5551 {
56- var node = TryGetAncestorForLocation < PropertyDeclarationSyntax > ( root , position ) ;
57- propertyDeclaration = node ;
58- if ( propertyDeclaration == null )
59- {
60- return false ;
61- }
62-
63- RoslynDebug . AssertNotNull ( node ) ;
64- return IsOnHeader ( root , position , node , node . Identifier ) ;
52+ var node = TryGetAncestorForLocation < PropertyDeclarationSyntax > ( root , position , out propertyDeclaration ) ;
53+ return node != null && IsOnHeader ( root , position , node , node . Identifier ) ;
6554 }
6655
6756 public override bool IsOnParameterHeader ( SyntaxNode root , int position , [ NotNullWhen ( true ) ] out SyntaxNode ? parameter )
6857 {
69- var node = TryGetAncestorForLocation < ParameterSyntax > ( root , position ) ;
70- parameter = node ;
71- if ( parameter == null )
72- {
73- return false ;
74- }
75-
76- RoslynDebug . AssertNotNull ( node ) ;
77- return IsOnHeader ( root , position , node , node ) ;
58+ var node = TryGetAncestorForLocation < ParameterSyntax > ( root , position , out parameter ) ;
59+ return node != null && IsOnHeader ( root , position , node , node ) ;
7860 }
7961
8062 public override bool IsOnMethodHeader ( SyntaxNode root , int position , [ NotNullWhen ( true ) ] out SyntaxNode ? method )
8163 {
82- var node = TryGetAncestorForLocation < MethodDeclarationSyntax > ( root , position ) ;
83- method = node ;
84- if ( method == null )
85- {
86- return false ;
87- }
88-
89- RoslynDebug . AssertNotNull ( node ) ;
90- return IsOnHeader ( root , position , node , node . ParameterList ) ;
64+ var node = TryGetAncestorForLocation < MethodDeclarationSyntax > ( root , position , out method ) ;
65+ return node != null && IsOnHeader ( root , position , node , node . ParameterList ) ;
9166 }
9267
9368 public override bool IsOnLocalFunctionHeader ( SyntaxNode root , int position , [ NotNullWhen ( true ) ] out SyntaxNode ? localFunction )
9469 {
95- var node = TryGetAncestorForLocation < LocalFunctionStatementSyntax > ( root , position ) ;
96- localFunction = node ;
97- if ( localFunction == null )
98- {
99- return false ;
100- }
101-
102- RoslynDebug . AssertNotNull ( node ) ;
103- return IsOnHeader ( root , position , node , node . ParameterList ) ;
70+ var node = TryGetAncestorForLocation < LocalFunctionStatementSyntax > ( root , position , out localFunction ) ;
71+ return node != null && IsOnHeader ( root , position , node , node . ParameterList ) ;
10472 }
10573
10674 public override bool IsOnLocalDeclarationHeader ( SyntaxNode root , int position , [ NotNullWhen ( true ) ] out SyntaxNode ? localDeclaration )
10775 {
108- var node = TryGetAncestorForLocation < LocalDeclarationStatementSyntax > ( root , position ) ;
109- localDeclaration = node ;
110- if ( localDeclaration == null )
111- {
112- return false ;
113- }
114-
115- var initializersExpressions = node ! . Declaration . Variables
76+ var node = TryGetAncestorForLocation < LocalDeclarationStatementSyntax > ( root , position , out localDeclaration ) ;
77+ return node != null && IsOnHeader ( root , position , node , node , holes : node . Declaration . Variables
11678 . Where ( v => v . Initializer != null )
117- . SelectAsArray ( initializedV => initializedV . Initializer ! . Value ) ;
118- return IsOnHeader ( root , position , node , node , holes : initializersExpressions ) ;
79+ . SelectAsArray ( initializedV => initializedV . Initializer ! . Value ) ) ;
11980 }
12081
12182 public override bool IsOnIfStatementHeader ( SyntaxNode root , int position , [ NotNullWhen ( true ) ] out SyntaxNode ? ifStatement )
12283 {
123- var node = TryGetAncestorForLocation < IfStatementSyntax > ( root , position ) ;
124- ifStatement = node ;
125- if ( ifStatement == null )
126- {
127- return false ;
128- }
129-
130- RoslynDebug . AssertNotNull ( node ) ;
131- return IsOnHeader ( root , position , node , node . CloseParenToken ) ;
84+ var node = TryGetAncestorForLocation < IfStatementSyntax > ( root , position , out ifStatement ) ;
85+ return node != null && IsOnHeader ( root , position , node , node . CloseParenToken ) ;
13286 }
13387
13488 public override bool IsOnWhileStatementHeader ( SyntaxNode root , int position , [ NotNullWhen ( true ) ] out SyntaxNode ? whileStatement )
13589 {
136- var node = TryGetAncestorForLocation < WhileStatementSyntax > ( root , position ) ;
137- whileStatement = node ;
138- if ( whileStatement == null )
139- {
140- return false ;
141- }
142-
143- RoslynDebug . AssertNotNull ( node ) ;
144- return IsOnHeader ( root , position , node , node . CloseParenToken ) ;
90+ var node = TryGetAncestorForLocation < WhileStatementSyntax > ( root , position , out whileStatement ) ;
91+ return node != null && IsOnHeader ( root , position , node , node . CloseParenToken ) ;
14592 }
14693
14794 public override bool IsOnForeachHeader ( SyntaxNode root , int position , [ NotNullWhen ( true ) ] out SyntaxNode ? foreachStatement )
14895 {
149- var node = TryGetAncestorForLocation < ForEachStatementSyntax > ( root , position ) ;
150- foreachStatement = node ;
151- if ( foreachStatement == null )
152- {
153- return false ;
154- }
155-
156- RoslynDebug . AssertNotNull ( node ) ;
157- return IsOnHeader ( root , position , node , node . CloseParenToken ) ;
96+ var node = TryGetAncestorForLocation < ForEachStatementSyntax > ( root , position , out foreachStatement ) ;
97+ return node != null && IsOnHeader ( root , position , node , node . CloseParenToken ) ;
15898 }
15999}
0 commit comments