Skip to content

Commit 172ce80

Browse files
committed
Merge branch 'next' of https://github.com/rubberduck-vba/Rubberduck into next
2 parents ff67522 + e3131ae commit 172ce80

File tree

6 files changed

+56
-37
lines changed

6 files changed

+56
-37
lines changed

RetailCoder.VBE/UI/Settings/SettingsControl.xaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
mc:Ignorable="d"
99
d:DesignHeight="300" d:DesignWidth="600"
1010
d:DataContext="{d:DesignInstance {x:Type settings:SettingsControlViewModel}, IsDesignTimeCreatable=False}">
11+
<UserControl.InputBindings>
12+
<KeyBinding Key="Esc"
13+
Command="{Binding CancelButtonCommand}" />
14+
</UserControl.InputBindings>
1115
<UserControl.Resources>
1216
<converters:SettingsViewToPageConverter x:Key="SettingsViewToPage" />
1317

@@ -157,7 +161,8 @@
157161
Height="20"
158162
Margin="5,0"
159163
Padding="10,0"
160-
Command="{Binding CancelButtonCommand}" />
164+
Command="{Binding CancelButtonCommand}">
165+
</Button>
161166
</Grid>
162167
</DockPanel>
163168
</Border>

Rubberduck.Parsing/Binding/IndexDefaultBinding.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,6 @@ with a parameter list that cannot accept any parameters and an <argument-list> t
132132
IBoundExpression boundExpression = null;
133133
var asTypeName = lExpression.ReferencedDeclaration.AsTypeName;
134134
var asTypeDeclaration = lExpression.ReferencedDeclaration.AsTypeDeclaration;
135-
if (asTypeDeclaration == null)
136-
{
137-
return null;
138-
}
139135
boundExpression = ResolveDefaultMember(lExpression, asTypeName, asTypeDeclaration);
140136
if (boundExpression != null)
141137
{
@@ -173,7 +169,8 @@ private IBoundExpression ResolveDefaultMember(IBoundExpression lExpression, stri
173169
The declared type of <l-expression> is a specific class, which has a public default Property
174170
Get, Property Let, function or subroutine, and one of the following is true:
175171
*/
176-
bool hasDefaultMember = asTypeDeclaration.DeclarationType == DeclarationType.ClassModule
172+
bool hasDefaultMember = asTypeDeclaration != null
173+
&& asTypeDeclaration.DeclarationType == DeclarationType.ClassModule
177174
&& ((ClassModuleDeclaration)asTypeDeclaration).DefaultMember != null;
178175
if (hasDefaultMember)
179176
{

Rubberduck.Parsing/Binding/MemberAccessDefaultBinding.cs

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public IBoundExpression Resolve()
6767
IBoundExpression boundExpression = null;
6868
if (_lExpressionBinding != null)
6969
{
70-
_lExpression = _lExpressionBinding.Resolve();
70+
_lExpression = _lExpressionBinding.Resolve();
7171
}
7272
if (_lExpression.Classification == ExpressionClassification.ResolutionFailed)
7373
{
@@ -98,9 +98,7 @@ public IBoundExpression Resolve()
9898
{
9999
return boundExpression;
100100
}
101-
var failedExpr = new ResolutionFailedExpression();
102-
failedExpr.AddSuccessfullyResolvedExpression(_lExpression);
103-
return failedExpr;
101+
return CreateFailedExpression(_lExpression);
104102
}
105103

106104
private IBoundExpression ResolveLExpressionIsVariablePropertyOrFunction()
@@ -133,6 +131,13 @@ expression is classified as an unbound member and has a declared type of Variant
133131
return null;
134132
}
135133
var lExpressionDeclaration = _lExpression.ReferencedDeclaration;
134+
// The referenced declaration being null might mean that an index expression (e.g. an array with Variant elements) is used in a member access expression.
135+
// If it's an assignment for example we still have to bind the array (and not the element's referenced declaration) thus have to return the rest of the tree.
136+
// TODO: Find a better way of dealing with this, perhaps create declarations for Variant, Object etc.
137+
if (_lExpression.ReferencedDeclaration == null)
138+
{
139+
return new MemberAccessExpression(null, ExpressionClassification.Unbound, _context, _unrestrictedNameContext, _lExpression);
140+
}
136141
var referencedType = lExpressionDeclaration.AsTypeDeclaration;
137142
if (referencedType == null)
138143
{
@@ -145,31 +150,37 @@ expression is classified as an unbound member and has a declared type of Variant
145150
var udtMember = _declarationFinder.FindMemberWithParent(_project, _module, _parent, referencedType, _name, DeclarationType.UserDefinedTypeMember);
146151
if (udtMember != null)
147152
{
148-
return new MemberAccessExpression(udtMember, ExpressionClassification.Variable, _context, _unrestrictedNameContext, _lExpression);
153+
return new MemberAccessExpression(udtMember, ExpressionClassification.Variable, _context, _unrestrictedNameContext, _lExpression);
149154
}
150155
var variable = _declarationFinder.FindMemberWithParent(_project, _module, _parent, referencedType, _name, DeclarationType.Variable);
151156
if (variable != null)
152157
{
153-
return new MemberAccessExpression(variable, ExpressionClassification.Variable, _context, _unrestrictedNameContext, _lExpression);
158+
return new MemberAccessExpression(variable, ExpressionClassification.Variable, _context, _unrestrictedNameContext, _lExpression);
154159
}
155160
var property = _declarationFinder.FindMemberWithParent(_project, _module, _parent, referencedType, _name, _propertySearchType);
156161
if (property != null)
157162
{
158-
return new MemberAccessExpression(property, ExpressionClassification.Property, _context, _unrestrictedNameContext, _lExpression);
163+
return new MemberAccessExpression(property, ExpressionClassification.Property, _context, _unrestrictedNameContext, _lExpression);
159164
}
160165
var function = _declarationFinder.FindMemberWithParent(_project, _module, _parent, referencedType, _name, DeclarationType.Function);
161166
if (function != null)
162167
{
163-
return new MemberAccessExpression(function, ExpressionClassification.Function, _context, _unrestrictedNameContext, _lExpression);
168+
return new MemberAccessExpression(function, ExpressionClassification.Function, _context, _unrestrictedNameContext, _lExpression);
164169
}
165170
var subroutine = _declarationFinder.FindMemberWithParent(_project, _module, _parent, referencedType, _name, DeclarationType.Procedure);
166171
if (subroutine != null)
167172
{
168-
return new MemberAccessExpression(subroutine, ExpressionClassification.Subroutine, _context, _unrestrictedNameContext, _lExpression);
173+
return new MemberAccessExpression(subroutine, ExpressionClassification.Subroutine, _context, _unrestrictedNameContext, _lExpression);
169174
}
170-
// Note: To not have to deal with declared types we simply assume that no match means unbound member.
171-
// This way the rest of the member access expression can still be bound.
172-
return new MemberAccessExpression(null, ExpressionClassification.Unbound, _context, _unrestrictedNameContext, _lExpression);
175+
// Assume that no match = failure on our side.
176+
return CreateFailedExpression(_lExpression);
177+
}
178+
179+
private IBoundExpression CreateFailedExpression(IBoundExpression expression)
180+
{
181+
var failedExpr = new ResolutionFailedExpression();
182+
failedExpr.AddSuccessfullyResolvedExpression(expression);
183+
return failedExpr;
173184
}
174185

175186
private IBoundExpression ResolveLExpressionIsUnbound()
@@ -178,7 +189,7 @@ private IBoundExpression ResolveLExpressionIsUnbound()
178189
{
179190
return null;
180191
}
181-
return new MemberAccessExpression(null, ExpressionClassification.Unbound, _context, _unrestrictedNameContext, _lExpression);
192+
return new MemberAccessExpression(null, ExpressionClassification.Unbound, _context, _unrestrictedNameContext, _lExpression);
182193
}
183194

184195
private IBoundExpression ResolveLExpressionIsProject()
@@ -269,12 +280,12 @@ private IBoundExpression ResolveProject()
269280
{
270281
if (_declarationFinder.IsMatch(_project.ProjectName, _name))
271282
{
272-
return new MemberAccessExpression(_project, ExpressionClassification.Project, _context, _unrestrictedNameContext, _lExpression);
283+
return new MemberAccessExpression(_project, ExpressionClassification.Project, _context, _unrestrictedNameContext, _lExpression);
273284
}
274285
var referencedProjectRightOfDot = _declarationFinder.FindReferencedProject(_project, _name);
275286
if (referencedProjectRightOfDot != null)
276287
{
277-
return new MemberAccessExpression(referencedProjectRightOfDot, ExpressionClassification.Project, _context, _unrestrictedNameContext, _lExpression);
288+
return new MemberAccessExpression(referencedProjectRightOfDot, ExpressionClassification.Project, _context, _unrestrictedNameContext, _lExpression);
278289
}
279290
return null;
280291
}
@@ -285,20 +296,20 @@ private IBoundExpression ResolveProceduralModule(bool lExpressionIsEnclosingProj
285296
{
286297
if (_module.DeclarationType == DeclarationType.ProceduralModule && _declarationFinder.IsMatch(_module.IdentifierName, _name))
287298
{
288-
return new MemberAccessExpression(_module, ExpressionClassification.ProceduralModule, _context, _unrestrictedNameContext, _lExpression);
299+
return new MemberAccessExpression(_module, ExpressionClassification.ProceduralModule, _context, _unrestrictedNameContext, _lExpression);
289300
}
290301
var proceduralModuleEnclosingProject = _declarationFinder.FindModuleEnclosingProjectWithoutEnclosingModule(_project, _module, _name, DeclarationType.ProceduralModule);
291302
if (proceduralModuleEnclosingProject != null)
292303
{
293-
return new MemberAccessExpression(proceduralModuleEnclosingProject, ExpressionClassification.ProceduralModule, _context, _unrestrictedNameContext, _lExpression);
304+
return new MemberAccessExpression(proceduralModuleEnclosingProject, ExpressionClassification.ProceduralModule, _context, _unrestrictedNameContext, _lExpression);
294305
}
295306
}
296307
else
297308
{
298309
var proceduralModuleInReferencedProject = _declarationFinder.FindModuleReferencedProject(_project, _module, referencedProject, _name, DeclarationType.ProceduralModule);
299310
if (proceduralModuleInReferencedProject != null)
300311
{
301-
return new MemberAccessExpression(proceduralModuleInReferencedProject, ExpressionClassification.ProceduralModule, _context, _unrestrictedNameContext, _lExpression);
312+
return new MemberAccessExpression(proceduralModuleInReferencedProject, ExpressionClassification.ProceduralModule, _context, _unrestrictedNameContext, _lExpression);
302313
}
303314
}
304315
return null;
@@ -332,20 +343,20 @@ private IBoundExpression ResolveMemberInReferencedProject(bool lExpressionIsEncl
332343
var foundType = _declarationFinder.FindMemberEnclosingModule(_module, _parent, _name, memberType);
333344
if (foundType != null)
334345
{
335-
return new MemberAccessExpression(foundType, classification, _context, _unrestrictedNameContext, _lExpression);
346+
return new MemberAccessExpression(foundType, classification, _context, _unrestrictedNameContext, _lExpression);
336347
}
337348
var accessibleType = _declarationFinder.FindMemberEnclosedProjectWithoutEnclosingModule(_project, _module, _parent, _name, memberType);
338349
if (accessibleType != null)
339350
{
340-
return new MemberAccessExpression(accessibleType, classification, _context, _unrestrictedNameContext, _lExpression);
351+
return new MemberAccessExpression(accessibleType, classification, _context, _unrestrictedNameContext, _lExpression);
341352
}
342353
}
343354
else
344355
{
345356
var referencedProjectType = _declarationFinder.FindMemberReferencedProject(_project, _module, _parent, referencedProject, _name, memberType);
346357
if (referencedProjectType != null)
347358
{
348-
return new MemberAccessExpression(referencedProjectType, classification, _context, _unrestrictedNameContext, _lExpression);
359+
return new MemberAccessExpression(referencedProjectType, classification, _context, _unrestrictedNameContext, _lExpression);
349360
}
350361
}
351362
return null;
@@ -415,12 +426,12 @@ private IBoundExpression ResolveMemberInModule(Declaration module, DeclarationTy
415426
var enclosingProjectType = _declarationFinder.FindMemberEnclosedProjectInModule(_project, _module, _parent, module, _name, memberType);
416427
if (enclosingProjectType != null)
417428
{
418-
return new MemberAccessExpression(enclosingProjectType, classification, _context, _unrestrictedNameContext, _lExpression);
429+
return new MemberAccessExpression(enclosingProjectType, classification, _context, _unrestrictedNameContext, _lExpression);
419430
}
420431
var referencedProjectType = _declarationFinder.FindMemberReferencedProjectInModule(_project, _module, _parent, module, _name, memberType);
421432
if (referencedProjectType != null)
422433
{
423-
return new MemberAccessExpression(referencedProjectType, classification, _context, _unrestrictedNameContext, _lExpression);
434+
return new MemberAccessExpression(referencedProjectType, classification, _context, _unrestrictedNameContext, _lExpression);
424435
}
425436
return null;
426437
}
@@ -439,7 +450,7 @@ as a value with the same declared type as the enum member.
439450
var enumMember = _declarationFinder.FindMemberWithParent(_project, _module, _parent, _lExpression.ReferencedDeclaration, _name, DeclarationType.EnumerationMember);
440451
if (enumMember != null)
441452
{
442-
return new MemberAccessExpression(enumMember, ExpressionClassification.Value, _context, _unrestrictedNameContext, _lExpression);
453+
return new MemberAccessExpression(enumMember, ExpressionClassification.Value, _context, _unrestrictedNameContext, _lExpression);
443454
}
444455
return null;
445456
}

Rubberduck.Parsing/Symbols/ClassModuleDeclaration.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,17 @@ public bool IsExposed
6565
{
6666
get
6767
{
68+
// TODO: Find out if there's info about "being exposed" in type libraries.
69+
// We take the conservative approach of treating all type library modules as exposed.
70+
if (IsBuiltIn)
71+
{
72+
_isExposed = true;
73+
return _isExposed.Value;
74+
}
6875
if (_isExposed.HasValue)
6976
{
7077
return _isExposed.Value;
7178
}
72-
7379
var attributeIsExposed = false;
7480
IEnumerable<string> value;
7581
if (Attributes.TryGetValue("VB_Exposed", out value))

Rubberduck.Parsing/Symbols/IdentifierReferenceResolver.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,9 @@ private void ResolveDefault(
142142
statementContext);
143143
if (boundExpression.Classification == ExpressionClassification.ResolutionFailed)
144144
{
145-
_logger.Trace(
145+
_logger.Warn(
146146
string.Format(
147-
"{0}/Default Context: Failed to resolve {1}. Binding all successfully resolved expressions anyway.",
148-
GetType().Name,
147+
"Default Context: Failed to resolve {0}. Binding as much as we can.",
149148
expression.GetText()));
150149
}
151150
_boundExpressionVisitor.AddIdentifierReferences(boundExpression, _qualifiedModuleName, _currentScope, _currentParent, isAssignmentTarget, false);
@@ -156,10 +155,9 @@ private void ResolveType(ParserRuleContext expression)
156155
var boundExpression = _bindingService.ResolveType(_moduleDeclaration, _currentParent, expression);
157156
if (boundExpression.Classification == ExpressionClassification.ResolutionFailed)
158157
{
159-
_logger.Trace(
158+
_logger.Warn(
160159
string.Format(
161-
"{0}/Type Context: Failed to resolve {1}. Binding all successfully resolved expressions anyway.",
162-
GetType().Name,
160+
"Type Context: Failed to resolve {0}. Binding as much as we can.",
163161
expression.GetText()));
164162
}
165163
_boundExpressionVisitor.AddIdentifierReferences(boundExpression, _qualifiedModuleName, _currentScope, _currentParent);

RubberduckTests/CodeExplorer/CodeExplorerTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,8 @@ End Sub
11951195
Assert.AreEqual(-1, new CompareByType().Compare(functionNode, subNode));
11961196
}
11971197

1198+
// TODO: Doesn't work until DisplayName is figured out.
1199+
[Ignore]
11981200
[TestMethod]
11991201
public void CompareByType_ReturnsClassModuleBelowDocument()
12001202
{

0 commit comments

Comments
 (0)