@@ -128,7 +128,8 @@ macro class FromJson implements ConstructorDefinitionMacro {
128
128
'Only named types are allowed on serializable classes' ,
129
129
target: type.asDiagnosticTarget),
130
130
Severity .error));
131
- return RawCode .fromString ('<Unable to deserialize type ${type .code }>' );
131
+ return RawCode .fromString (
132
+ '<Unable to deserialize type ${type .code .debugString }>' );
132
133
}
133
134
var typeDecl = await builder.typeDeclarationOf (type.identifier);
134
135
while (typeDecl is TypeAliasDeclaration ) {
@@ -140,7 +141,8 @@ macro class FromJson implements ConstructorDefinitionMacro {
140
141
'type alias ${type .code } resolved to a ${aliasedType .code }.' ,
141
142
target: type.asDiagnosticTarget),
142
143
Severity .error));
143
- return RawCode .fromString ('<Unable to deserialize type ${type .code }>' );
144
+ return RawCode .fromString (
145
+ '<Unable to deserialize type ${type .code .debugString }>' );
144
146
}
145
147
typeDecl = await builder.typeDeclarationOf (aliasedType.identifier);
146
148
}
@@ -151,7 +153,8 @@ macro class FromJson implements ConstructorDefinitionMacro {
151
153
'serializable classes' ,
152
154
target: type.asDiagnosticTarget),
153
155
Severity .error));
154
- return RawCode .fromString ('<Unable to deserialize type ${type .code }>' );
156
+ return RawCode .fromString (
157
+ '<Unable to deserialize type ${type .code .debugString }>' );
155
158
}
156
159
157
160
// The static type of the expected type, without any type arguments.
@@ -364,7 +367,8 @@ macro class ToJson implements MethodDefinitionMacro {
364
367
'Only fields with named types are allowed on serializable classes' ,
365
368
target: type.asDiagnosticTarget),
366
369
Severity .error));
367
- return RawCode .fromString ('<Unable to serialize type ${type .code }>' );
370
+ return RawCode .fromString (
371
+ '<Unable to serialize type ${type .code .debugString }>' );
368
372
}
369
373
var typeDecl = await builder.typeDeclarationOf (type.identifier);
370
374
while (typeDecl is TypeAliasDeclaration ) {
@@ -375,7 +379,8 @@ macro class ToJson implements MethodDefinitionMacro {
375
379
'Only fields with named types are allowed on serializable classes' ,
376
380
target: type.asDiagnosticTarget),
377
381
Severity .error));
378
- return RawCode .fromString ('<Unable to serialize type ${type .code }>' );
382
+ return RawCode .fromString (
383
+ '<Unable to serialize type ${type .code .debugString }>' );
379
384
}
380
385
typeDecl = await builder.typeDeclarationOf (aliasedType.identifier);
381
386
}
@@ -385,7 +390,8 @@ macro class ToJson implements MethodDefinitionMacro {
385
390
'Only classes are supported as field types for serializable classes' ,
386
391
target: type.asDiagnosticTarget),
387
392
Severity .error));
388
- return RawCode .fromString ('<Unable to serialize type ${type .code }>' );
393
+ return RawCode .fromString (
394
+ '<Unable to serialize type ${type .code .debugString }>' );
389
395
}
390
396
391
397
var typeDeclType = await builder.resolve (
@@ -497,3 +503,24 @@ extension _FirstWhereOrNull<T> on Iterable<T> {
497
503
return null ;
498
504
}
499
505
}
506
+
507
+ extension on Code {
508
+ String get debugString {
509
+ final buffer = StringBuffer ();
510
+ _writeDebugString (buffer);
511
+ return buffer.toString ();
512
+ }
513
+
514
+ void _writeDebugString (StringBuffer buffer) {
515
+ for (var part in parts) {
516
+ switch (part) {
517
+ case Code ():
518
+ part._writeDebugString (buffer);
519
+ case Identifier ():
520
+ buffer.write (part.name);
521
+ default :
522
+ buffer.write (part);
523
+ }
524
+ }
525
+ }
526
+ }
0 commit comments