Skip to content

Commit

Permalink
docs(katana_router_builder): Maintenance of Comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Oct 17, 2022
1 parent 09b8f51 commit f3d04b1
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 31 deletions.
6 changes: 4 additions & 2 deletions packages/katana_router_builder/lib/common/query_class.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
part of katana_router_builder;

/// Create classes for queries.
/// クエリー用のクラスを作成します。
///
/// Pass the value for the query to [model], the path created from the annotation to [path], and the annotation value to [annotation].
///
/// クエリー用のクラスを作成します。
///
/// [model]にクエリー用の値を[path]にアノテーションから作成されたパスを[annotation]にアノテーションの値を渡します。
List<Class> queryClass(
ClassValue model,
Expand Down Expand Up @@ -148,7 +150,7 @@ List<Class> queryClass(
)
])
..body = Code(
"return AppPageRoute<T>(path: path,routeQuery: query,builder: (context) => ${model.name}(${model.parameters.map((param) => "${param.name}:${param.name}").join(",")}),transition: query?.transition ?? TransitionQueryType.initial,);",
"return AppPageRoute<T>(path: path,transitionQuery: query,builder: (context) => ${model.name}(${model.parameters.map((param) => "${param.name}:${param.name}").join(",")}),);",
),
),
]),
Expand Down
6 changes: 4 additions & 2 deletions packages/katana_router_builder/lib/common/router_class.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
part of katana_router_builder;

/// Create a class for the router.
/// ルーター用のクラスを作成します。
///
/// Create a list of parsed queries in [queries].
///
/// ルーター用のクラスを作成します。
///
/// [queries]に解析されたクエリーのリストを作成します。
List<Class> routerClass(
List<QueryValue> queries,
Expand Down Expand Up @@ -71,7 +73,7 @@ List<Class> routerClass(
),
Parameter(
(p) => p
..name = "defaultRouteQuery"
..name = "defaultTransitionQuery"
..named = true
..toSuper = true,
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
part of katana_router_builder;

/// Automatic page generation.
///
/// ページの自動生成を行います。
class PageGenerator extends GeneratorForAnnotation<PagePath> {
/// Automatic page generation.
///
/// ページの自動生成を行います。
PageGenerator();

Expand Down
59 changes: 42 additions & 17 deletions packages/katana_router_builder/lib/generator/router_generator.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
part of katana_router_builder;

/// Automatic generation of routers.
///
/// ルーターの自動生成を行います。
class RouterGenerator extends GeneratorForAnnotation<AppRoute> {
/// Automatic generation of routers.
///
/// ルーターの自動生成を行います。
RouterGenerator();

Expand Down Expand Up @@ -36,6 +38,9 @@ class RouterGenerator extends GeneratorForAnnotation<AppRoute> {
);
}

int i = 0;
final import = <String, String>{};
final export = <String, List<String>>{};
final queries = <QueryValue>[];
final assets = buildStep.findAssets(Glob("**.dart"));
await for (final asset in assets) {
Expand Down Expand Up @@ -67,38 +72,58 @@ class RouterGenerator extends GeneratorForAnnotation<AppRoute> {
if (library.isEmpty) {
continue;
}
queries.add(
QueryValue(
library: library!,
path: path,
query: "${element.name}.${field.name}",
element: element,
),
);
if (!export.containsKey(library!)) {
export[library] = [element.name];
} else {
export[library]!.add(element.name);
}
if (!import.containsKey(library)) {
i++;
import[library] = "_\$$i";
queries.add(
QueryValue(
library: library,
path: path,
query: "${import[library]}.${element.name}.${field.name}",
element: element,
),
);
} else {
queries.add(
QueryValue(
library: library,
path: path,
query: "${import[library]}.${element.name}.${field.name}",
element: element,
),
);
}
}
}
}
}

final sorted = queries.sortTo((a, b) => a.path.compareTo(b.path));
final sorted = queries.sortTo((a, b) {
return b.path.compareTo(a.path);
});

final generated = Library(
(l) => l
..directives = ListBuilder([
Directive.import(
"package:katana_router/katana_router.dart",
),
...sorted
.map((e) => e.library)
.distinct()
.map((e) => Directive.import(e)),
...import
.toList((key, value) => Directive.import(key, as: value))
.toList()
.sortTo((a, b) => a.url.compareTo(b.url)),
Directive.export(
"package:katana_router/katana_router.dart",
),
...sorted
.map((e) => e.library)
.distinct()
.map((e) => Directive.export(e))
...export
.toList((key, value) => Directive.export(key, show: value))
.toList()
.sortTo((a, b) => a.url.compareTo(b.url)),
])
..body.addAll(
[
Expand Down
10 changes: 8 additions & 2 deletions packages/katana_router_builder/lib/src/builder.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
part of katana_router_builder;

/// Builder Factory for pages.
///
/// ページ用のビルダーファクトリー。
Builder katanaRouterPageBuilderFactory(BuilderOptions options) {
return PartBuilder(
[
PageGenerator(),
],
".page.dart",
header:
"// ignore_for_file: unused_field, unused_element, require_trailing_commas, prefer_const_constructors, unnecessary_overrides, prefer_const_literals_to_create_immutables, unnecessary_null_in_if_null_operators",
"// ignore_for_file: unused_field, unused_element, require_trailing_commas, prefer_const_constructors, unnecessary_overrides, prefer_const_literals_to_create_immutables, unnecessary_null_in_if_null_operators, library_prefixes, directives_ordering",
);
}

/// Builder factory for routers.
///
/// ルーター用のビルダーファクトリー。
Builder katanaRouterRouterBuilderFactory(BuilderOptions options) {
return source_gen.LibraryBuilder(
RouterGenerator(),
generatedExtension: ".router.dart",
header:
"// ignore_for_file: unused_field, unused_element, require_trailing_commas, prefer_const_constructors, unnecessary_overrides, prefer_const_literals_to_create_immutables, unnecessary_null_in_if_null_operators",
"// ignore_for_file: unused_field, unused_element, require_trailing_commas, prefer_const_constructors, unnecessary_overrides, prefer_const_literals_to_create_immutables, unnecessary_null_in_if_null_operators, library_prefixes, directives_ordering",
);
}
11 changes: 9 additions & 2 deletions packages/katana_router_builder/lib/value/annotation_value.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
part of katana_router_builder;

/// Class for storing annotation values.
/// アノテーションの値を保存するためのクラス。
///
/// Specify the class element in [element] and the annotation type in [annotationType].
///
/// アノテーションの値を保存するためのクラス。
///
/// [element]にクラスエレメント、[annotationType]にアノテーションのタイプを指定します。
class AnnotationValue {
/// Class for storing annotation values.
/// アノテーションの値を保存するためのクラス。
///
/// Specify the class element in [element] and the annotation type in [annotationType].
///
/// アノテーションの値を保存するためのクラス。
///
/// [element]にクラスエレメント、[annotationType]にアノテーションのタイプを指定します。
AnnotationValue(this.element, this.annotationType) {
final matcher = TypeChecker.fromRuntime(annotationType);
Expand All @@ -34,14 +38,17 @@ class AnnotationValue {
static final _regExp = RegExp(r"redirect:\s*\[([^\]]*)\]");

/// Class Element.
///
/// クラスエレメント。
final ClassElement element;

/// Annotation Type
///
/// アノテーションのタイプ
final Type annotationType;

/// List of `RedirectQuery`.
///
/// `RedirectQuery`の一覧。
late final List<String> redirectQueries;

Expand Down
11 changes: 9 additions & 2 deletions packages/katana_router_builder/lib/value/class_value.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
part of katana_router_builder;

/// Defines the value of the class to which the annotation is assigned.
/// アノテーションが付与されたクラスの値を定義します。
///
/// Specify the element to live in [element].
///
/// アノテーションが付与されたクラスの値を定義します。
///
/// [element]に暮らすエレメントを指定します。
class ClassValue {
/// Defines the value of the class to which the annotation is assigned.
/// アノテーションが付与されたクラスの値を定義します。
///
/// Specify the element to live in [element].
///
/// アノテーションが付与されたクラスの値を定義します。
///
/// [element]に暮らすエレメントを指定します。
ClassValue(this.element) {
name = element.displayName;
Expand All @@ -22,14 +26,17 @@ class ClassValue {
}

/// Class Element.
///
/// クラスエレメント。
final ClassElement element;

/// Class Name.
///
/// クラス名。
late final String name;

/// Class parameters.
///
/// クラスのパラメーター。
late final List<ParamaterValue> parameters;

Expand Down
13 changes: 11 additions & 2 deletions packages/katana_router_builder/lib/value/parameter_value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ part of katana_router_builder;
const _pageParamChecker = TypeChecker.fromRuntime(PageParam);

/// Parameter Value.
/// パラメーターの値。
///
/// Specify the parameter element in [element].
///
/// パラメーターの値。
///
/// [element]にパラメーターエレメントを指定します。
class ParamaterValue {
/// Parameter Value.
/// パラメーターの値。
///
/// Specify the parameter element in [element].
///
/// パラメーターの値。
///
/// [element]にパラメーターエレメントを指定します。
ParamaterValue(this.element) {
name = element.displayName;
Expand Down Expand Up @@ -45,22 +49,27 @@ class ParamaterValue {
}

/// Parameter Element.
///
/// パラメーターエレメント。
final ParameterElement element;

/// Default value of the parameter.
///
/// パラメーターのデフォルト値。
late final Object? defaultValue;

/// Parameter Type.
///
/// パラメーターのタイプ。
late final DartType type;

/// Name of parameter.
///
/// パラメーターの名前。
late final String name;

/// Name for the parameter path.
///
/// パラメーターのパス用の名前。
late final String pageParamName;

Expand Down
10 changes: 8 additions & 2 deletions packages/katana_router_builder/lib/value/path_value.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
part of katana_router_builder;

/// Value for path.
/// パス用の値。
///
/// Specify the path given in the annotation in [path].
///
/// パス用の値。
///
/// [path]にアノテーションに与えられたパスを指定します。
class PathValue {
/// Value for path.
/// パス用の値。
///
/// Specify the path given in the annotation in [path].
///
/// パス用の値。
///
/// [path]にアノテーションに与えられたパスを指定します。
PathValue(this.path) {
parameters = _pathRegExp.allMatches(path).mapAndRemoveEmpty(
Expand All @@ -18,10 +22,12 @@ class PathValue {
}

/// Path value.
///
/// パスの値。
late final String path;

/// Parameters specified in the path.
///
/// パスに指定されたパラメーター。
late final List<_PathValue> parameters;

Expand Down
6 changes: 6 additions & 0 deletions packages/katana_router_builder/lib/value/query_value.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
part of katana_router_builder;

/// Parameters for query.
///
/// クエリー用のパラメーター。
class QueryValue {
/// Parameters for query.
///
/// クエリー用のパラメーター。
const QueryValue({
required this.library,
Expand All @@ -13,18 +15,22 @@ class QueryValue {
});

/// Path for queries.
///
/// クエリー用のパス。
final String path;

/// Library for queries.
///
/// クエリー用のライブラリー。
final String library;

/// Query path for queries.
///
/// クエリー用のクエリーパス。
final String query;

/// Class elements for queries.
///
/// クエリー用のクラスエレメント。
final ClassElement element;
}

0 comments on commit f3d04b1

Please sign in to comment.