@@ -34,11 +34,11 @@ public class ASGenerator
3434 static private Regex reModifier = new Regex ( "(public |private |protected )" , RegexOptions . Compiled ) ;
3535 static private Regex reSuperCall = new Regex ( "^super\\ s*\\ (" , RegexOptions . Compiled ) ;
3636
37- static private string contextToken ;
38- static private string contextParam ;
39- static private Match contextMatch ;
40- static private ASResult contextResolved ;
41- static private MemberModel contextMember ;
37+ static internal string contextToken ;
38+ static internal string contextParam ;
39+ static internal Match contextMatch ;
40+ static internal ASResult contextResolved ;
41+ static internal MemberModel contextMember ;
4242 static private bool firstVar ;
4343
4444 static private bool IsHaxe
@@ -795,21 +795,28 @@ private static void ShowDelegateList(FoundDeclaration found, List<ICompletionLis
795795 options . Add ( new GeneratorItem ( label , GeneratorJobType . Delegate , found . member , found . inClass ) ) ;
796796 }
797797
798- private static void ShowEventList ( FoundDeclaration found , List < ICompletionListItem > options )
798+ internal static void ShowEventList ( FoundDeclaration found , List < ICompletionListItem > options )
799799 {
800800 string tmp = TextHelper . GetString ( "ASCompletion.Label.GenerateHandler" ) ;
801801 string labelEvent = String . Format ( tmp , "Event" ) ;
802802 string labelDataEvent = String . Format ( tmp , "DataEvent" ) ;
803803 string labelContext = String . Format ( tmp , contextParam ) ;
804- string [ ] choices = ( contextParam != "Event" ) ?
805- new string [ ] { labelContext , labelEvent } :
806- new string [ ] { labelEvent , labelDataEvent } ;
804+ string [ ] choices ;
805+ if ( contextParam != "Event" ) choices = new string [ ] { labelContext , labelEvent } ;
806+ else if ( HasDataEvent ( ) ) choices = new string [ ] { labelEvent , labelDataEvent } ;
807+ else choices = new string [ ] { labelEvent } ;
808+
807809 for ( int i = 0 ; i < choices . Length ; i ++ )
808810 {
809811 options . Add ( new GeneratorItem ( choices [ i ] ,
810812 choices [ i ] == labelContext ? GeneratorJobType . ComplexEvent : GeneratorJobType . BasicEvent ,
811813 found . member , found . inClass ) ) ;
812814 }
815+ }
816+
817+ private static bool HasDataEvent ( )
818+ {
819+ return ! ASContext . Context . ResolveType ( "flash.events.DataEvent" , ASContext . Context . CurrentModel ) . IsVoid ( ) ;
813820 }
814821
815822 private static void ShowGetSetList ( FoundDeclaration found , List < ICompletionListItem > options )
@@ -3553,22 +3560,12 @@ private static void GenerateEventHandler(string name, string type, MemberModel a
35533560 ClassModel eventClass = ASContext . Context . ResolveType ( type , ASContext . Context . CurrentModel ) ;
35543561 if ( eventClass . IsVoid ( ) )
35553562 {
3556- if ( type == "Event" )
3557- {
3558- List < string > typesUsed = new List < string > ( ) ;
3559- typesUsed . Add ( "flash.events.Event" ) ;
3560- delta = AddImportsByName ( typesUsed , sci . LineFromPosition ( position ) ) ;
3561- position += delta ;
3562- sci . SetSel ( position , position ) ;
3563- }
3564- else if ( type == "DataEvent" )
3565- {
3566- List < string > typesUsed = new List < string > ( ) ;
3567- typesUsed . Add ( "flash.events.DataEvent" ) ;
3568- delta = AddImportsByName ( typesUsed , sci . LineFromPosition ( position ) ) ;
3569- position += delta ;
3570- sci . SetSel ( position , position ) ;
3571- }
3563+ if ( TryImportType ( "flash.events." + type , ref delta , sci . LineFromPosition ( position ) ) )
3564+ {
3565+ position += delta ;
3566+ sci . SetSel ( position , position ) ;
3567+ }
3568+ else type = null ;
35723569 }
35733570 lookupPosition += delta ;
35743571 string acc = GetPrivateAccessor ( afterMethod , inClass ) ;
@@ -3592,6 +3589,18 @@ private static void GenerateEventHandler(string name, string type, MemberModel a
35923589 {
35933590 sci . EndUndoAction ( ) ;
35943591 }
3592+ }
3593+
3594+ private static bool TryImportType ( string type , ref int delta , int atLine )
3595+ {
3596+ ClassModel eventClass = ASContext . Context . ResolveType ( type , ASContext . Context . CurrentModel ) ;
3597+ if ( eventClass . IsVoid ( ) )
3598+ return false ;
3599+
3600+ List < string > typesUsed = new List < string > ( ) ;
3601+ typesUsed . Add ( type ) ;
3602+ delta += AddImportsByName ( typesUsed , atLine ) ;
3603+ return true ;
35953604 }
35963605
35973606 static private string AddRemoveEvent ( string eventName )
@@ -4586,7 +4595,7 @@ public Object Data
45864595 }
45874596 }
45884597
4589- class FoundDeclaration
4598+ internal class FoundDeclaration
45904599 {
45914600 public MemberModel member ;
45924601 public ClassModel inClass ;
0 commit comments