File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 8
8
using Mono . Options ;
9
9
10
10
using Xamarin . Android . Tools . Bytecode ;
11
+ using System . Text . Json ;
12
+ using System . Text . Json . Serialization ;
11
13
12
14
namespace Xamarin . Android . Tools {
13
15
@@ -159,6 +161,32 @@ static void DumpClassFile (ClassFile c, TextWriter output)
159
161
output . WriteLine ( "\t \t {0}" , attr ) ;
160
162
}
161
163
}
164
+
165
+ // Output Kotlin metadata if it exists
166
+ var kotlin_metadata = c . Attributes . OfType < RuntimeVisibleAnnotationsAttribute > ( )
167
+ . FirstOrDefault ( ) ? . Annotations
168
+ . FirstOrDefault ( a => a . Type == "Lkotlin/Metadata;" ) ;
169
+
170
+ if ( kotlin_metadata is not null ) {
171
+ var meta = KotlinMetadata . FromAnnotation ( kotlin_metadata ) ;
172
+ var jopt = new JsonSerializerOptions {
173
+ ReferenceHandler = ReferenceHandler . Preserve ,
174
+ WriteIndented = true ,
175
+ } ;
176
+
177
+ if ( meta . AsClassMetadata ( ) is KotlinClass kc ) {
178
+ output . WriteLine ( ) ;
179
+ var json = JsonSerializer . Serialize ( kc , jopt ) ;
180
+ output . WriteLine ( $ "Kotlin Class Metadata [{ meta . MetadataVersion } ]: { json } ") ;
181
+ } else if ( meta . AsFileMetadata ( ) is KotlinFile kf ) {
182
+ output . WriteLine ( ) ;
183
+ var json = JsonSerializer . Serialize ( kf , jopt ) ;
184
+ output . WriteLine ( $ "Kotlin File Metadata [{ meta . MetadataVersion } ]: { json } ") ;
185
+ }
186
+
187
+ output . WriteLine ( ) ;
188
+ output . WriteLine ( $ "Kotlin Metadata String Table: { JsonSerializer . Serialize ( meta . Data2 , jopt ) } ") ;
189
+ }
162
190
}
163
191
}
164
192
}
You can’t perform that action at this time.
0 commit comments