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 88using Mono . Options ;
99
1010using Xamarin . Android . Tools . Bytecode ;
11+ using System . Text . Json ;
12+ using System . Text . Json . Serialization ;
1113
1214namespace Xamarin . Android . Tools {
1315
@@ -159,6 +161,32 @@ static void DumpClassFile (ClassFile c, TextWriter output)
159161 output . WriteLine ( "\t \t {0}" , attr ) ;
160162 }
161163 }
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+ }
162190 }
163191 }
164192}
You can’t perform that action at this time.
0 commit comments