Skip to content

Commit b6667e1

Browse files
committed
update
1 parent 9ffdfac commit b6667e1

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

lib/src/_utils/extract_insights_from_file.dart

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,29 @@ import '../_index.g.dart';
1919

2020
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
2121

22-
/// Analyzes the Dart file at [filePath] using [analysisContextCollection], and
23-
/// and extracts class insights from it.
24-
///
25-
/// Each item in the list consists of the name of the analyzed class and the
26-
/// annotation applied to that class.
27-
Future<List<ClassInsight<GenerateDartModel>>> extractInsightsFromFile(
28-
AnalysisContextCollection analysisContextCollection,
22+
final class GenerateDartModelInsightExtractor {
23+
GenerateDartModelInsightExtractor._();
24+
25+
/// Analyzes the Dart file at [filePath] using [analysisContextCollection], and
26+
/// and extracts class insights from it.
27+
///
28+
/// Each item in the list consists of the name of the analyzed class and the
29+
/// annotation applied to that class.
30+
static Future<List<ClassInsight<GenerateDartModel>>> extract(
31+
String filePath,
32+
AnalysisContextCollection analysisContextCollection,
33+
) =>
34+
_extractInsightsFromFile(
35+
filePath,
36+
analysisContextCollection,
37+
);
38+
}
39+
40+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
41+
42+
Future<List<ClassInsight<GenerateDartModel>>> _extractInsightsFromFile(
2943
String filePath,
44+
AnalysisContextCollection analysisContextCollection,
3045
) async {
3146
final analyzer = DartAnnotatedClassAnalyzer(
3247
filePath: filePath,
@@ -38,8 +53,7 @@ Future<List<ClassInsight<GenerateDartModel>>> extractInsightsFromFile(
3853
await analyzer.analyze(
3954
inclClassAnnotations: {GenerateDartModel.CLASS_NAME},
4055
inclMemberAnnotations: {Field.CLASS_NAME},
41-
onClassAnnotationField: (p) async =>
42-
temp = _updateFromClassAnnotationField(temp, p),
56+
onClassAnnotationField: (p) async => temp = _updateFromClassAnnotationField(temp, p),
4357
onAnnotatedMember: (p) async => temp = _updateFromAnnotatedMember(temp, p),
4458
onPreAnalysis: (_, className) => temp = const GenerateDartModel(fields: {}),
4559
onPostAnalysis: (params) {
@@ -136,30 +150,22 @@ GenerateDartModel _updateFromAnnotatedMember(
136150
params.memberAnnotationFields[FieldModelFieldNames.fieldPath],
137151
);
138152
final a2 = [params.memberName];
139-
final b1 = params.memberAnnotationFields[FieldModelFieldNames.fieldType]
140-
?.toStringValue();
153+
final b1 = params.memberAnnotationFields[FieldModelFieldNames.fieldType]?.toStringValue();
141154
final b2 = params.memberType.getDisplayString();
142-
final nullable = params
143-
.memberAnnotationFields[FieldModelFieldNames.nullable]
144-
?.toBoolValue();
145-
final primaryKey = params
146-
.memberAnnotationFields[FieldModelFieldNames.primaryKey]
147-
?.toBoolValue();
148-
final foreignKey = params
149-
.memberAnnotationFields[FieldModelFieldNames.foreignKey]
150-
?.toBoolValue();
155+
final nullable = params.memberAnnotationFields[FieldModelFieldNames.nullable]?.toBoolValue();
156+
final primaryKey =
157+
params.memberAnnotationFields[FieldModelFieldNames.primaryKey]?.toBoolValue();
158+
final foreignKey =
159+
params.memberAnnotationFields[FieldModelFieldNames.foreignKey]?.toBoolValue();
151160
final children = (dartObjToObject(
152161
params.memberAnnotationFields[FieldModelFieldNames.children],
153162
) as List?)
154163
?.map((e) => (e as Map).map((k, v) => MapEntry(k.toString(), v)))
155164
.nonNulls
156165
.toList();
157-
final fallback = params
158-
.memberAnnotationFields[FieldModelFieldNames.fallback]
159-
?.toListValue();
160-
final description = params
161-
.memberAnnotationFields[FieldModelFieldNames.description]
162-
?.toStringValue();
166+
final fallback = params.memberAnnotationFields[FieldModelFieldNames.fallback]?.toListValue();
167+
final description =
168+
params.memberAnnotationFields[FieldModelFieldNames.description]?.toStringValue();
163169
final field = DartField(
164170
fieldPath: a1 ?? a2,
165171
fieldType: b1 ?? b2,

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
name: df_generate_dart_models_core
1414
description: A package that provides core dependencies for models generated with df_generate_dart_models.
15-
version: 0.8.10
15+
version: 0.9.0
1616
repository: https://github.com/DevCetra/df_generate_dart_models_core
1717
funding:
1818
- https://www.buymeacoffee.com/robmllze

0 commit comments

Comments
 (0)