-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into SuperTypesForDocumentModules
# Conflicts: # Rubberduck.Resources/Inspections/InspectionInfo.resx # Rubberduck.Resources/Inspections/InspectionNames.resx # Rubberduck.Resources/Inspections/InspectionResults.resx
- Loading branch information
Showing
104 changed files
with
6,398 additions
and
2,955 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
Rubberduck.CodeAnalysis/Inspections/Concrete/MisleadingByRefParameterInspection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using Rubberduck.CodeAnalysis.Inspections.Abstract; | ||
using Rubberduck.Parsing.Symbols; | ||
using Rubberduck.Parsing.VBA; | ||
using Rubberduck.Parsing.VBA.DeclarationCaching; | ||
using Rubberduck.Resources.Inspections; | ||
using System.Linq; | ||
|
||
namespace Rubberduck.CodeAnalysis.Inspections.Concrete | ||
{ | ||
/// <summary> | ||
/// Flags the value-parameter of a property mutators that are declared with an explict ByRef modifier. | ||
/// </summary> | ||
/// <why> | ||
/// Regardless of the presence or absence of an explicit ByRef or ByVal modifier, the value-parameter | ||
/// of a property mutator is always treated as though it had an explicit ByVal modifier. | ||
/// Exception: UserDefinedType parameters are always passed by reference. | ||
/// </why> | ||
/// <example hasResult="true"> | ||
/// <module name="MyModule" type="Standard Module"> | ||
/// <![CDATA[ | ||
/// Private fizzField As Long | ||
/// Public Property Get Fizz() As Long | ||
/// Fizz = fizzFiled | ||
/// End Property | ||
/// Public Property Let Fizz(ByRef arg As Long) | ||
/// fizzFiled = arg | ||
/// End Property | ||
/// ]]> | ||
/// </module> | ||
/// </example> | ||
/// <example hasResult="false"> | ||
/// <module name="MyModule" type="Standard Module"> | ||
/// <![CDATA[ | ||
/// Private fizzField As Long | ||
/// Public Property Get Fizz() As Long | ||
/// Fizz = fizzFiled | ||
/// End Property | ||
/// Public Property Let Fizz(arg As Long) | ||
/// fizzFiled = arg | ||
/// End Property | ||
/// ]]> | ||
/// </module> | ||
/// </example> | ||
internal sealed class MisleadingByRefParameterInspection : DeclarationInspectionBase | ||
{ | ||
public MisleadingByRefParameterInspection(IDeclarationFinderProvider declarationFinderProvider) | ||
: base(declarationFinderProvider, DeclarationType.Parameter) | ||
{ } | ||
|
||
protected override bool IsResultDeclaration(Declaration declaration, DeclarationFinder finder) | ||
{ | ||
return declaration is ParameterDeclaration parameter | ||
&& !(parameter.AsTypeDeclaration?.DeclarationType.HasFlag(DeclarationType.UserDefinedType) ?? false) | ||
&& parameter.ParentDeclaration is ModuleBodyElementDeclaration enclosingMethod | ||
&& (enclosingMethod.DeclarationType.HasFlag(DeclarationType.PropertyLet) | ||
|| enclosingMethod.DeclarationType.HasFlag(DeclarationType.PropertySet)) | ||
&& enclosingMethod.Parameters.Last() == parameter | ||
&& parameter.IsByRef && !parameter.IsImplicitByRef; | ||
} | ||
|
||
protected override string ResultDescription(Declaration declaration) | ||
{ | ||
return string.Format( | ||
InspectionResults.MisleadingByRefParameterInspection, | ||
declaration.IdentifierName, declaration.ParentDeclaration.QualifiedName.MemberName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.