Skip to content

Commit

Permalink
[src] Remove the UnifiedInternal attribute. (#19687)
Browse files Browse the repository at this point in the history
Remove support for the UnifiedInternal attribute from the generator, and remove
all usages of it in our api definitions - just use the Internal attribute.

The UnifiedInternal attribute was used to mark something as internal for
Unified Xamarin code, while still keeping it as public in Classic Xamarin
code.

Classic Xamarin has been dead for quite a few years ago now though, so there's
no need to keep his code around anymore.
  • Loading branch information
rolfbjarne authored Jan 2, 2024
1 parent 142d176 commit 8c3bbcc
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 57 deletions.
52 changes: 26 additions & 26 deletions src/avfoundation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2472,11 +2472,11 @@ interface AVAudioSession {
[Field ("AVAudioSessionPortVirtual")]
NSString PortVirtual { get; }

[UnifiedInternal, Field ("AVAudioSessionLocationUpper")]
NSString LocationUpper { get; }
[Internal, Field ("AVAudioSessionLocationUpper")]
NSString LocationUpper_ { get; }

[UnifiedInternal, Field ("AVAudioSessionLocationLower")]
NSString LocationLower { get; }
[Internal, Field ("AVAudioSessionLocationLower")]
NSString LocationLower_ { get; }

[NoMac]
[MacCatalyst (13, 1)]
Expand Down Expand Up @@ -2560,17 +2560,17 @@ interface AVAudioSession {
[Export ("maximumOutputNumberOfChannels")]
nint MaximumOutputNumberOfChannels { get; }

[UnifiedInternal, Field ("AVAudioSessionOrientationTop")]
NSString OrientationTop { get; }
[Internal, Field ("AVAudioSessionOrientationTop")]
NSString OrientationTop_ { get; }

[UnifiedInternal, Field ("AVAudioSessionOrientationBottom")]
NSString OrientationBottom { get; }
[Internal, Field ("AVAudioSessionOrientationBottom")]
NSString OrientationBottom_ { get; }

[UnifiedInternal, Field ("AVAudioSessionOrientationFront")]
NSString OrientationFront { get; }
[Internal, Field ("AVAudioSessionOrientationFront")]
NSString OrientationFront_ { get; }

[UnifiedInternal, Field ("AVAudioSessionOrientationBack")]
NSString OrientationBack { get; }
[Internal, Field ("AVAudioSessionOrientationBack")]
NSString OrientationBack_ { get; }

[MacCatalyst (13, 1)]
[Field ("AVAudioSessionOrientationLeft")]
Expand All @@ -2580,14 +2580,14 @@ interface AVAudioSession {
[Field ("AVAudioSessionOrientationRight")]
NSString OrientationRight { get; }

[UnifiedInternal, Field ("AVAudioSessionPolarPatternOmnidirectional")]
NSString PolarPatternOmnidirectional { get; }
[Internal, Field ("AVAudioSessionPolarPatternOmnidirectional")]
NSString PolarPatternOmnidirectional_ { get; }

[UnifiedInternal, Field ("AVAudioSessionPolarPatternCardioid")]
NSString PolarPatternCardioid { get; }
[Internal, Field ("AVAudioSessionPolarPatternCardioid")]
NSString PolarPatternCardioid_ { get; }

[UnifiedInternal, Field ("AVAudioSessionPolarPatternSubcardioid")]
NSString PolarPatternSubcardioid { get; }
[Internal, Field ("AVAudioSessionPolarPatternSubcardioid")]
NSString PolarPatternSubcardioid_ { get; }

[NoWatch, NoTV, NoMac, iOS (14, 0)]
[MacCatalyst (14, 0)]
Expand Down Expand Up @@ -2786,23 +2786,23 @@ interface AVAudioSessionDataSourceDescription {

[NoWatch]
[MacCatalyst (13, 1)]
[UnifiedInternal, Export ("supportedPolarPatterns"), NullAllowed]
NSString [] SupportedPolarPatterns { get; }
[Internal, Export ("supportedPolarPatterns"), NullAllowed]
NSString [] SupportedPolarPatterns_ { get; }

[NoWatch]
[MacCatalyst (13, 1)]
[UnifiedInternal, Export ("selectedPolarPattern", ArgumentSemantic.Copy), NullAllowed]
NSString SelectedPolarPattern { get; }
[Internal, Export ("selectedPolarPattern", ArgumentSemantic.Copy), NullAllowed]
NSString SelectedPolarPattern_ { get; }

[NoWatch]
[MacCatalyst (13, 1)]
[UnifiedInternal, Export ("preferredPolarPattern", ArgumentSemantic.Copy), NullAllowed]
NSString PreferredPolarPattern { get; }
[Internal, Export ("preferredPolarPattern", ArgumentSemantic.Copy), NullAllowed]
NSString PreferredPolarPattern_ { get; }

[NoWatch]
[MacCatalyst (13, 1)]
[UnifiedInternal, Export ("setPreferredPolarPattern:error:")]
bool SetPreferredPolarPattern ([NullAllowed] NSString pattern, out NSError outError);
[Internal, Export ("setPreferredPolarPattern:error:")]
bool SetPreferredPolarPattern_ ([NullAllowed] NSString pattern, out NSError outError);

}

Expand Down
2 changes: 0 additions & 2 deletions src/bgen/AttributeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ Type LookupReflectionType (string fullname, ICustomAttributeProvider provider)
return typeof (ThreadSafeAttribute);
case "TransientAttribute":
return typeof (TransientAttribute);
case "UnifiedInternalAttribute":
return typeof (UnifiedInternalAttribute);
case "Visibility":
return typeof (Visibility);
case "WrapAttribute":
Expand Down
3 changes: 3 additions & 0 deletions src/bgen/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,17 @@ public class InternalAttribute : Attribute {
public InternalAttribute () { }
}

#if !XAMCORE_5_0
// This is a conditional "Internal" method, that flags methods as internal only when
// compiling with Unified, otherwise, this is ignored.
//
// In addition, UnifiedInternal members automatically get an underscore after their name
// so [UnifiedInternal] void Foo(); becomes "Foo_()"
[Obsolete ("This attribute no longer has any effect; do no use")]
public class UnifiedInternalAttribute : Attribute {
public UnifiedInternalAttribute () { }
}
#endif

// When applied to a method or property, flags the resulting generated code as internal
public sealed class ProtectedAttribute : Attribute {
Expand Down
14 changes: 3 additions & 11 deletions src/bgen/Extensions/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,17 @@ public static List<MethodInfo> GatherMethods (this Type type, Generator generato

public static bool IsInternal (this MemberInfo mi, Generator generator)
{
return generator.AttributeManager.HasAttribute<InternalAttribute> (mi)
|| (generator.AttributeManager.HasAttribute<UnifiedInternalAttribute> (mi));
}

public static bool IsUnifiedInternal (this MemberInfo mi, Generator generator)
{
return (generator.AttributeManager.HasAttribute<UnifiedInternalAttribute> (mi));
return generator.AttributeManager.HasAttribute<InternalAttribute> (mi);
}

public static bool IsInternal (this PropertyInfo pi, Generator generator)
{
return generator.AttributeManager.HasAttribute<InternalAttribute> (pi)
|| (generator.AttributeManager.HasAttribute<UnifiedInternalAttribute> (pi));
return generator.AttributeManager.HasAttribute<InternalAttribute> (pi);
}

public static bool IsInternal (this Type type, Generator generator)
{
return generator.AttributeManager.HasAttribute<InternalAttribute> (type)
|| (generator.AttributeManager.HasAttribute<UnifiedInternalAttribute> (type));
return generator.AttributeManager.HasAttribute<InternalAttribute> (type);
}

public static List<MethodInfo> GatherMethods (this Type type, BindingFlags flags, Generator generator)
Expand Down
23 changes: 7 additions & 16 deletions src/bgen/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,7 @@ public void Go ()
selector = ba.Selector;
} else if (attr is StaticAttribute) {
continue;
} else if (attr is InternalAttribute || attr is UnifiedInternalAttribute || attr is ProtectedAttribute) {
} else if (attr is InternalAttribute || attr is ProtectedAttribute) {
continue;
} else if (attr is NeedsAuditAttribute) {
continue;
Expand Down Expand Up @@ -2698,16 +2698,13 @@ public string MakeSignature (MemberInformation minfo, bool is_async, ParameterIn

sb.Append (" ");
}
// Unified internal methods automatically get a _ appended
if (minfo.is_extension_method && minfo.Method.IsSpecialName) {
if (name.StartsWith ("get_", StringComparison.Ordinal))
name = "Get" + name.Substring (4);
else if (name.StartsWith ("set_", StringComparison.Ordinal))
name = "Set" + name.Substring (4);
}
sb.Append (name);
if (minfo.is_unified_internal)
sb.Append ("_");
sb.Append (" (");

bool comma = false;
Expand Down Expand Up @@ -3863,7 +3860,6 @@ void GenerateProperty (Type type, PropertyInfo pi, List<string> instance_fields_
string wrap;
var export = GetExportAttribute (pi, out wrap);
var minfo = new MemberInformation (this, this, pi, type, is_interface_impl);
bool use_underscore = minfo.is_unified_internal;
var mod = minfo.GetVisibility ();
Type inlinedType = pi.DeclaringType == type ? null : type;
minfo.protocolize = Protocolize (pi);
Expand Down Expand Up @@ -3899,13 +3895,12 @@ void GenerateProperty (Type type, PropertyInfo pi, List<string> instance_fields_
print_generated_code ();
PrintPropertyAttributes (pi, minfo.type);
PrintAttributes (pi, preserve: true, advice: true);
print ("{0} {1}{2}{3} {4}{5} {{",
print ("{0} {1}{2}{3} {4} {{",
mod,
minfo.GetModifiers (),
(minfo.protocolize ? "I" : "") + TypeManager.FormatType (pi.DeclaringType, pi.PropertyType),
nullable ? "?" : String.Empty,
pi.Name.GetSafeParamName (),
use_underscore ? "_" : "");
pi.Name.GetSafeParamName ());
indent++;
if (generate_getter) {
#if !NET
Expand Down Expand Up @@ -3996,13 +3991,12 @@ void GenerateProperty (Type type, PropertyInfo pi, List<string> instance_fields_
propertyTypeName = TypeManager.FormatType (pi.DeclaringType, pi.PropertyType);
}

print ("{0} {1}{2}{3} {4}{5} {{",
print ("{0} {1}{2}{3} {4} {{",
mod,
minfo.GetModifiers (),
propertyTypeName,
nullable ? "?" : "",
pi.Name.GetSafeParamName (),
use_underscore ? "_" : "");
pi.Name.GetSafeParamName ());
indent++;

if (minfo.has_inner_wrap_attribute) {
Expand Down Expand Up @@ -5895,8 +5889,6 @@ public void Generate (Type type)
var fieldAttr = AttributeManager.GetCustomAttribute<FieldAttribute> (field_pi);
ComputeLibraryName (fieldAttr, type, field_pi.Name, out string library_name, out string library_path);

bool is_unified_internal = field_pi.IsUnifiedInternal (this);

string fieldTypeName;
string smartEnumTypeName = null;
if (IsSmartEnum (field_pi.PropertyType)) {
Expand Down Expand Up @@ -5924,11 +5916,10 @@ public void Generate (Type type)
if (AttributeManager.HasAttribute<NotificationAttribute> (field_pi))
print ($"[Advice (\"Use {type.Name}.Notifications.Observe{GetNotificationName (field_pi)} helper method instead.\")]");

print ("{0} static {1}{2} {3}{4} {{", field_pi.IsInternal (this) ? "internal" : "public",
print ("{0} static {1}{2} {3} {{", field_pi.IsInternal (this) ? "internal" : "public",
smartEnumTypeName ?? fieldTypeName,
nullable ? "?" : "",
field_pi.Name,
is_unified_internal ? "_" : "");
field_pi.Name);
indent++;

PrintAttributes (field_pi, platform: true);
Expand Down
2 changes: 0 additions & 2 deletions src/bgen/Models/MemberInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class MemberInformation {
public readonly bool is_abstract;
public readonly bool is_protected;
public readonly bool is_internal;
public readonly bool is_unified_internal;
public readonly bool is_override;
public readonly bool is_new;
public readonly bool is_sealed;
Expand Down Expand Up @@ -57,7 +56,6 @@ public class MemberInformation {
is_abstract = AttributeManager.HasAttribute<AbstractAttribute> (mi) && mi.DeclaringType == type;
is_protected = AttributeManager.HasAttribute<ProtectedAttribute> (mi);
is_internal = mi.IsInternal (generator);
is_unified_internal = AttributeManager.HasAttribute<UnifiedInternalAttribute> (mi);
is_override = AttributeManager.HasAttribute<OverrideAttribute> (mi) || !Generator.MemberBelongsToType (mi.DeclaringType, type);
is_new = AttributeManager.HasAttribute<NewAttribute> (mi);
is_sealed = AttributeManager.HasAttribute<SealedAttribute> (mi);
Expand Down

6 comments on commit 8c3bbcc

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.