diff --git a/src/cli_gen/lib/src/types/arg_identifiers.dart b/src/cli_gen/lib/src/types/arg_identifiers.dart index f598b47..578d787 100644 --- a/src/cli_gen/lib/src/types/arg_identifiers.dart +++ b/src/cli_gen/lib/src/types/arg_identifiers.dart @@ -1,5 +1,6 @@ -import '../utils/identifier_part.dart'; +import 'models/identifier_part.dart'; +/// Identifiers for the `args` package. class ArgsIdentifiers { const ArgsIdentifiers(); diff --git a/src/cli_gen/lib/src/types/macro_identifiers.dart b/src/cli_gen/lib/src/types/cli_gen_identifiers.dart similarity index 52% rename from src/cli_gen/lib/src/types/macro_identifiers.dart rename to src/cli_gen/lib/src/types/cli_gen_identifiers.dart index 4bded85..2cf1103 100644 --- a/src/cli_gen/lib/src/types/macro_identifiers.dart +++ b/src/cli_gen/lib/src/types/cli_gen_identifiers.dart @@ -1,13 +1,14 @@ -import '../utils/identifier_part.dart'; +import 'models/identifier_part.dart'; -class MacroArgIdentifiers { - const MacroArgIdentifiers(); +/// Identifiers for the `cli_annotations` package. +class CliGenIdentifiers { + const CliGenIdentifiers(); Uri get _uri => Uri.parse('package:cli_annotations/cli_annotations.dart'); IdentifierPart get cliCommand => IdentifierPart('CliCommand', _uri); - IdentifierPart get cliSubCommand => IdentifierPart('CliSubCommand', _uri); + IdentifierPart get cliSubCommand => IdentifierPart('CliSubcommand', _uri); IdentifierPart get cliArgs => IdentifierPart('CliArgs', _uri); } diff --git a/src/cli_gen/lib/src/types/dart_identifiers.dart b/src/cli_gen/lib/src/types/dart_identifiers.dart index 8685fd7..eae8be1 100644 --- a/src/cli_gen/lib/src/types/dart_identifiers.dart +++ b/src/cli_gen/lib/src/types/dart_identifiers.dart @@ -1,5 +1,6 @@ -import '../utils/identifier_part.dart'; +import 'models/identifier_part.dart'; +/// Identifiers for the `dart:core` library. class DartCoreIdentifiers { const DartCoreIdentifiers(); diff --git a/src/cli_gen/lib/src/types/identifiers.dart b/src/cli_gen/lib/src/types/identifiers.dart index 7996f6e..9c62e25 100644 --- a/src/cli_gen/lib/src/types/identifiers.dart +++ b/src/cli_gen/lib/src/types/identifiers.dart @@ -1,16 +1,14 @@ import 'arg_identifiers.dart'; +import 'cli_gen_identifiers.dart'; import 'dart_identifiers.dart'; -import 'keyword_identifiers.dart'; -import 'macro_identifiers.dart'; +/// A collection of common identifiers used for code generation. class Identifiers { const Identifiers._(); static const args = ArgsIdentifiers(); - static const keywords = KeywordIdentifiers(); - static const dart = DartCoreIdentifiers(); - static const macro = MacroArgIdentifiers(); + static const cliGen = CliGenIdentifiers(); } diff --git a/src/cli_gen/lib/src/types/keyword_identifiers.dart b/src/cli_gen/lib/src/types/keyword_identifiers.dart deleted file mode 100644 index 21c7602..0000000 --- a/src/cli_gen/lib/src/types/keyword_identifiers.dart +++ /dev/null @@ -1,8 +0,0 @@ -import '../utils/identifier_part.dart'; - -class KeywordIdentifiers { - const KeywordIdentifiers(); - - static final _uri = Uri.parse('dart:core'); - IdentifierPart get assert_ => IdentifierPart('assert', _uri); -} diff --git a/src/cli_gen/lib/src/utils/identifier_part.dart b/src/cli_gen/lib/src/types/models/identifier_part.dart similarity index 83% rename from src/cli_gen/lib/src/utils/identifier_part.dart rename to src/cli_gen/lib/src/types/models/identifier_part.dart index 31971ba..2d328bb 100644 --- a/src/cli_gen/lib/src/utils/identifier_part.dart +++ b/src/cli_gen/lib/src/types/models/identifier_part.dart @@ -1,5 +1,10 @@ import 'package:code_builder/code_builder.dart'; +/// A utility class that represents a part of code. +/// +/// Each instance/part can be either a String or an Identifier. This utility +/// class was created to make it easier to share code geneation logic between +/// `macros` and `builders`. sealed class EmitterPart { const EmitterPart(); diff --git a/src/cli_gen/lib/src/types/models/macro_identifier_part.dart b/src/cli_gen/lib/src/types/models/macro_identifier_part.dart new file mode 100644 index 0000000..8f87e48 --- /dev/null +++ b/src/cli_gen/lib/src/types/models/macro_identifier_part.dart @@ -0,0 +1,38 @@ +// // ignore: implementation_imports, depend_on_referenced_packages +// import 'package:_fe_analyzer_shared/src/macros/api.dart'; + +// import 'identifier_part.dart'; + +// /// A reference to a Macro identifier. +// class MacroIdentifierPart extends IdentifierPart { +// MacroIdentifierPart( +// this.identifier, +// Uri uri, +// ) : super(identifier.name, uri); + +// final Identifier identifier; + +// @override +// String get name => identifier.name; + +// @override +// String toCodeString() => name; + +// @override +// String toString() { +// return 'MacroIdentifier{name: $name, uri: $uri}'; +// } + +// @override +// int get hashCode => name.hashCode ^ uri.hashCode ^ identifier.hashCode; + +// @override +// bool operator ==(Object other) { +// if (identical(this, other)) return true; + +// return other is MacroIdentifierPart && +// other.name == name && +// other.uri == uri && +// other.identifier == identifier; +// } +// } diff --git a/src/cli_gen/lib/src/types/types.dart b/src/cli_gen/lib/src/types/types.dart new file mode 100644 index 0000000..6c663d0 --- /dev/null +++ b/src/cli_gen/lib/src/types/types.dart @@ -0,0 +1,4 @@ +export 'arg_identifiers.dart'; +export 'cli_gen_identifiers.dart'; +export 'dart_identifiers.dart'; +export 'identifiers.dart'; diff --git a/src/cli_gen/lib/src/utils/identifiers/macro_identifier_part.dart b/src/cli_gen/lib/src/utils/identifiers/macro_identifier_part.dart deleted file mode 100644 index a6ccdda..0000000 --- a/src/cli_gen/lib/src/utils/identifiers/macro_identifier_part.dart +++ /dev/null @@ -1,38 +0,0 @@ -// ignore: implementation_imports, depend_on_referenced_packages -import 'package:_fe_analyzer_shared/src/macros/api.dart'; - -import '../identifier_part.dart'; - -/// A resolved reference to an identifier. -class MacroIdentifierPart extends IdentifierPart { - MacroIdentifierPart( - this.identifier, - Uri uri, - ) : super(identifier.name, uri); - - final Identifier identifier; - - @override - String get name => identifier.name; - - @override - String toCodeString() => name; - - @override - String toString() { - return 'MacroIdentifier{name: $name, uri: $uri}'; - } - - @override - int get hashCode => name.hashCode ^ uri.hashCode ^ identifier.hashCode; - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - - return other is MacroIdentifierPart && - other.name == name && - other.uri == uri && - other.identifier == identifier; - } -}