-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow marking constructors as callable from Java.
Continuing on the "activation constructor" train, we want to allow Java to pass parameters to a constructor. In .NET Android parlance: class Example : Java.Lang.Object { [Export] public Example (int value) {} } Commit 9027591 updated `JavaCallableAttribute` to allow it to be placed on constructors, but if we try that with `samples/Hello-NativeAOTFromJNI`, the Java Callable Wrapper doesn't build: // JCW /* partial */ class Example extends java.lang.Object { public Example (int p0) { super (p0); if (getClass () == Example.class) ManagedPeer.construct(…); } } To make this work, we need `ExportAttribute.SuperArgumentsString`. We *could* add this to `JavaCallableAttribute`, but that means we'd have a property which can only be used from constructors. (Yes, `ExportAttribute` has this "wonkiness", but that doens't mean we should continue it!) Add a new `JavaCallableConstructorAttribute`, which has a new `SuperConstructorExpression` property, along with `jcw-gen` support. This allows things to compile: // C# class Example : Java.Lang.Object { [JavaCallableConstructor (SuperConstructorExpression="")] public Example (int value) {} } // JCW /* partial */ class Example extends java.lang.Object { public Example (int p0) { super (); if (getClass () == Example.class) ManagedPeer.construct(…); } } …but it's not quite right yet, because the wrong constructor is invoked! ManagedPeer.construct ( /* self */ this, /* aqn */ "Namespace.Example, Assembly", /* ctor sig */ "", /* arguments */ new java.lang.Object[] { p0 } ); Oops! Update the `Signature`/`SignatureOptions` creation within `JavaCallableWrapperGenerator.cs` so that `ManagedParameters` is set for *all* constructor codepaths. ManagedPeer.construct ( /* self */ this, /* aqn */ "Namespace.Example, Assembly", /* ctor sig */ "System.Int32, System.Runtime", /* arguments */ new java.lang.Object[] { p0 } ); This appears to fix a long-standing bug/"thinko" in JCW generation!
- Loading branch information
Showing
9 changed files
with
232 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
16 changes: 16 additions & 0 deletions
16
src/Java.Interop.Export/Java.Interop/JavaCallableConstructorAttribute.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#nullable enable | ||
using System; | ||
|
||
namespace Java.Interop { | ||
|
||
[AttributeUsage (AttributeTargets.Constructor, AllowMultiple=false)] | ||
public sealed class JavaCallableConstructorAttribute : Attribute { | ||
|
||
public JavaCallableConstructorAttribute () | ||
{ | ||
} | ||
|
||
public string? SuperConstructorExpression {get; set;} | ||
public string? Signature {get; set;} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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