Skip to content

Commit 58429a1

Browse files
authored
Merge branch 'next' into Issue1759
2 parents 6932bdf + fc9ca28 commit 58429a1

File tree

7 files changed

+53
-5
lines changed

7 files changed

+53
-5
lines changed

RetailCoder.VBE/Inspections/ImplicitActiveSheetReferenceInspection.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
3636
}
3737

3838
var matches = BuiltInDeclarations.Where(item =>
39-
Targets.Contains(item.IdentifierName)).ToList();
39+
Targets.Contains(item.IdentifierName) &&
40+
item.ParentScope == "EXCEL.EXE;Excel._Global" &&
41+
item.AsTypeName == "Range").ToList();
4042

4143
var issues = matches.Where(item => item.References.Any())
4244
.SelectMany(declaration => declaration.References);

Rubberduck.Parsing/Binding/DefaultBindingContext.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ private IExpressionBinding Visit(Declaration module, Declaration parent, VBAPars
119119
return new SimpleNameDefaultBinding(_declarationFinder, Declaration.GetProjectParent(parent), module, parent, expression, Identifier.GetName(expression.identifier()), statementContext);
120120
}
121121

122+
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.IdentifierValueContext expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext)
123+
{
124+
return new SimpleNameDefaultBinding(_declarationFinder, Declaration.GetProjectParent(parent), module, parent, expression, Identifier.GetName(expression), statementContext);
125+
}
126+
122127
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.MemberAccessExprContext expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext)
123128
{
124129
dynamic lExpression = expression.lExpression();

Rubberduck.Parsing/Symbols/ClassModuleDeclaration.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ public bool IsGlobalClassModule
104104
attributeIsGlobalClassModule = value.Single() == "True";
105105
}
106106
_isGlobal = attributeIsGlobalClassModule;
107+
108+
if (!_isGlobal.Value)
109+
{
110+
foreach (var type in Subtypes)
111+
{
112+
if (type is ClassModuleDeclaration && ((ClassModuleDeclaration) type).IsGlobalClassModule)
113+
{
114+
_isGlobal = true;
115+
break;
116+
}
117+
}
118+
}
119+
107120
return _isGlobal.Value;
108121
}
109122
}

Rubberduck.Parsing/Symbols/ReferencedDeclarationsCollector.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ public List<Declaration> GetDeclarationsForReference(Reference reference)
207207
attributes.AddPredeclaredIdTypeAttribute();
208208
}
209209

210+
if (typeAttributes.wTypeFlags.HasFlag(TYPEFLAGS.TYPEFLAG_FAPPOBJECT))
211+
{
212+
attributes.AddGlobalClassAttribute();
213+
}
214+
210215
Declaration moduleDeclaration;
211216
switch (typeDeclarationType)
212217
{

Rubberduck.Parsing/VBA/Attributes.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,10 @@ public void AddPredeclaredIdTypeAttribute()
3939
{
4040
Add("VB_PredeclaredId", new[] {"True"});
4141
}
42+
43+
public void AddGlobalClassAttribute()
44+
{
45+
Add("VB_GlobalNamespace", new[] {"True"});
46+
}
4247
}
4348
}

Rubberduck.VBEEditor/NativeMethods.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,9 @@ internal static string GetWindowTextByHwnd(IntPtr windowHandle)
8484
/// <param name="parentWindowHandle"> Handle of the parent window. </param>
8585
internal static void ActivateWindow(IntPtr windowHandle, IntPtr parentWindowHandle)
8686
{
87-
const int WM_MOUSEACTIVATE = 0x21;
88-
const int HTCAPTION = 2;
89-
const int WM_LBUTTONDOWN = 0x201;
87+
const int WM_MDIACTIVATE = 0x0222;
9088

91-
SendMessage(windowHandle, WM_MOUSEACTIVATE, parentWindowHandle, new IntPtr(HTCAPTION + WM_LBUTTONDOWN * 0x10000));
89+
SendMessage(parentWindowHandle, WM_MDIACTIVATE, windowHandle, IntPtr.Zero);
9290
}
9391

9492
internal static void EnumChildWindows(IntPtr parentWindowHandle, EnumChildWindowsDelegate callBackEnumWindows)

RubberduckTests/Grammar/ResolverTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,6 +1957,26 @@ End Sub
19571957
Assert.AreEqual(4, declaration.References.Count());
19581958
}
19591959

1960+
[TestMethod]
1961+
public void FieldLengthStmt_IsReferenceToLocalVariable()
1962+
{
1963+
// arrange
1964+
var code = @"
1965+
Public Sub Test()
1966+
Const Len As Integer = 4
1967+
Dim a As String * Len
1968+
End Sub
1969+
";
1970+
// act
1971+
var state = Resolve(code);
1972+
1973+
// assert
1974+
var declaration = state.AllUserDeclarations.Single(item =>
1975+
item.DeclarationType == DeclarationType.Constant && item.IdentifierName == "Len");
1976+
1977+
Assert.AreEqual(1, declaration.References.Count());
1978+
}
1979+
19601980
// Ignored because handling forms/hierarchies is an open issue.
19611981
[Ignore]
19621982
[TestMethod]

0 commit comments

Comments
 (0)