@@ -659,7 +659,7 @@ private static void ShowNewVarList(FoundDeclaration found)
659
659
known . Add ( new GeneratorItem ( label , GeneratorJobType . Constant , found . member , found . inClass ) ) ;
660
660
}
661
661
662
- bool genProtectedDecl = ASContext . Context . Features . protectedKey != null && ASContext . CommonSettings . GenerateProtectedDeclarations ;
662
+ bool genProtectedDecl = GetDefaultVisibility ( found . inClass ) == Visibility . Protected ;
663
663
if ( exprAtCursor == null && exprLeft == null )
664
664
{
665
665
if ( genProtectedDecl ) label = TextHelper . GetString ( "ASCompletion.Label.GenerateProtectedVar" ) ;
@@ -711,7 +711,7 @@ private static void ShowNewMethodList(FoundDeclaration found)
711
711
bool isInterface = ( inClass . Flags & FlagType . Interface ) > 0 ;
712
712
if ( ! isInterface && result == null )
713
713
{
714
- if ( ASContext . Context . Features . protectedKey != null && ASContext . CommonSettings . GenerateProtectedDeclarations )
714
+ if ( GetDefaultVisibility ( found . inClass ) == Visibility . Protected )
715
715
label = TextHelper . GetString ( "ASCompletion.Label.GenerateProtectedFunction" ) ;
716
716
else label = TextHelper . GetString ( "ASCompletion.Label.GeneratePrivateFunction" ) ;
717
717
known . Add ( new GeneratorItem ( label , GeneratorJobType . Function , found . member , found . inClass ) ) ;
@@ -770,9 +770,9 @@ private static void ShowFieldFromParameter(FoundDeclaration found)
770
770
if ( GetLangIsValid ( ) )
771
771
{
772
772
Hashtable parameters = new Hashtable ( ) ;
773
- parameters [ "scope" ] = GetDefaultVisibility ( ) ;
773
+ parameters [ "scope" ] = GetDefaultVisibility ( found . inClass ) ;
774
774
string label ;
775
- if ( ASContext . Context . Features . protectedKey != null && ASContext . CommonSettings . GenerateProtectedDeclarations )
775
+ if ( GetDefaultVisibility ( found . inClass ) == Visibility . Protected )
776
776
label = TextHelper . GetString ( "ASCompletion.Label.GenerateProtectedFieldFromParameter" ) ;
777
777
else label = TextHelper . GetString ( "ASCompletion.Label.GeneratePrivateFieldFromParameter" ) ;
778
778
known . Add ( new GeneratorItem ( label , GeneratorJobType . FieldFromPatameter , found . member , found . inClass , parameters ) ) ;
@@ -892,7 +892,7 @@ static public void GenerateJob(GeneratorJobType job, MemberModel member, ClassMo
892
892
if ( latest == null )
893
893
{
894
894
if ( ASContext . CommonSettings . MethodsGenerationLocations == MethodsGenerationLocations . AfterSimilarAccessorMethod )
895
- latest = GetLatestMemberForFunction ( inClass , GetDefaultVisibility ( ) , member ) ;
895
+ latest = GetLatestMemberForFunction ( inClass , GetDefaultVisibility ( inClass ) , member ) ;
896
896
if ( latest == null )
897
897
latest = member ;
898
898
}
@@ -902,13 +902,13 @@ static public void GenerateJob(GeneratorJobType job, MemberModel member, ClassMo
902
902
string type = contextParam ;
903
903
if ( job == GeneratorJobType . BasicEvent )
904
904
if ( itemLabel . IndexOf ( "DataEvent" ) >= 0 ) type = "DataEvent" ; else type = "Event" ;
905
- GenerateEventHandler ( contextToken , type , member , position ) ;
905
+ GenerateEventHandler ( contextToken , type , member , position , inClass ) ;
906
906
break ;
907
907
908
908
case GeneratorJobType . Delegate :
909
909
position = Sci . PositionFromLine ( member . LineTo + 1 ) - ( ( Sci . EOLMode == 0 ) ? 2 : 1 ) ;
910
910
Sci . SetSel ( position , position ) ;
911
- GenerateDelegateMethod ( contextToken , member , position ) ;
911
+ GenerateDelegateMethod ( contextToken , member , position , inClass ) ;
912
912
break ;
913
913
914
914
case GeneratorJobType . Constant :
@@ -988,7 +988,7 @@ static public void GenerateJob(GeneratorJobType job, MemberModel member, ClassMo
988
988
{
989
989
if ( ! RemoveLocalDeclaration ( Sci , contextMember ) ) return ;
990
990
991
- latest = GetLatestMemberForVariable ( GeneratorJobType . Variable , inClass , GetDefaultVisibility ( ) , member ) ;
991
+ latest = GetLatestMemberForVariable ( GeneratorJobType . Variable , inClass , GetDefaultVisibility ( inClass ) , member ) ;
992
992
if ( latest == null ) return ;
993
993
994
994
position = FindNewVarPosition ( Sci , inClass , latest ) ;
@@ -998,7 +998,7 @@ static public void GenerateJob(GeneratorJobType job, MemberModel member, ClassMo
998
998
contextMember . Flags -= FlagType . LocalVar ;
999
999
if ( ( member . Flags & FlagType . Static ) > 0 )
1000
1000
contextMember . Flags |= FlagType . Static ;
1001
- contextMember . Access = GetDefaultVisibility ( ) ;
1001
+ contextMember . Access = GetDefaultVisibility ( inClass ) ;
1002
1002
GenerateVariable ( contextMember , position , detach ) ;
1003
1003
1004
1004
Sci . SetSel ( lookupPosition , lookupPosition ) ;
@@ -1190,7 +1190,7 @@ private static void GenerateProperty(GeneratorJobType job, MemberModel member, C
1190
1190
{
1191
1191
if ( ( member . Access & Visibility . Public ) > 0 ) // hide member
1192
1192
{
1193
- MakePrivate ( Sci , member ) ;
1193
+ MakePrivate ( Sci , member , inClass ) ;
1194
1194
}
1195
1195
if ( name == null ) // rename var with starting underscore
1196
1196
{
@@ -1412,7 +1412,7 @@ private static void ConvertToConst(ClassModel inClass, ScintillaControl Sci, Mem
1412
1412
Sci . SetSel ( position , position ) ;
1413
1413
}
1414
1414
1415
- MemberModel m = NewMember ( suggestion , member , FlagType . Variable | FlagType . Constant | FlagType . Static ) ;
1415
+ MemberModel m = NewMember ( suggestion , member , FlagType . Variable | FlagType . Constant | FlagType . Static , GetDefaultVisibility ( inClass ) ) ;
1416
1416
1417
1417
var features = ASContext . Context . Features ;
1418
1418
@@ -1812,7 +1812,7 @@ private static void GenerateFieldFromParameter(ScintillaControl Sci, MemberModel
1812
1812
if ( classMember . Name . Equals ( varName ) )
1813
1813
return ;
1814
1814
1815
- MemberModel latest = GetLatestMemberForVariable ( GeneratorJobType . Variable , inClass , GetDefaultVisibility ( ) , new MemberModel ( ) ) ;
1815
+ MemberModel latest = GetLatestMemberForVariable ( GeneratorJobType . Variable , inClass , GetDefaultVisibility ( inClass ) , new MemberModel ( ) ) ;
1816
1816
if ( latest == null ) return ;
1817
1817
1818
1818
int position = FindNewVarPosition ( Sci , inClass , latest ) ;
@@ -1956,7 +1956,7 @@ private static void GenerateVariableJob(GeneratorJobType job, ScintillaControl S
1956
1956
MemberModel latest = null ;
1957
1957
bool isOtherClass = false ;
1958
1958
1959
- Visibility varVisi = job . Equals ( GeneratorJobType . Variable ) ? GetDefaultVisibility ( ) : Visibility . Public ;
1959
+ Visibility varVisi = job . Equals ( GeneratorJobType . Variable ) ? GetDefaultVisibility ( inClass ) : Visibility . Public ;
1960
1960
FlagType ft = job . Equals ( GeneratorJobType . Constant ) ? FlagType . Constant : FlagType . Variable ;
1961
1961
1962
1962
// evaluate, if the variable (or constant) should be generated in other class
@@ -2443,7 +2443,7 @@ private static void GenerateFunctionJob(GeneratorJobType job, ScintillaControl S
2443
2443
MemberModel latest = null ;
2444
2444
bool isOtherClass = false ;
2445
2445
2446
- Visibility funcVisi = job . Equals ( GeneratorJobType . FunctionPublic ) ? Visibility . Public : GetDefaultVisibility ( ) ;
2446
+ Visibility funcVisi = job . Equals ( GeneratorJobType . FunctionPublic ) ? Visibility . Public : GetDefaultVisibility ( inClass ) ;
2447
2447
int wordPos = Sci . WordEndPosition ( Sci . CurrentPos , true ) ;
2448
2448
List < FunctionParameter > functionParameters = ParseFunctionParameters ( Sci , wordPos ) ;
2449
2449
@@ -2767,7 +2767,7 @@ public static void GenerateExtractMethod(ScintillaControl Sci, string NewName)
2767
2767
MemberModel latest = TemplateUtils . GetTemplateBlockMember ( Sci , TemplateUtils . GetBoundary ( "PrivateMethods" ) ) ;
2768
2768
2769
2769
if ( latest == null )
2770
- latest = GetLatestMemberForFunction ( found . inClass , GetDefaultVisibility ( ) , found . member ) ;
2770
+ latest = GetLatestMemberForFunction ( found . inClass , GetDefaultVisibility ( found . inClass ) , found . member ) ;
2771
2771
2772
2772
if ( latest == null )
2773
2773
latest = found . member ;
@@ -2781,7 +2781,7 @@ public static void GenerateExtractMethod(ScintillaControl Sci, string NewName)
2781
2781
flags |= FlagType . Static ;
2782
2782
}
2783
2783
2784
- MemberModel m = new MemberModel ( NewName , context . Features . voidKey , flags , GetDefaultVisibility ( ) ) ;
2784
+ MemberModel m = new MemberModel ( NewName , context . Features . voidKey , flags , GetDefaultVisibility ( found . inClass ) ) ;
2785
2785
2786
2786
template = NewLine + TemplateUtils . GetTemplate ( "Function" ) ;
2787
2787
template = TemplateUtils . ToDeclarationWithModifiersString ( m , template ) ;
@@ -3181,19 +3181,16 @@ private static MemberModel NewMember(string contextToken, MemberModel calledFrom
3181
3181
return new MemberModel ( contextToken , type , kind , visi ) ;
3182
3182
}
3183
3183
3184
- private static MemberModel NewMember ( string contextToken , MemberModel calledFrom , FlagType kind )
3185
- {
3186
- return NewMember ( contextToken , calledFrom , kind , GetDefaultVisibility ( ) ) ;
3187
- }
3188
-
3189
3184
/// <summary>
3190
3185
/// Get Visibility.Private or Visibility.Protected, depending on user setting forcing the use of protected.
3191
3186
/// </summary>
3192
- public static Visibility GetDefaultVisibility ( )
3193
- {
3194
- if ( ASContext . Context . Features . protectedKey != null && ASContext . CommonSettings . GenerateProtectedDeclarations )
3195
- return Visibility . Protected ;
3196
- else return Visibility . Private ;
3187
+ private static Visibility GetDefaultVisibility ( ClassModel model )
3188
+ {
3189
+ if ( ASContext . Context . Features . protectedKey != null
3190
+ && ASContext . CommonSettings . GenerateProtectedDeclarations
3191
+ && ( model . Flags & FlagType . Final ) == 0 )
3192
+ return Visibility . Protected ;
3193
+ return Visibility . Private ;
3197
3194
}
3198
3195
3199
3196
private static void GenerateFunction ( MemberModel member , int position , bool detach , ClassModel inClass )
@@ -3248,10 +3245,10 @@ private static void GenerateVariable(MemberModel member, int position, bool deta
3248
3245
InsertCode ( position , result ) ;
3249
3246
}
3250
3247
3251
- public static bool MakePrivate ( ScintillaControl Sci , MemberModel member )
3248
+ public static bool MakePrivate ( ScintillaControl Sci , MemberModel member , ClassModel inClass )
3252
3249
{
3253
3250
ContextFeatures features = ASContext . Context . Features ;
3254
- string visibility = GetPrivateKeyword ( ) ;
3251
+ string visibility = GetPrivateKeyword ( inClass ) ;
3255
3252
if ( features . publicKey == null || visibility == null ) return false ;
3256
3253
Regex rePublic = new Regex ( String . Format ( @"\s*({0})\s+" , features . publicKey ) ) ;
3257
3254
@@ -3374,11 +3371,11 @@ private static string GetNewPropertyNameFor(MemberModel member)
3374
3371
return "_" + member . Name ;
3375
3372
}
3376
3373
3377
- private static void GenerateDelegateMethod ( string name , MemberModel afterMethod , int position )
3374
+ private static void GenerateDelegateMethod ( string name , MemberModel afterMethod , int position , ClassModel inClass )
3378
3375
{
3379
3376
ContextFeatures features = ASContext . Context . Features ;
3380
3377
3381
- string acc = GetPrivateAccessor ( afterMethod ) ;
3378
+ string acc = GetPrivateAccessor ( afterMethod , inClass ) ;
3382
3379
string template = TemplateUtils . GetTemplate ( "Delegate" ) ;
3383
3380
string args = null ;
3384
3381
string type = features . voidKey ;
@@ -3396,15 +3393,16 @@ private static void GenerateDelegateMethod(string name, MemberModel afterMethod,
3396
3393
InsertCode ( position , decl ) ;
3397
3394
}
3398
3395
3399
- private static void GenerateEventHandler ( string name , string type , MemberModel afterMethod , int position )
3396
+ private static void GenerateEventHandler ( string name , string type , MemberModel afterMethod , int position , ClassModel inClass )
3400
3397
{
3401
3398
ScintillaControl Sci = ASContext . CurSciControl ;
3402
3399
Sci . BeginUndoAction ( ) ;
3403
3400
try
3404
3401
{
3405
3402
int delta = 0 ;
3406
3403
ClassModel eventClass = ASContext . Context . ResolveType ( type , ASContext . Context . CurrentModel ) ;
3407
- if ( eventClass . IsVoid ( ) )
3404
+ if ( eventClass . IsVoid ( ) )
3405
+ {
3408
3406
if ( type == "Event" )
3409
3407
{
3410
3408
List < string > typesUsed = new List < string > ( ) ;
@@ -3420,9 +3418,10 @@ private static void GenerateEventHandler(string name, string type, MemberModel a
3420
3418
delta = AddImportsByName ( typesUsed , Sci . LineFromPosition ( position ) ) ;
3421
3419
position += delta ;
3422
3420
Sci . SetSel ( position , position ) ;
3423
- }
3421
+ }
3422
+ }
3424
3423
lookupPosition += delta ;
3425
- string acc = GetPrivateAccessor ( afterMethod ) ;
3424
+ string acc = GetPrivateAccessor ( afterMethod , inClass ) ;
3426
3425
string template = TemplateUtils . GetTemplate ( "EventHandler" ) ;
3427
3426
string decl = NewLine + TemplateUtils . ReplaceTemplateVariable ( template , "Modifiers" , acc ) ;
3428
3427
decl = TemplateUtils . ReplaceTemplateVariable ( decl , "Name" , name ) ;
@@ -3530,16 +3529,16 @@ private static string GetStaticKeyword(MemberModel member)
3530
3529
return string . Empty ;
3531
3530
}
3532
3531
3533
- private static string GetPrivateAccessor ( MemberModel member )
3532
+ private static string GetPrivateAccessor ( MemberModel member , ClassModel inClass )
3534
3533
{
3535
3534
string acc = GetStaticKeyword ( member ) ;
3536
3535
if ( ! string . IsNullOrEmpty ( acc ) ) acc += " " ;
3537
- return acc + GetPrivateKeyword ( ) ;
3536
+ return acc + GetPrivateKeyword ( inClass ) ;
3538
3537
}
3539
3538
3540
- private static string GetPrivateKeyword ( )
3539
+ private static string GetPrivateKeyword ( ClassModel inClass )
3541
3540
{
3542
- if ( GetDefaultVisibility ( ) == Visibility . Protected ) return ASContext . Context . Features . protectedKey ?? "protected" ;
3541
+ if ( GetDefaultVisibility ( inClass ) == Visibility . Protected ) return ASContext . Context . Features . protectedKey ?? "protected" ;
3543
3542
return ASContext . Context . Features . privateKey ?? "private" ;
3544
3543
}
3545
3544
0 commit comments