@@ -119,53 +119,47 @@ private static void AnalyzeSummaryElement(SyntaxNodeAnalysisContext context, Xml
119119 var textElement = summaryElement . Content . FirstOrDefault ( ) as XmlTextSyntax ;
120120 var text = textElement == null ? string . Empty : XmlCommentHelper . GetText ( textElement , true ) . TrimStart ( ) ;
121121
122- if ( getter != null || expressionBody != null )
122+ bool startsWithGetOrSet = text . StartsWith ( startingTextGetsOrSets , StringComparison . Ordinal ) ;
123+ bool getterVisible , setterVisible ;
124+ if ( getter != null && setter != null )
123125 {
124- bool startsWithGetOrSet = text . StartsWith ( startingTextGetsOrSets , StringComparison . Ordinal ) ;
125-
126- if ( setter != null )
126+ if ( ! getter . Modifiers . Any ( ) && ! setter . Modifiers . Any ( ) )
127127 {
128- // There is no way getter is null (can't have expression body and accessor list)
129- bool getterVisible ;
130- bool setterVisible ;
131-
132- if ( ! getter . Modifiers . Any ( ) && ! setter . Modifiers . Any ( ) )
128+ // Case 1: The getter and setter have the same declared accessibility
129+ getterVisible = true ;
130+ setterVisible = true ;
131+ }
132+ else if ( getter . Modifiers . Any ( SyntaxKind . PrivateKeyword ) )
133+ {
134+ // Case 3
135+ getterVisible = false ;
136+ setterVisible = true ;
137+ }
138+ else if ( setter . Modifiers . Any ( SyntaxKind . PrivateKeyword ) )
139+ {
140+ // Case 3
141+ getterVisible = true ;
142+ setterVisible = false ;
143+ }
144+ else
145+ {
146+ var propertyAccessibility = propertyDeclaration . GetEffectiveAccessibility ( context . SemanticModel , context . CancellationToken ) ;
147+ bool propertyOnlyInternal = propertyAccessibility == Accessibility . Internal
148+ || propertyAccessibility == Accessibility . ProtectedAndInternal
149+ || propertyAccessibility == Accessibility . Private ;
150+ if ( propertyOnlyInternal )
133151 {
134- // Case 1: The getter and setter have the same declared accessibility
152+ // Case 2: Property only internal and no accessor is explicitly private
135153 getterVisible = true ;
136154 setterVisible = true ;
137155 }
138- else if ( getter . Modifiers . Any ( SyntaxKind . PrivateKeyword ) )
139- {
140- // Case 3
141- getterVisible = false ;
142- setterVisible = true ;
143- }
144- else if ( setter . Modifiers . Any ( SyntaxKind . PrivateKeyword ) )
145- {
146- // Case 3
147- getterVisible = true ;
148- setterVisible = false ;
149- }
150156 else
151157 {
152- var propertyAccessibility = propertyDeclaration . GetEffectiveAccessibility ( context . SemanticModel , context . CancellationToken ) ;
153- bool propertyOnlyInternal = propertyAccessibility == Accessibility . Internal
154- || propertyAccessibility == Accessibility . ProtectedAndInternal
155- || propertyAccessibility == Accessibility . Private ;
156- if ( propertyOnlyInternal )
157- {
158- // Case 2: Property only internal and no accessor is explicitly private
159- getterVisible = true ;
160- setterVisible = true ;
161- }
162- else
163- {
164- var getterAccessibility = getter . GetEffectiveAccessibility ( context . SemanticModel , context . CancellationToken ) ;
165- var setterAccessibility = setter . GetEffectiveAccessibility ( context . SemanticModel , context . CancellationToken ) ;
158+ var getterAccessibility = getter . GetEffectiveAccessibility ( context . SemanticModel , context . CancellationToken ) ;
159+ var setterAccessibility = setter . GetEffectiveAccessibility ( context . SemanticModel , context . CancellationToken ) ;
166160
167- switch ( getterAccessibility )
168- {
161+ switch ( getterAccessibility )
162+ {
169163 case Accessibility . Public :
170164 case Accessibility . ProtectedOrInternal :
171165 case Accessibility . Protected :
@@ -180,10 +174,10 @@ private static void AnalyzeSummaryElement(SyntaxNodeAnalysisContext context, Xml
180174 // The property is externally accessible, so the setter must be more accessible.
181175 getterVisible = false ;
182176 break ;
183- }
177+ }
184178
185- switch ( setterAccessibility )
186- {
179+ switch ( setterAccessibility )
180+ {
187181 case Accessibility . Public :
188182 case Accessibility . ProtectedOrInternal :
189183 case Accessibility . Protected :
@@ -198,70 +192,66 @@ private static void AnalyzeSummaryElement(SyntaxNodeAnalysisContext context, Xml
198192 // The property is externally accessible, so the getter must be more accessible.
199193 setterVisible = false ;
200194 break ;
201- }
202- }
203- }
204-
205- if ( getterVisible && ! setterVisible )
206- {
207- if ( startsWithGetOrSet )
208- {
209- diagnosticProperties . Add ( ExpectedTextKey , startingTextGets ) ;
210- diagnosticProperties . Add ( TextToRemoveKey , startingTextGetsOrSets ) ;
211- context . ReportDiagnostic ( Diagnostic . Create ( SA1624Descriptor , diagnosticLocation , diagnosticProperties . ToImmutable ( ) , "get" , startingTextGets ) ) ;
212- }
213- else if ( ! text . StartsWith ( startingTextGets , StringComparison . Ordinal ) )
214- {
215- diagnosticProperties . Add ( ExpectedTextKey , startingTextGets ) ;
216- context . ReportDiagnostic ( Diagnostic . Create ( SA1623Descriptor , diagnosticLocation , diagnosticProperties . ToImmutable ( ) , startingTextGets ) ) ;
217- }
218- }
219- else if ( ! getterVisible && setterVisible )
220- {
221- if ( startsWithGetOrSet )
222- {
223- diagnosticProperties . Add ( ExpectedTextKey , startingTextSets ) ;
224- diagnosticProperties . Add ( TextToRemoveKey , startingTextGetsOrSets ) ;
225- context . ReportDiagnostic ( Diagnostic . Create ( SA1624Descriptor , diagnosticLocation , diagnosticProperties . ToImmutable ( ) , "set" , startingTextSets ) ) ;
226- }
227- else if ( ! text . StartsWith ( startingTextSets , StringComparison . Ordinal ) )
228- {
229- diagnosticProperties . Add ( ExpectedTextKey , startingTextSets ) ;
230- context . ReportDiagnostic ( Diagnostic . Create ( SA1623Descriptor , diagnosticLocation , diagnosticProperties . ToImmutable ( ) , startingTextSets ) ) ;
231- }
232- }
233- else
234- {
235- if ( ! startsWithGetOrSet )
236- {
237- diagnosticProperties . Add ( ExpectedTextKey , startingTextGetsOrSets ) ;
238- context . ReportDiagnostic ( Diagnostic . Create ( SA1623Descriptor , diagnosticLocation , diagnosticProperties . ToImmutable ( ) , startingTextGetsOrSets ) ) ;
239195 }
240196 }
241197 }
198+ }
199+ else
200+ {
201+ if ( getter != null || expressionBody != null )
202+ {
203+ getterVisible = true ;
204+ setterVisible = false ;
205+ }
206+ else if ( setter != null )
207+ {
208+ getterVisible = false ;
209+ setterVisible = true ;
210+ }
242211 else
243212 {
244- if ( startsWithGetOrSet )
245- {
246- diagnosticProperties . Add ( ExpectedTextKey , startingTextGets ) ;
247- diagnosticProperties . Add ( TextToRemoveKey , startingTextGetsOrSets ) ;
248- context . ReportDiagnostic ( Diagnostic . Create ( SA1624Descriptor , diagnosticLocation , diagnosticProperties . ToImmutable ( ) , "get" , startingTextGets ) ) ;
249- }
250- else if ( ! text . StartsWith ( startingTextGets , StringComparison . Ordinal ) )
251- {
252- diagnosticProperties . Add ( ExpectedTextKey , startingTextGets ) ;
253- context . ReportDiagnostic ( Diagnostic . Create ( SA1623Descriptor , diagnosticLocation , diagnosticProperties . ToImmutable ( ) , startingTextGets ) ) ;
254- }
213+ // TODO Raise a NotImplementedException?
214+ getterVisible = false ;
215+ setterVisible = false ;
216+ }
217+ }
218+
219+ if ( getterVisible && ! setterVisible )
220+ {
221+ if ( startsWithGetOrSet )
222+ {
223+ diagnosticProperties . Add ( ExpectedTextKey , startingTextGets ) ;
224+ diagnosticProperties . Add ( TextToRemoveKey , startingTextGetsOrSets ) ;
225+ context . ReportDiagnostic ( Diagnostic . Create ( SA1624Descriptor , diagnosticLocation , diagnosticProperties . ToImmutable ( ) , "get" , startingTextGets ) ) ;
226+ }
227+ else if ( ! text . StartsWith ( startingTextGets , StringComparison . Ordinal ) )
228+ {
229+ diagnosticProperties . Add ( ExpectedTextKey , startingTextGets ) ;
230+ context . ReportDiagnostic ( Diagnostic . Create ( SA1623Descriptor , diagnosticLocation , diagnosticProperties . ToImmutable ( ) , startingTextGets ) ) ;
255231 }
256232 }
257- else if ( setter != null )
233+ else if ( ! getterVisible && setterVisible )
258234 {
259- if ( ! text . StartsWith ( startingTextSets , StringComparison . Ordinal ) )
235+ if ( startsWithGetOrSet )
236+ {
237+ diagnosticProperties . Add ( ExpectedTextKey , startingTextSets ) ;
238+ diagnosticProperties . Add ( TextToRemoveKey , startingTextGetsOrSets ) ;
239+ context . ReportDiagnostic ( Diagnostic . Create ( SA1624Descriptor , diagnosticLocation , diagnosticProperties . ToImmutable ( ) , "set" , startingTextSets ) ) ;
240+ }
241+ else if ( ! text . StartsWith ( startingTextSets , StringComparison . Ordinal ) )
260242 {
261243 diagnosticProperties . Add ( ExpectedTextKey , startingTextSets ) ;
262244 context . ReportDiagnostic ( Diagnostic . Create ( SA1623Descriptor , diagnosticLocation , diagnosticProperties . ToImmutable ( ) , startingTextSets ) ) ;
263245 }
264246 }
247+ else
248+ {
249+ if ( ! startsWithGetOrSet )
250+ {
251+ diagnosticProperties . Add ( ExpectedTextKey , startingTextGetsOrSets ) ;
252+ context . ReportDiagnostic ( Diagnostic . Create ( SA1623Descriptor , diagnosticLocation , diagnosticProperties . ToImmutable ( ) , startingTextGetsOrSets ) ) ;
253+ }
254+ }
265255 }
266256 }
267257}
0 commit comments