Skip to content

Commit a8b444d

Browse files
authored
[Java.Interop.Tools.JavaTypeSystem] ctors w/ generic type parameters (#919)
While [testing][0] the new JavaTypeSystem (f658ab2) on [AndroidX][1], the api-diff was reporting various constructors had been removed: ## Xamarin.Android.Glide.dll #### Type Changed: Bumptech.Glide.Registry.NoModelLoaderAvailableException Removed constructor: ```csharp public Registry.NoModelLoaderAvailableException (Java.Lang.Object model, System.Collections.IList matchingButNotHandlingModelLoaders); ``` Investigating let to realizing Java constructors can have generic type parameters: ```java public static class NoModelLoaderAvailableException extends MissingComponentException { public <M> NoModelLoaderAvailableException( @nonnull M model, @nonnull List<ModelLoader<M, ?>> matchingButNotHandlingModelLoaders) { super( "Found ModelLoaders for model class: " + matchingButNotHandlingModelLoaders + ", but none that handle this specific model instance: " + model); } ``` [(source)][2] `class-parse` correctly emits these constructors with generic types: ```xml <constructor deprecated="not deprecated" final="false" name="Registry.NoModelLoaderAvailableException" static="false" visibility="public" bridge="false" synthetic="false" jni-signature="(Ljava/lang/Object;Ljava/util/List;)V"> <typeParameters> <typeParameter name="M" jni-classBound="Ljava/lang/Object;" classBound="java.lang.Object" interfaceBounds="" jni-interfaceBounds="" /> </typeParameters> <parameter name="model" type="M" jni-type="TM;" not-null="true" /> <parameter name="matchingButNotHandlingModelLoaders" type="java.util.List&lt;com.bumptech.glide.load.model.ModelLoader&lt;M, ?&gt;&gt;" jni-type="Ljava/util/List&lt;Lcom/bumptech/glide/load/model/ModelLoader&lt;TM;*&gt;;&gt;;" not-null="true" /> </constructor> ``` We need to import this information in JavaTypeSystem so that the type parameters can be resolved. Without them, the constructor is omitted because the type `M` cannot be resolved: The constructor 'Constructor: com.bumptech.glide.Registry.NoModelLoaderAvailableException.Registry.NoModelLoaderAvailableException' was removed because the Java parameter type 'M' could not be found. Tested against AndroidX and this change restores the constructors. [0]: dotnet/android-libraries#414 [1]: https://github.com/xamarin/AndroidX [2]: https://github.com/bumptech/glide/blob/master/library/src/main/java/com/bumptech/glide/Registry.java
1 parent 0293360 commit a8b444d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/Java.Interop.Tools.JavaTypeSystem/Adapters/JavaXmlApiImporter.cs

+4
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ public static JavaConstructorModel ParseConstructor (JavaTypeModel type, XElemen
229229
isBridge: element.XGetAttributeAsBool ("bridge")
230230
);
231231

232+
// Yes, constructors in Java can have generic type parameters ¯\_(ツ)_/¯
233+
if (element.Element ("typeParameters") is XElement tp)
234+
ParseTypeParameters (method.TypeParameters, tp);
235+
232236
foreach (var child in element.Elements ("exception"))
233237
method.Exceptions.Add (ParseException (child));
234238

0 commit comments

Comments
 (0)