1+ using  System . Collections . Generic ; 
2+ using  System . Linq ; 
3+ using  Rubberduck . Inspections . Abstract ; 
4+ using  Rubberduck . Parsing . VBA ; 
5+ using  Rubberduck . Parsing . Inspections . Resources ; 
6+ using  Rubberduck . Parsing . Inspections . Abstract ; 
7+ using  Rubberduck . Parsing . Grammar ; 
8+ using  Antlr4 . Runtime ; 
9+ using  Rubberduck . Parsing ; 
10+ using  Rubberduck . VBEditor ; 
11+ using  Antlr4 . Runtime . Misc ; 
12+ using  Rubberduck . Inspections . Results ; 
13+ 
14+ namespace  Rubberduck . Inspections . Concrete 
15+ { 
16+     public  sealed  class  DefTypeStatementInspection  :  ParseTreeInspectionBase 
17+     { 
18+         public  DefTypeStatementInspection ( RubberduckParserState  state ) 
19+             :  base ( state ,  CodeInspectionSeverity . Suggestion ) 
20+         { 
21+             Listener  =  new  DefTypeStatementInspectionListener ( ) ; 
22+         } 
23+ 
24+         public  override  CodeInspectionType  InspectionType  =>  CodeInspectionType . LanguageOpportunities ; 
25+         public  override  IInspectionListener  Listener  {  get ;  } 
26+ 
27+         protected  override  IEnumerable < IInspectionResult >  DoGetInspectionResults ( ) 
28+         { 
29+             var  results  =  Listener . Contexts . Where ( context =>  ! IsIgnoringInspectionResultFor ( context . ModuleName ,  context . Context . Start . Line ) ) 
30+                 . Select ( context =>  new  QualifiedContextInspectionResult ( this , 
31+                                                                         string . Format ( InspectionsUI . DefTypeStatementInspectionResultFormat , 
32+                                                                                       GetTypeOfDefType ( context . Context . start . Text ) , 
33+                                                                                       context . Context . start . Text ) , 
34+                                                                         context ) ) ; 
35+             return  results ; 
36+         } 
37+ 
38+         public  class  DefTypeStatementInspectionListener  :  VBAParserBaseListener ,  IInspectionListener 
39+         { 
40+             private  readonly  List < QualifiedContext < ParserRuleContext > >  _contexts  =  new  List < QualifiedContext < ParserRuleContext > > ( ) ; 
41+             public  IReadOnlyList < QualifiedContext < ParserRuleContext > >  Contexts  =>  _contexts ; 
42+ 
43+             public  QualifiedModuleName  CurrentModuleName  {  get ;  set ;  } 
44+ 
45+             public  void  ClearContexts ( ) 
46+             { 
47+                 _contexts . Clear ( ) ; 
48+             } 
49+ 
50+             public  override  void  ExitDefType ( [ NotNull ]  VBAParser . DefTypeContext  context ) 
51+             { 
52+                 _contexts . Add ( new  QualifiedContext < ParserRuleContext > ( CurrentModuleName ,  context ) ) ; 
53+             } 
54+         } 
55+ 
56+         private  string  GetTypeOfDefType ( string  defType ) 
57+         { 
58+             _defTypes . TryGetValue ( defType ,  out  var  value ) ; 
59+             return  value ; 
60+         } 
61+ 
62+         private  readonly  Dictionary < string ,  string >  _defTypes  =  new  Dictionary < string ,  string > 
63+         { 
64+             {  "DefBool" ,  "Boolean"  } , 
65+             {  "DefByte" ,  "Byte"  } , 
66+             {  "DefInt" ,  "Integer"  } , 
67+             {  "DefLng" ,  "Long"  } , 
68+             {  "DefCur" ,  "Currency"  } , 
69+             {  "DefSng" ,  "Single"  } , 
70+             {  "DefDbl" ,  "Double"  } , 
71+             {  "DefDate" ,  "Date"  } , 
72+             {  "DefStr" ,  "String"  } , 
73+             {  "DefObj" ,  "Object"  } , 
74+             {  "DefVar" ,  "Variant"  } 
75+         } ; 
76+     } 
77+ } 
0 commit comments