@@ -13,13 +13,13 @@ public static class ManagedApiImporter
1313 [ Obsolete ( "Use the TypeDefinitionCache overload for better performance." , error : true ) ]
1414 public static JavaTypeCollection Parse ( AssemblyDefinition assembly , JavaTypeCollection collection ) => throw new NotSupportedException ( ) ;
1515
16- public static JavaTypeCollection Parse ( AssemblyDefinition assembly , JavaTypeCollection collection , TypeDefinitionCache resolver )
16+ public static JavaTypeCollection Parse ( AssemblyDefinition assembly , JavaTypeCollection collection , TypeDefinitionCache resolver , ApiImporterOptions options )
1717 {
1818 var types_to_add = new List < JavaTypeModel > ( ) ;
1919
2020 foreach ( var md in assembly . Modules )
2121 foreach ( var td in md . Types ) {
22- if ( ! ShouldSkipType ( td , resolver ) && ParseType ( td , collection ) is JavaTypeModel type )
22+ if ( ! ShouldSkipType ( td , resolver , options ) && ParseType ( td , collection , options ) is JavaTypeModel type )
2323 types_to_add . Add ( type ) ;
2424 }
2525
@@ -33,21 +33,21 @@ public static JavaTypeCollection Parse (AssemblyDefinition assembly, JavaTypeCol
3333 return collection ;
3434 }
3535
36- public static JavaTypeModel ? ParseType ( TypeDefinition type , JavaTypeCollection collection )
36+ public static JavaTypeModel ? ParseType ( TypeDefinition type , JavaTypeCollection collection , ApiImporterOptions options )
3737 {
3838 if ( ! type . IsPublic && ! type . IsNested )
3939 return null ;
4040
4141 if ( ! ShouldImport ( type ) )
4242 return null ;
4343
44- var model = type . IsInterface ? ( JavaTypeModel ? ) ParseInterface ( type , collection ) : ParseClass ( type , collection ) ;
44+ var model = type . IsInterface ? ( JavaTypeModel ? ) ParseInterface ( type , collection , options ) : ParseClass ( type , collection , options ) ;
4545
4646 if ( model is null )
4747 return null ;
4848
4949 foreach ( var nested in type . NestedTypes )
50- if ( ParseType ( nested , collection ) is JavaTypeModel nested_model )
50+ if ( ParseType ( nested , collection , options ) is JavaTypeModel nested_model )
5151 model . NestedTypes . Add ( nested_model ) ;
5252
5353 return model ;
@@ -89,19 +89,19 @@ static bool ShouldImport (TypeDefinition td)
8989 return true ;
9090 }
9191
92- public static JavaClassModel ? ParseClass ( TypeDefinition type , JavaTypeCollection collection )
92+ public static JavaClassModel ? ParseClass ( TypeDefinition type , JavaTypeCollection collection , ApiImporterOptions options )
9393 {
9494 // TODO: type parameters?
9595 var obs_attr = GetObsoleteAttribute ( type . CustomAttributes ) ;
96- var reg_attr = GetRegisterAttribute ( type . CustomAttributes ) ;
96+ var reg_attr = GetRegisterAttribute ( type . CustomAttributes , options ) ;
9797
9898 if ( reg_attr is null )
9999 return null ;
100100
101101 var encoded_fullname = ( ( string ) reg_attr . ConstructorArguments [ 0 ] . Value ) . Replace ( '/' , '.' ) ;
102102 var ( package , nested_name ) = DecodeRegisterJavaFullName ( encoded_fullname ) ;
103103
104- var base_jni = GetBaseTypeJni ( type ) ;
104+ var base_jni = GetBaseTypeJni ( type , options ) ;
105105
106106 var model = new JavaClassModel (
107107 javaPackage : GetOrCreatePackage ( collection , package , type . Namespace ) ,
@@ -118,20 +118,20 @@ static bool ShouldImport (TypeDefinition td)
118118 annotatedVisibility : string . Empty
119119 ) ; ;
120120
121- ParseImplementedInterfaces ( type , model ) ;
121+ ParseImplementedInterfaces ( type , model , options ) ;
122122
123123 foreach ( var method in type . Methods . Where ( m => ! m . IsConstructor ) )
124- if ( ParseMethod ( method , model ) is JavaMethodModel m )
124+ if ( ParseMethod ( method , model , options ) is JavaMethodModel m )
125125 model . Methods . Add ( m ) ;
126126
127127 return model ;
128128 }
129129
130- public static JavaInterfaceModel ? ParseInterface ( TypeDefinition type , JavaTypeCollection collection )
130+ public static JavaInterfaceModel ? ParseInterface ( TypeDefinition type , JavaTypeCollection collection , ApiImporterOptions options )
131131 {
132132 // TODO: type paramters?
133133 var obs_attr = GetObsoleteAttribute ( type . CustomAttributes ) ;
134- var reg_attr = GetRegisterAttribute ( type . CustomAttributes ) ;
134+ var reg_attr = GetRegisterAttribute ( type . CustomAttributes , options ) ;
135135
136136 if ( reg_attr is null )
137137 return null ;
@@ -149,22 +149,22 @@ static bool ShouldImport (TypeDefinition td)
149149 annotatedVisibility : ""
150150 ) ;
151151
152- ParseImplementedInterfaces ( type , model ) ;
152+ ParseImplementedInterfaces ( type , model , options ) ;
153153
154154 foreach ( var method in type . Methods )
155- if ( ParseMethod ( method , model ) is JavaMethodModel m )
155+ if ( ParseMethod ( method , model , options ) is JavaMethodModel m )
156156 model . Methods . Add ( m ) ;
157157
158158 return model ;
159159 }
160160
161- public static JavaMethodModel ? ParseMethod ( MethodDefinition method , JavaTypeModel declaringType )
161+ public static JavaMethodModel ? ParseMethod ( MethodDefinition method , JavaTypeModel declaringType , ApiImporterOptions options )
162162 {
163163 if ( method . IsPrivate || method . IsAssembly )
164164 return null ;
165165
166166 var obs_attr = GetObsoleteAttribute ( method . CustomAttributes ) ;
167- var reg_attr = GetRegisterAttribute ( method . CustomAttributes ) ;
167+ var reg_attr = GetRegisterAttribute ( method . CustomAttributes , options ) ;
168168
169169 if ( reg_attr is null )
170170 return null ;
@@ -225,7 +225,7 @@ static void AddReferenceTypeRecursive (JavaTypeModel type, JavaTypeCollection co
225225 AddReferenceTypeRecursive ( nested , collection ) ;
226226 }
227227
228- static bool ShouldSkipType ( TypeDefinition type , TypeDefinitionCache cache )
228+ static bool ShouldSkipType ( TypeDefinition type , TypeDefinitionCache cache , ApiImporterOptions options )
229229 {
230230 // We want to use Java's collection types instead of our managed adapter.
231231 // eg: 'Java.Util.ArrayList' over 'Android.Runtime.JavaList'
@@ -246,28 +246,28 @@ static bool ShouldSkipType (TypeDefinition type, TypeDefinitionCache cache)
246246 ? type . Module . GetType ( type . FullName . Substring ( 0 , type . FullName . IndexOf ( '`' ) ) )
247247 : null ;
248248
249- if ( ShouldSkipGeneric ( type , non_generic_type , cache ) )
249+ if ( ShouldSkipGeneric ( type , non_generic_type , cache , options ) )
250250 return true ;
251251
252252 return false ;
253253 }
254254
255- static bool ShouldSkipGeneric ( TypeDefinition ? a , TypeDefinition ? b , TypeDefinitionCache cache )
255+ static bool ShouldSkipGeneric ( TypeDefinition ? a , TypeDefinition ? b , TypeDefinitionCache cache , ApiImporterOptions options )
256256 {
257257 if ( a == null || b == null )
258258 return false ;
259259 if ( ! a . ImplementsInterface ( "Android.Runtime.IJavaObject" , cache ) || ! b . ImplementsInterface ( "Android.Runtime.IJavaObject" , cache ) )
260260 return false ;
261261
262- return GetRegisteredJavaTypeName ( a ) == GetRegisteredJavaTypeName ( b ) ;
262+ return GetRegisteredJavaTypeName ( a , options ) == GetRegisteredJavaTypeName ( b , options ) ;
263263 }
264264
265- static string ? TypeReferenceToJavaType ( TypeReference type )
265+ static string ? TypeReferenceToJavaType ( TypeReference type , ApiImporterOptions options )
266266 {
267- var retval = GetRegisteredJavaName ( type ) ;
267+ var retval = GetRegisteredJavaName ( type , options ) ;
268268
269269 if ( retval != null && type is GenericInstanceType generic ) {
270- var parameters = generic . GenericArguments . Select ( ga => GetRegisteredJavaName ( ga . Resolve ( ) ) ) . ToArray ( ) ;
270+ var parameters = generic . GenericArguments . Select ( ga => GetRegisteredJavaName ( ga . Resolve ( ) , options ) ) . ToArray ( ) ;
271271
272272 if ( parameters . WhereNotNull ( ) . Any ( ) )
273273 retval += $ "<{ string . Join ( ", " , parameters . WhereNotNull ( ) ) } >";
@@ -276,14 +276,14 @@ static bool ShouldSkipGeneric (TypeDefinition? a, TypeDefinition? b, TypeDefinit
276276 return retval ;
277277 }
278278
279- static string ? GetRegisteredJavaName ( TypeReference type )
279+ static string ? GetRegisteredJavaName ( TypeReference type , ApiImporterOptions options )
280280 {
281281 var td = type . Resolve ( ) ;
282282
283- return GetRegisteredJavaTypeName ( td ) ;
283+ return GetRegisteredJavaTypeName ( td , options ) ;
284284 }
285285
286- static void ParseImplementedInterfaces ( TypeDefinition type , JavaTypeModel model )
286+ static void ParseImplementedInterfaces ( TypeDefinition type , JavaTypeModel model , ApiImporterOptions options )
287287 {
288288 foreach ( var iface_impl in type . Interfaces ) {
289289 var iface = iface_impl . InterfaceType ;
@@ -292,7 +292,7 @@ static void ParseImplementedInterfaces (TypeDefinition type, JavaTypeModel model
292292 if ( iface_def is null || iface_def . IsNotPublic )
293293 continue ;
294294
295- if ( GetRegisterAttribute ( iface_def . CustomAttributes ) is CustomAttribute reg_attr ) {
295+ if ( GetRegisterAttribute ( iface_def . CustomAttributes , options ) is CustomAttribute reg_attr ) {
296296 var jni = ( string ) reg_attr . ConstructorArguments [ 0 ] . Value ;
297297 var name = jni . Replace ( '/' , '.' ) . Replace ( '$' , '.' ) ;
298298
@@ -301,7 +301,7 @@ static void ParseImplementedInterfaces (TypeDefinition type, JavaTypeModel model
301301 }
302302 }
303303
304- static string GetBaseTypeJni ( TypeDefinition type )
304+ static string GetBaseTypeJni ( TypeDefinition type , ApiImporterOptions options )
305305 {
306306 // Find a Java base type, ignoring generic types, if nothing else it will be Java.Lang.Object
307307 TypeDefinition ? base_type = type ;
@@ -319,7 +319,7 @@ static string GetBaseTypeJni (TypeDefinition type)
319319 if ( base_type . HasGenericParameters || base_type . IsGenericInstance )
320320 continue ;
321321
322- if ( GetRegisterAttribute ( base_type . CustomAttributes ) is CustomAttribute reg_attr )
322+ if ( GetRegisterAttribute ( base_type . CustomAttributes , options ) is CustomAttribute reg_attr )
323323 return ( string ) reg_attr . ConstructorArguments [ 0 ] . Value ;
324324 }
325325
@@ -329,19 +329,19 @@ static string GetBaseTypeJni (TypeDefinition type)
329329 static CustomAttribute ? GetObsoleteAttribute ( Collection < CustomAttribute > attributes ) =>
330330 attributes . FirstOrDefault ( a => a . AttributeType . FullNameCorrected ( ) == "System.ObsoleteAttribute" ) ;
331331
332- static CustomAttribute ? GetRegisterAttribute ( Collection < CustomAttribute > attributes ) =>
332+ static CustomAttribute ? GetRegisterAttribute ( Collection < CustomAttribute > attributes , ApiImporterOptions options ) =>
333333 attributes . FirstOrDefault ( a => {
334334 var attrType = a . AttributeType . FullNameCorrected ( ) ;
335- return attrType == "Android.Runtime.RegisterAttribute" ||
336- attrType == "Java.Interop.JniTypeSignatureAttribute" ;
335+
336+ return options . SupportedTypeMapAttributes . Contains ( attrType ) ;
337337 } ) ;
338338
339- static string ? GetRegisteredJavaTypeName ( TypeDefinition type )
339+ static string ? GetRegisteredJavaTypeName ( TypeDefinition type , ApiImporterOptions options )
340340 {
341341 if ( GetSpecialCase ( type ) is string s )
342342 return s ;
343343
344- if ( GetRegisterAttribute ( type . CustomAttributes ) is CustomAttribute reg_attr )
344+ if ( GetRegisterAttribute ( type . CustomAttributes , options ) is CustomAttribute reg_attr )
345345 return ( ( string ) reg_attr . ConstructorArguments [ 0 ] . Value ) . Replace ( '/' , '.' ) ;
346346
347347 return null ;
0 commit comments