Skip to content

Commit 5fe4afc

Browse files
committed
Some refactorings to improve clarity.
1 parent f81f17a commit 5fe4afc

File tree

4 files changed

+57
-32
lines changed

4 files changed

+57
-32
lines changed

Rubberduck.Parsing/Annotations/VBAParserAnnotationFactory.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,29 @@ public VBAParserAnnotationFactory()
2828
public IAnnotation Create(VBAParser.AnnotationContext context, QualifiedSelection qualifiedSelection)
2929
{
3030
string annotationName = context.annotationName().GetText();
31-
List<string> parameters = new List<string>();
32-
var argList = context.annotationArgList();
33-
if (argList != null)
31+
List<string> parameters = AnnotationParametersFromContext(context);
32+
return CreateAnnotation(annotationName, parameters, qualifiedSelection);
33+
}
34+
35+
private static List<string> AnnotationParametersFromContext(VBAParser.AnnotationContext context)
3436
{
35-
parameters.AddRange(argList.annotationArg().Select(arg => arg.GetText()));
37+
List<string> parameters = new List<string>();
38+
var argList = context.annotationArgList();
39+
if (argList != null)
40+
{
41+
parameters.AddRange(argList.annotationArg().Select(arg => arg.GetText()));
42+
}
43+
return parameters;
3644
}
37-
Type annotationCLRType = null;
38-
if (_creators.TryGetValue(annotationName.ToUpperInvariant(), out annotationCLRType))
45+
46+
private IAnnotation CreateAnnotation(string annotationName, List<string> parameters, QualifiedSelection qualifiedSelection)
3947
{
40-
return (IAnnotation)Activator.CreateInstance(annotationCLRType, qualifiedSelection, parameters);
48+
Type annotationCLRType = null;
49+
if (_creators.TryGetValue(annotationName.ToUpperInvariant(), out annotationCLRType))
50+
{
51+
return (IAnnotation)Activator.CreateInstance(annotationCLRType, qualifiedSelection, parameters);
52+
}
53+
return null;
4154
}
42-
return null;
43-
}
4455
}
4556
}

Rubberduck.Parsing/Binding/DefaultBindingContext.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public IBoundExpression Resolve(Declaration module, Declaration parent, ParserRu
3434
public IExpressionBinding BuildTree(Declaration module, Declaration parent, ParserRuleContext expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext)
3535
{
3636
dynamic dynamicExpression = expression;
37-
var type = expression.GetType();
3837
return Visit(module, parent, dynamicExpression, withBlockVariable, statementContext);
3938
}
4039

Rubberduck.Parsing/Binding/SimpleNameDefaultBinding.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -350,25 +350,34 @@ private bool IsValidMatch(Declaration match, string name)
350350
{
351351
return true;
352352
}
353-
var functionSubroutinePropertyGet = match.DeclarationType == DeclarationType.Function
354-
|| match.DeclarationType == DeclarationType.Procedure
355-
|| match.DeclarationType == DeclarationType.PropertyGet;
356-
if (!functionSubroutinePropertyGet)
353+
if (!IsFunctionSubroutinePropertyGet(match))
357354
{
358355
return true;
359356
}
360357
if (((IDeclarationWithParameter)match).Parameters.Count() > 0)
361358
{
362359
return true;
363360
}
364-
if (match.AsTypeName != null
365-
&& match.AsTypeName.ToUpperInvariant() != "VARIANT"
366-
&& match.AsTypeName.ToUpperInvariant() != "OBJECT"
367-
&& match.AsTypeIsBaseType)
361+
if (IsTypeDeclarationOfSpecificBaseType(match))
368362
{
369363
return false;
370364
}
371365
return true;
372366
}
367+
368+
private static bool IsFunctionSubroutinePropertyGet(Declaration match)
369+
{
370+
return match.DeclarationType == DeclarationType.Function
371+
|| match.DeclarationType == DeclarationType.Procedure
372+
|| match.DeclarationType == DeclarationType.PropertyGet;
373+
}
374+
375+
private static bool IsTypeDeclarationOfSpecificBaseType(Declaration match)
376+
{
377+
return match.AsTypeName != null
378+
&& match.AsTypeName.ToUpperInvariant() != "VARIANT"
379+
&& match.AsTypeName.ToUpperInvariant() != "OBJECT"
380+
&& match.AsTypeIsBaseType;
381+
}
373382
}
374383
}

Rubberduck.Parsing/Symbols/Declaration.cs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,25 +159,31 @@ public Declaration(
159159

160160
_projectId = _qualifiedName.QualifiedModuleName.ProjectId;
161161

162-
var @namespace = Annotations.FirstOrDefault(annotation => annotation.AnnotationType == AnnotationType.Folder);
163-
string result;
164-
if (@namespace == null)
165-
{
166-
result = _qualifiedName.QualifiedModuleName.Project == null
167-
? _projectId
168-
: _qualifiedName.QualifiedModuleName.Project.Name;
169-
}
170-
else
171-
{
172-
var value = ((FolderAnnotation)@namespace).FolderName;
173-
result = value;
174-
}
175-
_customFolder = result;
162+
_customFolder = FolderFromAnnotations();
176163
_isArray = isArray;
177164
_asTypeContext = asTypeContext;
178165
_typeHint = typeHint;
179166
}
180167

168+
private string FolderFromAnnotations()
169+
{
170+
var @namespace = Annotations.FirstOrDefault(annotation => annotation.AnnotationType == AnnotationType.Folder);
171+
string result;
172+
if (@namespace == null)
173+
{
174+
result = _qualifiedName.QualifiedModuleName.Project == null
175+
? _projectId
176+
: _qualifiedName.QualifiedModuleName.Project.Name;
177+
}
178+
else
179+
{
180+
var value = ((FolderAnnotation)@namespace).FolderName;
181+
result = value;
182+
}
183+
return result;
184+
}
185+
186+
181187
public static Declaration GetModuleParent(Declaration declaration)
182188
{
183189
if (declaration == null)

0 commit comments

Comments
 (0)