Skip to content

Commit e9a35b8

Browse files
authored
[swift2objc] Availability annotations (#2476)
1 parent 89f91be commit e9a35b8

32 files changed

+378
-18
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// A Swift declaration's availability info.
6+
abstract interface class Availability {
7+
abstract final List<AvailabilityInfo> availability;
8+
}
9+
10+
/// The availability for a single domain.
11+
class AvailabilityInfo {
12+
String domain;
13+
bool unavailable;
14+
AvailabilityVersion? introduced;
15+
AvailabilityVersion? deprecated;
16+
AvailabilityVersion? obsoleted;
17+
18+
AvailabilityInfo({
19+
required this.domain,
20+
required this.unavailable,
21+
required this.introduced,
22+
required this.deprecated,
23+
required this.obsoleted,
24+
});
25+
}
26+
27+
/// A version for availability.
28+
class AvailabilityVersion {
29+
int major;
30+
int? minor;
31+
int? patch;
32+
33+
AvailabilityVersion(
34+
{required this.major, required this.minor, required this.patch});
35+
36+
@override
37+
String toString() => [major, minor, patch].nonNulls.join('.');
38+
}

pkgs/swift2objc/lib/src/ast/_core/interfaces/declaration.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
import '../../ast_node.dart';
66
import '../shared/referred_type.dart';
7+
import 'availability.dart';
78

89
/// A common interface for all Swift entities declarations.
9-
abstract interface class Declaration implements AstNode {
10+
abstract interface class Declaration implements AstNode, Availability {
1011
abstract final String id;
1112
abstract final String name;
1213
}

pkgs/swift2objc/lib/src/ast/declarations/built_in/built_in_declaration.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import '../../_core/interfaces/availability.dart';
56
import '../../_core/interfaces/declaration.dart';
67
import '../../_core/interfaces/objc_annotatable.dart';
78
import '../../ast_node.dart';
@@ -15,6 +16,9 @@ class BuiltInDeclaration extends AstNode
1516
@override
1617
final String name;
1718

19+
@override
20+
List<AvailabilityInfo> get availability => const [];
21+
1822
@override
1923
bool get hasObjCAnnotation => true;
2024

pkgs/swift2objc/lib/src/ast/declarations/compounds/class_declaration.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import '../../_core/interfaces/availability.dart';
56
import '../../_core/interfaces/compound_declaration.dart';
67
import '../../_core/interfaces/declaration.dart';
78
import '../../_core/interfaces/nestable_declaration.dart';
@@ -23,6 +24,9 @@ class ClassDeclaration extends AstNode
2324
@override
2425
String name;
2526

27+
@override
28+
List<AvailabilityInfo> availability;
29+
2630
@override
2731
covariant List<PropertyDeclaration> properties;
2832

@@ -63,6 +67,7 @@ class ClassDeclaration extends AstNode
6367
ClassDeclaration({
6468
required this.id,
6569
required this.name,
70+
required this.availability,
6671
this.properties = const [],
6772
this.methods = const [],
6873
this.nestingParent,

pkgs/swift2objc/lib/src/ast/declarations/compounds/members/initializer_declaration.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import '../../../_core/interfaces/availability.dart';
56
import '../../../_core/interfaces/can_async.dart';
67
import '../../../_core/interfaces/can_throw.dart';
78
import '../../../_core/interfaces/declaration.dart';
@@ -28,6 +29,9 @@ class InitializerDeclaration extends AstNode
2829
@override
2930
String get name => 'init';
3031

32+
@override
33+
List<AvailabilityInfo> availability;
34+
3135
@override
3236
bool hasObjCAnnotation;
3337

@@ -55,6 +59,7 @@ class InitializerDeclaration extends AstNode
5559

5660
InitializerDeclaration({
5761
required this.id,
62+
required this.availability,
5863
required this.params,
5964
this.statements = const [],
6065
required this.hasObjCAnnotation,

pkgs/swift2objc/lib/src/ast/declarations/compounds/members/method_declaration.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import '../../../_core/interfaces/availability.dart';
56
import '../../../_core/interfaces/function_declaration.dart';
67
import '../../../_core/interfaces/objc_annotatable.dart';
78
import '../../../_core/interfaces/overridable.dart';
@@ -19,6 +20,9 @@ class MethodDeclaration extends AstNode
1920
@override
2021
String name;
2122

23+
@override
24+
List<AvailabilityInfo> availability;
25+
2226
@override
2327
List<Parameter> params;
2428

@@ -55,6 +59,7 @@ class MethodDeclaration extends AstNode
5559
MethodDeclaration(
5660
{required this.id,
5761
required this.name,
62+
required this.availability,
5863
required this.returnType,
5964
required this.params,
6065
this.typeParams = const [],

pkgs/swift2objc/lib/src/ast/declarations/compounds/members/property_declaration.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import '../../../_core/interfaces/availability.dart';
56
import '../../../_core/interfaces/executable.dart';
67
import '../../../_core/interfaces/objc_annotatable.dart';
78
import '../../../_core/interfaces/variable_declaration.dart';
@@ -18,6 +19,9 @@ class PropertyDeclaration extends AstNode
1819
@override
1920
String name;
2021

22+
@override
23+
List<AvailabilityInfo> availability;
24+
2125
@override
2226
bool hasObjCAnnotation;
2327

@@ -51,6 +55,7 @@ class PropertyDeclaration extends AstNode
5155
PropertyDeclaration(
5256
{required this.id,
5357
required this.name,
58+
required this.availability,
5459
required this.type,
5560
this.hasSetter = false,
5661
this.isConstant = false,

pkgs/swift2objc/lib/src/ast/declarations/compounds/protocol_declaration.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import '../../_core/interfaces/availability.dart';
56
import '../../_core/interfaces/compound_declaration.dart';
67
import '../../_core/interfaces/nestable_declaration.dart';
78
import '../../_core/shared/referred_type.dart';
@@ -18,6 +19,9 @@ class ProtocolDeclaration extends AstNode implements CompoundDeclaration {
1819
@override
1920
String name;
2021

22+
@override
23+
List<AvailabilityInfo> availability;
24+
2125
@override
2226
covariant List<PropertyDeclaration> properties;
2327

@@ -42,6 +46,7 @@ class ProtocolDeclaration extends AstNode implements CompoundDeclaration {
4246
ProtocolDeclaration({
4347
required this.id,
4448
required this.name,
49+
required this.availability,
4550
required this.properties,
4651
required this.methods,
4752
required this.initializers,

pkgs/swift2objc/lib/src/ast/declarations/compounds/struct_declaration.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import '../../_core/interfaces/availability.dart';
56
import '../../_core/interfaces/compound_declaration.dart';
67
import '../../_core/interfaces/nestable_declaration.dart';
78
import '../../_core/shared/referred_type.dart';
@@ -19,6 +20,9 @@ class StructDeclaration extends AstNode implements CompoundDeclaration {
1920
@override
2021
String name;
2122

23+
@override
24+
List<AvailabilityInfo> availability;
25+
2226
@override
2327
covariant List<PropertyDeclaration> properties;
2428

@@ -43,6 +47,7 @@ class StructDeclaration extends AstNode implements CompoundDeclaration {
4347
StructDeclaration({
4448
required this.id,
4549
required this.name,
50+
required this.availability,
4651
this.properties = const [],
4752
this.methods = const [],
4853
this.initializers = const [],

pkgs/swift2objc/lib/src/ast/declarations/enums/associated_value_enum_declaration.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import '../../_core/interfaces/availability.dart';
56
import '../../_core/interfaces/enum_declaration.dart';
67
import '../../_core/interfaces/nestable_declaration.dart';
78
import '../../_core/interfaces/parameterizable.dart';
@@ -19,6 +20,9 @@ class AssociatedValueEnumDeclaration extends AstNode
1920
@override
2021
String name;
2122

23+
@override
24+
List<AvailabilityInfo> availability;
25+
2226
@override
2327
covariant List<AssociatedValueEnumCase> cases;
2428

@@ -37,6 +41,7 @@ class AssociatedValueEnumDeclaration extends AstNode
3741
AssociatedValueEnumDeclaration({
3842
required this.id,
3943
required this.name,
44+
required this.availability,
4045
required this.cases,
4146
required this.typeParams,
4247
required this.conformedProtocols,
@@ -68,12 +73,16 @@ class AssociatedValueEnumCase extends AstNode
6873
@override
6974
String name;
7075

76+
@override
77+
List<AvailabilityInfo> availability;
78+
7179
@override
7280
covariant List<AssociatedValueParam> params;
7381

7482
AssociatedValueEnumCase({
7583
required this.id,
7684
required this.name,
85+
required this.availability,
7786
required this.params,
7887
});
7988

0 commit comments

Comments
 (0)