@@ -33,48 +33,88 @@ public override void Fix(IInspectionResult result, IRewriteSession rewriteSessio
33
33
}
34
34
35
35
private void ConvertFunction ( IInspectionResult result , VBAParser . FunctionStmtContext functionContext , IModuleRewriter rewriter )
36
+ {
37
+ RemoveAsTypeDeclaration ( functionContext , rewriter ) ;
38
+ RemoveTypeHint ( result , functionContext , rewriter ) ;
39
+
40
+ ConvertFunctionDeclaration ( functionContext , rewriter ) ;
41
+ ConvertExitFunctionStatements ( functionContext , rewriter ) ;
42
+
43
+ RemoveReturnStatements ( result , rewriter ) ;
44
+ }
45
+
46
+ private static void RemoveAsTypeDeclaration ( ParserRuleContext functionContext , IModuleRewriter rewriter )
36
47
{
37
48
var asTypeContext = functionContext . GetChild < VBAParser . AsTypeClauseContext > ( ) ;
38
49
if ( asTypeContext != null )
39
50
{
40
51
rewriter . Remove ( asTypeContext ) ;
41
- rewriter . Remove ( functionContext . children . ElementAt ( functionContext . children . IndexOf ( asTypeContext ) - 1 ) as ParserRuleContext ) ;
52
+ rewriter . Remove (
53
+ functionContext . children . ElementAt ( functionContext . children . IndexOf ( asTypeContext ) -
54
+ 1 ) as ParserRuleContext ) ;
42
55
}
56
+ }
43
57
58
+ private static void RemoveTypeHint ( IInspectionResult result , ParserRuleContext functionContext , IModuleRewriter rewriter )
59
+ {
44
60
if ( result . Target . TypeHint != null )
45
61
{
46
62
rewriter . Remove ( functionContext . GetDescendent < VBAParser . TypeHintContext > ( ) ) ;
47
63
}
64
+ }
48
65
49
- rewriter . Replace ( functionContext . FUNCTION ( ) , Tokens . Sub ) ;
50
- rewriter . Replace ( functionContext . END_FUNCTION ( ) , "End Sub" ) ;
51
-
66
+ private void RemoveReturnStatements ( IInspectionResult result , IModuleRewriter rewriter )
67
+ {
52
68
foreach ( var returnStatement in GetReturnStatements ( result . Target ) )
53
69
{
54
70
rewriter . Remove ( returnStatement ) ;
55
71
}
56
72
}
57
73
58
- private void ConvertPropertyGet ( IInspectionResult result , VBAParser . PropertyGetStmtContext propertyGetContext , IModuleRewriter rewriter )
74
+ private static void ConvertFunctionDeclaration ( VBAParser . FunctionStmtContext functionContext , IModuleRewriter rewriter )
59
75
{
60
- var asTypeContext = propertyGetContext . GetChild < VBAParser . AsTypeClauseContext > ( ) ;
61
- if ( asTypeContext != null )
62
- {
63
- rewriter . Remove ( asTypeContext ) ;
64
- rewriter . Remove ( propertyGetContext . children . ElementAt ( propertyGetContext . children . IndexOf ( asTypeContext ) - 1 ) as ParserRuleContext ) ;
65
- }
76
+ rewriter . Replace ( functionContext . FUNCTION ( ) , Tokens . Sub ) ;
77
+ rewriter . Replace ( functionContext . END_FUNCTION ( ) , "End Sub" ) ;
78
+ }
66
79
67
- if ( result . Target . TypeHint != null )
80
+ private static void ConvertExitFunctionStatements ( VBAParser . FunctionStmtContext context , IModuleRewriter rewriter )
81
+ {
82
+ var exitStatements = context . GetDescendents < VBAParser . ExitStmtContext > ( ) ;
83
+ foreach ( var exitStatement in exitStatements )
68
84
{
69
- rewriter . Remove ( propertyGetContext . GetDescendent < VBAParser . TypeHintContext > ( ) ) ;
85
+ if ( exitStatement . EXIT_FUNCTION ( ) != null )
86
+ {
87
+ rewriter . Replace ( exitStatement , $ "{ Tokens . Exit } { Tokens . Sub } ") ;
88
+ }
70
89
}
90
+ }
91
+
92
+ private void ConvertPropertyGet ( IInspectionResult result , VBAParser . PropertyGetStmtContext propertyGetContext , IModuleRewriter rewriter )
93
+ {
94
+ RemoveAsTypeDeclaration ( propertyGetContext , rewriter ) ;
95
+ RemoveTypeHint ( result , propertyGetContext , rewriter ) ;
71
96
97
+ ConvertPropertyGetDeclaration ( propertyGetContext , rewriter ) ;
98
+ ConvertExitPropertyStatements ( propertyGetContext , rewriter ) ;
99
+
100
+ RemoveReturnStatements ( result , rewriter ) ;
101
+ }
102
+
103
+ private static void ConvertPropertyGetDeclaration ( VBAParser . PropertyGetStmtContext propertyGetContext , IModuleRewriter rewriter )
104
+ {
72
105
rewriter . Replace ( propertyGetContext . PROPERTY_GET ( ) , Tokens . Sub ) ;
73
106
rewriter . Replace ( propertyGetContext . END_PROPERTY ( ) , "End Sub" ) ;
107
+ }
74
108
75
- foreach ( var returnStatement in GetReturnStatements ( result . Target ) )
109
+ private static void ConvertExitPropertyStatements ( VBAParser . PropertyGetStmtContext context , IModuleRewriter rewriter )
110
+ {
111
+ var exitStatements = context . GetDescendents < VBAParser . ExitStmtContext > ( ) ;
112
+ foreach ( var exitStatement in exitStatements )
76
113
{
77
- rewriter . Remove ( returnStatement ) ;
114
+ if ( exitStatement . EXIT_PROPERTY ( ) != null )
115
+ {
116
+ rewriter . Replace ( exitStatement , $ "{ Tokens . Exit } { Tokens . Sub } ") ;
117
+ }
78
118
}
79
119
}
80
120
0 commit comments