Skip to content

Commit d1c0cf7

Browse files
authored
Merge pull request #4247 from rkapka/rkapka-master
Annotation for obsolete members + inspection
2 parents 22561bf + 3f7c774 commit d1c0cf7

20 files changed

+418
-209
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Rubberduck.Inspections.Abstract;
4+
using Rubberduck.Inspections.Results;
5+
using Rubberduck.Parsing.Annotations;
6+
using Rubberduck.Parsing.Inspections.Abstract;
7+
using Rubberduck.Parsing.Symbols;
8+
using Rubberduck.Parsing.VBA;
9+
using Rubberduck.Resources.Inspections;
10+
11+
namespace Rubberduck.Inspections.Inspections.Concrete
12+
{
13+
public sealed class ObsoleteMemberUsageInspection : InspectionBase
14+
{
15+
public ObsoleteMemberUsageInspection(RubberduckParserState state) : base(state)
16+
{
17+
}
18+
19+
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
20+
{
21+
var declarations = State.AllUserDeclarations
22+
.Where(declaration => declaration.DeclarationType.HasFlag(DeclarationType.Member) &&
23+
declaration.Annotations.Any(annotation =>annotation.AnnotationType == AnnotationType.Obsolete));
24+
25+
var issues = new List<IdentifierReferenceInspectionResult>();
26+
27+
foreach (var declaration in declarations)
28+
{
29+
var replacementDocumentation =
30+
((ObsoleteAnnotation) declaration.Annotations.First(annotation =>
31+
annotation.AnnotationType == AnnotationType.Obsolete)).ReplacementDocumentation;
32+
33+
issues.AddRange(declaration.References.Select(reference =>
34+
new IdentifierReferenceInspectionResult(this,
35+
string.Format(InspectionResults.ObsoleteMemberUsageInspection, reference.IdentifierName, replacementDocumentation),
36+
State, reference)));
37+
}
38+
39+
return issues;
40+
}
41+
}
42+
}

Rubberduck.CodeAnalysis/Rubberduck.CodeAnalysis.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
<Compile Include="Inspections\Concrete\BooleanAssignedInIfElseInspection.cs" />
8181
<Compile Include="Inspections\Concrete\EmptyWhileWendBlockInspection.cs" />
8282
<Compile Include="Inspections\Concrete\ObsoleteErrorSyntaxInspection.cs" />
83+
<Compile Include="Inspections\Concrete\ObsoleteMemberUsageInspection.cs" />
8384
<Compile Include="Inspections\Concrete\SheetAccessedUsingStringInspection.cs" />
8485
<Compile Include="Inspections\Concrete\StepIsNotSpecifiedInspection.cs" />
8586
<Compile Include="Inspections\Concrete\StepOneIsRedundantInspection.cs" />

Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerMemberViewModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Text;
55
using System.Windows.Media.Imaging;
6+
using Rubberduck.Parsing.Annotations;
67
using Rubberduck.Parsing.Grammar;
78
using Rubberduck.Parsing.Symbols;
89
using Rubberduck.VBEditor;
@@ -175,5 +176,8 @@ public void ParentComponentHasError()
175176
private BitmapImage _icon;
176177
public override BitmapImage CollapsedIcon => _icon;
177178
public override BitmapImage ExpandedIcon => _icon;
179+
180+
public bool IsObsolete =>
181+
Declaration.Annotations.Any(annotation => annotation.AnnotationType == AnnotationType.Obsolete);
178182
}
179183
}

Rubberduck.Core/Properties/Settings.Designer.cs

Lines changed: 34 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.Core/Properties/Settings.settings

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,30 @@
181181
&lt;MinimumLogLevel&gt;6&lt;/MinimumLogLevel&gt;
182182
&lt;EnableExperimentalFeatures /&gt;
183183
&lt;/GeneralSettings&gt;</Value>
184+
</Setting>
185+
<Setting Name="AutoCompleteSettings" Type="Rubberduck.Settings.AutoCompleteSettings" Scope="Application">
186+
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
187+
&lt;AutoCompleteSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" CompleteBlockOnTab="true" CompleteBlockOnEnter="true" EnableSmartConcat="true"&gt;
188+
&lt;AutoCompletes&gt;
189+
&lt;AutoComplete Key="AutoCompleteClosingBrace" IsEnabled="true" /&gt;
190+
&lt;AutoComplete Key="AutoCompleteClosingBracket" IsEnabled="true" /&gt;
191+
&lt;AutoComplete Key="AutoCompleteClosingParenthese" IsEnabled="true" /&gt;
192+
&lt;AutoComplete Key="AutoCompleteClosingString" IsEnabled="true" /&gt;
193+
&lt;AutoComplete Key="AutoCompleteDoBlock" IsEnabled="true" /&gt;
194+
&lt;AutoComplete Key="AutoCompleteEnumBlock" IsEnabled="true" /&gt;
195+
&lt;AutoComplete Key="AutoCompleteForBlock" IsEnabled="true" /&gt;
196+
&lt;AutoComplete Key="AutoCompleteFunctionBlock" IsEnabled="true" /&gt;
197+
&lt;AutoComplete Key="AutoCompleteIfBlock" IsEnabled="true" /&gt;
198+
&lt;AutoComplete Key="AutoCompleteOnErrorResumeNextBlock" IsEnabled="true" /&gt;
199+
&lt;AutoComplete Key="AutoCompletePrecompilerIfBlock" IsEnabled="true" /&gt;
200+
&lt;AutoComplete Key="AutoCompletePropertyBlock" IsEnabled="true" /&gt;
201+
&lt;AutoComplete Key="AutoCompleteSelectBlock" IsEnabled="true" /&gt;
202+
&lt;AutoComplete Key="AutoCompleteSubBlock" IsEnabled="true" /&gt;
203+
&lt;AutoComplete Key="AutoCompleteTypeBlock" IsEnabled="true" /&gt;
204+
&lt;AutoComplete Key="AutoCompleteWhileBlock" IsEnabled="true" /&gt;
205+
&lt;AutoComplete Key="AutoCompleteWithBlock" IsEnabled="true" /&gt;
206+
&lt;/AutoCompletes&gt;
207+
&lt;/AutoCompleteSettings&gt;</Value>
184208
</Setting>
185209
<Setting Name="CodeInspectionSettings" Type="Rubberduck.Settings.CodeInspectionSettings" Scope="Application">
186210
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
@@ -252,34 +276,11 @@
252276
&lt;CodeInspection Name="StepIsNotSpecifiedInspection" Severity="DoNotShow" InspectionType="LanguageOpportunities" /&gt;
253277
&lt;CodeInspection Name="StepOneIsRedundantInspection" Severity="Hint" InspectionType="LanguageOpportunities" /&gt;
254278
&lt;CodeInspection Name="SheetAccessedUsingStringInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" /&gt;
279+
&lt;CodeInspection Name="ObsoleteMemberUsageInspection" Severity="Warning" InspectionType="MaintainabilityAndReadabilityIssues" /&gt;
255280
&lt;/CodeInspections&gt;
256281
&lt;WhitelistedIdentifiers /&gt;
257282
&lt;RunInspectionsOnSuccessfulParse&gt;true&lt;/RunInspectionsOnSuccessfulParse&gt;
258283
&lt;/CodeInspectionSettings&gt;</Value>
259284
</Setting>
260-
<Setting Name="AutoCompleteSettings" Type="Rubberduck.Settings.AutoCompleteSettings" Scope="Application">
261-
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
262-
&lt;AutoCompleteSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" CompleteBlockOnTab="true" CompleteBlockOnEnter="true" EnableSmartConcat="true"&gt;
263-
&lt;AutoCompletes&gt;
264-
&lt;AutoComplete Key="AutoCompleteClosingBrace" IsEnabled="true" /&gt;
265-
&lt;AutoComplete Key="AutoCompleteClosingBracket" IsEnabled="true" /&gt;
266-
&lt;AutoComplete Key="AutoCompleteClosingParenthese" IsEnabled="true" /&gt;
267-
&lt;AutoComplete Key="AutoCompleteClosingString" IsEnabled="true" /&gt;
268-
&lt;AutoComplete Key="AutoCompleteDoBlock" IsEnabled="true" /&gt;
269-
&lt;AutoComplete Key="AutoCompleteEnumBlock" IsEnabled="true" /&gt;
270-
&lt;AutoComplete Key="AutoCompleteForBlock" IsEnabled="true" /&gt;
271-
&lt;AutoComplete Key="AutoCompleteFunctionBlock" IsEnabled="true" /&gt;
272-
&lt;AutoComplete Key="AutoCompleteIfBlock" IsEnabled="true" /&gt;
273-
&lt;AutoComplete Key="AutoCompleteOnErrorResumeNextBlock" IsEnabled="true" /&gt;
274-
&lt;AutoComplete Key="AutoCompletePrecompilerIfBlock" IsEnabled="true" /&gt;
275-
&lt;AutoComplete Key="AutoCompletePropertyBlock" IsEnabled="true" /&gt;
276-
&lt;AutoComplete Key="AutoCompleteSelectBlock" IsEnabled="true" /&gt;
277-
&lt;AutoComplete Key="AutoCompleteSubBlock" IsEnabled="true" /&gt;
278-
&lt;AutoComplete Key="AutoCompleteTypeBlock" IsEnabled="true" /&gt;
279-
&lt;AutoComplete Key="AutoCompleteWhileBlock" IsEnabled="true" /&gt;
280-
&lt;AutoComplete Key="AutoCompleteWithBlock" IsEnabled="true" /&gt;
281-
&lt;/AutoCompletes&gt;
282-
&lt;/AutoCompleteSettings&gt;</Value>
283-
</Setting>
284285
</Settings>
285286
</SettingsFile>

Rubberduck.Core/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@
8888
<Setter Property="ToolTip" Value="{Binding Name}" />
8989
<Setter Property="ToolTipService.InitialShowDelay" Value="500" />
9090
<Setter Property="TextTrimming" Value="CharacterEllipsis" />
91+
<Style.Triggers>
92+
<DataTrigger Binding="{Binding IsObsolete}" Value="true">
93+
<Setter Property="Foreground" Value="Gray" />
94+
<Setter Property="TextDecorations" Value="Strikethrough" />
95+
</DataTrigger>
96+
</Style.Triggers>
9197
</Style>
9298

9399
<Style x:Key="TreeViewItemStyleWithSignatures" TargetType="TextBlock">
@@ -98,6 +104,12 @@
98104
<Setter Property="ToolTip" Value="{Binding NameWithSignature}" />
99105
<Setter Property="ToolTipService.InitialShowDelay" Value="500" />
100106
<Setter Property="TextTrimming" Value="CharacterEllipsis" />
107+
<Style.Triggers>
108+
<DataTrigger Binding="{Binding IsObsolete}" Value="true">
109+
<Setter Property="Foreground" Value="Gray" />
110+
<Setter Property="TextDecorations" Value="Strikethrough" />
111+
</DataTrigger>
112+
</Style.Triggers>
101113
</Style>
102114

103115
<Style x:Key="TreeViewIconStyle" TargetType="Image" BasedOn="{StaticResource IconStyle}">

Rubberduck.Core/app.config

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,33 @@
233233
</GeneralSettings>
234234
</value>
235235
</setting>
236+
<setting name="AutoCompleteSettings" serializeAs="Xml">
237+
<value>
238+
<AutoCompleteSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
239+
xmlns:xsd="http://www.w3.org/2001/XMLSchema" CompleteBlockOnTab="true"
240+
CompleteBlockOnEnter="true" EnableSmartConcat="true">
241+
<AutoCompletes>
242+
<AutoComplete Key="AutoCompleteClosingBrace" IsEnabled="true" />
243+
<AutoComplete Key="AutoCompleteClosingBracket" IsEnabled="true" />
244+
<AutoComplete Key="AutoCompleteClosingParenthese" IsEnabled="true" />
245+
<AutoComplete Key="AutoCompleteClosingString" IsEnabled="true" />
246+
<AutoComplete Key="AutoCompleteDoBlock" IsEnabled="true" />
247+
<AutoComplete Key="AutoCompleteEnumBlock" IsEnabled="true" />
248+
<AutoComplete Key="AutoCompleteForBlock" IsEnabled="true" />
249+
<AutoComplete Key="AutoCompleteFunctionBlock" IsEnabled="true" />
250+
<AutoComplete Key="AutoCompleteIfBlock" IsEnabled="true" />
251+
<AutoComplete Key="AutoCompleteOnErrorResumeNextBlock" IsEnabled="true" />
252+
<AutoComplete Key="AutoCompletePrecompilerIfBlock" IsEnabled="true" />
253+
<AutoComplete Key="AutoCompletePropertyBlock" IsEnabled="true" />
254+
<AutoComplete Key="AutoCompleteSelectBlock" IsEnabled="true" />
255+
<AutoComplete Key="AutoCompleteSubBlock" IsEnabled="true" />
256+
<AutoComplete Key="AutoCompleteTypeBlock" IsEnabled="true" />
257+
<AutoComplete Key="AutoCompleteWhileBlock" IsEnabled="true" />
258+
<AutoComplete Key="AutoCompleteWithBlock" IsEnabled="true" />
259+
</AutoCompletes>
260+
</AutoCompleteSettings>
261+
</value>
262+
</setting>
236263
<setting name="CodeInspectionSettings" serializeAs="Xml">
237264
<value>
238265
<CodeInspectionSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -369,39 +396,14 @@
369396
InspectionType="LanguageOpportunities" />
370397
<CodeInspection Name="SheetAccessedUsingStringInspection" Severity="Suggestion"
371398
InspectionType="LanguageOpportunities" />
399+
<CodeInspection Name="ObsoleteMemberUsageInspection" Severity="Warning"
400+
InspectionType="MaintainabilityAndReadabilityIssues" />
372401
</CodeInspections>
373402
<WhitelistedIdentifiers />
374403
<RunInspectionsOnSuccessfulParse>true</RunInspectionsOnSuccessfulParse>
375404
</CodeInspectionSettings>
376405
</value>
377406
</setting>
378-
<setting name="AutoCompleteSettings" serializeAs="Xml">
379-
<value>
380-
<AutoCompleteSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
381-
xmlns:xsd="http://www.w3.org/2001/XMLSchema" CompleteBlockOnTab="true"
382-
CompleteBlockOnEnter="true" EnableSmartConcat="true">
383-
<AutoCompletes>
384-
<AutoComplete Key="AutoCompleteClosingBrace" IsEnabled="true" />
385-
<AutoComplete Key="AutoCompleteClosingBracket" IsEnabled="true" />
386-
<AutoComplete Key="AutoCompleteClosingParenthese" IsEnabled="true" />
387-
<AutoComplete Key="AutoCompleteClosingString" IsEnabled="true" />
388-
<AutoComplete Key="AutoCompleteDoBlock" IsEnabled="true" />
389-
<AutoComplete Key="AutoCompleteEnumBlock" IsEnabled="true" />
390-
<AutoComplete Key="AutoCompleteForBlock" IsEnabled="true" />
391-
<AutoComplete Key="AutoCompleteFunctionBlock" IsEnabled="true" />
392-
<AutoComplete Key="AutoCompleteIfBlock" IsEnabled="true" />
393-
<AutoComplete Key="AutoCompleteOnErrorResumeNextBlock" IsEnabled="true" />
394-
<AutoComplete Key="AutoCompletePrecompilerIfBlock" IsEnabled="true" />
395-
<AutoComplete Key="AutoCompletePropertyBlock" IsEnabled="true" />
396-
<AutoComplete Key="AutoCompleteSelectBlock" IsEnabled="true" />
397-
<AutoComplete Key="AutoCompleteSubBlock" IsEnabled="true" />
398-
<AutoComplete Key="AutoCompleteTypeBlock" IsEnabled="true" />
399-
<AutoComplete Key="AutoCompleteWhileBlock" IsEnabled="true" />
400-
<AutoComplete Key="AutoCompleteWithBlock" IsEnabled="true" />
401-
</AutoCompletes>
402-
</AutoCompleteSettings>
403-
</value>
404-
</setting>
405407
</Rubberduck.Properties.Settings>
406408
</applicationSettings>
407409
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" /></startup>

Rubberduck.Parsing/Annotations/AnnotationType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public enum AnnotationType
4343
PredeclaredId = 1 << 16 | Attribute | ModuleAnnotation,
4444
[AttributeAnnotation("VB_Exposed", "True")]
4545
Exposed = 1 << 17 | Attribute | ModuleAnnotation,
46+
Obsolete = 1 << 18 | MemberAnnotation
4647
}
4748

4849
[AttributeUsage(AttributeTargets.Field)]

0 commit comments

Comments
 (0)