@@ -3,101 +3,6 @@ import 'package:reflectable/reflectable.dart';
33
44import 'model/index.dart' ;
55
6- Type typeOf <T >() => T ;
7-
8- const kIsWeb = identical (0 , 0.0 );
9-
10- /// Provides logic for traversing Json object tree
11- class JsonMap {
12- final pathDelimiter = '/' ;
13-
14- Map map;
15- List <JsonMap >? parentMaps = [];
16- Json ? jsonMeta;
17-
18- JsonMap (this .map, [this .jsonMeta, this .parentMaps]);
19-
20- bool hasProperty (String name) {
21- return _isPathExists (_getPath (name));
22- }
23-
24- dynamic getPropertyValue (String name) {
25- dynamic result;
26- final path = _getPath (name);
27- _isPathExists (path, (m, k) {
28- result = (m is Map && m.containsKey (k) && k != path) ? m[k] : m;
29- });
30- return result;
31- }
32-
33- void setPropertyValue (String name, dynamic value) {
34- _isPathExists (_getPath (name), (m, k) {}, true , value);
35- }
36-
37- String _decodePath (String path) {
38- if (path.startsWith ('#' )) {
39- path = Uri .decodeComponent (path).substring (1 );
40- }
41- return path;
42- }
43-
44- String _getPath (String propertyName) {
45- final rootObjectSegments = jsonMeta != null && jsonMeta! .name != null
46- ? _decodePath (jsonMeta! .name! ).split (pathDelimiter)
47- : [];
48- final propertySegments = _decodePath (propertyName).split (pathDelimiter);
49- rootObjectSegments.addAll (propertySegments);
50- rootObjectSegments.removeWhere ((value) => value == '' );
51- return rootObjectSegments.join (pathDelimiter);
52- }
53-
54- bool _isPathExists (String path,
55- [Function ? propertyVisitor, bool ? autoCreate, dynamic autoValue]) {
56- final segments = path
57- .split (pathDelimiter)
58- .map ((p) => p.replaceAll ('~1' , pathDelimiter).replaceAll ('~0' , '~' ))
59- .toList ();
60- dynamic current = map;
61- var existingSegmentsCount = 0 ;
62- for (var segment in segments) {
63- final idx = int .tryParse (segment);
64- if (segment == JsonProperty .parentReference) {
65- final nearestParent =
66- parentMaps! .lastWhereOrNull ((element) => element.map != current);
67- if (nearestParent != null ) {
68- current = nearestParent.map;
69- existingSegmentsCount++ ;
70- }
71- continue ;
72- }
73- if (current is List &&
74- idx != null &&
75- (current.length > idx) &&
76- (idx >= 0 ) &&
77- current.elementAt (idx) != null ) {
78- current = current.elementAt (idx);
79- existingSegmentsCount++ ;
80- }
81- if (current is Map && current.containsKey (segment)) {
82- current = current[segment];
83- existingSegmentsCount++ ;
84- } else {
85- if (autoCreate == true ) {
86- existingSegmentsCount++ ;
87- final isLastSegment = segments.length == existingSegmentsCount;
88- current[segment] = isLastSegment ? autoValue : {};
89- current = current[segment];
90- }
91- }
92- }
93- if (propertyVisitor != null && current != null ) {
94- propertyVisitor (current, segments.last);
95- }
96- return segments.length == existingSegmentsCount &&
97- existingSegmentsCount > 0 ;
98- }
99- }
100-
1016/// Provides unified access to class information based on [ClassMirror]
1027class ClassInfo {
1038 ClassMirror classMirror;
@@ -431,4 +336,4 @@ class ClassInfo {
431336 }
432337 return result;
433338 }
434- }
339+ }
0 commit comments