Skip to content
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

Cannot add annotations to JCW for methods that implement interface methods #1260

Open
jpobst opened this issue Sep 30, 2024 · 0 comments
Open
Labels
bug Component does not function as intended callable-wrappers Issues with Java Callable Wrappers

Comments

@jpobst
Copy link
Contributor

jpobst commented Sep 30, 2024

Context: dotnet/maui@0820530
Context: dotnet/android#7714

Imagine that you have the following Java interface and annotation:

public interface DoSomething {
  void do ();
}

public abstract interface JavascriptInterface implements Annotation { }

You want to implement DoSomething.Do () in C# and apply the [JavascriptInterface] attribute to it, hoping the @JavascriptInterface Java annotation will be added to your JCW method.

public class MyClass : Java.Lang.Object, IDoSomething {
  [JavascriptInterface]
  public void Do () { ... }
}

If Do () was an override to a Java class method this would work. However when we generate JCWs for implemented interface methods, we do not consider what the user has written. We (correctly) assume that the user has provided an implementation for every required interface method. That is, we generate a JCW method for every method we find on implemented interfaces.

Because we ignore what the user has written when generating the JCW method, we will not see that they have added an attribute to their method, and we will not add the requested Java annotation to the JCW method.

To fix this, we need to figure out which methods in the user's code implements an interface method so we can apply any attributes the user has added to the JCW method.

Note that the implementation for this is likely quite complex. We will have to build a map between the user's methods and the implemented interface methods so we can determine which user methods are interface implementations and which aren't. This also gets more complicated with things like generics, explicit interface implementations, and default interface methods.

@jpobst jpobst added bug Component does not function as intended callable-wrappers Issues with Java Callable Wrappers labels Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Component does not function as intended callable-wrappers Issues with Java Callable Wrappers
Projects
None yet
Development

No branches or pull requests

1 participant