11using System . Collections . Generic ;
2+ using System . Diagnostics ;
23using System . Reflection ;
34using System . Windows . Forms ;
45using ASCompletion . Completion ;
56using ASCompletion . Context ;
7+ using ASCompletion . Model ;
68using PluginCore ;
79using PluginCore . Controls ;
810using ScintillaNet ;
911
1012namespace PostfixCodeCompletion . Helpers
1113{
12- static class Reflector
14+ internal static class Reflector
1315 {
1416 internal static readonly CompletionListReflector CompletionList = new CompletionListReflector ( ) ;
1517 internal static readonly ASCompleteReflector ASComplete = new ASCompleteReflector ( ) ;
@@ -18,21 +20,23 @@ static class Reflector
1820
1921 internal class CompletionListReflector
2022 {
21- internal ListBox completionList
23+ internal ListBox CompletionList
2224 {
2325 get
2426 {
25- var member = typeof ( CompletionList ) . GetField ( "completionList" , BindingFlags . Instance | BindingFlags . NonPublic | BindingFlags . Static ) ;
26- return ( ListBox ) member . GetValue ( typeof ( ListBox ) ) ;
27+ var fieldInfo = typeof ( CompletionList ) . GetField ( "completionList" , BindingFlags . Instance | BindingFlags . NonPublic | BindingFlags . Static ) ;
28+ Debug . Assert ( fieldInfo != null , "fieldInfo != null" ) ;
29+ return ( ListBox ) fieldInfo . GetValue ( typeof ( ListBox ) ) ;
2730 }
2831 }
2932
30- internal List < ICompletionListItem > allItems
33+ internal List < ICompletionListItem > AllItems
3134 {
3235 get
3336 {
34- var member = typeof ( CompletionList ) . GetField ( "allItems" , BindingFlags . Instance | BindingFlags . NonPublic | BindingFlags . Static ) ;
35- return ( List < ICompletionListItem > ) member . GetValue ( typeof ( List < ICompletionListItem > ) ) ;
37+ var fieldInfo = typeof ( CompletionList ) . GetField ( "allItems" , BindingFlags . Instance | BindingFlags . NonPublic | BindingFlags . Static ) ;
38+ Debug . Assert ( fieldInfo != null , "fieldInfo != null" ) ;
39+ return ( List < ICompletionListItem > ) fieldInfo . GetValue ( typeof ( List < ICompletionListItem > ) ) ;
3640 }
3741 }
3842 }
@@ -42,7 +46,8 @@ internal class ASCompleteReflector
4246 internal bool HandleDotCompletion ( ScintillaControl sci , bool autoHide )
4347 {
4448 var methodInfo = typeof ( ASComplete ) . GetMethod ( "HandleDotCompletion" , BindingFlags . Instance | BindingFlags . NonPublic | BindingFlags . Static ) ;
45- return ( bool ) methodInfo . Invoke ( null , new object [ ] { sci , autoHide } ) ;
49+ Debug . Assert ( methodInfo != null , "methodInfo != null" ) ;
50+ return ( bool ) methodInfo . Invoke ( null , new object [ ] { sci , autoHide } ) ;
4651 }
4752 }
4853
@@ -51,31 +56,43 @@ internal class ASGeneratorReflector
5156 internal string CleanType ( string type )
5257 {
5358 var methodInfo = typeof ( ASGenerator ) . GetMethod ( "CleanType" , BindingFlags . Instance | BindingFlags . NonPublic | BindingFlags . Static ) ;
54- return ( string ) methodInfo . Invoke ( null , new object [ ] { type } ) ;
59+ Debug . Assert ( methodInfo != null , "methodInfo != null" ) ;
60+ return ( string ) methodInfo . Invoke ( null , new object [ ] { type } ) ;
5561 }
5662
5763 internal string GuessVarName ( string name , string type )
5864 {
5965 var methodInfo = typeof ( ASGenerator ) . GetMethod ( "GuessVarName" , BindingFlags . Instance | BindingFlags . NonPublic | BindingFlags . Static ) ;
60- return ( string ) methodInfo . Invoke ( null , new object [ ] { name , type } ) ;
66+ Debug . Assert ( methodInfo != null , "methodInfo != null" ) ;
67+ return ( string ) methodInfo . Invoke ( null , new object [ ] { name , type } ) ;
6168 }
6269
6370 internal string GetShortType ( string type )
6471 {
6572 var methodInfo = typeof ( ASGenerator ) . GetMethod ( "GetShortType" , BindingFlags . Instance | BindingFlags . NonPublic | BindingFlags . Static ) ;
66- return ( string ) methodInfo . Invoke ( null , new object [ ] { type } ) ;
73+ Debug . Assert ( methodInfo != null , "methodInfo != null" ) ;
74+ return ( string ) methodInfo . Invoke ( null , new object [ ] { type } ) ;
6775 }
6876
6977 internal StatementReturnType GetStatementReturnType ( ScintillaControl sci , string line , int positionFromLine )
7078 {
79+ var currentClass = ASContext . Context . CurrentClass ;
80+ if ( currentClass . InFile . Context == null )
81+ {
82+ currentClass = ( ClassModel ) currentClass . Clone ( ) ;
83+ var language = PluginBase . MainForm . SciConfig . GetLanguageFromFile ( currentClass . InFile . BasePath ) ;
84+ currentClass . InFile . Context = ASContext . GetLanguageContext ( language ) ?? ASContext . Context ;
85+ }
7186 var methodInfo = typeof ( ASGenerator ) . GetMethod ( "GetStatementReturnType" , BindingFlags . Instance | BindingFlags . NonPublic | BindingFlags . Static ) ;
72- var returnType = methodInfo . Invoke ( null , new object [ ] { sci , ASContext . Context . CurrentClass , line , positionFromLine } ) ;
87+ Debug . Assert ( methodInfo != null , "methodInfo != null" ) ;
88+ var returnType = methodInfo . Invoke ( null , new object [ ] { sci , currentClass , line , positionFromLine } ) ;
7389 if ( returnType == null ) return null ;
90+ var type = returnType . GetType ( ) ;
7491 var result = new StatementReturnType
7592 {
76- Resolve = ( ASResult ) returnType . GetType ( ) . GetField ( "resolve" ) . GetValue ( returnType ) ,
77- Position = ( int ) returnType . GetType ( ) . GetField ( "position" ) . GetValue ( returnType ) ,
78- Word = ( string ) returnType . GetType ( ) . GetField ( "word" ) . GetValue ( returnType )
93+ Resolve = ( ASResult ) type . GetField ( "resolve" ) . GetValue ( returnType ) ,
94+ Position = ( int ) type . GetField ( "position" ) . GetValue ( returnType ) ,
95+ Word = ( string ) type . GetField ( "word" ) . GetValue ( returnType )
7996 } ;
8097 return result ;
8198 }
0 commit comments