Skip to content

Commit b4c250c

Browse files
committed
fixed UntypedFunctionUsageInspection
1 parent 8bdc215 commit b4c250c

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

RetailCoder.VBE/Inspections/UntypedFunctionUsageInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
4444
{
4545
var declarations = BuiltInDeclarations
4646
// note: these *should* be functions, but somehow they're not defined as such
47-
.Where(item => _tokens.Any(token => item.IdentifierName == ("_B_var_" + token) && item.References.Any()));
47+
.Where(item => _tokens.Any(token => item.References.Any() && (item.IdentifierName == token || item.IdentifierName == "_B_var_" + token)));
4848

4949
return declarations.SelectMany(declaration => declaration.References
5050
.Select(item => new UntypedFunctionUsageInspectionResult(this, string.Format(Description, declaration.IdentifierName), item.QualifiedModuleName, item.Context)));

Rubberduck.Parsing/Grammar/Tokens.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static class Tokens
9898
public static readonly string LBound = "LBound";
9999
public static readonly string LCase = "LCase";
100100
public static readonly string Left = "Left";
101-
public static readonly string LeftB = "Left";
101+
public static readonly string LeftB = "LeftB";
102102
public static readonly string Len = "Len";
103103
public static readonly string LenB = "LenB";
104104
public static readonly string Let = "Let";
@@ -113,7 +113,7 @@ public static class Tokens
113113
public static readonly string LTrim = "LTrim";
114114
public static readonly string Me = "Me";
115115
public static readonly string Mid = "Mid";
116-
public static readonly string MidB = "Mid";
116+
public static readonly string MidB = "MidB";
117117
public static readonly string Minute = "Minute";
118118
public static readonly string MkDir = "MkDir";
119119
public static readonly string Mod = "Mod";
@@ -147,7 +147,7 @@ public static class Tokens
147147
public static readonly string Resume = "Resume";
148148
public static readonly string Return = "Return";
149149
public static readonly string Right = "Right";
150-
public static readonly string RightB = "Right";
150+
public static readonly string RightB = "RightB";
151151
public static readonly string RmDir = "RmDir";
152152
public static readonly string Rnd = "Rnd";
153153
public static readonly string RTrim = "RTrim";

Rubberduck.Parsing/Symbols/IdentifierReferenceResolver.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,13 +1088,26 @@ private Declaration FindModuleScopeProcedure(string identifierName, Declaration
10881088
return result.Count == 1 ? result.SingleOrDefault() : null;
10891089
}
10901090

1091+
private bool IsStdModuleMember(Declaration declaration)
1092+
{
1093+
return declaration.ParentDeclaration != null
1094+
&& declaration.ParentDeclaration.DeclarationType == DeclarationType.Module;
1095+
}
1096+
1097+
private bool IsStaticClass(Declaration declaration)
1098+
{
1099+
return declaration.ParentDeclaration != null
1100+
&& declaration.ParentDeclaration.DeclarationType == DeclarationType.Class
1101+
&& (declaration.ParentDeclaration.HasPredeclaredId || declaration.IsBuiltIn);
1102+
}
1103+
10911104
private Declaration FindProjectScopeDeclaration(string identifierName, Declaration localScope = null, ContextAccessorType accessorType = ContextAccessorType.GetValueOrReference, bool hasStringQualifier = false)
10921105
{
1093-
// the "$" in e.g. "UCase$" isn't picked up as part of the identifierName, so we need to add it manually:
10941106
var matches = _declarationFinder.MatchName(identifierName).Where(item =>
1095-
item.ParentDeclaration != null && ((item.ParentDeclaration.DeclarationType == DeclarationType.Module
1096-
|| item.ParentDeclaration.HasPredeclaredId))
1097-
|| item.ParentScopeDeclaration.Equals(localScope)).ToList();
1107+
item.ParentDeclaration == null
1108+
|| IsStdModuleMember(item)
1109+
|| IsStaticClass(item)
1110+
|| item.ParentScopeDeclaration.Equals(localScope)).ToList();
10981111

10991112
if (matches.Count == 1)
11001113
{

Rubberduck.Parsing/Symbols/ReferencedDeclarationsCollector.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using TYPEATTR = System.Runtime.InteropServices.ComTypes.TYPEATTR;
1717
using FUNCDESC = System.Runtime.InteropServices.ComTypes.FUNCDESC;
1818
using ELEMDESC = System.Runtime.InteropServices.ComTypes.ELEMDESC;
19+
using TYPEFLAGS = System.Runtime.InteropServices.ComTypes.TYPEFLAGS;
1920
using VARDESC = System.Runtime.InteropServices.ComTypes.VARDESC;
2021

2122
namespace Rubberduck.Parsing.Symbols
@@ -125,14 +126,20 @@ public IEnumerable<Declaration> GetDeclarationsForReference(Reference reference)
125126
typeQualifiedMemberName = new QualifiedMemberName(typeQualifiedModuleName, typeName);
126127
}
127128

128-
var moduleDeclaration = new Declaration(typeQualifiedMemberName, projectDeclaration, projectDeclaration, typeName, false, false, Accessibility.Global, typeDeclarationType, null, Selection.Home);
129-
yield return moduleDeclaration;
130-
131129
IntPtr typeAttributesPointer;
132130
info.GetTypeAttr(out typeAttributesPointer);
133131

134132
var typeAttributes = (TYPEATTR)Marshal.PtrToStructure(typeAttributesPointer, typeof (TYPEATTR));
135133
//var implements = GetImplementedInterfaceNames(typeAttributes, info);
134+
135+
var attributes = new Attributes();
136+
if (typeAttributes.wTypeFlags.HasFlag(TYPEFLAGS.TYPEFLAG_FPREDECLID))
137+
{
138+
attributes.AddPredeclaredIdTypeAttribute();
139+
}
140+
141+
var moduleDeclaration = new Declaration(typeQualifiedMemberName, projectDeclaration, projectDeclaration, typeName, false, false, Accessibility.Global, typeDeclarationType, null, Selection.Home, true, null, attributes);
142+
yield return moduleDeclaration;
136143

137144
for (var memberIndex = 0; memberIndex < typeAttributes.cFuncs; memberIndex++)
138145
{

0 commit comments

Comments
 (0)