Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the code to only use 'IsPubliclyAccessible' #544

Merged
merged 2 commits into from
Jul 7, 2017

Conversation

Evangelink
Copy link
Contributor

No description provided.

Copy link
Contributor

@michalb-sonar michalb-sonar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double-check that the rules are consistent with rspecs.

Otherwise, LGTM.

@@ -29,7 +29,7 @@ private class MyPrivateSubClass

protected class MyProtectedSubClass
{
public double Pi4 = 3.14;
public double Pi4 = 3.14; // Noncompliant
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double-check (if you haven't already) that the behaviour is consistent with rspec.

@@ -61,7 +61,7 @@ protected sealed override void Initialize(SonarAnalysisContext context)

if (containingMethod == null ||
containingMethod.IsOverride ||
!containingMethod.IsPublicApi() ||
!containingMethod.IsPubliclyAccessible() ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double-check with rspec.

Copy link
Contributor

@valhristov valhristov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes, otherwise LGTM

if (symbol == null || !symbol.IsPublicApi())

if (symbol != null &&
symbol.GetEffectiveAccessibility() == Accessibility.Public)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could remove the previous check, GetEffectiveVisibility will handle the null

{
return false;
}

var effectiveAccessibility = GetEffectiveAccessibility(symbol);

return effectiveAccessibility == Accessibility.Public ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't if using a HashSet would be faster...

return result;
}

public static bool IsPubliclyAccessible(this ISymbol symbol)
{
if (symbol == null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed. The next call will return NotApplicable... I don't know if this check will improve performance though... Probably not.

@@ -36,7 +36,7 @@ protected static bool FieldIsRelevant(IFieldSymbol fieldSymbol)
return fieldSymbol != null &&
!fieldSymbol.IsStatic &&
!fieldSymbol.IsConst &&
fieldSymbol.IsPublicApi() &&
fieldSymbol.GetEffectiveAccessibility() == Accessibility.Public &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not IsPubliclyAccessible here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we care only about public fields not protected.

@@ -58,7 +58,7 @@ protected sealed override void Initialize(SonarAnalysisContext context)
var symbol = c.SemanticModel.GetDeclaredSymbol(anyVariable) as IFieldSymbol;
if (symbol == null ||
!symbol.IsConst ||
!symbol.IsPublicApi())
symbol.GetEffectiveAccessibility()!= Accessibility.Public)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces around !=

@Evangelink Evangelink merged commit 28963a3 into master Jul 7, 2017
@Evangelink Evangelink deleted the refactor-public-accessibility branch July 7, 2017 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants