Skip to content

Commit

Permalink
Naming improvements in Swiftgen models & interfaces (#1197)
Browse files Browse the repository at this point in the history
* improve naming of AST models & interfaces

* add a description of DeclaredType and GenericType
  • Loading branch information
Mohammad3id committed Jun 7, 2024
1 parent 58d6944 commit acf7d21
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'confomingable.dart';
import 'protocol_conformable.dart';
import 'declaration.dart';
import 'genericable.dart';
import 'type_parameterizable.dart';
import '../shared/referred_type.dart';
import 'paramable.dart';
import 'parameterizable.dart';

/// An interface for the declaration of all compound Swift entities. See `ClassDeclaration`,
/// `StructDeclaration` and `ProtocolDeclaration` for concrete implementations.
abstract interface class CompoundDeclaration
implements Declaration, Genericable, Conformingable {
implements Declaration, TypeParameterizable, ProtocolConformable {
abstract List<CompoundPropertyDeclaration> properties;
abstract List<CompoundMethodDeclaration> methods;
}
Expand All @@ -26,6 +26,6 @@ abstract interface class CompoundPropertyDeclaration implements Declaration {
/// An interface for a compound method. See `ClassMethodDeclaration`,
/// `StructMethodDeclaration` and `ProtocolMethodDeclaration` for concrete implementations.
abstract interface class CompoundMethodDeclaration
implements Declaration, Genericable, Paramable {
implements Declaration, TypeParameterizable, Parameterizable {
abstract ReferredType returnType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'confomingable.dart';
import 'protocol_conformable.dart';
import 'declaration.dart';
import 'genericable.dart';
import 'type_parameterizable.dart';

/// An interface for describing the declaration of a Swift enum. See `NormalEnumDeclaration`,
/// `AssociatedValueEnumDeclaration` and `RawValueEnumDeclaration` for concrete implementations.
abstract interface class EnumDeclaration
implements Declaration, Genericable, Conformingable {
implements Declaration, TypeParameterizable, ProtocolConformable {
abstract List<EnumCase> cases;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
import '../shared/parameter.dart';

/// An interface to describe a Swift entity's ability to have parameters (e.g functions).
abstract interface class Paramable {
abstract interface class Parameterizable {
abstract List<Parameter> params;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import '../../declarations/compounds/protocol_declaration.dart';
import '../shared/referred_type.dart';

/// An interface to describe a Swift entity's ability to confom to protocols.
abstract interface class Conformingable {
abstract interface class ProtocolConformable {
abstract List<DeclaredType<ProtocolDeclaration>> conformedProtocols;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
import '../shared/referred_type.dart';

/// An interface to describe a Swift entity's ability to have generic parameters.
abstract interface class Genericable {
abstract List<GenericType> genericParams;
abstract interface class TypeParameterizable {
abstract List<GenericType> typeParams;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@

import '../interfaces/declaration.dart';

/// Describes a type regerence in declaration of Swift entities (e.g a method return type).
/// Describes a type reference in declaration of Swift entities (e.g a method return type).
/// See `DeclaredType` and `GenericType` for concrete implementation.
abstract class ReferredType {
String id;

ReferredType({required this.id});
}

/// Describes a reference of a user-defined type.
class DeclaredType<T extends Declaration> extends ReferredType {
T declaration;
List<ReferredType> genericParams;
List<ReferredType> typeParams;

DeclaredType({
required super.id,
required this.declaration,
required this.genericParams,
required this.typeParams,
});
}

/// Describes a reference of a generic type (e.g a method return type `T` within a generic class).
class GenericType extends ReferredType {
String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import '../../_core/interfaces/compund_declaration.dart';
import '../../_core/interfaces/compound_declaration.dart';
import '../../_core/interfaces/objc_annotatable.dart';
import '../../_core/shared/parameter.dart';
import '../../_core/shared/referred_type.dart';
Expand All @@ -26,7 +26,7 @@ class ClassDeclaration implements CompoundDeclaration, ObjCAnnotatable {
List<DeclaredType<ProtocolDeclaration>> conformedProtocols;

@override
List<GenericType> genericParams;
List<GenericType> typeParams;

@override
bool hasObjCAnnotation;
Expand All @@ -39,7 +39,7 @@ class ClassDeclaration implements CompoundDeclaration, ObjCAnnotatable {
required this.properties,
required this.methods,
required this.conformedProtocols,
required this.genericParams,
required this.typeParams,
required this.hasObjCAnnotation,
this.superClass,
});
Expand Down Expand Up @@ -85,7 +85,7 @@ class ClassMethodDeclaration
List<Parameter> params;

@override
List<GenericType> genericParams;
List<GenericType> typeParams;

@override
ReferredType returnType;
Expand All @@ -97,7 +97,7 @@ class ClassMethodDeclaration
required this.id,
required this.name,
required this.params,
required this.genericParams,
required this.typeParams,
required this.returnType,
required this.hasObjCAnnotation,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import '../../_core/interfaces/compund_declaration.dart';
import '../../_core/interfaces/compound_declaration.dart';
import '../../_core/shared/parameter.dart';
import '../../_core/shared/referred_type.dart';

Expand All @@ -24,15 +24,15 @@ class ProtocolDeclaration implements CompoundDeclaration {
List<DeclaredType<ProtocolDeclaration>> conformedProtocols;

@override
List<GenericType> genericParams;
List<GenericType> typeParams;

ProtocolDeclaration({
required this.id,
required this.name,
required this.properties,
required this.methods,
required this.conformedProtocols,
required this.genericParams,
required this.typeParams,
});
}

Expand Down Expand Up @@ -70,7 +70,7 @@ class ProtocolMethodDeclaration implements CompoundMethodDeclaration {
List<Parameter> params;

@override
List<GenericType> genericParams;
List<GenericType> typeParams;

@override
ReferredType returnType;
Expand All @@ -79,7 +79,7 @@ class ProtocolMethodDeclaration implements CompoundMethodDeclaration {
required this.id,
required this.name,
required this.params,
required this.genericParams,
required this.typeParams,
required this.returnType,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import '../../_core/interfaces/compund_declaration.dart';
import '../../_core/interfaces/compound_declaration.dart';
import '../../_core/shared/parameter.dart';
import '../../_core/shared/referred_type.dart';
import 'protocol_declaration.dart';
Expand All @@ -25,15 +25,15 @@ class StructDeclaration implements CompoundDeclaration {
List<DeclaredType<ProtocolDeclaration>> conformedProtocols;

@override
List<GenericType> genericParams;
List<GenericType> typeParams;

StructDeclaration({
required this.id,
required this.name,
required this.properties,
required this.methods,
required this.conformedProtocols,
required this.genericParams,
required this.typeParams,
});
}

Expand Down Expand Up @@ -71,7 +71,7 @@ class StructMethodDeclaration implements CompoundMethodDeclaration {
List<Parameter> params;

@override
List<GenericType> genericParams;
List<GenericType> typeParams;

@override
ReferredType returnType;
Expand All @@ -80,7 +80,7 @@ class StructMethodDeclaration implements CompoundMethodDeclaration {
required this.id,
required this.name,
required this.params,
required this.genericParams,
required this.typeParams,
required this.returnType,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import '../../_core/interfaces/enum_declaration.dart';
import '../../_core/interfaces/paramable.dart';
import '../../_core/interfaces/parameterizable.dart';
import '../../_core/shared/parameter.dart';
import '../../_core/shared/referred_type.dart';
import '../compounds/protocol_declaration.dart';
Expand All @@ -20,7 +20,7 @@ class AssociatedValueEnumDeclaration implements EnumDeclaration {
covariant List<AssociatedValueEnumCase> cases;

@override
List<GenericType> genericParams;
List<GenericType> typeParams;

@override
List<DeclaredType<ProtocolDeclaration>> conformedProtocols;
Expand All @@ -29,13 +29,13 @@ class AssociatedValueEnumDeclaration implements EnumDeclaration {
required this.id,
required this.name,
required this.cases,
required this.genericParams,
required this.typeParams,
required this.conformedProtocols,
});
}

/// Describes the declaration of a Swift enum case with associated values.
class AssociatedValueEnumCase implements EnumCase, Paramable {
class AssociatedValueEnumCase implements EnumCase, Parameterizable {
@override
String id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class NormalEnumDeclaration implements EnumDeclaration {
covariant List<NormalEnumCase> cases;

@override
List<GenericType> genericParams;
List<GenericType> typeParams;

@override
List<DeclaredType<ProtocolDeclaration>> conformedProtocols;
Expand All @@ -27,7 +27,7 @@ class NormalEnumDeclaration implements EnumDeclaration {
required this.id,
required this.name,
required this.cases,
required this.genericParams,
required this.typeParams,
required this.conformedProtocols,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RawValueEnumDeclaration<T> implements EnumDeclaration, ObjCAnnotatable {
covariant List<RawValueEnumCase<T>> cases;

@override
List<GenericType> genericParams;
List<GenericType> typeParams;

@override
List<DeclaredType<ProtocolDeclaration>> conformedProtocols;
Expand All @@ -33,7 +33,7 @@ class RawValueEnumDeclaration<T> implements EnumDeclaration, ObjCAnnotatable {
required this.id,
required this.name,
required this.cases,
required this.genericParams,
required this.typeParams,
required this.conformedProtocols,
required this.hasObjCAnnotation,
required this.rawValueType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// BSD-style license that can be found in the LICENSE file.

import '../../_core/interfaces/declaration.dart';
import '../../_core/interfaces/genericable.dart';
import '../../_core/interfaces/paramable.dart';
import '../../_core/interfaces/type_parameterizable.dart';
import '../../_core/interfaces/parameterizable.dart';
import '../../_core/shared/parameter.dart';
import '../../_core/shared/referred_type.dart';

Expand All @@ -20,7 +20,8 @@ class Globals {
}

/// Describes a globally defined function.
class GlobalFunction implements Declaration, Paramable, Genericable {
class GlobalFunction
implements Declaration, Parameterizable, TypeParameterizable {
@override
String id;

Expand All @@ -31,15 +32,15 @@ class GlobalFunction implements Declaration, Paramable, Genericable {
List<Parameter> params;

@override
List<GenericType> genericParams;
List<GenericType> typeParams;

ReferredType returnType;

GlobalFunction({
required this.id,
required this.name,
required this.params,
required this.genericParams,
required this.typeParams,
required this.returnType,
});
}
Expand Down

0 comments on commit acf7d21

Please sign in to comment.