@@ -51,58 +51,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
51
51
private bool IsAssignedByRefArgument ( Declaration enclosingProcedure , IdentifierReference reference )
52
52
{
53
53
var argExpression = reference . Context . GetAncestor < VBAParser . ArgumentExpressionContext > ( ) ;
54
- if ( argExpression ? . GetDescendent < VBAParser . ParenthesizedExprContext > ( ) != null || argExpression ? . BYVAL ( ) != null )
55
- {
56
- // not an argument, or argument is parenthesized and thus passed ByVal
57
- return false ;
58
- }
59
-
60
- var callStmt = argExpression ? . GetAncestor < VBAParser . CallStmtContext > ( ) ;
61
- var procedureName = callStmt ? . GetDescendent < VBAParser . LExpressionContext > ( )
62
- . GetDescendents < VBAParser . IdentifierContext > ( )
63
- . LastOrDefault ( ) ? . GetText ( ) ;
64
- if ( procedureName == null )
65
- {
66
- // if we don't know what we're calling, we can't dig any further
67
- return false ;
68
- }
69
-
70
- var procedure = State . DeclarationFinder . MatchName ( procedureName )
71
- . Where ( p => AccessibilityCheck . IsAccessible ( enclosingProcedure , p ) )
72
- . SingleOrDefault ( p => ! p . DeclarationType . HasFlag ( DeclarationType . Property ) || p . DeclarationType . HasFlag ( DeclarationType . PropertyGet ) ) ;
73
- if ( procedure ? . ParentScopeDeclaration is ClassModuleDeclaration )
74
- {
75
- // we can't know that the member is on the class' default interface
76
- return false ;
77
- }
78
-
79
- var parameters = State . DeclarationFinder . Parameters ( procedure ) ;
80
-
81
- ParameterDeclaration parameter ;
82
- var namedArg = argExpression . GetAncestor < VBAParser . NamedArgumentContext > ( ) ;
83
- if ( namedArg != null )
84
- {
85
- // argument is named: we're lucky
86
- var parameterName = namedArg . unrestrictedIdentifier ( ) . GetText ( ) ;
87
- parameter = parameters . SingleOrDefault ( p => p . IdentifierName == parameterName ) ;
88
- }
89
- else
90
- {
91
- // argument is positional: work out its index
92
- var argList = callStmt . GetDescendent < VBAParser . ArgumentListContext > ( ) ;
93
- var args = argList . GetDescendents < VBAParser . PositionalArgumentContext > ( ) . ToArray ( ) ;
94
- var parameterIndex = args . Select ( ( a , i ) =>
95
- a . GetDescendent < VBAParser . ArgumentExpressionContext > ( ) == argExpression ? ( a , i ) : ( null , - 1 ) )
96
- . SingleOrDefault ( item => item . a != null ) . i ;
97
- parameter = parameters . OrderBy ( p => p . Selection ) . Select ( ( p , i ) => ( p , i ) )
98
- . SingleOrDefault ( item => item . i == parameterIndex ) . p ;
99
- }
100
-
101
- if ( parameter == null )
102
- {
103
- // couldn't locate parameter
104
- return false ;
105
- }
54
+ var parameter = State . DeclarationFinder . FindParameterFromArgument ( argExpression , enclosingProcedure ) ;
106
55
107
56
// note: not recursive, by design.
108
57
return ( parameter . IsImplicitByRef || parameter . IsByRef )
0 commit comments