1
+ using Rubberduck . CodeAnalysis . Inspections ;
2
+ using Rubberduck . CodeAnalysis . Inspections . Concrete ;
3
+ using Rubberduck . CodeAnalysis . QuickFixes . Abstract ;
4
+ using Rubberduck . Parsing . Rewriter ;
5
+ using Rubberduck . Refactorings ;
6
+ using Rubberduck . Refactorings . ImplicitTypeToExplicit ;
7
+
8
+ namespace Rubberduck . CodeAnalysis . QuickFixes . Concrete
9
+ {
10
+ /// <summary>
11
+ /// Assigns an explicit data type to an implicitly typed declaration.
12
+ /// </summary>
13
+ /// <inspections>
14
+ /// <inspection name="VariableTypeNotDeclaredInspection" />
15
+ /// <inspection name="ImplicitlyTypedConstInspection" />
16
+ /// </inspections>
17
+ /// <canfix multiple="true" procedure="false" module="true" project="true" all="true" />
18
+ /// <example>
19
+ /// <before>
20
+ /// <![CDATA[
21
+ /// Public Sub DoSomething(ByRef arg As String)
22
+ /// Dim localVar
23
+ /// localVar = arg
24
+ /// End Sub
25
+ /// ]]>
26
+ /// </before>
27
+ /// <after>
28
+ /// <![CDATA[
29
+ /// Public Sub DoSomething(ByRef arg As String)
30
+ /// Dim localVar As String
31
+ /// localVar = arg
32
+ /// End Sub
33
+ /// ]]>
34
+ /// </after>
35
+ /// </example>
36
+ /// <example>
37
+ /// <before>
38
+ /// <![CDATA[
39
+ /// Public Const PI = 3.14
40
+ /// ]]>
41
+ /// </before>
42
+ /// <after>
43
+ /// <![CDATA[
44
+ /// Public Const PI As Double = 3.14
45
+ /// ]]>
46
+ /// </after>
47
+ /// </example>
48
+ /// <example>
49
+ /// <before>
50
+ /// <![CDATA[
51
+ /// Public Sub DoSomething(Optional ByVal arg = 2)
52
+ /// End Sub
53
+ /// ]]>
54
+ /// </before>
55
+ /// <after>
56
+ /// <![CDATA[
57
+ /// Public Sub DoSomething(Optional ByVal arg As Long = 2)
58
+ /// End Sub
59
+ /// ]]>
60
+ /// </after>
61
+ /// </example>
62
+ /// <example>
63
+ /// <before>
64
+ /// <![CDATA[
65
+ /// Public Sub DoSomething(ByRef arg)
66
+ /// arg = CCur(Sheet1.Range("A1").Value)
67
+ /// End Sub
68
+ /// ]]>
69
+ /// </before>
70
+ /// <after>
71
+ /// <![CDATA[
72
+ /// Public Sub DoSomething(ByRef arg As Currency)
73
+ /// arg = CCur(Sheet1.Range("A1").Value)
74
+ /// End Sub
75
+ /// ]]>
76
+ /// </after>
77
+ /// </example>
78
+ internal sealed class DeclareAsExplicitTypeQuickFix : QuickFixBase
79
+ {
80
+ private readonly ICodeOnlyRefactoringAction < ImplicitTypeToExplicitModel > _refactoring ;
81
+ public DeclareAsExplicitTypeQuickFix ( ImplicitTypeToExplicitRefactoringAction refactoringAction )
82
+ : base ( typeof ( VariableTypeNotDeclaredInspection ) , typeof ( ImplicitlyTypedConstInspection ) )
83
+ {
84
+ _refactoring = refactoringAction ;
85
+ }
86
+
87
+ public override bool CanFixMultiple => true ;
88
+ public override bool CanFixInProcedure => false ;
89
+ public override bool CanFixInModule => true ;
90
+ public override bool CanFixInProject => true ;
91
+ public override bool CanFixAll => true ;
92
+
93
+ public override void Fix ( IInspectionResult result , IRewriteSession rewriteSession )
94
+ {
95
+ _refactoring . Refactor ( new ImplicitTypeToExplicitModel ( result . Target ) , rewriteSession ) ;
96
+ }
97
+
98
+ public override string Description ( IInspectionResult result )
99
+ => Resources . Inspections . QuickFixes . DeclareAsExplicitTypeQuickFix ;
100
+ }
101
+ }
0 commit comments