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

[Java.Base, generator] Bind all of package java.io #968

Merged
merged 1 commit into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<PackageReference Update="Microsoft.Build.Framework" Version="16.11.0" />
<PackageReference Update="Microsoft.Build.Utilities.Core" Version="16.11.0" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version="3.11.0" />
<PackageReference Update="Microsoft.DotNet.GenAPI" Version="7.0.0-beta.22103.1" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Update="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" />
<PackageReference Update="Mono.CSharp" Version="4.0.0.143" />
Expand Down
5,312 changes: 5,312 additions & 0 deletions src/Java.Base-ref.cs

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/Java.Base/Java.Base.targets
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<GeneratorPath>$(UtilityOutputFullPath)generator.dll</GeneratorPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.DotNet.GenAPI" GeneratePathProperty="true" IncludeAssets="none" />
</ItemGroup>

<Target Name="_GetJavaBaseJmodPath">
<PropertyGroup Condition=" '$(Java11SdkDirectory)' != '' ">
<_JavaBaseJmod>$(Java11SdkDirectory)/jmods/java.base.jmod</_JavaBaseJmod>
Expand Down Expand Up @@ -75,4 +79,17 @@
</PropertyGroup>
</Target>

<Target Name="_GenerateRefApi"
Condition=" '$(PkgMicrosoft_DotNet_GenAPI)' != '' And '$(TargetPath)' != '' "
AfterTargets="Build"
Inputs="$(TargetPath)"
Outputs="..\Java.Base-ref.cs">
<PropertyGroup>
<_GenApi>$(PkgMicrosoft_DotNet_GenAPI)/tools/netcoreapp3.1/Microsoft.DotNet.GenAPI.dll</_GenApi>
<_Output>-o "../Java.Base-ref.cs"</_Output>
<_Libpath>--lib-path "$(OutputPath.TrimEnd('\'))"</_Libpath>
</PropertyGroup>
<Exec Command="$(DotnetToolPath) $(_GenApi) &quot;$(TargetPath)&quot; $(_Libpath) $(_Output)" />
</Target>

</Project>
13 changes: 13 additions & 0 deletions src/Java.Base/Java.IO/PrintStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using Java.Interop;

namespace Java.IO {

public partial class PrintStream : Java.Lang.IAppendable {

Java.Lang.IAppendable? Java.Lang.IAppendable.Append (char p0) => Append (p0);
Java.Lang.IAppendable? Java.Lang.IAppendable.Append (Java.Lang.ICharSequence? p0) => Append (p0);
Java.Lang.IAppendable? Java.Lang.IAppendable.Append (Java.Lang.ICharSequence? p0, int p1, int p2) => Append (p0, p1, p2);
}
}
13 changes: 13 additions & 0 deletions src/Java.Base/Java.IO/Writer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using Java.Interop;

namespace Java.IO {

public partial class Writer : Java.Lang.IAppendable {

Java.Lang.IAppendable? Java.Lang.IAppendable.Append (char p0) => Append (p0);
Java.Lang.IAppendable? Java.Lang.IAppendable.Append (Java.Lang.ICharSequence? p0) => Append (p0);
Java.Lang.IAppendable? Java.Lang.IAppendable.Append (Java.Lang.ICharSequence? p0, int p1, int p2) => Append (p0, p1, p2);
}
}
4 changes: 3 additions & 1 deletion src/Java.Base/Transforms/Metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<metadata>
<!-- For now, just bind java.lang.* -->
<remove-node path="//api/package[not(starts-with(@name, 'java.lang'))]" />
<remove-node path="//api/package[not(starts-with(@name, 'java.lang')
or starts-with(@name, 'java.io')
)]" />

<!-- Type / Namespace conflicts -->
<ns-replace source="java.lang.module" replacement="Java.Lang.Modules" />
Expand Down
7 changes: 6 additions & 1 deletion tools/generator/SourceWriters/BoundFieldAsProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ protected override void WriteSetterBody (CodeWriter writer)
writer.Write ($"\t_members.{indirect}.SetValue (__id{(field.IsStatic ? "" : ", this")}, ");

if (opt.CodeGenerationTarget == CodeGenerationTarget.JavaInterop1) {
writer.WriteLine ($"{(invokeType != "Object" ? arg : $"{arg}?.PeerReference ?? default")});");
if (invokeType != "Object" || have_prep) {
writer.Write (arg);
} else {
writer.Write ($"{arg}?.PeerReference ?? default");
}
writer.WriteLine (");");
} else {
writer.WriteLine ($"{(invokeType != "Object" ? arg : "new JniObjectReference (" + arg + ")")});");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public BoundMethodAbstractDeclaration (GenBase gen, Method method, CodeGeneratio
if (method.DeclaringType.IsGeneratable)
Comments.Add ($"// Metadata.xml XPath method reference: path=\"{method.GetMetadataXPathReference (method.DeclaringType)}\"");

// TODO: shouldn't `[Obsolete]` be added for *all* CodeGenerationTargets?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it would make sense to always prevent that warning. In the real world it's nearly impossible to bind libraries with <TreatWarningsAsErrors>, but it's something we should continue working towards.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpobst: The implicit question here is whether all CodeGenerationTargets should add [Obsolete] to abstract methods, or just CodeGenerationTarget.JavaInterop1.

I opted to only update CodeGenerationTarget.JavaInterop1 for expediency, but I suspect this should be done for everything.

if (opt.CodeGenerationTarget == CodeGenerationTarget.JavaInterop1 && method.Deprecated.HasValue ()) {
Attributes.Add (new ObsoleteAttr (method.Deprecated.Replace ("\"", "\"\"")));
}

SourceWriterExtensions.AddSupportedOSPlatform (Attributes, method, opt);

if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1) {
Expand Down