Skip to content

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

Open
@jpobst

Description

@jpobst

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    callable-wrappersIssues with Java Callable Wrappers

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions