Skip to content

Commit 3cd52cc

Browse files
committed
Merge branch 'next' of https://github.com/rubberduck-vba/rubberduck into Issue4159
2 parents 3b94644 + 496dcf9 commit 3cd52cc

File tree

103 files changed

+10832
-3197
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+10832
-3197
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<img src="https://user-images.githubusercontent.com/5751684/38372412-c3247d70-38bc-11e8-8eaa-2f2d19595a42.png" width=100% />
1+
<img src="https://user-images.githubusercontent.com/5751684/46327997-aeb98d00-c5d2-11e8-9de5-ba6f9cd1eea3.png" />
22

33
<!-- campaign is no longer accepting donations
44
### Donate!
@@ -29,7 +29,6 @@ If you like this project and would like to thank its contributors, you are welco
2929
* [Installing](https://github.com/rubberduck-vba/Rubberduck/wiki/Installing)
3030
* [Getting Started](https://github.com/rubberduck-vba/Rubberduck/blob/next/docs/GettingStarted.md) using Rubberduck
3131
* [Contributing](https://github.com/rubberduck-vba/Rubberduck/blob/next/CONTRIBUTING.md)
32-
* [User Testimonials](https://github.com/rubberduck-vba/Rubberduck/blob/next/thanks.md)
3332

3433
---
3534

Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitDefaultMemberAssignmentInspection.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Diagnostics;
23
using System.Linq;
34
using Rubberduck.Inspections.Abstract;
45
using Rubberduck.Inspections.Results;
@@ -28,7 +29,10 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2829
.Where(reference =>
2930
{
3031
var letStmtContext = reference.Context.GetAncestor<VBAParser.LetStmtContext>();
31-
return reference.IsAssignment && letStmtContext != null && letStmtContext.LET() == null;
32+
return reference.IsAssignment
33+
&& letStmtContext != null
34+
&& letStmtContext.LET() == null
35+
&& !reference.IsIgnoringInspectionResultFor(AnnotationName);
3236
});
3337

3438
return interestingReferences.Select(reference => new IdentifierReferenceInspectionResult(this,

Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteCallStatementInspection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
3030
foreach (var context in Listener.Contexts.Where(context => !IsIgnoringInspectionResultFor(context.ModuleName, context.Context.Start.Line)))
3131
{
3232
string lines;
33-
using (var module = State.ProjectsProvider.Component(context.ModuleName).CodeModule)
33+
var component = State.ProjectsProvider.Component(context.ModuleName);
34+
using (var module = component.CodeModule)
3435
{
3536
lines = module.GetLines(context.Context.Start.Line,
3637
context.Context.Stop.Line - context.Context.Start.Line + 1);

Rubberduck.CodeAnalysis/Inspections/Concrete/UnassignedVariableUsageInspection.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,22 @@ public UnassignedVariableUsageInspection(RubberduckParserState state)
2121
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2222
{
2323
var declarations = State.DeclarationFinder.UserDeclarations(DeclarationType.Variable)
24-
.Where(result => !IsIgnoringInspectionResultFor(result, AnnotationName))
25-
.Where(declaration =>
26-
State.DeclarationFinder.MatchName(declaration.AsTypeName).All(d => d.DeclarationType != DeclarationType.UserDefinedType)
24+
.Where(declaration =>
25+
State.DeclarationFinder.MatchName(declaration.AsTypeName)
26+
.All(d => d.DeclarationType != DeclarationType.UserDefinedType)
2727
&& !declaration.IsSelfAssigned
28-
&& !declaration.References.Any(reference => reference.IsAssignment && !IsIgnoringInspectionResultFor(reference, AnnotationName)));
28+
&& !declaration.References.Any(reference => reference.IsAssignment));
2929

30-
//The parameter scoping was apparently incorrect before - need to filter for the actual function.
30+
//See https://github.com/rubberduck-vba/Rubberduck/issues/2010 for why these are being excluded.
31+
//TODO: These need to be modified to correctly work in VB6.
3132
var lenFunction = BuiltInDeclarations.SingleOrDefault(s => s.DeclarationType == DeclarationType.Function && s.Scope.Equals("VBE7.DLL;VBA.Strings.Len"));
32-
var lenbFunction = BuiltInDeclarations.SingleOrDefault(s => s.DeclarationType == DeclarationType.Function && s.Scope.Equals("VBE7.DLL;VBA.Strings.Len"));
33+
var lenbFunction = BuiltInDeclarations.SingleOrDefault(s => s.DeclarationType == DeclarationType.Function && s.Scope.Equals("VBE7.DLL;VBA.Strings.LenB"));
3334

3435
return declarations.Where(d => d.References.Any() &&
3536
!DeclarationReferencesContainsReference(lenFunction, d) &&
3637
!DeclarationReferencesContainsReference(lenbFunction, d))
3738
.SelectMany(d => d.References)
39+
.Where(r => !r.IsIgnoringInspectionResultFor(AnnotationName))
3840
.Select(r => new IdentifierReferenceInspectionResult(this,
3941
string.Format(InspectionResults.UnassignedVariableUsageInspection, r.IdentifierName),
4042
State,
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
using Antlr4.Runtime;
2+
using Rubberduck.Parsing.PreProcessing;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Data;
6+
using System.Globalization;
7+
8+
namespace Rubberduck.Inspections.Concrete.UnreachableCaseInspection
9+
{
10+
public class ComparableDateValue : IValue, IComparable<ComparableDateValue>
11+
{
12+
private readonly DateValue _dateValue;
13+
private readonly int _hashCode;
14+
15+
public ComparableDateValue(DateValue dateValue)
16+
{
17+
_dateValue = dateValue;
18+
_hashCode = dateValue.AsDecimal.GetHashCode();
19+
}
20+
21+
public Parsing.PreProcessing.ValueType ValueType => _dateValue.ValueType;
22+
23+
public bool AsBool => _dateValue.AsBool;
24+
25+
public byte AsByte => _dateValue.AsByte;
26+
27+
public decimal AsDecimal => _dateValue.AsDecimal;
28+
29+
public DateTime AsDate => _dateValue.AsDate;
30+
31+
public string AsString => _dateValue.AsString;
32+
33+
public IEnumerable<IToken> AsTokens => _dateValue.AsTokens;
34+
35+
public int CompareTo(ComparableDateValue dateValue)
36+
=> _dateValue.AsDecimal.CompareTo(dateValue._dateValue.AsDecimal);
37+
38+
public override int GetHashCode() => _hashCode;
39+
40+
public override bool Equals(object obj)
41+
{
42+
if (obj is ComparableDateValue decorator)
43+
{
44+
return decorator.CompareTo(this) == 0;
45+
}
46+
47+
if (obj is DateValue dateValue)
48+
{
49+
return dateValue.AsDecimal == _dateValue.AsDecimal;
50+
}
51+
52+
return false;
53+
}
54+
55+
public override string ToString()
56+
{
57+
return _dateValue.ToString();
58+
}
59+
60+
public string AsDateLiteral()
61+
{
62+
var asString = AsDate.ToString(CultureInfo.InvariantCulture);
63+
var prePostPend = "#";
64+
var result = asString.StartsWith(prePostPend) ? asString : $"{prePostPend}{asString}";
65+
result = result.EndsWith(prePostPend) ? result : $"{result}{prePostPend}";
66+
return result;
67+
}
68+
69+
public static ComparableDateValue Parse(string valueText)
70+
{
71+
var literal = new DateLiteralExpression(new ConstantExpression(new StringValue(valueText)));
72+
return new ComparableDateValue((DateValue)literal.Evaluate());
73+
}
74+
75+
public static bool TryParse(string valueText, out ComparableDateValue value)
76+
{
77+
value = default;
78+
if (!(valueText.StartsWith("#") && valueText.EndsWith("#")))
79+
{
80+
return false;
81+
}
82+
83+
try
84+
{
85+
value = Parse(valueText);
86+
return true;
87+
}
88+
catch (SyntaxErrorException)
89+
{
90+
return false;
91+
}
92+
catch (ArgumentOutOfRangeException)
93+
{
94+
return false;
95+
}
96+
catch (InputMismatchException)
97+
{
98+
return false;
99+
}
100+
catch (Exception e)
101+
{
102+
//even though a SyntaxErrorException/InputMismatchException is thrown,
103+
//this catch-all block seems to be needed(?)
104+
return false;
105+
}
106+
}
107+
}
108+
}

Rubberduck.CodeAnalysis/Inspections/Concrete/UnreachableCaseInspection/ContextWrapperBase.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)