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

Call tests #21

Merged
merged 854 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
854 commits
Select commit Hold shift + click to select a range
16ed12b
Sonar fixes
josephmoresena May 31, 2024
d3c1085
Sonar fixes
josephmoresena May 31, 2024
a2afea7
Merge branch 'remove_virtuals' into building
josephmoresena May 31, 2024
bf62f22
Merge branch 'main' into building
josephmoresena May 31, 2024
02b1648
Fix GetTypeMetadata
josephmoresena May 31, 2024
1080560
GetTypeMetadata trace
josephmoresena May 31, 2024
525a6af
Update ClassFeature.cs
josephmoresena May 31, 2024
dbfd58c
Sonar fixes
josephmoresena May 31, 2024
51b7155
Merge branch 'main' into building
josephmoresena May 31, 2024
9033bda
FindClass trace improvements
josephmoresena Jun 1, 2024
d4a4694
.
josephmoresena Jun 1, 2024
abec7bc
Remove GetClassNameFixedPointer
josephmoresena Jun 1, 2024
66c78f4
.
josephmoresena Jun 1, 2024
6231448
Incrase frame size
josephmoresena Jun 1, 2024
45b2bf1
Public ObjectMetadata
josephmoresena Jun 1, 2024
f36da87
Generalize internal frame sizes.
josephmoresena Jun 1, 2024
32b1dae
Fix JThrowableObject.ToString()
josephmoresena Jun 1, 2024
3f7559e
GetSuperTypeCapacity
josephmoresena Jun 1, 2024
b38a587
Fix LocalFrame disposing
josephmoresena Jun 2, 2024
b276a22
.
josephmoresena Jun 2, 2024
2178509
Exclude result from frame clear.
josephmoresena Jun 2, 2024
5a09f71
Fix tests
josephmoresena Jun 2, 2024
cea7f3f
Fix CopyTo in JLocalObject
josephmoresena Jun 2, 2024
cbe5159
NullPointerException
josephmoresena Jun 2, 2024
7b9738a
Fix FindClass with Frames
josephmoresena Jun 2, 2024
5fe64b3
Update MetadataHelper.cs
josephmoresena Jun 3, 2024
732f2f8
Sonar fixes
josephmoresena Jun 3, 2024
3ee47be
Fix global reference unloading
josephmoresena Jun 3, 2024
e769f10
Merge branch 'main' into building
josephmoresena Jun 3, 2024
efe80de
Move DeadThread
josephmoresena Jun 3, 2024
0c74d3b
Update DeadThread.cs
josephmoresena Jun 3, 2024
ff03145
Substitute JTrace methods.
josephmoresena Jun 4, 2024
6ded0fb
.
josephmoresena Jun 5, 2024
1d90654
CreateWithValidation
josephmoresena Jun 5, 2024
835922a
.
josephmoresena Jun 5, 2024
4a4996d
Optimize Trimming
josephmoresena Jun 5, 2024
ed9836e
.
josephmoresena Jun 5, 2024
f77af70
Remove unused UTF-16 strings.
josephmoresena Jun 6, 2024
1bbe5a6
.
josephmoresena Jun 6, 2024
2edddfc
.
josephmoresena Jun 6, 2024
26fc40f
Organize Constants
josephmoresena Jun 6, 2024
7f79dcb
ObjectArrayElementHelper
josephmoresena Jun 6, 2024
a9eb6db
Update ObjectArrayElementHelper.cs
josephmoresena Jun 6, 2024
afdc5cb
ClassNameHelper
josephmoresena Jun 7, 2024
0f152be
Switch DisableNestingArrayAutoGeneration
josephmoresena Jun 7, 2024
e2ac904
Remove IReflectionMetadata
josephmoresena Jun 8, 2024
7b3e2fe
Generic ThrowableException as internal
josephmoresena Jun 9, 2024
763beef
Implementation switches
josephmoresena Jun 9, 2024
bc2db4f
GetVoidClass and CheckJniError
josephmoresena Jun 9, 2024
aeb31d4
.
josephmoresena Jun 9, 2024
be30565
Records -> Class
josephmoresena Jun 10, 2024
1535103
Sonar fixes
josephmoresena Jun 10, 2024
b392176
Removing empty interfaces
josephmoresena Jun 11, 2024
c6ee96c
Removing empty interfaces P2
josephmoresena Jun 11, 2024
fe7823c
Removing empty interfaces P3
josephmoresena Jun 11, 2024
e2b642a
Removing empty interfaces P4
josephmoresena Jun 11, 2024
1207fab
Removing empty interfaces P5
josephmoresena Jun 12, 2024
34141df
Update DataTypeTests.cs
josephmoresena Jun 12, 2024
8e6c01a
.
josephmoresena Jun 12, 2024
079c42d
Merge branch 'main' into building
josephmoresena Jun 12, 2024
33073fa
GetClass
josephmoresena Jun 12, 2024
d1da41e
Update ObjectLifetime.cs
josephmoresena Jun 12, 2024
0bc08eb
Fix GetClassInformation
josephmoresena Jun 13, 2024
e1c5f93
Fix Call class
josephmoresena Jun 13, 2024
ebcf866
Sonar fixes
josephmoresena Jun 13, 2024
9a6ebd8
Merge branch 'main' into building
josephmoresena Jun 13, 2024
e2cd078
Merge branch 'main' into building
josephmoresena Jun 13, 2024
7b1be65
Update Rxmxnx.JNetInterface.Base.Intermediate.csproj
josephmoresena Jun 14, 2024
018e152
Update ClassFeature.cs
josephmoresena Jun 14, 2024
ebc13eb
Update Rxmxnx.JNetInterface.Core.csproj
josephmoresena Jun 15, 2024
c46f37b
.
josephmoresena Jun 15, 2024
36f1f31
JNetInterface.DisableTypeMetadataToString Feature
josephmoresena Jun 16, 2024
d3faaa4
JNetInterface.DisableTypeMetadataToString fixes
josephmoresena Jun 16, 2024
1ad35c8
Fix tests
josephmoresena Jun 16, 2024
848727e
Update ClassObjectMetadata.cs
josephmoresena Jun 16, 2024
045dec4
Update DataTypeTests.cs
josephmoresena Jun 16, 2024
6a68f84
JTrace class methods improvements
josephmoresena Jun 16, 2024
6835412
Fixes
josephmoresena Jun 16, 2024
a083b68
Fix call class unloading
josephmoresena Jun 16, 2024
0dad041
Hides
josephmoresena Jun 17, 2024
3d20ea4
Merge branch 'main' into building
josephmoresena Jun 17, 2024
c9a4a15
Merge branch 'main' into building
josephmoresena Jun 18, 2024
d9e05c7
Sample improvements
josephmoresena Jun 21, 2024
e69c6b7
Update ManagedCallback.cs
josephmoresena Jun 21, 2024
d179908
Fix final array call parameter
josephmoresena Jun 21, 2024
d08292a
Int2D array sample
josephmoresena Jun 21, 2024
0a272af
More Exceptions
josephmoresena Jun 21, 2024
425941d
JIllegalAccessExceptionObject
josephmoresena Jun 21, 2024
f425d06
Parameterless
josephmoresena Jun 24, 2024
18756d5
.
josephmoresena Jun 24, 2024
6b53c41
Native memory as class.
josephmoresena Jun 24, 2024
744130a
Update JavaFile.cs
josephmoresena Jun 24, 2024
bdb1344
Update JavaFile.cs
josephmoresena Jun 24, 2024
e384648
Create README.md
josephmoresena Jun 24, 2024
7330dfa
.
josephmoresena Jun 25, 2024
b303e40
Sonar fixes
josephmoresena Jun 25, 2024
56a6c9c
.
josephmoresena Jun 25, 2024
d68c1d2
Merge branch 'main' into building
josephmoresena Jun 25, 2024
7a89cc6
Merge branch 'main' into building
josephmoresena Jun 27, 2024
b7e726e
Initial Implementation Tests
josephmoresena Jun 29, 2024
d062b51
Some improvements
josephmoresena Jun 29, 2024
f1b8f6f
Merge branch 'building' into implementationTests
josephmoresena Jun 29, 2024
24f3fbc
Merge branch 'main' into implementationTests
josephmoresena Jun 29, 2024
2851045
NativeInterfaceProxy
josephmoresena Jun 29, 2024
0efbfa4
GetStringRegionFunction Fixes
josephmoresena Jun 29, 2024
84ec8d8
Merge branch 'building' into implementationTests
josephmoresena Jun 29, 2024
4a90a3e
NativeInterfaceHelper
josephmoresena Jun 30, 2024
530c73b
.
josephmoresena Jun 30, 2024
dac6c84
.
josephmoresena Jun 30, 2024
f888f70
Update ReferenceCache.cs
josephmoresena Jun 30, 2024
3a62eb3
Update JVirtualMachineTests.cs
josephmoresena Jun 30, 2024
4761066
Merge branch 'building' into implementationTests
josephmoresena Jun 30, 2024
89acfb0
Fix field
josephmoresena Jun 30, 2024
40804a0
Fix UnmanagedCallersOnly
josephmoresena Jun 30, 2024
dd6908c
.
josephmoresena Jul 3, 2024
e923acc
.
josephmoresena Jul 3, 2024
eeb85f5
GetVirtualMachineTest
josephmoresena Jul 4, 2024
2cbc2ad
Improvements
josephmoresena Jul 5, 2024
6ef9ee1
JVirtualMachine tests
josephmoresena Jul 6, 2024
4416485
Update JVirtualMachineTests.cs
josephmoresena Jul 6, 2024
a67181c
Update JVirtualMachineTests.cs
josephmoresena Jul 6, 2024
923d943
Update JVirtualMachineTests.cs
josephmoresena Jul 6, 2024
84557b9
Update JVirtualMachineTests.cs
josephmoresena Jul 6, 2024
af0687a
Sonar fix
josephmoresena Jul 6, 2024
bfbd5a3
Fix IThread.Attached
josephmoresena Jul 6, 2024
0b53d35
Implementation fixes
josephmoresena Jul 10, 2024
e3d4285
RegisterTest
josephmoresena Jul 10, 2024
638cbbe
More tests
josephmoresena Jul 10, 2024
7e32693
Avoid VirtualMachine instantiation when removing Environment.
josephmoresena Jul 11, 2024
9191cba
.
josephmoresena Jul 11, 2024
52c35a8
Update IManagedCallback.cs
josephmoresena Jul 11, 2024
a78605d
Update ProxyFactory.cs
josephmoresena Jul 11, 2024
59d45e5
Update ProxyFactory.cs
josephmoresena Jul 11, 2024
f53fc66
Update IManagedCallback.cs
josephmoresena Jul 11, 2024
ac8db34
Avoid calling isPrimitive() for reference type classes.
josephmoresena Jul 11, 2024
b9f15ce
StaticParameterlessCall test
josephmoresena Jul 11, 2024
a2250b1
Update JVirtualMachineTests.cs
josephmoresena Jul 11, 2024
d0d7fa9
Update JVirtualMachineTests.cs
josephmoresena Jul 11, 2024
4fde3ec
Fixes
josephmoresena Jul 11, 2024
f613b50
Agnostic typed instance parameterlessCall test
josephmoresena Jul 11, 2024
150bd80
Fix Implementation tests
josephmoresena Jul 14, 2024
1874c3f
TypedStaticParameterlessCall test
josephmoresena Jul 15, 2024
15e36de
Split JNativeCallAdapterTests
josephmoresena Jul 15, 2024
44a8332
.
josephmoresena Jul 15, 2024
7fdc463
.
josephmoresena Jul 15, 2024
e25f4bf
Simplify CreateInitialObject
josephmoresena Jul 15, 2024
bb0d051
Initial UnknownParametersCallTest
josephmoresena Jul 15, 2024
e2ccfde
Update CallFrame.cs
josephmoresena Jul 15, 2024
c7f8532
CallFrame improvements
josephmoresena Jul 16, 2024
403beeb
GetMainClassGlobalRef
josephmoresena Jul 16, 2024
9bd34e1
Sonar fixes
josephmoresena Jul 16, 2024
3b36edb
Update Private.cs
josephmoresena Jul 16, 2024
ffd42c7
Fix unloading implementation tests
josephmoresena Jul 16, 2024
ae7d31d
.
josephmoresena Jul 16, 2024
530df5c
AllowedThread
josephmoresena Jul 16, 2024
207a63d
Parameters call tests
josephmoresena Jul 16, 2024
e41c411
JNativeCallAdapterTests
josephmoresena Jul 17, 2024
54383d6
LocalFrame tests
josephmoresena Jul 17, 2024
cc88cec
MainClassFail enum
josephmoresena Jul 17, 2024
90d9167
InitializationTest
josephmoresena Jul 19, 2024
c05f1b5
Simplify Environment finalize
josephmoresena Jul 19, 2024
38302d2
UsedStackBytes and UsableStackBytes in IEnvironment
josephmoresena Jul 20, 2024
205750d
WellKnownSuperTypeParameterCal test
josephmoresena Jul 21, 2024
d525582
Sonar fixes
josephmoresena Jul 21, 2024
f7afb13
JFloat exlude operators
josephmoresena Jul 21, 2024
4b3f3ff
JByte exclude operators
josephmoresena Jul 21, 2024
32e8a93
Pre-compute TypeMetadata for array element class.
josephmoresena Jul 22, 2024
a32022f
Exclude primitive operators.
josephmoresena Jul 22, 2024
581e829
DeadThread tests
josephmoresena Jul 23, 2024
5db8a76
Update DeadThreadTests.cs
josephmoresena Jul 23, 2024
d6ede14
Nio tests
josephmoresena Jul 23, 2024
aab4048
Avoid CheckJniError stack overflow.
josephmoresena Jul 23, 2024
ccb63fd
ExceptionHandling initial tests
josephmoresena Jul 23, 2024
2aecd13
ExceptionOccurred test
josephmoresena Jul 26, 2024
874e2eb
.
josephmoresena Jul 26, 2024
2bd7106
.
josephmoresena Jul 26, 2024
b362502
ExceptionOccurred theory test
josephmoresena Jul 27, 2024
e9c2bd2
GetPrimitiveClass and FindPrimitiveClass tests
josephmoresena Jul 27, 2024
a56b947
Optimize GetPrimitiveClass
josephmoresena Jul 28, 2024
78396d6
ClassParse tests
josephmoresena Jul 28, 2024
3f93154
Rxmxnx.JNetInterface.LibraryTest
josephmoresena Jul 28, 2024
899c339
Invocation tests
josephmoresena Jul 28, 2024
fa3f5e1
Update Program.cs
josephmoresena Jul 28, 2024
e339658
NativeMethod test
josephmoresena Jul 28, 2024
8842098
Update ObjectTracker.cs
josephmoresena Jul 28, 2024
b7249be
.
josephmoresena Jul 29, 2024
d2b96bc
.
josephmoresena Aug 1, 2024
f7d3163
Merge branch 'main' into implementationTests
josephmoresena Aug 1, 2024
a172c12
Merge branch 'main' into building
josephmoresena Aug 4, 2024
3a8e947
Fix NativeAOT (NET9.0) compilation
josephmoresena Aug 5, 2024
ddb8053
Merge branch 'main' into building
josephmoresena Aug 5, 2024
8257106
Initial Support
josephmoresena Aug 26, 2024
9ea6cb0
Improvements
josephmoresena Aug 26, 2024
5d78a99
Application in F# and VB
josephmoresena Aug 27, 2024
b9a61b4
Update Rxmxnx.JNetInterface.sln
josephmoresena Aug 27, 2024
0d8398b
Update Packages
josephmoresena Aug 27, 2024
e56f5c2
.
josephmoresena Aug 27, 2024
2a684f0
Update Rxmxnx.JNetInterface.SourceGenerator.csproj
josephmoresena Aug 27, 2024
ac51ce5
Update build.yml
josephmoresena Aug 27, 2024
08ce1f6
Sonar fixes
josephmoresena Aug 27, 2024
df89889
Update JVirtualMachineLibrary.cs
josephmoresena Aug 27, 2024
23912be
Update build.yml
josephmoresena Aug 27, 2024
73e7da0
Update build.yml
josephmoresena Aug 27, 2024
c8556f8
Update build.yml
josephmoresena Aug 27, 2024
f1620bf
Update build.yml
josephmoresena Aug 27, 2024
2424e27
Update build.yml
josephmoresena Aug 27, 2024
80808f6
Update build.yml
josephmoresena Aug 27, 2024
fa3a336
Update build.yml
josephmoresena Aug 27, 2024
93483df
Update build.yml
josephmoresena Aug 27, 2024
cb03c7a
Update build.yml
josephmoresena Aug 27, 2024
d2e73ff
Update build.yml
josephmoresena Aug 27, 2024
7326771
.
josephmoresena Aug 27, 2024
1952899
Update build.yml
josephmoresena Aug 27, 2024
0b8e556
Update build.yml
josephmoresena Aug 27, 2024
4bad436
Update build.yml
josephmoresena Aug 27, 2024
3d5d1e2
Update build.yml
josephmoresena Aug 27, 2024
50414f0
Update build.yml
josephmoresena Aug 27, 2024
d8c6e02
Update build.yml
josephmoresena Aug 27, 2024
db801b3
Update build.yml
josephmoresena Aug 27, 2024
e4a358a
Update IDataType.cs
josephmoresena Aug 27, 2024
9faf771
Uninstantiable improvments
josephmoresena Aug 28, 2024
3deacb8
IDataType<> extending IObject
josephmoresena Aug 28, 2024
3033543
Update PrintMetadataInfo.vb
josephmoresena Aug 28, 2024
200364c
Update PrintMetadataInfo.vb
josephmoresena Aug 28, 2024
40aa317
Update PrintMetadataInfo.vb
josephmoresena Aug 28, 2024
e09c9f8
32 bit support fix
josephmoresena Aug 28, 2024
35152c4
ConsoleTest
josephmoresena Aug 29, 2024
6b715ea
Update build.yml
josephmoresena Aug 29, 2024
5bf96bd
Update Static.cs
josephmoresena Aug 29, 2024
43a8695
MetadataTypeTests
josephmoresena Aug 29, 2024
1b90210
Update MetadataTypeTests.cs
josephmoresena Aug 29, 2024
9267dd8
Fix Memory adapter
josephmoresena Aug 29, 2024
d4810c6
String native chars tests
josephmoresena Aug 29, 2024
f3ded05
Update StringMemoryTests.cs
josephmoresena Aug 29, 2024
af441d2
Primitive array memory test initial
josephmoresena Aug 29, 2024
52aef9b
Update PrimitiveArrayMemoryTests.cs
josephmoresena Aug 29, 2024
2f9001d
Update PrimitiveArrayMemoryTests.cs
josephmoresena Aug 29, 2024
210b9a2
Update Arrays.cs
josephmoresena Aug 29, 2024
77b45a8
Merge branch 'main' into building
josephmoresena Aug 29, 2024
6d557cb
Call tests
josephmoresena Sep 1, 2024
ee734e8
.
josephmoresena Sep 1, 2024
5b12831
Args Span
josephmoresena Sep 2, 2024
5b2e16d
Sonar fixes
josephmoresena Sep 2, 2024
aacba8b
Update ILLink.Substitutions.xml
josephmoresena Sep 2, 2024
d925e40
Constructor Call tests
josephmoresena Sep 3, 2024
3b10eeb
Get/Set field tests
josephmoresena Sep 3, 2024
2e064b9
Throw new tests
josephmoresena Sep 3, 2024
3155601
.
josephmoresena Sep 4, 2024
679891c
README.md for F# and VB
josephmoresena Sep 4, 2024
2bc5f48
Build package at build.yml
josephmoresena Sep 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ jobs:
if ($LastExitCode -ne 0) { exit $LastExitCode }
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
if ($LastExitCode -ne 0) { exit $LastExitCode }

- name: Patch Native ILLink.Substitutions
working-directory: ./src/Intermediate/Rxmxnx.JNetInterface.Native.Intermediate/ILLink
run: sed -i -z 's/Rxmxnx.JNetInterface.Native.Intermediate/Rxmxnx.JNetInterface.Core/g;' ILLink.Substitutions.xml
- name: Patch Implementation ILLink.Substitutions
working-directory: ./src/Intermediate/Rxmxnx.JNetInterface.Implementation.Intermediate/ILLink
run: sed -i -z 's/Rxmxnx.JNetInterface.Implementation.Intermediate/Rxmxnx.JNetInterface/g;' ILLink.Substitutions.xml
- name: Pack core assembly
working-directory: ./package/Rxmxnx.JNetInterface.Core
run: dotnet pack -c Release -o ../Nuget /p:Version=9999.99.99.99-tmp
- name: Pack main assembly
working-directory: ./package/Rxmxnx.JNetInterface
run: dotnet pack -c Release -o ../Nuget /p:Version=9999.99.99.99-tmp

run-linux:
runs-on: ubuntu-latest
Expand Down
285 changes: 285 additions & 0 deletions src/ApplicationTest/Rxmxnx.JNetInterface.FsApplicationTest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
# F# Support

To support the use of `JNetInterface` in F#, it is necessary to explicitly use some constructors and methods that are
not usually required in C# code.

## Primitives
In C#, `JNetInterface` uses operators to convert from one primitive type to another. However, this functionality must
be done explicitly in F# using constructors.

```fsharp
let booleanValue = JBoolean true
let byteValue = JByte -2y
let charValue = JChar '\n'
let doubleValue = JDouble 3.14159265359
let floatValue = JFloat 2.71828f
let intValue = JInt 486
let longValue = JLong 3000000000L
let shortValue = JShort 1024s
```

## Reference Types
To map reference types from Java through `JNetInterface`, it is necessary to create classes (according to the rules
established for each case) that implement the indicated interfaces according to the reference type to be mapped.

Unlike C#, F# does not support virtual implementation of static methods in interfaces, so it may be necessary to
implement homonymous methods according to the `JNetInterface` hierarchy.

### Extensible class (`java.lang.Package`)
```fsharp
type JPackageObject =
inherit JLocalObject

static let typeMetadata =
JLocalObject.TypeMetadataBuilder<JPackageObject>
.Create("java/lang/Package"B)
.Build()

new(initializer: IReferenceType.ClassInitializer) = { inherit JLocalObject(initializer) }
new(initializer: IReferenceType.GlobalInitializer) = { inherit JLocalObject(initializer) }
new(initializer: IReferenceType.ObjectInitializer) = { inherit JLocalObject(initializer) }

interface IDataType<JPackageObject> with
static member get_Metadata() = typeMetadata

interface IReferenceType<JPackageObject> with
static member Create(initializer: IReferenceType.ObjectInitializer) = new JPackageObject(initializer)

interface IClassType<JPackageObject> with
static member get_Metadata() = typeMetadata
static member Create(initializer: IReferenceType.ClassInitializer) = new JPackageObject(initializer)
static member Create(initializer: IReferenceType.GlobalInitializer) = new JPackageObject(initializer)
static member Create(initializer: IReferenceType.ObjectInitializer) = new JPackageObject(initializer)

static member GetPackage(env: IEnvironment, packageName: String) : JPackageObject =
GetPackageDefinition.GetPackage(env, packageName)

and private GetPackageDefinition private () =
inherit JFunctionDefinition<JPackageObject>("getPackage"B, JArgumentMetadata.Get<JStringObject>())

static member val private Instance = GetPackageDefinition() with get

member this.GetPackage(packageName: JStringObject) : JPackageObject =
let env = packageName.Environment
let args = this.CreateArgumentsArray()
let packageClass = JClassObject.GetClass<JPackageObject>(env)
args.[0] <- packageName
this.StaticInvoke(packageClass, args)

static member GetPackage(env: IEnvironment, packageName: String) : JPackageObject =
use jString = JStringObject.Create(env, packageName)
env.WithFrame(3, jString, GetPackageDefinition.Instance.GetPackage)
```

### Non-instantiable class (`java.lang.Math`):
```fsharp
[<Sealed>]
type JMathObject private () =
inherit JLocalObject.Uninstantiable<JMathObject>()

static let typeMetadata =
JLocalObject.TypeMetadataBuilder<JMathObject>.Create("java/lang/Math"B).Build()

static let eDef = JFieldDefinition<JDouble>("E"B)
static let piDef = JFieldDefinition<JDouble>("PI"B)
static let absDef = MathFuncDefinition<JDouble, JDouble>("abs"B)
static let atan2Def = MathFuncDefinition<JDouble, JDouble, JDouble>("atan2"B)

static member GetE(env: IEnvironment) : JDouble = JMathObject.GetField(env, eDef)
static member GetPi(env: IEnvironment) : JDouble = JMathObject.GetField(env, piDef)
static member Abs(env: IEnvironment, value: JDouble) : JDouble = absDef.Invoke(env, value)
static member Atan2(env: IEnvironment, y: JDouble, x: JDouble) : JDouble = atan2Def.Invoke(env, y, x)

interface IDataType<JMathObject> with
static member get_Metadata() = typeMetadata

interface IReferenceType<JMathObject> with
static member Create(initializer: IReferenceType.ObjectInitializer) =
IUninstantiableType.ThrowInstantiation<JMathObject>()

interface IUninstantiableType<JMathObject> with
static member get_Metadata() = typeMetadata

static member Create(initializer: IReferenceType.ClassInitializer) =
IUninstantiableType.ThrowInstantiation<JMathObject>()

static member Create(initializer: IReferenceType.GlobalInitializer) =
IUninstantiableType.ThrowInstantiation<JMathObject>()

static member Create(initializer: IReferenceType.ObjectInitializer) =
IUninstantiableType.ThrowInstantiation<JMathObject>()

static member private GetField<'T
when 'T: unmanaged and 'T :> IPrimitiveType<'T> and 'T: (new: unit -> 'T) and 'T :> ValueType>
(
env: IEnvironment,
field: JFieldDefinition<'T>
) : 'T =
let state = { Environment = env; Def = field }
env.WithFrame(2, state, JMathObject.GetField<'T>)

static member private GetField<'T
when 'T: unmanaged and 'T :> IPrimitiveType<'T> and 'T: (new: unit -> 'T) and 'T :> ValueType>
(state: FieldState<'T>)
: 'T =
let mathClass = JClassObject.GetClass<JMathObject>(state.Environment)
state.Def.StaticGet(mathClass)

and [<Struct>] FieldState<'T
when 'T: struct and 'T :> IPrimitiveType<'T> and 'T: unmanaged and 'T: (new: unit -> 'T) and 'T :> ValueType> =
{ Environment: IEnvironment
Def: JFieldDefinition<'T> }

and private MathFuncDefinition<'TF, 'TX when 'TF :> IDataType<'TF> and 'TX :> IDataType<'TX>>
(funcName: ReadOnlySpan<byte>) =
inherit JFunctionDefinition<'TF>(funcName, JArgumentMetadata.Get<'TX>())

member this.Invoke(env: IEnvironment, x: 'TX) : 'TF =
let state = { Environment = env; Def = this; X = x }
env.WithFrame(2, state, MathFuncDefinition<'TF, 'TX>.Invoke)

static member Invoke(state: State<'TF, 'TX>) : 'TF =
let mathClass = JClassObject.GetClass<JMathObject>(state.Environment)
let args = state.Def.CreateArgumentsArray()
args.[0] <- state.X :> IObject
state.Def.StaticInvoke(mathClass, args)

and [<Struct>] private State<'TF, 'TX when 'TF :> IDataType<'TF> and 'TX :> IDataType<'TX>> =
{ Environment: IEnvironment
Def: MathFuncDefinition<'TF, 'TX>
X: 'TX }

and private MathFuncDefinition<'TF, 'TX, 'TY
when 'TF :> IDataType<'TF> and 'TX :> IDataType<'TX> and 'TY :> IDataType<'TY>>(funcName: ReadOnlySpan<byte>) =
inherit JFunctionDefinition<'TF>(funcName, JArgumentMetadata.Get<'TX>(), JArgumentMetadata.Get<'TY>())

member this.Invoke(env: IEnvironment, x: 'TX, y: 'TY) : 'TF =
let state =
{ Environment = env
Def = this
X = x
Y = y }

env.WithFrame(2, state, MathFuncDefinition<'TF, 'TX, 'TY>.Invoke)

static member Invoke(state: State<'TF, 'TX, 'TY>) : 'TF =
let mathClass = JClassObject.GetClass<JMathObject>(state.Environment)
let args = state.Def.CreateArgumentsArray()
args.[0] <- state.X :> IObject
args.[1] <- state.Y :> IObject
state.Def.StaticInvoke(mathClass, args)

and [<Struct>] private State<'TF, 'TX, 'TY
when 'TF :> IDataType<'TF> and 'TX :> IDataType<'TX> and 'TY :> IDataType<'TY>> =
{ Environment: IEnvironment
Def: MathFuncDefinition<'TF, 'TX, 'TY>
X: 'TX
Y: 'TY }
```

### Throwable class (`java.lang.CloneNotSupportedException`):
```fsharp
type JCloneNotSupportedExceptionObject =
inherit JExceptionObject
static let typeMetadata =
JThrowableObject.TypeMetadataBuilder<JExceptionObject>
.Create<JCloneNotSupportedExceptionObject>("java/lang/CloneNotSupportedException"B)
.Build()

new(initializer: IReferenceType.ClassInitializer) = { inherit JExceptionObject(initializer) }
new(initializer: IReferenceType.GlobalInitializer) = { inherit JExceptionObject(initializer) }
new(initializer: IReferenceType.ObjectInitializer) = { inherit JExceptionObject(initializer) }

interface IDataType<JCloneNotSupportedExceptionObject> with
static member get_Metadata() = typeMetadata

interface IReferenceType<JCloneNotSupportedExceptionObject> with
static member Create(initializer: IReferenceType.ObjectInitializer) = new JCloneNotSupportedExceptionObject(initializer)

interface IClassType<JCloneNotSupportedExceptionObject> with
static member get_Metadata() = typeMetadata
static member Create(initializer: IReferenceType.ClassInitializer) = new JCloneNotSupportedExceptionObject(initializer)
static member Create(initializer: IReferenceType.GlobalInitializer) = new JCloneNotSupportedExceptionObject(initializer)
static member Create(initializer: IReferenceType.ObjectInitializer) = new JCloneNotSupportedExceptionObject(initializer)

interface IThrowableType<JCloneNotSupportedExceptionObject> with
static member get_Metadata() = typeMetadata
```

### Enum class (`java.lang.Thread.State`):
Note that in this case, the enum values were not declared. However, this functionality is supported in F#.

```fsharp
[<Sealed>]
type JThreadStateObject =
inherit JEnumObject<JThreadStateObject>

static let typeMetadata =
JEnumObject.TypeMetadataBuilder<JThreadStateObject>
.Create("java/lang/Thread$State"B)
.Build()

new(initializer: IReferenceType.ClassInitializer) = { inherit JEnumObject<JThreadStateObject>(initializer) }
new(initializer: IReferenceType.GlobalInitializer) = { inherit JEnumObject<JThreadStateObject>(initializer) }
new(initializer: IReferenceType.ObjectInitializer) = { inherit JEnumObject<JThreadStateObject>(initializer) }

interface IDataType<JThreadStateObject> with
static member get_Metadata() = typeMetadata

interface IReferenceType<JThreadStateObject> with
static member Create(initializer: IReferenceType.ObjectInitializer) = new JThreadStateObject(initializer)

interface IEnumType<JThreadStateObject> with
static member get_Metadata() = typeMetadata
static member Create(initializer: IReferenceType.ClassInitializer) = new JThreadStateObject(initializer)
static member Create(initializer: IReferenceType.GlobalInitializer) = new JThreadStateObject(initializer)
static member Create(initializer: IReferenceType.ObjectInitializer) = new JThreadStateObject(initializer)
```

### Interface type (`java.lang.AutoCloseable`):
```fsharp
[<Sealed>]
type JAutoCloseableObject =
inherit JInterfaceObject<JAutoCloseableObject>

static let typeMetadata =
JInterfaceObject.TypeMetadataBuilder<JAutoCloseableObject>
.Create("java/lang/AutoCloseable"B)
.Build()

new(initializer: IReferenceType.ObjectInitializer) = { inherit JInterfaceObject<JAutoCloseableObject>(initializer) }

interface IDataType<JAutoCloseableObject> with
static member get_Metadata() = typeMetadata

interface IReferenceType<JAutoCloseableObject> with
static member Create(initializer: IReferenceType.ObjectInitializer) = new JAutoCloseableObject(initializer)

interface IInterfaceType<JAutoCloseableObject> with
static member get_Metadata() = typeMetadata
static member Create(initializer: IReferenceType.ObjectInitializer) = new JAutoCloseableObject(initializer)
```

### Annotation type (`java.lang.Deprecated`):
```fsharp
[<Sealed>]
type JDeprecatedObject =
inherit JAnnotationObject<JDeprecatedObject>

static let typeMetadata =
JInterfaceObject.TypeMetadataBuilder<JDeprecatedObject>
.Create("java/lang/Deprecated"B)
.Build()

new(initializer: IReferenceType.ObjectInitializer) = { inherit JAnnotationObject<JDeprecatedObject>(initializer) }

interface IDataType<JDeprecatedObject> with
static member get_Metadata() = typeMetadata

interface IReferenceType<JDeprecatedObject> with
static member Create(initializer: IReferenceType.ObjectInitializer) = new JDeprecatedObject(initializer)

interface IInterfaceType<JDeprecatedObject> with
static member get_Metadata() = typeMetadata
static member Create(initializer: IReferenceType.ObjectInitializer) = new JDeprecatedObject(initializer)
```
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,5 @@ public class GetObjectDefinition : JFunctionDefinition<JLocalObject>
private GetObjectDefinition() : base("getObject"u8, JArgumentMetadata.Get<JInt>()) { }

public JLocalObject? Invoke(JClassObject helloDotnetClass, JInt value)
{
IObject?[] invokeArgs = this.CreateArgumentsArray();
invokeArgs[0] = value;
return this.StaticInvoke(helloDotnetClass, invokeArgs);
}
=> this.StaticInvoke(helloDotnetClass, [value,]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Visual Basic .NET Support

`JNetInterface` is partially compatible with Visual Basic .NET because the latter does not support many of the modern
.NET features such as ref structs and static members in interfaces.

Thus, any application or library in Visual Basic .NET can use the APIs and types exposed in `JNetInterface` (or in F#
or C# assemblies derived from it), but it will not be able to create Java reference types as in C# or F#.

## Primitives
In C#, `JNetInterface` uses operators to convert from one primitive type to another. In Visual Basic .NET, `widening` can be used natively, but to use `narrowing` (which is implemented in C# through explicit operators), you must use the functions `CBool`, `CSByte`, `CChar`, `CDbl`, `CSng`, `CInt`, `CLng`, and `CShort` on the `Value` property of each primitive type.

```vb
Dim booleanValue As JBoolean = True
Dim byteValue As JByte = CSByte(-2)
Dim charValue As JChar = "."C
Dim doubleValue As JDouble = 3.14159265359
Dim floatValue As JFloat = 2.71828F
Dim intValue As JInt = 486
Dim longValue As JLong = 3000000000L
Dim shortValue As JShort = 1024S
```
10 changes: 10 additions & 0 deletions src/Intermediate/Rxmxnx.JNetInterface.Base.Intermediate/IObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@ internal void CopyTo(Span<Byte> span)
/// <param name="span">Binary span.</param>
/// <param name="index">Index to copy current value.</param>
internal void CopyTo(Span<JValue> span, Int32 index);
/// <summary>
/// Indicates current instance is default value.
/// </summary>
/// <returns><see langword="true"/> if current instance is default; otherwise, <see langword="false"/>.</returns>
internal Boolean IsDefault()
{
Span<Byte> values = stackalloc Byte[JValue.Size];
this.CopyTo(values);
return values.SequenceEqual(NativeUtilities.AsBytes(in JValue.Empty));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ public abstract partial class JCallDefinition
/// </summary>
/// <param name="name">Call defined name.</param>
/// <param name="metadata">Metadata of the types of call arguments.</param>
private protected JCallDefinition(ReadOnlySpan<Byte> name, params JArgumentMetadata[] metadata) : this(
name, stackalloc Byte[1] { CommonNames.VoidSignatureChar, }, metadata) { }
private protected JCallDefinition(ReadOnlySpan<Byte> name, ReadOnlySpan<JArgumentMetadata> metadata = default) :
this(name, [CommonNames.VoidSignatureChar,], metadata) { }
/// <summary>
/// Internal constructor.
/// </summary>
/// <param name="name">Call defined name.</param>
/// <param name="returnTypeSignature">Method return type defined signature.</param>
/// <param name="metadata">Metadata of the types of call arguments.</param>
private protected JCallDefinition(ReadOnlySpan<Byte> name, ReadOnlySpan<Byte> returnTypeSignature,
params JArgumentMetadata[] metadata) : base(new CStringSequence(
name,
JCallDefinition.CreateDescriptor(
returnTypeSignature, out Int32 size, out Int32[] sizes,
out Int32 referenceCount, metadata)))
ReadOnlySpan<JArgumentMetadata> metadata) : base(new CStringSequence(
name,
JCallDefinition.CreateDescriptor(
returnTypeSignature, out Int32 size, out Int32[] sizes,
out Int32 referenceCount, metadata)))
{
this._callSize = size;
this._sizes = sizes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract partial class JCallDefinition
/// <param name="metadata">Metadata of the types of call arguments.</param>
/// <returns>Method descriptor.</returns>
private static CString CreateDescriptor(ReadOnlySpan<Byte> returnSignature, out Int32 totalSize, out Int32[] sizes,
out Int32 referenceCount, params JArgumentMetadata[] metadata)
out Int32 referenceCount, ReadOnlySpan<JArgumentMetadata> metadata)
{
referenceCount = 0;
totalSize = 0;
Expand Down
Loading
Loading