-
Notifications
You must be signed in to change notification settings - Fork 64
multitargeting (TargetFrameworks) #235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
1st run Browser Mondroid11.0 car MonoAndroid11.0 |
jonpryor
pushed a commit
to dotnet/java-interop
that referenced
this pull request
Jan 5, 2021
Context: dotnet/android-libraries#235 Consider the following Java API: // Java public interface MyInterface { default void doSomething() {} } public class MyAbstractClass implements MyInterface { } which is then bound in C# as: // C# [Register (…)] public interface IMyInterface { [Register(…)] public void DoSomething() => …; // default interface method } [Register (…)] public abstract class MyAbstractClass : Java.Lang.Object, IMyInterface { // Doesn't override IMyInterface.DoSomething() } `generator` needs to ensure that `Method.IsInterfaceDefaultMethod()` gets set for `IMyInterface.DoSomething()` so that the `BoundClass.AddInterfaceAbstractMembers()` logic knows it does not need to create an `abstract` method `MyAbstractClass.DoSomething()`. This works correctly if the interface is in the assembly we are binding, because it uses `XmlApiImporter`. That is, `generator` output is valid if `MyInterface` and `MyAbstractClass` are in the same `.jar`. However, if the interface is in a reference assembly -- `MyInterface` and `MyAbstractClass` are in different assemblies -- then `generator` uses `CecilApiImporter`, and our Cecil importer only marks Java Interface Default Methods if the method has a `[JavaInterfaceDefaultMethodAttribute]` custom attribute, which we don't appear to ever emit. Consequently, when `MyInterface` and `MyAbstractClass` are in separate libraries, then `MyAbstractClass` is bound as: // C# [Register (…)] public abstract class MyAbstractClass : Java.Lang.Object, IMyInterface { public abstract void DoSomething(); } which causes most bindings that inherit `MyAbstractClass` to fail, as they typically don't override the interface default method: // C# [Register (…)] public class MyClass : MyAbstractClass { } // error CS0534: 'MyClass' does not implemented inherited abstract member 'MyAbstractClass.DoSomething()' Update `generator` and `CecilApiImporter` to properly detect C#8 default interface methods without requiring the presence of the (unused!) `[JavaInterfaceDefaultMethodAttribute]` custom attribute, so that classes don't re-declare C#8 interface default methods as "new" abstract methods. This fixes the generated `MyAbstractClass` declaration to be: // C* [Register (…)] public class MyAbstractClass : Java.Lang.Object, IMyInterface { // No `DoSomething()` declaration }
jonpryor
pushed a commit
to dotnet/java-interop
that referenced
this pull request
Jan 5, 2021
Context: dotnet/android-libraries#235 Consider the following Java API: // Java public interface MyInterface { default void doSomething() {} } public class MyAbstractClass implements MyInterface { } which is then bound in C# as: // C# [Register (…)] public interface IMyInterface { [Register(…)] public void DoSomething() => …; // default interface method } [Register (…)] public abstract class MyAbstractClass : Java.Lang.Object, IMyInterface { // Doesn't override IMyInterface.DoSomething() } `generator` needs to ensure that `Method.IsInterfaceDefaultMethod()` gets set for `IMyInterface.DoSomething()` so that the `BoundClass.AddInterfaceAbstractMembers()` logic knows it does not need to create an `abstract` method `MyAbstractClass.DoSomething()`. This works correctly if the interface is in the assembly we are binding, because it uses `XmlApiImporter`. That is, `generator` output is valid if `MyInterface` and `MyAbstractClass` are in the same `.jar`. However, if the interface is in a reference assembly -- `MyInterface` and `MyAbstractClass` are in different assemblies -- then `generator` uses `CecilApiImporter`, and our Cecil importer only marks Java Interface Default Methods if the method has a `[JavaInterfaceDefaultMethodAttribute]` custom attribute, which we don't appear to ever emit. Consequently, when `MyInterface` and `MyAbstractClass` are in separate libraries, then `MyAbstractClass` is bound as: // C# [Register (…)] public abstract class MyAbstractClass : Java.Lang.Object, IMyInterface { public abstract void DoSomething(); } which causes most bindings that inherit `MyAbstractClass` to fail, as they typically don't override the interface default method: // C# [Register (…)] public class MyClass : MyAbstractClass { } // error CS0534: 'MyClass' does not implemented inherited abstract member 'MyAbstractClass.DoSomething()' Update `generator` and `CecilApiImporter` to properly detect C#8 default interface methods without requiring the presence of the (unused!) `[JavaInterfaceDefaultMethodAttribute]` custom attribute, so that classes don't re-declare C#8 interface default methods as "new" abstract methods. This fixes the generated `MyAbstractClass` declaration to be: // C* [Register (…)] public class MyAbstractClass : Java.Lang.Object, IMyInterface { // No `DoSomething()` declaration }
jonpryor
pushed a commit
to dotnet/java-interop
that referenced
this pull request
Jan 5, 2021
Context: dotnet/android-libraries#235 Consider the following Java API: // Java public interface MyInterface { default void doSomething() {} } public class MyAbstractClass implements MyInterface { } which is then bound in C# as: // C# [Register (…)] public interface IMyInterface { [Register(…)] public void DoSomething() => …; // default interface method } [Register (…)] public abstract class MyAbstractClass : Java.Lang.Object, IMyInterface { // Doesn't override IMyInterface.DoSomething() } `generator` needs to ensure that `Method.IsInterfaceDefaultMethod()` gets set for `IMyInterface.DoSomething()` so that the `BoundClass.AddInterfaceAbstractMembers()` logic knows it does not need to create an `abstract` method `MyAbstractClass.DoSomething()`. This works correctly if the interface is in the assembly we are binding, because it uses `XmlApiImporter`. That is, `generator` output is valid if `MyInterface` and `MyAbstractClass` are in the same `.jar`. However, if the interface is in a reference assembly -- `MyInterface` and `MyAbstractClass` are in different assemblies -- then `generator` uses `CecilApiImporter`, and our Cecil importer only marks Java Interface Default Methods if the method has a `[JavaInterfaceDefaultMethodAttribute]` custom attribute, which we don't appear to ever emit. Consequently, when `MyInterface` and `MyAbstractClass` are in separate libraries, then `MyAbstractClass` is bound as: // C# [Register (…)] public abstract class MyAbstractClass : Java.Lang.Object, IMyInterface { public abstract void DoSomething(); } which causes most bindings that inherit `MyAbstractClass` to fail, as they typically don't override the interface default method: // C# [Register (…)] public class MyClass : MyAbstractClass { } // error CS0534: 'MyClass' does not implemented inherited abstract member 'MyAbstractClass.DoSomething()' Update `generator` and `CecilApiImporter` to properly detect C#8 default interface methods without requiring the presence of the (unused!) `[JavaInterfaceDefaultMethodAttribute]` custom attribute, so that classes don't re-declare C#8 interface default methods as "new" abstract methods. This fixes the generated `MyAbstractClass` declaration to be: // C* [Register (…)] public class MyAbstractClass : Java.Lang.Object, IMyInterface { // No `DoSomething()` declaration }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Support Libraries Version (eg: 23.3.0):
Does this change any of the generated binding API's?
Describe your contribution