From 0dc105c8aae68f8e62d043bade7b2fb03682a08e Mon Sep 17 00:00:00 2001 From: Simon Rozsival Date: Fri, 4 Sep 2026 12:29:41 +0200 Subject: [PATCH] Remove IntDefinitionAttribute and the dead javadoc-to-mdoc tool This is an experimental, intentionally breaking change proposed as a draft PR for feedback, not a change intended to merge as-is. IntDefinitionAttribute ----------------------- `Android.Runtime.IntDefinitionAttribute` was applied by the generator to every enum member (11,243 applications across Mono.Android API-37) to record the originating Java field name/managed member name for the sole purpose of feeding a legacy javadoc-to-mdoc enum-mapping importer. That importer is not part of any build in this repo (see below), so the attribute has no remaining in-tree consumer: * BindingStudio does not read it; it consumes api.xml/map.csv/methodmap.csv. * The modern docs pipeline (`_RunMdoc`/`UpdateExternalDocumentation` in Mono.Android.targets) shells out to the external `mdoc.exe`/`mdoc.dll` tool and never touches this attribute. * Trimmed apps already strip every instance of it via ILLink.LinkAttributes.xml's `RemoveAttributeInstances`, so this mainly benefits reference assemblies, NuGet package size, and non-trimmed (library/Debug) consumption. Changes: * Delete `Android.Runtime.IntDefinitionAttribute` and its PublicAPI entries (marked `*REMOVED*` in every active API level's PublicAPI.Unshipped.txt, following repo convention). * Stop the generator (EnumGenerator.cs) from emitting `[IntDefinition]`; remove the now-dead `IntDefinitionAttr` SourceWriter, its support fixture, and update generator test baselines (489/489 generator-Tests pass). * Remove the one hand-authored usage (VibrationEffectEffectType), preserving the enum values themselves. * Remove the now-moot ILLink.LinkAttributes.xml entry for the type. Measured impact (API-37, this machine, before/after, generator rebuilt for each side): * Debug: runtime -1,399,296 bytes, ref -1,399,296 bytes * Release: runtime -1,398,784 bytes, ref -1,398,784 bytes * CustomAttribute table: exactly 11,243 IntDefinitionAttribute rows removed in every configuration (plus ~7-11 additional CA rows from attributes on the deleted type/members themselves). * #Blob heap: ~1,263,300 bytes smaller in every configuration, closely matching the prior estimate of 1,263,277 bytes. * TypeDef -1, MethodDef -5 (the attribute class + its 5 members). * `dotnet build` ApiCompat against the committed tests/api-compatibility reference assembly (10,095 attribute usages in the recorded contract) now reports exactly the expected break: `TypesMustExist: Type 'Android.Runtime.IntDefinitionAttribute' does not exist in the implementation but it does exist in the contract`, Total Issues: 1. This is intentionally NOT suppressed via the acceptable-breakages file so CI surfaces it for review. * GeneratedEnumAttribute is untouched (separate file, separate SourceWriter/CecilApiImporter path) and generated enums are otherwise unaffected. Old/pre-compiled bindings that reference the removed attribute type will continue to compile, load, and run normally for all code that does not reflect over it; standard CLR semantics mean only reflection calls that enumerate custom attributes on members decorated with IntDefinitionAttribute (e.g. `GetCustomAttributes()`) will fail once the type is gone, since attribute type resolution happens lazily at the point of reflection. This is the accepted breaking-change surface for this draft. javadoc-to-mdoc / JavadocImporter ----------------------------------- `src/Xamarin.Android.Tools.JavadocImporter/` (javadoc-to-mdoc.cs and support files) and `tools/javadoc2mdoc/` (its console driver) are not referenced by any .slnx/.sln in this repo -- grepping Xamarin.Android.slnx, Xamarin.Android.Build.Tasks.slnx, and Xamarin.Android-Tests.slnx for "javadoc" returns zero matches, so neither project is part of the current build graph. The MSBuild flag that would route to it, `_UseLegacyJavadocImport`, is never set to `true` anywhere in-repo, so its only consumer (`Xamarin.Android.Tasks.ImportJavaDoc`, invoked from Xamarin.Android.Bindings.Documentation.targets' `BuildDocumentation` target) was already unreachable dead code before this change. No CI workflow, Makefile target, or doc references the tool either. Changes: * Delete `src/Xamarin.Android.Tools.JavadocImporter/` and `tools/javadoc2mdoc/` entirely (16 files; no .csproj/.slnx changes needed since neither was referenced anywhere). * Remove the `JavadocToMdocToolExe` property (Xamarin.Android.Bindings.Core.targets) and the dead `ImportJavaDoc` MSBuild task invocation + UsingTask declaration (Xamarin.Android.Bindings.Documentation.targets), plus the now-unused `ImportJavaDoc.cs` task class in Xamarin.Android.Build.Tasks. * Left `JavaDoc`/`MDoc` tasks, `_ExtractJavaDocJars`, `_GenerateJavaDocFromSourceJars`, and the `JavaDocJar`/`JavaSourceJar` item groups untouched: these wrap the JDK's own `javadoc` tool and the external `mdoc.exe`, are unrelated to the deleted javadoc-to-mdoc.cs tool, and remain part of the (still-gated, unrelated) legacy binding-project doc-extraction infrastructure -- out of scope for this change. * Left the already-`[Obsolete("Do not use.")]` `Xamarin.AndroidTools.MonoDroidSdk.JavaDocToMDocExe` string constant untouched (different assembly, already marked dead by a prior maintainer, no project dependency). * Confirmed via full-repo search that the only remaining references to IntDefinitionAttribute/JavadocImporter/javadoc-to-mdoc are in `bin/` build output (gitignored) and the `external/android-api-docs` submodule's already-published historical docs (out of scope, a separate repo/history). Validated with: * `dotnet test external/Java.Interop/tests/generator-Tests/generator-Tests.csproj` -> 489/489 passed. * `dotnet build src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj` (which pulls in Mono.Android) -> 0 errors with `-p:DisableApiCompatibilityCheck=True`; without it, exactly the expected single ApiCompat TypesMustExist finding. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../SupportFiles/IntDefinitionAttribute.cs | 17 - .../JavaInterop1/WriteCtorDeprecated.txt | 1 - .../WriteCtorDeprecated.txt | 1 - .../XAJavaInterop1/WriteCtorDeprecated.txt | 1 - .../WriteBasicEnum.txt | 2 - .../WriteEnumWithGens.txt | 2 - .../WriteFlagsEnum.txt | 2 - .../EnumGenerator.cs | 11 - .../Attributes/IntDefinitionAttr.cs | 23 - .../Android.OS/VibrationEffectEffectType.cs | 4 - .../Android.Runtime/IntDefinitionAttribute.cs | 17 - .../ILLink/ILLink.LinkAttributes.xml | 3 - src/Mono.Android/Mono.Android.csproj | 1 - .../PublicAPI/API-35/PublicAPI.Shipped.txt | 6 - .../PublicAPI/API-35/PublicAPI.Unshipped.txt | 6 + .../PublicAPI/API-36.1/PublicAPI.Shipped.txt | 6 - .../API-36.1/PublicAPI.Unshipped.txt | 6 + .../PublicAPI/API-36/PublicAPI.Shipped.txt | 6 - .../PublicAPI/API-36/PublicAPI.Unshipped.txt | 6 + .../PublicAPI/API-37.1/PublicAPI.Shipped.txt | 6 - .../API-37.1/PublicAPI.Unshipped.txt | 6 + .../PublicAPI/API-37.2/PublicAPI.Shipped.txt | 6 - .../API-37.2/PublicAPI.Unshipped.txt | 6 + .../PublicAPI/API-37/PublicAPI.Shipped.txt | 6 - .../PublicAPI/API-37/PublicAPI.Unshipped.txt | 6 + .../Xamarin.Android.Bindings.Core.targets | 1 - ...rin.Android.Bindings.Documentation.targets | 12 - .../Tasks/ImportJavaDoc.cs | 55 -- .../Xamarin.Android.Build.Tasks.csproj | 3 - .../CustomAttributeExtensions.cs | 49 - .../DocumentElement.cs | 413 --------- .../DocumentSection.cs | 483 ---------- .../HTMLlat1.ent | 194 ---- .../HTMLspecial.ent | 77 -- .../HTMLsymbol.ent | 241 ----- .../HtmlLoader.cs | 253 ----- .../Logger.cs | 80 -- .../MdocHelper.cs | 311 ------- .../MyClass.cs | 10 - .../TypeUtilities.cs | 69 -- ...marin.Android.Tools.JavadocImporter.csproj | 57 -- .../javadoc-to-mdoc.cs | 613 ------------ .../samples.cs | 240 ----- .../strict.dtd | 870 ------------------ tools/javadoc2mdoc/Driver.cs | 142 --- tools/javadoc2mdoc/javadoc2mdoc.csproj | 16 - 46 files changed, 36 insertions(+), 4310 deletions(-) delete mode 100644 external/Java.Interop/tests/generator-Tests/SupportFiles/IntDefinitionAttribute.cs delete mode 100644 external/Java.Interop/tools/generator/SourceWriters/Attributes/IntDefinitionAttr.cs delete mode 100644 src/Mono.Android/Android.Runtime/IntDefinitionAttribute.cs delete mode 100644 src/Xamarin.Android.Build.Tasks/Tasks/ImportJavaDoc.cs delete mode 100644 src/Xamarin.Android.Tools.JavadocImporter/CustomAttributeExtensions.cs delete mode 100644 src/Xamarin.Android.Tools.JavadocImporter/DocumentElement.cs delete mode 100644 src/Xamarin.Android.Tools.JavadocImporter/DocumentSection.cs delete mode 100644 src/Xamarin.Android.Tools.JavadocImporter/HTMLlat1.ent delete mode 100644 src/Xamarin.Android.Tools.JavadocImporter/HTMLspecial.ent delete mode 100644 src/Xamarin.Android.Tools.JavadocImporter/HTMLsymbol.ent delete mode 100644 src/Xamarin.Android.Tools.JavadocImporter/HtmlLoader.cs delete mode 100644 src/Xamarin.Android.Tools.JavadocImporter/Logger.cs delete mode 100644 src/Xamarin.Android.Tools.JavadocImporter/MdocHelper.cs delete mode 100644 src/Xamarin.Android.Tools.JavadocImporter/MyClass.cs delete mode 100644 src/Xamarin.Android.Tools.JavadocImporter/TypeUtilities.cs delete mode 100644 src/Xamarin.Android.Tools.JavadocImporter/Xamarin.Android.Tools.JavadocImporter.csproj delete mode 100644 src/Xamarin.Android.Tools.JavadocImporter/javadoc-to-mdoc.cs delete mode 100644 src/Xamarin.Android.Tools.JavadocImporter/samples.cs delete mode 100644 src/Xamarin.Android.Tools.JavadocImporter/strict.dtd delete mode 100644 tools/javadoc2mdoc/Driver.cs delete mode 100644 tools/javadoc2mdoc/javadoc2mdoc.csproj diff --git a/external/Java.Interop/tests/generator-Tests/SupportFiles/IntDefinitionAttribute.cs b/external/Java.Interop/tests/generator-Tests/SupportFiles/IntDefinitionAttribute.cs deleted file mode 100644 index 8249751a3f3..00000000000 --- a/external/Java.Interop/tests/generator-Tests/SupportFiles/IntDefinitionAttribute.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; - -namespace Android.Runtime -{ - [AttributeUsage (AttributeTargets.Field)] - public class IntDefinitionAttribute : Attribute - { - public IntDefinitionAttribute (string constantMember) - { - ConstantMember = constantMember; - } - - public string ConstantMember { get; set; } - public string JniField { get; set; } - } -} - diff --git a/external/Java.Interop/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteCtorDeprecated.txt b/external/Java.Interop/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteCtorDeprecated.txt index 159077c9b6b..954d3e6b91c 100644 --- a/external/Java.Interop/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteCtorDeprecated.txt +++ b/external/Java.Interop/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteCtorDeprecated.txt @@ -2,7 +2,6 @@ [Register (".ctor", "", "")] [Obsolete (@"This constructor is obsolete")] [MyAttribute] -[global::Android.Runtime.IntDefinition (null, JniField = "xamarin/test/SomeObject.SOME_VALUE")] unsafe Object () : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) { diff --git a/external/Java.Interop/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteCtorDeprecated.txt b/external/Java.Interop/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteCtorDeprecated.txt index 159077c9b6b..954d3e6b91c 100644 --- a/external/Java.Interop/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteCtorDeprecated.txt +++ b/external/Java.Interop/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteCtorDeprecated.txt @@ -2,7 +2,6 @@ [Register (".ctor", "", "")] [Obsolete (@"This constructor is obsolete")] [MyAttribute] -[global::Android.Runtime.IntDefinition (null, JniField = "xamarin/test/SomeObject.SOME_VALUE")] unsafe Object () : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) { diff --git a/external/Java.Interop/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteCtorDeprecated.txt b/external/Java.Interop/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteCtorDeprecated.txt index 159077c9b6b..954d3e6b91c 100644 --- a/external/Java.Interop/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteCtorDeprecated.txt +++ b/external/Java.Interop/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteCtorDeprecated.txt @@ -2,7 +2,6 @@ [Register (".ctor", "", "")] [Obsolete (@"This constructor is obsolete")] [MyAttribute] -[global::Android.Runtime.IntDefinition (null, JniField = "xamarin/test/SomeObject.SOME_VALUE")] unsafe Object () : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) { diff --git a/external/Java.Interop/tests/generator-Tests/Unit-Tests/EnumGeneratorExpectedResults/WriteBasicEnum.txt b/external/Java.Interop/tests/generator-Tests/Unit-Tests/EnumGeneratorExpectedResults/WriteBasicEnum.txt index 7ec7750b80e..d9449243498 100644 --- a/external/Java.Interop/tests/generator-Tests/Unit-Tests/EnumGeneratorExpectedResults/WriteBasicEnum.txt +++ b/external/Java.Interop/tests/generator-Tests/Unit-Tests/EnumGeneratorExpectedResults/WriteBasicEnum.txt @@ -2,11 +2,9 @@ namespace Android.App { public enum RecentTaskFlags { - [global::Android.Runtime.IntDefinition (null, JniField = "android/app/ActivityManager.RECENT_IGNORE_UNAVAILABLE")] [global::System.Runtime.Versioning.SupportedOSPlatformAttribute ("android30.0")] WithExcluded = 1, - [global::Android.Runtime.IntDefinition (null, JniField = "android/app/ActivityManager.RECENT_WITH_EXCLUDED")] IgnoreUnavailable = 2, } diff --git a/external/Java.Interop/tests/generator-Tests/Unit-Tests/EnumGeneratorExpectedResults/WriteEnumWithGens.txt b/external/Java.Interop/tests/generator-Tests/Unit-Tests/EnumGeneratorExpectedResults/WriteEnumWithGens.txt index 5d437326f07..d9449243498 100644 --- a/external/Java.Interop/tests/generator-Tests/Unit-Tests/EnumGeneratorExpectedResults/WriteEnumWithGens.txt +++ b/external/Java.Interop/tests/generator-Tests/Unit-Tests/EnumGeneratorExpectedResults/WriteEnumWithGens.txt @@ -2,11 +2,9 @@ namespace Android.App { public enum RecentTaskFlags { - [global::Android.Runtime.IntDefinition ("android.app.ActivityManager.RECENT_IGNORE_UNAVAILABLE", JniField = "android/app/ActivityManager.RECENT_IGNORE_UNAVAILABLE")] [global::System.Runtime.Versioning.SupportedOSPlatformAttribute ("android30.0")] WithExcluded = 1, - [global::Android.Runtime.IntDefinition (null, JniField = "android/app/ActivityManager.RECENT_WITH_EXCLUDED")] IgnoreUnavailable = 2, } diff --git a/external/Java.Interop/tests/generator-Tests/Unit-Tests/EnumGeneratorExpectedResults/WriteFlagsEnum.txt b/external/Java.Interop/tests/generator-Tests/Unit-Tests/EnumGeneratorExpectedResults/WriteFlagsEnum.txt index 6f6bbc154ee..95d45994f75 100644 --- a/external/Java.Interop/tests/generator-Tests/Unit-Tests/EnumGeneratorExpectedResults/WriteFlagsEnum.txt +++ b/external/Java.Interop/tests/generator-Tests/Unit-Tests/EnumGeneratorExpectedResults/WriteFlagsEnum.txt @@ -3,11 +3,9 @@ namespace Android.App [System.Flags] public enum RecentTaskFlags { - [global::Android.Runtime.IntDefinition (null, JniField = "android/app/ActivityManager.RECENT_IGNORE_UNAVAILABLE")] [global::System.Runtime.Versioning.SupportedOSPlatformAttribute ("android30.0")] WithExcluded = 1, - [global::Android.Runtime.IntDefinition (null, JniField = "android/app/ActivityManager.RECENT_WITH_EXCLUDED")] IgnoreUnavailable = 2, } diff --git a/external/Java.Interop/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/EnumGenerator.cs b/external/Java.Interop/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/EnumGenerator.cs index 16a9f6e069b..4d4f502fd9e 100644 --- a/external/Java.Interop/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/EnumGenerator.cs +++ b/external/Java.Interop/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/EnumGenerator.cs @@ -7,8 +7,6 @@ using Xamarin.SourceWriter; using static MonoDroid.Generation.EnumMappings; -using CodeGenerationTarget = Xamarin.Android.Binder.CodeGenerationTarget; - namespace MonoDroid.Generation { class EnumGenerator @@ -52,10 +50,6 @@ EnumWriter CreateWriter (CodeGenerationOptions opt, KeyValuePair - - - diff --git a/src/Mono.Android/Mono.Android.csproj b/src/Mono.Android/Mono.Android.csproj index a8b5764cad1..7dca7555bfb 100644 --- a/src/Mono.Android/Mono.Android.csproj +++ b/src/Mono.Android/Mono.Android.csproj @@ -236,7 +236,6 @@ - diff --git a/src/Mono.Android/PublicAPI/API-35/PublicAPI.Shipped.txt b/src/Mono.Android/PublicAPI/API-35/PublicAPI.Shipped.txt index 51b11d6abcc..e69297ed61e 100644 --- a/src/Mono.Android/PublicAPI/API-35/PublicAPI.Shipped.txt +++ b/src/Mono.Android/PublicAPI/API-35/PublicAPI.Shipped.txt @@ -29693,12 +29693,6 @@ Android.Runtime.IntDefAttribute.Flag.set -> void Android.Runtime.IntDefAttribute.IntDefAttribute() -> void Android.Runtime.IntDefAttribute.Type.get -> string? Android.Runtime.IntDefAttribute.Type.set -> void -Android.Runtime.IntDefinitionAttribute -Android.Runtime.IntDefinitionAttribute.ConstantMember.get -> string? -Android.Runtime.IntDefinitionAttribute.ConstantMember.set -> void -Android.Runtime.IntDefinitionAttribute.IntDefinitionAttribute(string? constantMember) -> void -Android.Runtime.IntDefinitionAttribute.JniField.get -> string? -Android.Runtime.IntDefinitionAttribute.JniField.set -> void Android.Runtime.JavaArray Android.Runtime.JavaArray.Add(T item) -> void Android.Runtime.JavaArray.Clear() -> void diff --git a/src/Mono.Android/PublicAPI/API-35/PublicAPI.Unshipped.txt b/src/Mono.Android/PublicAPI/API-35/PublicAPI.Unshipped.txt index 96701c76f82..200520703e6 100644 --- a/src/Mono.Android/PublicAPI/API-35/PublicAPI.Unshipped.txt +++ b/src/Mono.Android/PublicAPI/API-35/PublicAPI.Unshipped.txt @@ -27,3 +27,9 @@ REMOVED virtual Xamarin.Android.Net.AndroidClientHandler.WriteRequestContentToOu Android.App.ApplicationAttribute.EnableOnBackInvokedCallback.get -> bool Android.App.ApplicationAttribute.EnableOnBackInvokedCallback.set -> void Java.Interop.BaseExportAttribute +*REMOVED*Android.Runtime.IntDefinitionAttribute +*REMOVED*Android.Runtime.IntDefinitionAttribute.ConstantMember.get -> string? +*REMOVED*Android.Runtime.IntDefinitionAttribute.ConstantMember.set -> void +*REMOVED*Android.Runtime.IntDefinitionAttribute.IntDefinitionAttribute(string? constantMember) -> void +*REMOVED*Android.Runtime.IntDefinitionAttribute.JniField.get -> string? +*REMOVED*Android.Runtime.IntDefinitionAttribute.JniField.set -> void diff --git a/src/Mono.Android/PublicAPI/API-36.1/PublicAPI.Shipped.txt b/src/Mono.Android/PublicAPI/API-36.1/PublicAPI.Shipped.txt index 787ea1db79d..3d525a42e82 100644 --- a/src/Mono.Android/PublicAPI/API-36.1/PublicAPI.Shipped.txt +++ b/src/Mono.Android/PublicAPI/API-36.1/PublicAPI.Shipped.txt @@ -31665,12 +31665,6 @@ Android.Runtime.IntDefAttribute.Flag.set -> void Android.Runtime.IntDefAttribute.IntDefAttribute() -> void Android.Runtime.IntDefAttribute.Type.get -> string? Android.Runtime.IntDefAttribute.Type.set -> void -Android.Runtime.IntDefinitionAttribute -Android.Runtime.IntDefinitionAttribute.ConstantMember.get -> string? -Android.Runtime.IntDefinitionAttribute.ConstantMember.set -> void -Android.Runtime.IntDefinitionAttribute.IntDefinitionAttribute(string? constantMember) -> void -Android.Runtime.IntDefinitionAttribute.JniField.get -> string? -Android.Runtime.IntDefinitionAttribute.JniField.set -> void Android.Runtime.JavaArray Android.Runtime.JavaArray.Add(T item) -> void Android.Runtime.JavaArray.Clear() -> void diff --git a/src/Mono.Android/PublicAPI/API-36.1/PublicAPI.Unshipped.txt b/src/Mono.Android/PublicAPI/API-36.1/PublicAPI.Unshipped.txt index 96701c76f82..200520703e6 100644 --- a/src/Mono.Android/PublicAPI/API-36.1/PublicAPI.Unshipped.txt +++ b/src/Mono.Android/PublicAPI/API-36.1/PublicAPI.Unshipped.txt @@ -27,3 +27,9 @@ REMOVED virtual Xamarin.Android.Net.AndroidClientHandler.WriteRequestContentToOu Android.App.ApplicationAttribute.EnableOnBackInvokedCallback.get -> bool Android.App.ApplicationAttribute.EnableOnBackInvokedCallback.set -> void Java.Interop.BaseExportAttribute +*REMOVED*Android.Runtime.IntDefinitionAttribute +*REMOVED*Android.Runtime.IntDefinitionAttribute.ConstantMember.get -> string? +*REMOVED*Android.Runtime.IntDefinitionAttribute.ConstantMember.set -> void +*REMOVED*Android.Runtime.IntDefinitionAttribute.IntDefinitionAttribute(string? constantMember) -> void +*REMOVED*Android.Runtime.IntDefinitionAttribute.JniField.get -> string? +*REMOVED*Android.Runtime.IntDefinitionAttribute.JniField.set -> void diff --git a/src/Mono.Android/PublicAPI/API-36/PublicAPI.Shipped.txt b/src/Mono.Android/PublicAPI/API-36/PublicAPI.Shipped.txt index 7af16e4c6d2..4327e85f7eb 100644 --- a/src/Mono.Android/PublicAPI/API-36/PublicAPI.Shipped.txt +++ b/src/Mono.Android/PublicAPI/API-36/PublicAPI.Shipped.txt @@ -29693,12 +29693,6 @@ Android.Runtime.IntDefAttribute.Flag.set -> void Android.Runtime.IntDefAttribute.IntDefAttribute() -> void Android.Runtime.IntDefAttribute.Type.get -> string? Android.Runtime.IntDefAttribute.Type.set -> void -Android.Runtime.IntDefinitionAttribute -Android.Runtime.IntDefinitionAttribute.ConstantMember.get -> string? -Android.Runtime.IntDefinitionAttribute.ConstantMember.set -> void -Android.Runtime.IntDefinitionAttribute.IntDefinitionAttribute(string? constantMember) -> void -Android.Runtime.IntDefinitionAttribute.JniField.get -> string? -Android.Runtime.IntDefinitionAttribute.JniField.set -> void Android.Runtime.JavaArray Android.Runtime.JavaArray.Add(T item) -> void Android.Runtime.JavaArray.Clear() -> void diff --git a/src/Mono.Android/PublicAPI/API-36/PublicAPI.Unshipped.txt b/src/Mono.Android/PublicAPI/API-36/PublicAPI.Unshipped.txt index 8ab7b82ed22..098466d4f24 100644 --- a/src/Mono.Android/PublicAPI/API-36/PublicAPI.Unshipped.txt +++ b/src/Mono.Android/PublicAPI/API-36/PublicAPI.Unshipped.txt @@ -4403,3 +4403,9 @@ virtual Java.Util.IdentityHashMap.Replace(Java.Lang.Object? key, Java.Lang.Objec Android.App.ApplicationAttribute.EnableOnBackInvokedCallback.get -> bool Android.App.ApplicationAttribute.EnableOnBackInvokedCallback.set -> void Java.Interop.BaseExportAttribute +*REMOVED*Android.Runtime.IntDefinitionAttribute +*REMOVED*Android.Runtime.IntDefinitionAttribute.ConstantMember.get -> string? +*REMOVED*Android.Runtime.IntDefinitionAttribute.ConstantMember.set -> void +*REMOVED*Android.Runtime.IntDefinitionAttribute.IntDefinitionAttribute(string? constantMember) -> void +*REMOVED*Android.Runtime.IntDefinitionAttribute.JniField.get -> string? +*REMOVED*Android.Runtime.IntDefinitionAttribute.JniField.set -> void diff --git a/src/Mono.Android/PublicAPI/API-37.1/PublicAPI.Shipped.txt b/src/Mono.Android/PublicAPI/API-37.1/PublicAPI.Shipped.txt index a3ae260f2da..35a49d7d88d 100644 --- a/src/Mono.Android/PublicAPI/API-37.1/PublicAPI.Shipped.txt +++ b/src/Mono.Android/PublicAPI/API-37.1/PublicAPI.Shipped.txt @@ -31665,12 +31665,6 @@ Android.Runtime.IntDefAttribute.Flag.set -> void Android.Runtime.IntDefAttribute.IntDefAttribute() -> void Android.Runtime.IntDefAttribute.Type.get -> string? Android.Runtime.IntDefAttribute.Type.set -> void -Android.Runtime.IntDefinitionAttribute -Android.Runtime.IntDefinitionAttribute.ConstantMember.get -> string? -Android.Runtime.IntDefinitionAttribute.ConstantMember.set -> void -Android.Runtime.IntDefinitionAttribute.IntDefinitionAttribute(string? constantMember) -> void -Android.Runtime.IntDefinitionAttribute.JniField.get -> string? -Android.Runtime.IntDefinitionAttribute.JniField.set -> void Android.Runtime.JavaArray Android.Runtime.JavaArray.Add(T item) -> void Android.Runtime.JavaArray.Clear() -> void diff --git a/src/Mono.Android/PublicAPI/API-37.1/PublicAPI.Unshipped.txt b/src/Mono.Android/PublicAPI/API-37.1/PublicAPI.Unshipped.txt index ae1d14901c7..9f3358705b7 100644 --- a/src/Mono.Android/PublicAPI/API-37.1/PublicAPI.Unshipped.txt +++ b/src/Mono.Android/PublicAPI/API-37.1/PublicAPI.Unshipped.txt @@ -2,3 +2,9 @@ Android.App.ApplicationAttribute.EnableOnBackInvokedCallback.get -> bool Android.App.ApplicationAttribute.EnableOnBackInvokedCallback.set -> void static Android.Runtime.JNIEnv.BridgeProcessingGeneration.get -> int +*REMOVED*Android.Runtime.IntDefinitionAttribute +*REMOVED*Android.Runtime.IntDefinitionAttribute.ConstantMember.get -> string? +*REMOVED*Android.Runtime.IntDefinitionAttribute.ConstantMember.set -> void +*REMOVED*Android.Runtime.IntDefinitionAttribute.IntDefinitionAttribute(string? constantMember) -> void +*REMOVED*Android.Runtime.IntDefinitionAttribute.JniField.get -> string? +*REMOVED*Android.Runtime.IntDefinitionAttribute.JniField.set -> void diff --git a/src/Mono.Android/PublicAPI/API-37.2/PublicAPI.Shipped.txt b/src/Mono.Android/PublicAPI/API-37.2/PublicAPI.Shipped.txt index a3ae260f2da..35a49d7d88d 100644 --- a/src/Mono.Android/PublicAPI/API-37.2/PublicAPI.Shipped.txt +++ b/src/Mono.Android/PublicAPI/API-37.2/PublicAPI.Shipped.txt @@ -31665,12 +31665,6 @@ Android.Runtime.IntDefAttribute.Flag.set -> void Android.Runtime.IntDefAttribute.IntDefAttribute() -> void Android.Runtime.IntDefAttribute.Type.get -> string? Android.Runtime.IntDefAttribute.Type.set -> void -Android.Runtime.IntDefinitionAttribute -Android.Runtime.IntDefinitionAttribute.ConstantMember.get -> string? -Android.Runtime.IntDefinitionAttribute.ConstantMember.set -> void -Android.Runtime.IntDefinitionAttribute.IntDefinitionAttribute(string? constantMember) -> void -Android.Runtime.IntDefinitionAttribute.JniField.get -> string? -Android.Runtime.IntDefinitionAttribute.JniField.set -> void Android.Runtime.JavaArray Android.Runtime.JavaArray.Add(T item) -> void Android.Runtime.JavaArray.Clear() -> void diff --git a/src/Mono.Android/PublicAPI/API-37.2/PublicAPI.Unshipped.txt b/src/Mono.Android/PublicAPI/API-37.2/PublicAPI.Unshipped.txt index 4f7e6a01587..f9c68a219cb 100644 --- a/src/Mono.Android/PublicAPI/API-37.2/PublicAPI.Unshipped.txt +++ b/src/Mono.Android/PublicAPI/API-37.2/PublicAPI.Unshipped.txt @@ -1,3 +1,9 @@ #nullable enable Android.App.ApplicationAttribute.EnableOnBackInvokedCallback.get -> bool Android.App.ApplicationAttribute.EnableOnBackInvokedCallback.set -> void +*REMOVED*Android.Runtime.IntDefinitionAttribute +*REMOVED*Android.Runtime.IntDefinitionAttribute.ConstantMember.get -> string? +*REMOVED*Android.Runtime.IntDefinitionAttribute.ConstantMember.set -> void +*REMOVED*Android.Runtime.IntDefinitionAttribute.IntDefinitionAttribute(string? constantMember) -> void +*REMOVED*Android.Runtime.IntDefinitionAttribute.JniField.get -> string? +*REMOVED*Android.Runtime.IntDefinitionAttribute.JniField.set -> void diff --git a/src/Mono.Android/PublicAPI/API-37/PublicAPI.Shipped.txt b/src/Mono.Android/PublicAPI/API-37/PublicAPI.Shipped.txt index 787ea1db79d..3d525a42e82 100644 --- a/src/Mono.Android/PublicAPI/API-37/PublicAPI.Shipped.txt +++ b/src/Mono.Android/PublicAPI/API-37/PublicAPI.Shipped.txt @@ -31665,12 +31665,6 @@ Android.Runtime.IntDefAttribute.Flag.set -> void Android.Runtime.IntDefAttribute.IntDefAttribute() -> void Android.Runtime.IntDefAttribute.Type.get -> string? Android.Runtime.IntDefAttribute.Type.set -> void -Android.Runtime.IntDefinitionAttribute -Android.Runtime.IntDefinitionAttribute.ConstantMember.get -> string? -Android.Runtime.IntDefinitionAttribute.ConstantMember.set -> void -Android.Runtime.IntDefinitionAttribute.IntDefinitionAttribute(string? constantMember) -> void -Android.Runtime.IntDefinitionAttribute.JniField.get -> string? -Android.Runtime.IntDefinitionAttribute.JniField.set -> void Android.Runtime.JavaArray Android.Runtime.JavaArray.Add(T item) -> void Android.Runtime.JavaArray.Clear() -> void diff --git a/src/Mono.Android/PublicAPI/API-37/PublicAPI.Unshipped.txt b/src/Mono.Android/PublicAPI/API-37/PublicAPI.Unshipped.txt index 61a2234c60d..ea36f9578f4 100644 --- a/src/Mono.Android/PublicAPI/API-37/PublicAPI.Unshipped.txt +++ b/src/Mono.Android/PublicAPI/API-37/PublicAPI.Unshipped.txt @@ -4693,3 +4693,9 @@ virtual Java.Nio.CharBuffer.GetChars(int srcBegin, int srcEnd, char[]! dst, int virtual Javax.Net.Ssl.ExtendedSSLSession.StatusResponses.get -> System.Collections.Generic.IList? virtual Javax.Net.Ssl.SSLParameters.GetNamedGroups() -> string![]? virtual Javax.Net.Ssl.SSLParameters.SetNamedGroups(string![]? namedGroups) -> void +*REMOVED*Android.Runtime.IntDefinitionAttribute +*REMOVED*Android.Runtime.IntDefinitionAttribute.ConstantMember.get -> string? +*REMOVED*Android.Runtime.IntDefinitionAttribute.ConstantMember.set -> void +*REMOVED*Android.Runtime.IntDefinitionAttribute.IntDefinitionAttribute(string? constantMember) -> void +*REMOVED*Android.Runtime.IntDefinitionAttribute.JniField.get -> string? +*REMOVED*Android.Runtime.IntDefinitionAttribute.JniField.set -> void diff --git a/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Bindings.Core.targets b/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Bindings.Core.targets index 37047bc3904..89b3a14b251 100644 --- a/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Bindings.Core.targets +++ b/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Bindings.Core.targets @@ -22,7 +22,6 @@ It is shared between "legacy" binding projects and .NET 5 projects. $(IntermediateOutputPath)api.xml class-parse.dll generator.dll - javadoc-to-mdoc.exe <_GeneratorStampFile>$(_AndroidStampDirectory)generator.stamp diff --git a/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Bindings.Documentation.targets b/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Bindings.Documentation.targets index 1ffaa07c332..8629347efb4 100644 --- a/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Bindings.Documentation.targets +++ b/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Bindings.Documentation.targets @@ -11,7 +11,6 @@ This file is only used by "legacy" Xamarin Android binding projects. - @@ -62,17 +61,6 @@ This file is only used by "legacy" Xamarin Android binding projects. ToolPath="$(MonoAndroidToolsDirectory)" ToolExe="$(MDocToolExe)" /> - "IJD"; - - public string []? JavaDocs { get; set; } - - public string []? References { get; set; } - - public string []? Transforms { get; set; } - - [Required] - public string TargetAssembly { get; set; } = ""; - - [Required] - public string OutputDocDirectory { get; set; } = ""; - - protected override string GenerateCommandLineCommands () - { - if (!Directory.Exists (OutputDocDirectory)) - Directory.CreateDirectory (OutputDocDirectory); - - var cmd = base.GetCommandLineBuilder (); - cmd.AppendSwitch (Path.GetFullPath (TargetAssembly)); - //foreach (var r in References) - // cmd.AppendSwitch (r); - cmd.AppendSwitch ("-v=2"); - cmd.AppendSwitchIfNotNull ("--out=", OutputDocDirectory); - if (JavaDocs != null) { - foreach (var j in JavaDocs) - cmd.AppendSwitchIfNotNull ("--doc-dir=", Path.GetDirectoryName (j)); - } - if (Transforms != null) { - foreach (var t in Transforms) { - if (t.EndsWith ("Metadata.xml", StringComparison.InvariantCultureIgnoreCase)) - cmd.AppendSwitchIfNotNull ("--metadata=", t); - else - cmd.AppendSwitchIfNotNull ("--enum-map=", t); - } - } - return cmd.ToString (); - } - } -} diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj index 2be97ec0043..319eab540b4 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj @@ -98,9 +98,6 @@ Mono.Android\GrantUriPermissionAttribute.cs - - Mono.Android\IntDefinitionAttribute.cs - Mono.Android\BoundExceptionType.cs diff --git a/src/Xamarin.Android.Tools.JavadocImporter/CustomAttributeExtensions.cs b/src/Xamarin.Android.Tools.JavadocImporter/CustomAttributeExtensions.cs deleted file mode 100644 index 38c634d32de..00000000000 --- a/src/Xamarin.Android.Tools.JavadocImporter/CustomAttributeExtensions.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Linq; -//using IKVM.Reflection; -//using Type = IKVM.Reflection.Type; -using Mono.Cecil; -using Type = Mono.Cecil.TypeDefinition; - -namespace Android.Runtime -{ - public static class IKVMAttributeExtensions - { - public static string GetMemberType (this IMemberDefinition m) - { - var md = m as MethodDefinition; - if (md != null) - return md.IsConstructor ? "Constructor" : "Method"; - if (m is PropertyDefinition) - return "Property"; - if (m is FieldDefinition) - return "Field"; - if (m is EventDefinition) - return "Event"; - if (m is TypeDefinition) - return "Type"; - throw new NotImplementedException (); - } - - public static T [] GetCustomAttributes (this Mono.Cecil.IMemberDefinition m, bool dummy) - { - return m.CustomAttributes.Where (ca => ca.AttributeType.FullName == typeof(T).FullName) - .Select (ca => (T) ca.CreateInstance (typeof (T))).ToArray (); - } - public static T CreateInstance (this CustomAttribute attr) - { - return (T) CreateInstance (attr, typeof(T)); - } - - public static object CreateInstance (this CustomAttribute attr, System.Type type) - { - var obj = Activator.CreateInstance (type, attr.ConstructorArguments.Select (a => a.Value).ToArray ()); - foreach (var f in attr.Fields) - type.GetField (f.Name).SetValue (obj, f.Argument.Value); - foreach (var p in attr.Properties) - type.GetProperty (p.Name).SetValue (obj, p.Argument.Value, null); - return obj; - } - } -} - diff --git a/src/Xamarin.Android.Tools.JavadocImporter/DocumentElement.cs b/src/Xamarin.Android.Tools.JavadocImporter/DocumentElement.cs deleted file mode 100644 index 08ceeca3ca5..00000000000 --- a/src/Xamarin.Android.Tools.JavadocImporter/DocumentElement.cs +++ /dev/null @@ -1,413 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Xml; -using System.Xml.Linq; -using System.Xml.XPath; - -using Android.Runtime; - -using Mono.Cecil; - -using MemberInfo = Mono.Cecil.IMemberDefinition; -using MethodInfo = Mono.Cecil.MethodDefinition; -using PropertyInfo = Mono.Cecil.PropertyDefinition; - -namespace Xamarin.Android.Tools.JavaDocToMdoc -{ - - abstract class JavaDocDocumentElement - { - protected JavaDocDocumentElement (MdocHelper mdoc, XElement docElem) - { - Mdoc = mdoc; - Element = docElem; - } - - public MdocHelper Mdoc { get; private set; } - public XElement Element { get; private set; } - - public virtual void UpdateSince (XElement mdRemarks) - { - // no document element for "since API Level" by default. - } - - public void UpdateTypeDocs (XElement mdoc, RegisterAttribute tregister) - { - var jd = Element; - var mdRemarks = mdoc.XPathSelectElement ("Docs/remarks"); - mdRemarks.Value = ""; - var nodes = GetTypeSummaryNodes (jd); - mdRemarks.Add (Mdoc.FromHtml (nodes)); - Application.FixupMdoc (mdRemarks); - Application.AddAndroidDocUrlWithOptionalContent (mdRemarks, tregister, null); - UpdateSince (mdRemarks); - Application.SetSummaryFromRemarks (mdoc.Element ("Docs")); - } - - public abstract void UpdateEnumField (XElement dest, string member, string java); - - public abstract IEnumerable GetTypeSummaryNodes (XElement jd); - - public abstract DocumentSection CreateSection (XElement sectionAnchor, string anchor, RegisterAttribute mregister); - - public virtual XElement GetSectionAnchor (string localAnchor) - { - return Element.Descendants ("a").FirstOrDefault (a => { - var n = a.Attribute ("name"); - if (n == null || n.Value != localAnchor) - return false; - return true; - }); - } - - public DocumentSection GetSection (MemberInfo member, RegisterAttribute tregister) - { - XElement jd = Element; - string anchor = null; - - var mattrs = (RegisterAttribute [])member.GetCustomAttributes (false); - if (mattrs.Length == 0) { - return null; - } - var mregister = mattrs.Single (); - if (member is MethodDefinition && - ((MethodInfo)member).IsPrivate) - return null; - if (member is TypeDefinition) - return null; - anchor = Application.GetAnchor (tregister, mregister); - if (Application.ProcessingContext.MessageLevel > 1) - Logger.Log (LoggingVerbosity.Debug, 0, "\tUpdating member anchor: {0}", anchor); - string localAnchor = anchor; - XElement sectionAnchor = GetSectionAnchor (localAnchor); - if (sectionAnchor == null) { - Logger.Log (LoggingVerbosity.Warning, Errors.JavaDocSectionNotFound, "Could not find JavaDoc for member '{1}' - managed member is '{0}'", member, anchor); - return null; - } - - return CreateSection (sectionAnchor, anchor, mregister); - } - - public void UpdateMemberDocs (XElement mdoc, IMemberDefinition member, RegisterAttribute tregister) - { - XElement jd = Element; - - var section = GetSection (member, tregister); - if (section == null) - return; - - PropertyInfo property; - IEnumerable destinations = GetMdocMembers (mdoc, member, section.RegisterAttribute, out property); - MemberInfo secondPropertyMember = null; - DocumentSection secondSection = null; - string prefix = null, secondPrefix = null; - if (property != null) { - MethodInfo mi = member as MethodInfo; - if (mi == property.SetMethod) - return; - secondPropertyMember = property.SetMethod; - if (secondPropertyMember != null) { - secondSection = GetSection (secondPropertyMember, tregister); - if (secondSection != null) { - prefix = "Get"; - secondPrefix = "Set"; - } - } - } - - foreach (XElement dest in destinations) { - section.UpdateMemberSection (member, tregister, dest, prefix, true); - if (secondSection != null) { - secondSection.UpdateMemberSection (secondPropertyMember, tregister, dest, secondPrefix, false); - foreach (var e in dest.Descendants ("format")) - foreach (var attr in e.Attributes ("tmp").ToList ()) - attr.Remove (); - } - } - } - - static IEnumerable GetMdocMembers (XElement mdoc, MemberInfo member, RegisterAttribute register, out PropertyInfo property) - { - MethodInfo method = member as MethodInfo; - if (method != null && method.IsSpecialName && !method.IsConstructor) { - // member is a get or set method for a property, and the property - // won't have a [Register] attribute in the docs. - property = method.DeclaringType.Properties// (DefaultBindingFlags) - .Single (p => (p.GetMethod == method) || (p.SetMethod == method)); - string name = property.Name; - return mdoc.XPathSelectElements ("Members/Member") - .Where (m => m.Attribute ("MemberName").Value == name && m.Element ("MemberType").Value == "Property"); - } - property = null; - string attribute = string.IsNullOrEmpty (register.Signature) && string.IsNullOrEmpty (register.Connector) - ? string.Format ("Android.Runtime.Register(\"{0}\")", register.Name) - : string.Format ("Android.Runtime.Register(\"{0}\", \"{1}\", \"{2}\")", - register.Name, register.Signature, register.Connector); - - return - from m in mdoc.XPathSelectElements ("Members/Member") - where m.Elements ("Attributes") - .Elements ("Attribute") - .Elements ("AttributeName") - // now n.Value may have ", ApiSince=xx" suffix, which requires partial matching... - .Any (n => string.CompareOrdinal (n.Value, 0, attribute, 0, attribute.Length - 1) == 0) - select m; - } - } - - class DroidDocDocumentElement : JavaDocDocumentElement - { - public DroidDocDocumentElement (MdocHelper mdoc, XElement documentElement) - : base (mdoc, documentElement) - { - } - - public override DocumentSection CreateSection (XElement sectionAnchor, string anchor, RegisterAttribute mregister) - { - var section = sectionAnchor.ElementsAfterSelf ("div").First (d => Application.HasHtmlClass (d, "jd-details")); - var jdSummaryDiv = section.Descendants ("div").First (d => Application.HasHtmlClass (d, "jd-tagdescr")); - return new DroidDocDocumentSection (section, jdSummaryDiv) { Mdoc = Mdoc, Anchor = anchor, RegisterAttribute = mregister }; - } - - public override XElement GetSectionAnchor (string localAnchor) - { - return Element.Descendants ("a").FirstOrDefault (a => { - var n = a.Attribute ("name"); - if (n == null || n.Value != localAnchor) - return false; - var div = a.ElementsAfterSelf ("div").FirstOrDefault (); - return div != null && Application.HasHtmlClass (div, "jd-details"); - }); - } - - public override void UpdateSince (XElement mdRemarks) - { - Element.Descendants ("div").FirstOrDefault (d => Application.HasHtmlClass (d, "api-level")); - } - - public override IEnumerable GetTypeSummaryNodes (XElement jd) - { - var jdSummaryDiv = jd.Descendants ("div") - .Where (d => Application.HasHtmlClass (d, "jd-descr") && - d.Descendants ("h2").Any (h2 => h2.Value == "Class Overview")) - .FirstOrDefault (); - if (jdSummaryDiv == null) - return null; - return jdSummaryDiv.Descendants ("h2").First ().NodesAfterSelf (); - } - - public override void UpdateEnumField (XElement dest, string member, string java) - { - XElement jd = Element; - - var div = jd.Descendants ("div").Where (d => Application.HasHtmlClass (d, "jd-details") && - d.Descendants ("h4").Any (h4 => h4.LastNode.ToString ().Trim () == java)).FirstOrDefault (); - if (div == null) - return; - var srcDoc = div.Descendants ("div").Where (d => Application.HasHtmlClass (d, "jd-tagdescr")).Elements (); - if (srcDoc == null) - return; - var dSummary = dest.Descendants ("Member").Where (d => d.Attribute ("MemberName").Value == member).Descendants ("summary").FirstOrDefault (); - if (dSummary == null) - return; - dSummary.Value = ""; - dSummary.Add (Mdoc.FromHtml (srcDoc)); - Application.FixupMdoc (dSummary); - } - } - - class DroidDoc2DocumentElement : DroidDocDocumentElement - { - public DroidDoc2DocumentElement (MdocHelper mdoc, XElement documentElement) - : base (mdoc, documentElement) - { - } - - - static readonly XName name_a = XName.Get ("a"); - static readonly XName name_href = XName.Get ("href"); - static readonly XName name_tr = XName.Get ("tr"); - - List> hrefs; - - bool IsNamedAnchor (XElement a) - { - return a.Parent?.Parent?.Name?.LocalName == "td" && a.Attribute (name_href) != null; - } - - public override DocumentSection CreateSection (XElement sectionAnchor, string anchor, RegisterAttribute mregister) - { - if (hrefs == null) - hrefs = this.Element.Descendants (name_a).Where (IsNamedAnchor) - .Select (a => Tuple.Create (TypeUtilities.StripGenericArgument (a.Attribute (name_href).Value), a)) - .ToList (); - var section = sectionAnchor.ElementsAfterSelf ("div").First (d => d.Elements ().Any (p => Application.HasHtmlClass (p, "api-signature"))); - var summary = hrefs.FirstOrDefault (p => p.Item1 == '#' + anchor)?.Item2?.Parent?.Parent ?? - // sometimes DroidDoc hrefs have generic arguments within their links, which is annoying... - this.Element.Descendants (name_a).FirstOrDefault (a => IsNamedAnchor (a) && (a.Attribute (name_href)?.Value.EndsWith ('#' + anchor, StringComparison.Ordinal) ?? false))?.Parent?.Parent; - if (summary == null) - return null; - return new DroidDoc2DocumentSection (section, summary) { Mdoc = Mdoc, Anchor = anchor, RegisterAttribute = mregister }; - } - - public override XElement GetSectionAnchor (string localAnchor) - { - return Element.Descendants ("a").FirstOrDefault (a => { - var n = a.Attribute ("name"); - if (n == null || TypeUtilities.StripGenericArgument (n.Value) != localAnchor) - return false; - var div = a.ElementsAfterSelf ("div").FirstOrDefault ( - d => d.Elements ().Any (p => Application.HasHtmlClass (p, "api-signature"))); - return div != null; - }); - } - - public override IEnumerable GetTypeSummaryNodes (XElement jd) - { - var table = jd.Descendants ("table") - .Where (d => Application.HasHtmlClass (d, "jd-inheritance-table")) - .FirstOrDefault (); - var p = table.ElementsAfterSelf ("p") - .Take (1); - return p; - } - - public override void UpdateEnumField (XElement dest, string member, string java) - { - XElement jd = Element; - - var div = jd.Descendants ("div").Where (d => Application.HasHtmlClass (d, "api") && - d.Elements ("h3").Any (h3 => h3.LastNode.ToString ().Trim () == java)).FirstOrDefault (); - if (div == null) - return; - var srcDoc = div.Descendants ("p"); - if (srcDoc == null) - return; - var dSummary = dest.Descendants ("Member").Where (d => d.Attribute ("MemberName").Value == member).Descendants ("summary").FirstOrDefault (); - if (dSummary == null) - return; - dSummary.Value = ""; - dSummary.Add (Mdoc.FromHtml (srcDoc)); - Application.FixupMdoc (dSummary); - } - } - - class JavaDoc6DocumentElement : JavaDocDocumentElement - { - public JavaDoc6DocumentElement (MdocHelper mdoc, XElement documentElement) - : base (mdoc, documentElement) - { - } - - public override DocumentSection CreateSection (XElement sectionAnchor, string anchor, RegisterAttribute mregister) - { - return new JavaDoc6DocumentSection (sectionAnchor) { Mdoc = Mdoc, Anchor = anchor, RegisterAttribute = mregister }; - } - - public override IEnumerable GetTypeSummaryNodes (XElement jd) - { - var classDataComment = jd.DescendantNodes () - .Where (n => n.NodeType == XmlNodeType.Comment && ((XComment)n).Value.IndexOf ("======== START OF CLASS DATA ========", StringComparison.Ordinal) > 0) - .FirstOrDefault (); - if (classDataComment == null) - yield break; - var dlStart = classDataComment.ElementsAfterSelf () - .Where (e => e.Name.LocalName == "dl" && e.XPathSelectElement ("dt/pre") != null || e.Element ("pre") != null) - .FirstOrDefault (); - if (dlStart == null) - yield break; - foreach (var n in dlStart.NodesAfterSelf ()) { - //n.WriteTo (xw); - // The next comment node is the end of this CLASS SUMMARY. It could be different comments - if (n.NodeType == XmlNodeType.Comment) { - var c = (XComment)n; - if (c.Value.IndexOf (" SUMMARY ========", StringComparison.Ordinal) > 0) - yield break; - } else if (n is XText) { - // FIXME: we don't use HAP for JavaDoc6 anymore, so we don't need such a mess. - - // HtmlAgilityPack somehow returns sequential split text nodes. - // We don't want to wrap everything in separate

element, so merge them here. - // So we concat every following XText in one single node. - if (n.PreviousNode != null && n.PreviousNode.NodeType == XmlNodeType.Text) - continue; - var v = ((XText)n).Value + string.Concat (n.NodesAfterSelf ().TakeWhile (x => x.NodeType == XmlNodeType.Text).Cast ().Select (x => x.Value)); - yield return new XElement ("p", v); - } else { - // Sometimes this NESTED CLASS SUMMARY node could come *inside* a

tag. I think it is wrong, but - // 1) I don't trust SgmlReader, and 2) I don't trust javadoc/doclet. - var e = n as XElement; - if (e != null && e.Nodes ().Any (x => x.NodeType == XmlNodeType.Comment && ((XComment)x).Value.IndexOf (" SUMMARY ========", StringComparison.Ordinal) > 0)) - yield break; - // skip empty

tag. - if (e == null || e.Name.LocalName != "p" || e.Nodes ().Any ()) - yield return n; - } - } - } - - public override void UpdateEnumField (XElement dest, string member, string java) - { - throw new NotImplementedException (); - } - } - - class JavaDoc7DocumentElement : JavaDocDocumentElement - { - public JavaDoc7DocumentElement (MdocHelper mdoc, XElement documentElement) - : base (mdoc, documentElement) - { - } - - public override DocumentSection CreateSection (XElement sectionAnchor, string anchor, RegisterAttribute mregister) - { - return new JavaDoc7DocumentSection (sectionAnchor) { Mdoc = Mdoc, Anchor = anchor, RegisterAttribute = mregister }; - } - - public override IEnumerable GetTypeSummaryNodes (XElement jd) - { - var desc = jd.Descendants ("div").Where (e => Application.HasHtmlClass (e, "contentContainer")) - .Elements ("div").Where (e => Application.HasHtmlClass (e, "description")) - .First (); - if (desc == null) - return Array.Empty (); - var div = desc.XPathSelectElement ("ul/li/div"); - if (div == null) - return Array.Empty (); - return div.Nodes (); - } - - public override void UpdateEnumField (XElement dest, string member, string java) - { - throw new NotImplementedException (); - } - } - - class JavaDoc8DocumentElement : JavaDoc7DocumentElement - { - public JavaDoc8DocumentElement (MdocHelper mdoc, XElement documentElement) - : base (mdoc, documentElement) - { - } - - public override DocumentSection CreateSection (XElement sectionAnchor, string anchor, RegisterAttribute mregister) - { - return new JavaDoc8DocumentSection (sectionAnchor) { Mdoc = Mdoc, Anchor = anchor, RegisterAttribute = mregister }; - } - - public override XElement GetSectionAnchor (string localAnchor) - { - localAnchor = localAnchor.Replace ('(', '-').Replace (')', '-').Replace (',', '-').Replace (" ", string.Empty).Replace ("[]", ":A"); - while (localAnchor.IndexOf ('<') >= 0 && localAnchor.IndexOf ('>') > localAnchor.IndexOf ('<')) - localAnchor = localAnchor.Substring (0, localAnchor.IndexOf ('<')) + localAnchor.Substring (localAnchor.IndexOf ('>') + 1); - return Element.Descendants ("a").FirstOrDefault (a => { - var n = a.Attribute ("name"); - if (n == null || n.Value.Replace ("...", ":A") != localAnchor) - return false; - return true; - }); - } - } -} diff --git a/src/Xamarin.Android.Tools.JavadocImporter/DocumentSection.cs b/src/Xamarin.Android.Tools.JavadocImporter/DocumentSection.cs deleted file mode 100644 index d858cf82030..00000000000 --- a/src/Xamarin.Android.Tools.JavadocImporter/DocumentSection.cs +++ /dev/null @@ -1,483 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Xml; -using System.Xml.Linq; -using System.Xml.XPath; - -using Android.Runtime; - -using MemberInfo = Mono.Cecil.IMemberDefinition; -using MethodInfo = Mono.Cecil.MethodDefinition; - -namespace Xamarin.Android.Tools.JavaDocToMdoc -{ - - abstract class DocumentSection - { - protected DocumentSection () - { - } - - public MdocHelper Mdoc { get; set; } - public string Anchor { get; set; } - public RegisterAttribute RegisterAttribute { get; set; } - - public virtual void UpdateSince (XElement mdRemarks) - { - // no document element for "since API Level" by default. - } - - public abstract void UpdateMemberParameters (XElement mdoc); - - public abstract void UpdateMemberExceptions (XElement mdoc, bool clean); - - public abstract void UpdateMemberReturns (XElement mdoc, bool clean); - - public abstract void UpdateMemberSeeAlso (XElement mdoc, bool clean); - - public void UpdateMemberSection (MemberInfo member, RegisterAttribute tregister, XElement dest, string prefix, bool firstPass) - { - //XElement jdSummaryDiv = section.SummaryDiv; - string anchor = Anchor; - - var mdRemarks = dest.XPathSelectElement ("Docs/remarks"); - if (firstPass) - mdRemarks.Value = ""; - if (prefix != null) - Application.AddAndroidDocUrlWithOptionalContent (mdRemarks, tregister, anchor, prefix + " method documentation", Mdoc.FromHtml (GetSummaryNodes ())); - else { - mdRemarks.Add (Mdoc.FromHtml (GetSummaryNodes ())); - Application.AddAndroidDocUrlWithOptionalContent (mdRemarks, tregister, anchor); - } - Application.FixupMdoc (mdRemarks); - if (firstPass) { - UpdateSince (mdRemarks); - Application.SetSummaryFromRemarks (dest.Element ("Docs"), prefix, firstPass); - } - // if method.IsSpecialName is true, then it's probably a property, in - // which case the parameter names will NOT match. - var method = member as MethodInfo; - if (method != null && !method.IsSpecialName) - UpdateMemberParameters (dest); - UpdateMemberExceptions (dest, firstPass); - UpdateMemberReturns (dest, firstPass); - UpdateMemberSeeAlso (dest, firstPass); - } - - public abstract IEnumerable GetSummaryNodes (); - - // method parameter update common utility - protected void UpdateParameter (string name, IEnumerable contents, XElement mdoc) - { - if (Application.ProcessingContext.MessageLevel > 1) - Logger.Log (LoggingVerbosity.Debug, 0, "\t\tUpdating method parameter: {0}", name); - XElement mdp = mdoc.Element ("Docs").Elements ("param").FirstOrDefault (p => p.Attribute ("name").Value == name); - if (mdp == null) { - Logger.Log (LoggingVerbosity.Warning, Errors.ManagedParameterNotFound, "Could not find parameter '{0}' for type '{1}', member '{2}'.", - name, - mdoc.Parent.Parent.Attribute ("FullName").Value, - mdoc.Element ("MemberSignature").Attribute ("Value").Value); - return; - } - mdp.Value = ""; - mdp.Add (contents); - } - } - - - class DroidDoc2DocumentSection : DroidDocDocumentSection - { - public DroidDoc2DocumentSection (XElement section, XElement summaryDiv) - : base (section, summaryDiv) - { - if (summaryDiv == null) - throw new ArgumentNullException (nameof (summaryDiv)); - Section = section; - SummaryDiv = summaryDiv; - } - - public override IEnumerable GetSummaryNodes () - { - return SummaryDiv.Elements (XName.Get ("p")); - } - - public override void UpdateMemberParameters (XElement mdoc) - { - XElement jd = Section; - - XElement jdParameters = GetJavaDocSectionTable (jd, "Parameters"); - if (jdParameters == null) - return; - - foreach (XElement jdp in jdParameters.Elements ("tr").Where (e => e.Element ("td") != null)) { - string name = jdp.Elements ().First ().Value.Trim (); - if (name == "event") - name = "e"; - var nodes = Mdoc.FromHtml (jdp.Elements ().Last ().Nodes ()); - - UpdateParameter (name, nodes, mdoc); - } - } - - public override void UpdateMemberReturns (XElement mdoc, bool clean) - { - XElement jd = Section; - - XElement jdReturns = GetJavaDocSectionTable (jd, "Returns"); - if (jdReturns == null) - return; - - XElement mdReturns = mdoc.Element ("Docs").Element ("returns") ?? mdoc.Element ("Docs").Element ("value"); - if (mdReturns == null) - return; - - XElement jdr = jdReturns.Elements ("tr").Last (); - string name = jdr.Elements ().First ().Value.Trim (); - var nodes = Mdoc.FromHtml (jdr.Elements ().Last ().Nodes ()); - if (clean) - mdReturns.Value = ""; - - mdReturns.Add (Mdoc.FromHtml (jdr.Elements ().Last ())); - Application.FixupMdoc (mdReturns); - } - - XElement GetJavaDocSectionTable (XElement jd, string section) - { - return jd.Descendants ("table").FirstOrDefault (t => t.XPathSelectElement ("tr/th[string(th) = '" + section + "']") != null); - } - } - - class DroidDocDocumentSection : DocumentSection - { - public DroidDocDocumentSection (XElement section, XElement summaryDiv) - - { - if (summaryDiv == null) - throw new ArgumentNullException (nameof (summaryDiv)); - Section = section; - SummaryDiv = summaryDiv; - } - - public XElement Section { get; protected set; } - public XElement SummaryDiv { get; protected set; } - - public override IEnumerable GetSummaryNodes () - { - return SummaryDiv.Nodes (); - } - - public override void UpdateSince (XElement mdRemarks) - { - Section.Descendants ("div").FirstOrDefault (d => Application.HasHtmlClass (d, "api-level")); - } - - public override void UpdateMemberExceptions (XElement mdoc, bool clean) - { - XElement jd = Section; - - XElement jdThrows = GetJavaDocSectionTable (jd, "Throws"); - if (jdThrows == null) - return; - - XElement mdDocs = mdoc.Element ("Docs"); - if (clean) - foreach (XElement e in mdDocs.Elements ("exception").ToList ()) - e.Remove (); - - foreach (XElement jdp in jdThrows.Elements ("tr").Elements ("th")) { - XElement type = jdp.Element ("a"); - if (type != null) { - mdDocs.Add (new XElement ("exception", - new XAttribute ("cref", Mdoc.CrefFromHref (type.Attribute ("href").Value)), - Mdoc.FromHtml (ExceptionDocs (type)))); - } else if ((type = jdp.Element ("td")) != null) { - mdDocs.Add (new XElement ("exception", - new XAttribute ("cref", Mdoc.CrefFromJavaType (type.Value.Trim ())), - Mdoc.FromHtml (ExceptionDocs (type)))); - } - } - - } - - IEnumerable ExceptionDocs (XElement type) - { - return type.NodesAfterSelf () - .Select (n => (n is XElement && ((XElement)n).Name == "td") - ? ((XElement)n).Nodes () - : new [] { n }) - .SelectMany (n => n); - } - - public override void UpdateMemberParameters (XElement mdoc) - { - XElement jd = Section; - - XElement jdParameters = GetJavaDocSectionTable (jd, "Parameters"); - if (jdParameters == null) - return; - - foreach (XElement jdp in jdParameters.Elements ("tr").Elements ("th")) { - string name = jdp.FirstNode.ToString ().Trim (); - if (name == "event") - name = "e"; - var nodes = Mdoc.FromHtml (jdp.Element ("td").Nodes ()); - - UpdateParameter (name, nodes, mdoc); - } - } - - public override void UpdateMemberReturns (XElement mdoc, bool clean) - { - bool firstPass = clean; - if (firstPass) - return; - - XElement jd = Section; - - XElement jdReturns = GetJavaDocSection (jd, "Returns"); - if (jdReturns == null) - return; - - XElement mdReturns = mdoc.Element ("Docs").Element ("returns") ?? mdoc.Element ("Docs").Element ("value"); - if (mdReturns == null) - return; - - if (clean) - mdReturns.Value = ""; - mdReturns.Add (Mdoc.FromHtml (jdReturns.ElementsAfterSelf ("ul").First ())); - Application.FixupMdoc (mdReturns); - } - - public override void UpdateMemberSeeAlso (XElement mdoc, bool clean) - { - XElement jd = Section; - - XElement mdDocs = mdoc.Element ("Docs"); - if (clean) - foreach (XElement e in mdDocs.Elements ("altmember").ToList ()) - e.Remove (); - - XElement jdSeeAlso = GetJavaDocSection (jd, "See Also"); - if (jdSeeAlso == null) - return; - - foreach (XElement jdp in jdSeeAlso.ElementsAfterSelf ("ul").Elements ("li").Elements ("code")) { - XElement link = jdp.Element ("a"); - if (link == null) - continue; - - string cref = Mdoc.CrefFromHref (link.Attribute ("href").Value); - if (cref.Length > 0 && cref [0] == '!') - continue; - - mdDocs.Add (new XElement ("altmember", new XAttribute ("cref", cref))); - } - } - - XElement GetJavaDocSectionTable (XElement jd, string section) - { - XElement e = GetJavaDocSection (jd, section); - if (e == null) - return null; - return e.ElementsAfterSelf ("table").FirstOrDefault (); - } - - static XElement GetJavaDocSection (XElement jd, string section) - { - return jd.Descendants ("h5").FirstOrDefault (d => Application.HasHtmlClass (d, "jd-tagtitle") && d.Value == section); - } - } - - // JavaDoc6 output format is... ugly. There is no structured information on the output, and document nodes cannot be - // really parsable in certain format. So we need a lot of ugly decompiling hacks. - // - // The worst part is member contents. Parameters, Returns and Related Items are all in plain definition lists - // (DL/DT/DD elements) and they cannot be distinguished by any structure. Parameters may be missing for non-parameter - // methods. Returns is missing if the return type is void. Related Items may be missing by nature. No positional - // assumption works. Those items are only labeled with element e.g. Parameters:. And the labels can be - // *translated* e.g. it is NOT Parameters if it was Japanese environment when javadoc ran to generate docs. - // - // The only possibility I found was that we try *all those translated labels* in JDK (can be done only for OpenJDK). - // http://hg.openjdk.java.net/jdk7/tl/langtools/file/a72412b148d7/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/ - // as indirectly indicated at http://openjdk.java.net/groups/i18n/ - // - // Fortunately there are only ja_JP and zh_CN which have translations (the source is for JDK7, but they would be the - // same). - - abstract class JavaDocDocumentSection : DocumentSection - { - static readonly string [] param_labels = { "Parameters:", "\u53C2\u6570:", "\u30D1\u30E9\u30E1\u30FC\u30BF:" }; - static readonly string [] returns_labels = { "Returns:", "\u8FD4\u56DE:", "\u623B\u308A\u5024:" }; - static readonly string [] exception_labels = { "Throws:", "\u629B\u51FA:", "\u4F8B\u5916:" }; - static readonly string [] seealso_labels = { "See Also:", "\u53E6\u8BF7\u53C2\u9605:", "\u95A2\u9023\u9805\u76EE:" }; - protected XElement section_node, params_node, returns_node, exception_node, seealso_node; - - public abstract string SectionNameWrapperTag { get; } - - public JavaDocDocumentSection (XElement sectionNode) - { - if (sectionNode == null) - return; // Any derived classes might pass null element here. Since we cannot reject it here, we ignore the entire section. - - section_node = sectionNode; - foreach (XElement pp in section_node.XPathSelectElements (".//dl/dt")) { - var b = pp.XPathSelectElement (SectionNameWrapperTag); - if (b == null) - continue; - if (param_labels.Contains (b.Value)) - params_node = pp; - else if (returns_labels.Contains (b.Value)) - returns_node = pp; - else if (exception_labels.Contains (b.Value)) - exception_node = pp; - else if (seealso_labels.Contains (b.Value)) - seealso_node = pp; - } - } - - public override void UpdateMemberParameters (XElement mdoc) - { - if (params_node == null) - return; - - foreach (XElement pe in params_node.ElementsAfterSelf ().TakeWhile (e => e.Name.LocalName == "dd")) { - var code = pe.Element (XName.Get ("code")); - string name = code.Value; - if (name == "event") - name = "e"; - var nodes = Mdoc.FromHtml (code.NodesAfterSelf ()); - - UpdateParameter (name, nodes, mdoc); - } - } - - public override void UpdateMemberReturns (XElement mdoc, bool clean) - { - XElement mdReturns = mdoc.Element ("Docs").Element ("returns") ?? mdoc.Element ("Docs").Element ("value"); - if (mdReturns == null) - return; - - if (clean) - mdReturns.Value = ""; - - if (returns_node == null) - return; - - mdReturns.Add (Mdoc.FromHtml (returns_node.ElementsAfterSelf ("dd").First ().Nodes ())); - Application.FixupMdoc (mdReturns); - } - - public override void UpdateMemberExceptions (XElement mdoc, bool clean) - { - if (exception_node == null) - return; - - XElement mdDocs = mdoc.Element ("Docs"); - if (clean) - foreach (XElement e in mdDocs.Elements ("exception").ToList ()) - e.Remove (); - - foreach (XElement jdp in exception_node.ElementsAfterSelf ().TakeWhile (e => e.Name.LocalName == "dd")) { - XElement type = jdp.Descendants ("a").FirstOrDefault (); - if (type != null) { - mdDocs.Add (new XElement ("exception", - new XAttribute ("cref", Mdoc.CrefFromHref (type.Attribute ("href").Value)), - Mdoc.FromHtml (ExceptionDocs (type)))); - } - } - } - - IEnumerable ExceptionDocs (XElement type) - { - return type.Parent.NodesAfterSelf (); - } - - public override void UpdateMemberSeeAlso (XElement mdoc, bool clean) - { - XElement mdDocs = mdoc.Element ("Docs"); - if (clean) - foreach (XElement e in mdDocs.Elements ("altmember").ToList ()) - e.Remove (); - - if (seealso_node == null) - return; - - foreach (XElement pe in seealso_node.ElementsAfterSelf ().TakeWhile (e => e.Name.LocalName == "dd")) { - XElement link = pe.Element ("a"); - if (link == null) - continue; - - // FIXME: CrefFromHref() is valid only for DroidDoc. It needs to be rewritten. - string cref = Mdoc.CrefFromHref (link.Attribute ("href").Value); - if (cref.Length > 0 && cref [0] == '!') - continue; - - mdDocs.Add (new XElement ("altmember", new XAttribute ("cref", cref))); - } - } - } - - class JavaDoc6DocumentSection : JavaDocDocumentSection - { - public JavaDoc6DocumentSection (XElement anchorNode) - : base (anchorNode.ElementsAfterSelf ("dl").FirstOrDefault ()) - { - } - - public override string SectionNameWrapperTag { - get { return "b"; } - } - - public override IEnumerable GetSummaryNodes () - { - if (section_node == null) - return Enumerable.Empty (); - var sumDL = section_node.Elements (XName.Get ("dd")).FirstOrDefault (); - return sumDL == null ? Enumerable.Empty () : - sumDL.Nodes ().TakeWhile (n => !(n is XElement && ((XElement)n).Name.LocalName != "dl")) - .Where (n => n.NodeType != XmlNodeType.Text || ((XText)n).Value.Length > 0) - .Select (n => n.NodeType == XmlNodeType.Text ? new XElement ("p", n) : n); - } - } - - class JavaDoc7DocumentSection : JavaDocDocumentSection - { - public JavaDoc7DocumentSection (XElement anchorNode) - : base (anchorNode.ElementsAfterSelf ("ul").Elements ("li").FirstOrDefault ()) - { - } - - public override string SectionNameWrapperTag { - get { return "span"; } - } - - public override IEnumerable GetSummaryNodes () - { - var div = section_node.Elements ("div").FirstOrDefault (); - return div == null ? Enumerable.Empty () : div.Nodes () - .Where (n => n.NodeType != XmlNodeType.Text || ((XText)n).Value.Length > 0) - .Select (n => n.NodeType == XmlNodeType.Text ? new XElement ("p", n) : n); - } - } - - class JavaDoc8DocumentSection : JavaDocDocumentSection - { - public JavaDoc8DocumentSection (XElement anchorNode) - : base (anchorNode.ElementsAfterSelf ("ul").Elements ("li").FirstOrDefault ()) - { - } - - public override string SectionNameWrapperTag { - get { return "span"; } - } - - public override IEnumerable GetSummaryNodes () - { - var div = section_node.Elements ("div").FirstOrDefault (); - return div == null ? Enumerable.Empty () : div.Nodes () - .Where (n => n.NodeType != XmlNodeType.Text || ((XText)n).Value.Length > 0) - .Select (n => n.NodeType == XmlNodeType.Text ? new XElement ("p", n) : n); - } - } -} diff --git a/src/Xamarin.Android.Tools.JavadocImporter/HTMLlat1.ent b/src/Xamarin.Android.Tools.JavadocImporter/HTMLlat1.ent deleted file mode 100644 index c6444860477..00000000000 --- a/src/Xamarin.Android.Tools.JavadocImporter/HTMLlat1.ent +++ /dev/null @@ -1,194 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Xamarin.Android.Tools.JavadocImporter/HTMLspecial.ent b/src/Xamarin.Android.Tools.JavadocImporter/HTMLspecial.ent deleted file mode 100644 index 5ce5c6ad01f..00000000000 --- a/src/Xamarin.Android.Tools.JavadocImporter/HTMLspecial.ent +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Xamarin.Android.Tools.JavadocImporter/HTMLsymbol.ent b/src/Xamarin.Android.Tools.JavadocImporter/HTMLsymbol.ent deleted file mode 100644 index 524bfe11bc4..00000000000 --- a/src/Xamarin.Android.Tools.JavadocImporter/HTMLsymbol.ent +++ /dev/null @@ -1,241 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Xamarin.Android.Tools.JavadocImporter/HtmlLoader.cs b/src/Xamarin.Android.Tools.JavadocImporter/HtmlLoader.cs deleted file mode 100644 index 9751811a2ce..00000000000 --- a/src/Xamarin.Android.Tools.JavadocImporter/HtmlLoader.cs +++ /dev/null @@ -1,253 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System.Xml; -using System.Xml.Linq; -using Sgml; - -namespace Xamarin.Android.Tools.JavaDocToMdoc -{ - - class HtmlLoader - { - // okay, SgmlReader itself has something similar, but I need something that makes sure to resolve only embedded resources. - class EmbeddedResourceEntityResolver : Sgml.IEntityResolver - { - public IEntityContent GetContent (Uri uri) - { - return new EmbeddedResourceEntityContent (uri.LocalPath); - } - - class EmbeddedResourceEntityContent : Sgml.IEntityContent - { - public EmbeddedResourceEntityContent (string name) - { - if (name == null) - throw new ArgumentNullException (nameof (name)); - this.name = name; - } - - string name; - - public Encoding Encoding { - get { return Encoding.UTF8; } - } - - public string MimeType { - get { return "text/plain"; } - } - - public Uri Redirect { - get { return new Uri (this.name, UriKind.Relative); } - } - - public Stream Open () - { - return typeof (HtmlLoader).Assembly.GetManifestResourceStream (name); - } - } - } - - enum JavaDocKind - { - DroidDoc, - DroidDoc2, - Java6, - Java7, - Java8 - } - - Sgml.SgmlDtd HtmlDtd; - - public HtmlLoader (ProcessingContext options) - { - HtmlDtd = Sgml.SgmlDtd.Parse (new Uri ("urn:anything"), - "HTML", - "-//W3C//DTD HTML 4.01//EN", - "strict.dtd", - string.Empty, new NameTable (), new EmbeddedResourceEntityResolver ()); - SourceDocumentationRoot = options.SourceDocumentationRoot; - } - - public string SourceDocumentationRoot { get; private set; } - - JavaDocDocumentElement GetJavaDocDocumentElement (JavaDocKind kind, XElement jd) - { - if (jd == null) - return null; - switch (kind) { - case JavaDocKind.DroidDoc: - return new DroidDocDocumentElement (new DroidDocMdocHelper (), jd); - case JavaDocKind.DroidDoc2: - return new DroidDoc2DocumentElement (new DroidDocMdocHelper (), jd); - case JavaDocKind.Java6: - return new JavaDoc6DocumentElement (new JavaDocMdocHelper (), jd); - case JavaDocKind.Java7: - return new JavaDoc7DocumentElement (new JavaDocMdocHelper (), jd); - case JavaDocKind.Java8: - return new JavaDoc8DocumentElement (new JavaDocMdocHelper (), jd); - } - throw new InvalidOperationException (); - } - - internal JavaDocDocumentElement GetJavaDocDocumentElement (string name) - { - JavaDocKind kind; - var path = GetJavaDocPath (name); - if (path == null) - return null; - var el = GetJavaDocFile (path, out kind); - return GetJavaDocDocumentElement (kind, el); - } - - public XElement GetJavaDocFile (string path) - { - JavaDocKind kind; - return GetJavaDocFile (path, out kind); - } - - XElement GetJavaDocFile (string path, out JavaDocKind kind) - { - kind = JavaDocKind.DroidDoc; - string rawHTML = ReadHtmlFile (path); - if (rawHTML.Substring (0, Math.Min (rawHTML.Length, 5000)).IndexOf (" 0) - kind = JavaDocKind.DroidDoc2; - if (rawHTML.Substring (0, Math.Min (rawHTML.Length, 500)).IndexOf ("Generated by javadoc (build 1.6", StringComparison.Ordinal) > 0) - kind = JavaDocKind.Java6; - if (rawHTML.Substring (0, Math.Min (rawHTML.Length, 500)).IndexOf ("Generated by javadoc (version 1.7", StringComparison.Ordinal) > 0) - kind = JavaDocKind.Java7; - if (rawHTML.Substring (0, Math.Min (rawHTML.Length, 500)).IndexOf ("Generated by javadoc (1.8", StringComparison.Ordinal) > 0) - kind = JavaDocKind.Java8; - if (kind == JavaDocKind.DroidDoc) { - throw new NotSupportedException ("Old DroidDoc is not supported anymore."); - } else { - var html = new Sgml.SgmlReader () { - InputStream = new StringReader (rawHTML), - CaseFolding = Sgml.CaseFolding.ToLower, - Dtd = HtmlDtd - }; - var doc = XDocument.Load (html); - - return doc.Root; - } - } - - string ReadHtmlFile (string path) - { - var info = new FileInfo (path); - var contents = new StringBuilder (checked((int)info.Length)); - bool veryFirstChar = true; - int wasPI = 0; - using (var r = info.OpenText ()) { - - int ch; - while ((ch = r.Read ()) >= 0) { - // Some of the HTML files are invalid, containing constructs such as - // 'foo <0', which should be 'foo <0'... - // - // There are also which needs to be replaced by <?>, but this involves 3 chars so I replace it later. - int next; - if (wasPI == 2) { - wasPI = 0; - contents.Append (">"); - } else if (wasPI == 1) { - if (r.Peek () == '>') - wasPI = 2; - else - wasPI = 0; - contents.Append ('?'); - } else if (ch == '<' && (next = r.Peek ()) >= 0 && - (char.IsDigit ((char)next) || ((char)next) == '=' || ((char)next) == '.' || (char)next == '-' || (char)next == '?' && !veryFirstChar)) { - contents.Append ("<"); - if (next == '?') - wasPI = 1; - } else if (ch == '&') { - var b = new List (); - while ((ch = r.Read ()) >= 0 && ((char)ch) != ';') - b.Add ((char)ch); - var entity = new string (b.ToArray ()); - switch (entity) { - case "#124": - contents.Append ("|"); - break; - case "#160": - case "#xA0": - case "nbsp": - contents.Append ("\u00A0"); - break; - case "8211": - contents.Append ("\u2011"); - break; - default: - contents.Append ("&").Append (entity).Append (";"); - break; - } - } else if (ch == '\0') - contents.Append ("NUL"); - else - contents.Append ((char)ch); - if (veryFirstChar) - veryFirstChar = false; - } - } - - var firstPass = contents.ToString (); - contents.Clear (); - int open_count = 0; - bool in_quot = false, in_apos = false; - foreach (char ch in firstPass) { - if (ch == '"' && open_count > 0) { - if (in_quot) - open_count = 1; // reset. Something like <... ...="...<..." (without '>') happened - in_quot = !in_quot; - } - if (ch == '\'' && open_count > 0) { - if (in_quot) - open_count = 1; // reset. Something like <... ...='...<...' (without '>') happened - in_apos = !in_apos; - } - - if (ch == '<') { - if (open_count > 0) - contents.Append ("<"); - else - contents.Append ((char)ch); - open_count++; - } else if (ch == '>') { - if (open_count > 0) - open_count--; - if (open_count > 0) - contents.Append (">"); - else - contents.Append ((char)ch); - } else - contents.Append ((char)ch); - } - - // FIXME: this should not be required, but Java.Util.Concurrent.ThreadPoolExecutor fails by invalid PI. - return contents.Replace ("", "<?>").ToString (); - } - - public string GetJavaDocPath (string name) - { - if (name.StartsWith ("mono/", StringComparison.OrdinalIgnoreCase)) { - // generator.exe-generated type; there are no docs - return null; - } - - var path = new StringBuilder (SourceDocumentationRoot.Length + 1 + name.Length + 5) - .Append (SourceDocumentationRoot) - .Append (Path.DirectorySeparatorChar) - .Append (name.Replace ('$', '.')) - .Append (".html"); - - string file = path.ToString (); - if (!File.Exists (file)) { - Logger.Log (LoggingVerbosity.Warning, Errors.CouldNotFindSourceJavadoc, "Could not find source JavaDoc file: {0}.", file); - return null; - } - return file; - } - } -} diff --git a/src/Xamarin.Android.Tools.JavadocImporter/Logger.cs b/src/Xamarin.Android.Tools.JavadocImporter/Logger.cs deleted file mode 100644 index c2dafd9828e..00000000000 --- a/src/Xamarin.Android.Tools.JavadocImporter/Logger.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.IO; - -namespace Xamarin.Android.Tools.JavaDocToMdoc -{ - public static class Logger - { - const string LogCategoryName = "JavadocToMDoc"; - - static TextWriter Output { - get { return Application.ProcessingContext.LoggingOutput; } - } - - public static LoggingVerbosity Verbosity { get; set; } = LoggingVerbosity.Warning; - - static bool ShouldLog (LoggingVerbosity toCheck) - { - return (int) toCheck <= (int) Verbosity; - } - - static string LoggingVerbosityToLabel (LoggingVerbosity v) - { - switch (v) { - case LoggingVerbosity.Error: return "error "; - case LoggingVerbosity.Warning: return "warning "; - case LoggingVerbosity.Debug: return string.Empty; - default: throw new NotSupportedException (); - } - } - - internal static void Log (LoggingVerbosity verbosity, int errorCode, string message) - { - if (!ShouldLog (verbosity)) - return; - switch (verbosity) { - case LoggingVerbosity.Error: - case LoggingVerbosity.Warning: - Output.Write (LoggingVerbosityToLabel (verbosity)); - break; - } - Output.Write (LogCategoryName); - switch (verbosity) { - case LoggingVerbosity.Error: - case LoggingVerbosity.Warning: - Output.Write (errorCode.ToString ("D04")); - break; - } - Output.Write (" : "); - Output.WriteLine (message); - } - - internal static void Log (LoggingVerbosity verbosity, int errorCode, string format, params object [] args) - { - if (!ShouldLog (verbosity)) - return; - switch (verbosity) { - case LoggingVerbosity.Error: - case LoggingVerbosity.Warning: - Output.Write (LoggingVerbosityToLabel (verbosity)); - break; - } - Output.Write (LogCategoryName); - switch (verbosity) { - case LoggingVerbosity.Error: - case LoggingVerbosity.Warning: - Output.Write (errorCode.ToString ("D04")); - break; - } - Output.Write (" : "); - Output.WriteLine (format, args); - } - } - - public enum LoggingVerbosity - { - Error, - Warning, - Debug, - } -} diff --git a/src/Xamarin.Android.Tools.JavadocImporter/MdocHelper.cs b/src/Xamarin.Android.Tools.JavadocImporter/MdocHelper.cs deleted file mode 100644 index 049a20cfe61..00000000000 --- a/src/Xamarin.Android.Tools.JavadocImporter/MdocHelper.cs +++ /dev/null @@ -1,311 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; -using System.Xml.Linq; - -using MonoDroid.Utils; - -using Android.Runtime; - -using Mono.Cecil; - -using Type = Mono.Cecil.TypeDefinition;//IKVM.Reflection.Type; -using MemberInfo = Mono.Cecil.IMemberDefinition; -using MethodInfo = Mono.Cecil.MethodDefinition; -using PropertyInfo = Mono.Cecil.PropertyDefinition; -using ParameterInfo = Mono.Cecil.ParameterDefinition; - -namespace Xamarin.Android.Tools.JavaDocToMdoc -{ - - abstract class MdocHelper - { - - Dictionary> HtmlToMdocElementMapping; - - Regex typeInHref; - - public abstract string TypeInHrefPrefix { get; } - - protected MdocHelper () - { - typeInHref = new Regex (TypeInHrefPrefix + @"(?.*)\.html(#(?.*))?$"); - - HtmlToMdocElementMapping = new Dictionary> { - { "a", (e, i) => ConvertLink (e, i) }, - { "code", (e, i) => ConvertCode (e, i) }, - { "div", (e, i) => FromHtml (e.Nodes (), i) }, - { "em", (e, i) => new XElement ("i", FromHtml (e.Nodes (), i)) }, - { "li", (e, i) => new XElement ("item", new XElement ("term", FromHtml (e.Nodes (), i))) }, - { "ol", (e, i) => new XElement ("list", new XAttribute ("type", "number"), FromHtml (e.Nodes ())) }, - { "p", (e, i) => new XElement ("para", new XAttribute ("tool", "javadoc-to-mdoc"), FromHtml (e.Nodes (), i)) }, - { "span", (e, i) => FromHtml (e.Nodes (), i) }, - { "strong", (e, i) => new XElement ("i", FromHtml (e.Nodes (), i)) }, - { "tt", (e, i) => new XElement ("c", FromHtml (e.Nodes (), i)) }, - { "ul", (e, i) => new XElement ("list", new XAttribute ("type", "bullet"), FromHtml (e.Nodes ())) }, - { "pre", (e, i) => ConvertPre (e, i) } - }; - } - - public string CrefFromHref (string href) - { - var m = typeInHref.Match (href); - if (!m.Success) - return string.Format ("!:BadHref:{0}", href); - string jniTypeName = m.Groups ["type"].Value.Replace ('.', '$'); - if (jniTypeName.EndsWith ("package-summary", StringComparison.Ordinal)) - return CreateNamespaceCref (jniTypeName); - Type type = GetAvailableTypes () - .FirstOrDefault (t => { - var r = (RegisterAttribute [])t.GetCustomAttributes (false); - if (r.Length == 0) - return false; - return r [0].Name == jniTypeName; - }); - if (type == null) - return string.Format ("!:NoType:{0};Href={1}", jniTypeName, href); - string member = m.Groups ["member"].Value; - if (string.IsNullOrEmpty (member)) - return "T:" + type.FullName.Replace ('/', '+'); - member = TypeUtilities.StripGenericArgument (member); - - var tregister = ((RegisterAttribute [])type.GetCustomAttributes (false)) [0]; - MemberInfo mi = type.Fields.Cast ().Concat (type.Properties).Concat (type.Methods) - .FirstOrDefault (x => { - var ras = (RegisterAttribute [])x.GetCustomAttributes (false); - return ras.Any (ra => Application.GetAnchor (tregister, ra) == member); - }); - if (mi != null) - return CreateCref (mi); - - string enumRef; - if (Application.EnumMappings != null && Application.EnumMappings.TryGetValue (jniTypeName + "." + member, out enumRef)) - return enumRef; - return "!:" + type.FullName + "." + member; - } - - IEnumerable GetAvailableTypes () - { - var assemblies = Application.Assemblies/* - .SelectMany (a => a.MainModule.AssemblyReferences) - .Select (an => - {try - {return AssemblyDefinition.ReadAssembly (an.Name); } - catch - {return (Assembly) null;}}) - .Where (a => a != null) - .Concat (Application.Assemblies)*/; - return assemblies.SelectMany (a => a.Modules.SelectMany (m => m.Types).SelectMany (t => t.FlattenTypeHierarchy ())); - } - - string CreateNamespaceCref (string jniTypeName) - { - string package = jniTypeName.Substring (0, jniTypeName.LastIndexOf ('/')); - package = package.Replace ('/', '.'); - if (Application.PackageRenames.ContainsKey (package)) - package = Application.PackageRenames [package]; - return "N:" + StringRocks.PackageToPascalCase (package); - } - - PropertyInfo GetPropertyForMember (MemberInfo member) - { - var method = member as MethodInfo; - if (method == null || !method.IsSpecialName) - return null; - foreach (var p in method.DeclaringType.Properties) { - if (p.GetMethod == method || p.SetMethod == method) - return p; - } - return null; - } - - string CreateCref (MemberInfo member) - { - member = GetPropertyForMember (member) ?? member; - var cref = new StringBuilder (); - switch (member.GetMemberType ()) { - case "Constructor": cref.Append ("C"); break; - case "Event": cref.Append ("E"); break; - case "Field": cref.Append ("F"); break; - case "Method": cref.Append ("M"); break; - case "Property": cref.Append ("P"); break; - case "Type": cref.Append ("T"); break; - default: - throw new InvalidOperationException ("Unable to create cref for member: " + member + "."); - } - cref.Append (":"); - - AppendMemberRef (cref, member); - - return cref.ToString (); - } - - StringBuilder AppendMemberRef (StringBuilder cref, TypeReference type) - { - cref.Append (type.Namespace).Append ('.').Append (type.Name); - return cref; - } - - StringBuilder AppendMemberRef (StringBuilder cref, MemberInfo member) - { - switch (member.GetMemberType ()) { - case "Type": { - Type type = (Type)member; - cref.Append (type.Namespace).Append ('.').Append (type.Name); - return cref; - } - default: AppendMemberRef (cref, (MemberInfo)member.DeclaringType); break; - } - - if (member.GetMemberType () != "Constructor") - cref.Append (".").Append (member.Name); - - Mono.Collections.Generic.Collection p = null; - if (member is MethodDefinition) - p = ((MethodDefinition)member).Parameters; - else if (member is PropertyDefinition) - p = ((PropertyInfo)member).GetMethod.Parameters; - if (p != null && p.Count > 0) { - cref.Append ("("); - AppendMemberRef (cref, p [0].ParameterType); - for (int i = 1; i < p.Count; ++i) { - cref.Append (", "); - AppendMemberRef (cref, p [1].ParameterType); - } - cref.Append (")"); - } - - return cref; - } - - public string CrefFromJavaType (string javaType) - { - Type type = Application.Assemblies.SelectMany (a => a.Modules.SelectMany (m => m.Types)) - .FirstOrDefault (t => { - var r = (RegisterAttribute [])t.GetCustomAttributes (false); - if (r.Length == 0) - return false; - return r [0].Name.Replace ('/', '.').Replace ('$', '.') == javaType; - }); - if (type == null) - return string.Format ("!:NoType:{0}", javaType); - - return "T:" + type.FullName; - } - - object ConvertLink (XElement e, bool insideFormat) - { - var href = e.Attribute ("href"); - if (href == null) - return ""; - var cref = CrefFromHref (href.Value); - if (!cref.StartsWith ("!:BadHref", StringComparison.Ordinal)) - return new XElement ("see", - new XAttribute ("cref", cref)); - int packageStart = href.Value.LastIndexOf ("../", StringComparison.Ordinal); - if (packageStart < 0) - return ""; - var url = href.Value.Substring (packageStart + "../".Length); - url = Application.OnlineDocumentationPrefix + "../" + url; - var a = new XElement ("a", new XAttribute ("href", url), - e.Value); - return insideFormat - ? a - : new XElement ("format", new XAttribute ("type", "text/html"), - a); - } - - object ConvertPre (XElement e, bool insideFormat) - { - string content = e.Value; - XElement result = null; - SampleDesc desc; - string snippet; - - if (!Application.ProcessingContext.ImportSamples) - return null; - if ((snippet = Application.Samples.GetSampleFromContent (content, out desc)) != null) { - result = new XElement ("example", - new XElement ("code", - new XAttribute ("lang", desc.Language ?? "java"), - // new XAttribute (XNamespace.Xml + "space", "preserve"), - snippet)); - } else { - string language = content.TrimStart (); - language = (string.IsNullOrEmpty (language) || language [0] != '<') - ? "java" : "xml"; - SampleDesc d = new SampleDesc { - Language = language, - FullTypeName = Application.ProcessingContext.CurrentType.FullName, - DocumentationFilePath = Application.ProcessingContext.CurrentFilePath - }; - var id = Application.Samples.RegisterSample (content, d); - result = new XElement ("sample", new XAttribute ("external-id", id)); - } - return result; - } - - XElement ConvertCode (XElement e, bool insideFormat) - { - if (e.Value == "YES") - return new XElement ("see", new XAttribute ("langword", "true")); - if (e.Value == "NO") - return new XElement ("see", new XAttribute ("langword", "false")); - return new XElement ("c", FromHtml (e.Nodes (), insideFormat)); - } - - public IEnumerable FromHtml (IEnumerable rest) - { - return FromHtml (rest, false); - } - - public IEnumerable FromHtml (IEnumerable rest, bool insideFormat) - { - if (rest != null) - foreach (var e in rest) - yield return FromHtml (e, insideFormat); - } - - public object FromHtml (XElement e) - { - return FromHtml (e, false); - } - - public object FromHtml (XNode n, bool insideFormat) - { - // Try to intelligently convert HTML into mdoc(5). - object r = null; - var e = n as XElement; - if (e != null && HtmlToMdocElementMapping.ContainsKey (e.Name.LocalName)) - r = HtmlToMdocElementMapping [e.Name.LocalName] (e, insideFormat); - else if (e != null && !insideFormat) - r = new XElement ("format", - new XAttribute ("type", "text/html"), - FromHtml (e, true)); - else if (e != null) - r = new XElement (e.Name, - e.Attributes (), - FromHtml (e.Nodes (), insideFormat)); - else - r = n; - return r; - } - - public object FromHtml (XElement e, IEnumerable rest) - { - return FromHtml (new [] { e }.Concat (rest).Cast (), false); - } - } - - class DroidDocMdocHelper : MdocHelper - { - public override string TypeInHrefPrefix { get { return "reference\\/"; } } - } - - class JavaDocMdocHelper : MdocHelper - { - public override string TypeInHrefPrefix { get { return @"(\.\.\/)*"; } } - } -} diff --git a/src/Xamarin.Android.Tools.JavadocImporter/MyClass.cs b/src/Xamarin.Android.Tools.JavadocImporter/MyClass.cs deleted file mode 100644 index 41a0c39ebb7..00000000000 --- a/src/Xamarin.Android.Tools.JavadocImporter/MyClass.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -namespace Xamarin.Android.Tools.JavadocImporter -{ - public class MyClass - { - public MyClass () - { - } - } -} diff --git a/src/Xamarin.Android.Tools.JavadocImporter/TypeUtilities.cs b/src/Xamarin.Android.Tools.JavadocImporter/TypeUtilities.cs deleted file mode 100644 index e8bb809b256..00000000000 --- a/src/Xamarin.Android.Tools.JavadocImporter/TypeUtilities.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Type = Mono.Cecil.TypeDefinition;//IKVM.Reflection.Type; - -namespace Xamarin.Android.Tools.JavaDocToMdoc -{ - static class TypeUtilities - { - public static string FlattenName (this Type type) - { - return type.Name.Replace ('.', '+'); // ugh, this is ugly. - } - - public static string FlattenFullName (this Type type) - { - return (type.DeclaringType != null ? FlattenFullName (type.DeclaringType) + '.' : null) + type.FullName; - } - - internal static IEnumerable FlattenTypeHierarchy (this Type type) - { - yield return type; - foreach (var nt in type.NestedTypes.SelectMany (_ => _.FlattenTypeHierarchy ())) - yield return nt; - } - - // It should not generate any docs for invokers and implementors. - public static bool ShouldExcludeType (Type type, string registeredTypeName) - { - return type.Name.EndsWith ("Invoker", StringComparison.Ordinal) && !registeredTypeName.EndsWith ("Invoker", StringComparison.Ordinal) - || type.Name.EndsWith ("Implementor", StringComparison.Ordinal) && !registeredTypeName.EndsWith ("Implementor", StringComparison.Ordinal) - || registeredTypeName.StartsWith ("mono/", StringComparison.Ordinal) && registeredTypeName.EndsWith ("Implementor", StringComparison.Ordinal); - } - - public static string StripGenericArgument (string signature) - { - int idx = signature.IndexOf ('#'); - if (idx < 0) - return StripGenericArgument (signature, 0); - else - return StripGenericArgument (signature.Substring (idx), 0); - } - - static string StripGenericArgument (string signature, int idx) - { - if (signature.IndexOf ('<') < 0) - return signature; - var sb = new StringBuilder (); - while (idx < signature.Length) { - var next = signature.IndexOf ('<', idx); - if (next < 0) - break; - sb.Append (signature.Substring (idx, next - idx)); - int open = 0; - for (idx = next + 1; idx < signature.Length; idx++) { - if (signature [idx] == '<') - open++; - else if (signature [idx] == '>' && open-- == 0) - break; - } - idx++; - } - if (idx < signature.Length) - sb.Append (signature.Substring (idx)); - return sb.ToString (); - } - } -} diff --git a/src/Xamarin.Android.Tools.JavadocImporter/Xamarin.Android.Tools.JavadocImporter.csproj b/src/Xamarin.Android.Tools.JavadocImporter/Xamarin.Android.Tools.JavadocImporter.csproj deleted file mode 100644 index 1cf29a3ea74..00000000000 --- a/src/Xamarin.Android.Tools.JavadocImporter/Xamarin.Android.Tools.JavadocImporter.csproj +++ /dev/null @@ -1,57 +0,0 @@ - - - - netstandard2.0 - true - false - true - $(NoWarn);CA1305 - annotations - - - - - - - - - - - StringRocks.cs - - - Crc64.cs - - - Crc64Helper.cs - - - Crc64.Table.cs - - - - - - HTMLlat1.ent - - - HTMLsymbol.ent - - - HTMLspecial.ent - - - strict.dtd - - - - - - - - - - - - - diff --git a/src/Xamarin.Android.Tools.JavadocImporter/javadoc-to-mdoc.cs b/src/Xamarin.Android.Tools.JavadocImporter/javadoc-to-mdoc.cs deleted file mode 100644 index 7289b5d772c..00000000000 --- a/src/Xamarin.Android.Tools.JavadocImporter/javadoc-to-mdoc.cs +++ /dev/null @@ -1,613 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.IO; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; -using System.Xml; -using System.Xml.Linq; -using System.Xml.XPath; - -using Mono.Options; - -using Java.Interop.Tools.TypeNameMappings; - -using Android.Runtime; - -using Mono.Cecil; - -using Assembly = Mono.Cecil.AssemblyDefinition; -using Type = Mono.Cecil.TypeDefinition;//IKVM.Reflection.Type; - -namespace Xamarin.Android.Tools.JavaDocToMdoc -{ - public partial class Application - { - internal static Dictionary PackageRenames; - - internal const string OnlineDocumentationPrefix = "http://developer.android.com/reference/"; - - internal static ReadOnlyCollection Assemblies; - internal static Dictionary EnumMappings; - internal static Dictionary EnumMappingsReversed; - - internal static ProcessingContext ProcessingContext; - - internal static HtmlLoader HtmlLoader; - - internal static SampleRepository Samples; - - public static void Run (ProcessingContext options) - { - if (options == null) - throw new ArgumentNullException (nameof (options)); - ProcessingContext = options; - HtmlLoader = new HtmlLoader (ProcessingContext); - - // samples are valid only for DroidDoc. Do not try to read them for other doclets. - try { - Samples = options.SamplesPath != null ? File.Exists (options.SamplesPath) ? SampleRepository.LoadFrom (options.SamplesPath) : new SampleRepository (options.SamplesPath) : null; - } catch { - } - - Assemblies = LoadAssemblies (options.Assemblies); - EnumMappings = CreateEnumMappings (out EnumMappingsReversed); - PackageRenames = CreatePackageRenames (); - ProcessAssemblies (options.TypesToProcess, options.TypesToSkip); - if (Samples != null) - Samples.Close (true); - } - - static Dictionary CreatePackageRenames () - { - var renames = Assemblies.SelectMany (assembly => assembly.CustomAttributes).Where (a => a.AttributeType.FullName == "Android.Runtime.NamespaceMappingAttribute") - .ToDictionary (a => (string)a.Properties.FirstOrDefault (p => p.Name == "Java").Argument.Value, - a => (string)a.Properties.FirstOrDefault (p => p.Name == "Managed").Argument.Value); - return renames; - } - - static Dictionary CreateEnumMappings (out Dictionary reversed) - { - var mappings = Assemblies.Where (a => a.CustomAttributes.Any (c => c.AttributeType.FullName == "Android.Runtime.NamespaceMappingAttribute")) // any valid binding dll should contain at least one [NamespaceMapping]. - .SelectMany (a => a.Modules).SelectMany (m => m.Types).Where (t => t.IsEnum) - .SelectMany (t => t.Fields.Where (f => f.HasConstant)) - .Select (f => new { - Java = f.CustomAttributes.FirstOrDefault (ca => ca.AttributeType.FullName == "Android.Runtime.IntDefinitionAttribute") - ?.Properties.FirstOrDefault (p => p.Name == "JniField").Argument.Value as string, - Managed = "F:" + f.FullName - }) - .Where (p => p.Java != null); - var ret = new Dictionary (); - foreach (var p in mappings) - ret [p.Java] = p.Managed; - reversed = ret.Where (p => p.Value != null).ToDictionary (p => p.Value, p => p.Key); - - return ret; - } - - static ReadOnlyCollection LoadAssemblies (IEnumerable assemblies) - { - return new ReadOnlyCollection (assemblies.Select (a => AssemblyDefinition.ReadAssembly (a/*, null, false*/)).ToList ()); - } - - static void ProcessAssemblies (IEnumerable types, IEnumerable skip) - { - bool checkTypes = types.Count () > 0; - var packages = new HashSet (); - - foreach (Assembly a in Assemblies) { - foreach (Type t in a.Modules.SelectMany (m => m.Types).SelectMany (t => t.FlattenTypeHierarchy ())) { - if (checkTypes && !types.Contains (t.FlattenFullName ())) - continue; - if (skip.Contains (t.FlattenFullName ())) - continue; - RegisterAttribute tregister = ImportDocsForType (t); - if (tregister == null) - continue; - if (string.IsNullOrEmpty (t.Namespace)) - continue; - string package = GetPackageName (tregister.Name); - if (package == null || packages.Contains (package)) - continue; - - packages.Add (package); - ImportDocsForPackage (package, t.Namespace); - } - } - } - - static string GetPackageName (string jniName) - { - if (string.IsNullOrEmpty (jniName)) - return null; - int s = jniName.LastIndexOf ('/'); - if (s == -1) - return null; - return jniName.Substring (0, s); - } - - static void ClearEnumDoc (XElement dest) - { - var summary = dest.Descendants ("summary").FirstOrDefault (); - if (summary != null) - summary.Value = ""; - var remarks = dest.Descendants ("remarks").FirstOrDefault (); - if (remarks != null) - remarks.Value = ""; - } - - static void ImportDocsForEnum (Type type) - { - string srcType = null; - JavaDocDocumentElement src = null; - string destFile = GetMdocFileName (type); - XElement dest = GetMdocFile (type, destFile); - if (dest == null) - return; - - if (ProcessingContext.MessageLevel > 1) - Logger.Log (LoggingVerbosity.Debug, 0, "Importing docs for enum: {0}", type); - - foreach (var info in type.Fields.Where (f => f.IsPublic && f.HasConstant)) { - string jniField; - if (Application.EnumMappingsReversed.TryGetValue ("F:" + type.FlattenFullName () + "." + info.Name, out jniField)) { - int index = jniField.LastIndexOf ('.'); - if (index < 0) - continue; - string jniType = jniField.Substring (0, index); - string jniName = jniField.Substring (index + 1); - if (srcType != jniType) { - src = HtmlLoader.GetJavaDocDocumentElement (jniType); - if (src == null) - return; - if (srcType == null) - ClearEnumDoc (dest); - srcType = jniType; - } - src.UpdateEnumField (dest, info.Name, jniName); - } - } - WriteMdocFile (destFile, dest); - } - - static RegisterAttribute ImportDocsForType (Type type) - { - if (type.IsNotPublic) - return null; - - var tattrs = type.CustomAttributes.Where (t => t.AttributeType.FullName == "Android.Runtime.RegisterAttribute").ToArray (); - if (tattrs.Length == 0) { - if (type.IsEnum && Application.EnumMappingsReversed != null) - ImportDocsForEnum (type); - return null; - } - if (TypeUtilities.ShouldExcludeType (type, (string)tattrs.First ().ConstructorArguments [0].Value)) - return null; - - Logger.Log (LoggingVerbosity.Debug, 0, "Importing docs for type: {0}", type); - - RegisterAttribute tregister = tattrs.Single ().CreateInstance (); - - var source = HtmlLoader.GetJavaDocDocumentElement (tregister.Name); - string destFile = GetMdocFileName (type); - XElement dest = GetMdocFile (type, destFile); - if (source == null || dest == null) - return null; - - ProcessingContext.CurrentFilePath = HtmlLoader.GetJavaDocPath (tregister.Name); - ProcessingContext.CurrentType = type; - - source.UpdateTypeDocs (dest, tregister); - UpdateTypeIntPtrConstructorDocs (dest); - UpdateTypeThresholdClassProperty (dest); - UpdateTypeThresholdTypeProperty (dest); - - foreach (var member in type.Fields.Cast ().Concat (type.Properties).Concat (type.Methods)) { - source.UpdateMemberDocs (dest, member, tregister); - } - - WriteMdocFile (destFile, dest); - return tregister; - } - } - - partial class Application - { - static XElement GetMdocFile (Type type, string file) - { - if (!File.Exists (file)) { - Logger.Log (LoggingVerbosity.Warning, Errors.MissingFileForRegeneration, "Documentation updates for {0} is on hold due to missing file: {1}", type.FlattenFullName (), file); - return null; - } - return GetMdocFile (file); - } - - static XElement GetMdocFile (string file) - { - return XElement.Load (file); - } - - static string GetMdocFileName (Type type) - { - var nsType = type.DeclaringType ?? type; - var path = new StringBuilder () - .Append (ProcessingContext.DestDocumentationRoot) - .Append (Path.DirectorySeparatorChar) - .Append (nsType.Namespace) - .Append (Path.DirectorySeparatorChar); - - var typeParts = new List (); - while (type != null) { - typeParts.Add (type.FlattenName ()); - type = type.DeclaringType; - } - typeParts.Reverse (); - - path.Append (string.Join ("+", typeParts.ToArray ())); - path.Append (".xml"); - - return path.ToString (); - } - - static void UpdateTypeIntPtrConstructorDocs (XElement mdoc) - { - XElement ctorDocs = mdoc.Elements ("Members") - .Elements ("Member") - .Where (m => (string) m.Attribute ("MemberName") == ".ctor" && - m.Elements ("Parameters").Elements ("Parameter").Count () == 2 && - (string) m.Element ("Parameters").Elements ("Parameter").ElementAt (0).Attribute ("Type") == "System.IntPtr" && - (string) m.Element ("Parameters").Elements ("Parameter").ElementAt (1).Attribute ("Type") == "Android.Runtime.JniHandleOwnership") - .Select (m => m.Element ("Docs")) - .FirstOrDefault (); - if (ctorDocs == null) - return; - var name = (string) ctorDocs.Elements ("param").ElementAt (0).Attribute ("name"); - var transfer = (string) ctorDocs.Elements ("param").ElementAt (1).Attribute ("name"); - ctorDocs.ReplaceAll ( - new XElement ("param", - new XAttribute ("name", name), - "A ", - new XElement ("see", new XAttribute ("cref", "T:System.IntPtr")), - "containing a Java Native Interface (JNI) object reference."), - new XElement ("param", - new XAttribute ("name", transfer), - "A ", - new XElement ("see", new XAttribute ("cref", "T:Android.Runtime.JniHandleOwnership")), - "indicating how to handle ", - new XElement ("paramref", new XAttribute ("name", name))), - new XElement ("summary", - "A constructor used when creating managed representations of JNI objects; called by the runtime."), - new XElement ("remarks", - new XElement ("para", - new XAttribute ("tool", "javadoc-to-mdoc"), - "This constructor is invoked by the runtime infrastructure (", - new XElement ("see", - new XAttribute ("cref", "M:Java.Lang.Object.GetObject``1(System.IntPtr,Android.Runtime.JniHandleOwnership)")), - ") to create a new managed representation for a Java Native Interface object."), - new XElement ("para", - new XAttribute ("tool", "javadoc-to-mdoc"), - "The constructor will initializes the ", - new XElement ("see", - new XAttribute ("cref", "P:Android.Runtime.IJavaObject.Handle")), - " property of the new instance using ", - new XElement ("paramref", - new XAttribute ("name", name)), - " and ", - new XElement ("paramref", new XAttribute ("name", transfer)), - "."))); - } - - static void UpdateTypeThresholdClassProperty (XElement mdoc) - { - XElement prop = mdoc.Elements ("Members") - .Elements ("Member") - .Where (m => (string) m.Attribute ("MemberName") == "ThresholdClass" && - m.Element ("MemberType").Value == "Property") - .Select (m => m.Element ("Docs")) - .FirstOrDefault (); - if (prop == null) - return; - prop.ReplaceAll ( - new XElement ("summary", - "This API supports the .NET for Android infrastructure and is not intended to be used directly from your code."), - new XElement ("value", - "A ", - new XElement ("see", new XAttribute ("cref", "T:System.IntPtr")), - " which contains the ", - new XElement ("c", "java.lang.Class"), - " JNI value corresponding to this type."), - new XElement ("remarks", - new XElement ("para", - new XAttribute ("tool", "javadoc-to-mdoc"), - "This property is used to control which ", - new XElement ("c", "jclass"), - " is provided to methods like ", - new XElement ("see", new XAttribute ("cref", "M:Android.Runtime.JNIEnv.CallNonVirtualVoidMethod")), - "."))); - } - - static void UpdateTypeThresholdTypeProperty (XElement mdoc) - { - XElement prop = mdoc.Elements ("Members") - .Elements ("Member") - .Where (m => (string) m.Attribute ("MemberName") == "ThresholdType" && - m.Element ("MemberType").Value == "Property") - .Select (m => m.Element ("Docs")) - .FirstOrDefault (); - if (prop == null) - return; - prop.ReplaceAll ( - new XElement ("summary", - "This API supports the .NET for Android infrastructure and is not intended to be used directly from your code."), - new XElement ("value", - "A ", - new XElement ("see", new XAttribute ("cref", "T:System.Type")), - " which provides the declaring type."), - new XElement ("remarks", - new XElement ("para", - new XAttribute ("tool", "javadoc-to-mdoc"), - "This property is used to control virtual vs. non virtual method dispatch " + - "against the underlying JNI object. When this property is equal to the " + - "declaring type, then virtual method invocation against the JNI object is " + - "performed; otherwise, we assume that the method was overridden by a derived " + - "type, and perform non-virtual methdo invocation."))); - } - - internal static bool HasHtmlClass (XElement e, string @class) - { - XAttribute c = e.Attribute ("class"); - if (c == null) - return false; - return Regex.IsMatch (c.Value, @"\b" + @class + @"\b"); - } - - internal static void SetSummaryFromRemarks (XElement docs, string prefix = null, bool clean = true) - { - var mdRemarks = GetFirstDocumentationElement (docs); - var mdSummary = docs.Element ("summary"); - if (clean) - mdSummary.Value = ""; - if (mdRemarks == null) - return; - foreach (XNode n in mdRemarks.Nodes ()) { - if (prefix != null) { - XElement xe = n as XElement; - if (xe != null && xe.Name == "format" && xe.Attribute ("tmp") != null) - continue; - } - XText t = n as XText; - if (t == null) { - mdSummary.Add (n); - continue; - } - string value = t.Value; - int e = value.IndexOf ('.'); - if (e == -1) { - mdSummary.Add (t); - continue; - } - // Often times the summary is overly truncated because an abbreviation - // is used. Try to detect the end of the sentence by looking for caps. - for (int i = e; i < value.Length; ++i) { - if (char.IsWhiteSpace (value [i])) - continue; - if (char.IsUpper (value [i])) - break; - if (char.IsLower (value [i])) { - e = value.IndexOf ('.', i); - if (e == -1) - break; - i = e; - } - } - if (e == -1) { - mdSummary.Add (t); - continue; - } - mdSummary.Add (value.Substring (0, e+1)); - break; - } - } - - static XElement GetFirstDocumentationElement (XElement docs) - { - var mdRemarks = docs.Element ("remarks"); - - return mdRemarks.Descendants ("para").FirstOrDefault (); - } - - internal static void AddAndroidDocUrlWithOptionalContent (XElement mdoc, RegisterAttribute tregister, string anchor, string prefix = null, object content = null) - { - string url = OnlineDocumentationPrefix + - tregister.Name.Replace ('$', '.') + - ".html"; - if (anchor != null) - url += "#" + anchor; - XElement format = new XElement ("format", new XAttribute ("type", "text/html")); - if (prefix != null) { - format.Add (new XAttribute ("tmp", "")); - format.Add (new XElement ("b", prefix)); - format.Add (" "); - } - format.Add (new XElement ("a", new XAttribute ("href", url), new XAttribute ("target", "_blank"), - "[Android Documentation]")); - if (prefix != null) - format.Add (new XElement ("br")); - XElement para = new XElement ("para", - new XAttribute ("tool", "javadoc-to-mdoc" + (prefix == null ? "" : ": " + prefix)), - format); - if (content != null) { - para.Add (content); - XElement last = para.Elements ().Last (); - if (last.Name == "para") { - last.Remove (); - para.Add (last.Nodes ()); - } - } - mdoc.Add (para); - } - - internal static string GetAnchor (RegisterAttribute tregister, RegisterAttribute mregister) - { - string name = mregister.Name; - if (name == ".ctor") { - name = tregister.Name.Replace ('$', '.'); - int n = name.LastIndexOf ('/'); - if (n >= 0) - name = name.Substring (n+1); - } - - if (mregister.Signature == null) - return name; - - var anchor = new StringBuilder () - .Append (name) - .Append ("("); - bool first = true; - foreach (JniTypeName t in JavaNativeTypeManager.FromSignature (mregister.Signature)) { - if (!first) - anchor.Append (", "); - first = false; - anchor.Append (t.Type); - } - anchor.Append (")"); - - return anchor.ToString (); - } - - static void WriteMdocFile (string file, XElement contents) - { - var settings = new XmlWriterSettings () { - Encoding = new UTF8Encoding (false), - Indent = true, - OmitXmlDeclaration = true, - }; - using (var output = new StreamWriter (file, false, settings.Encoding)) { - using (var writer = XmlWriter.Create (output, settings)) - contents.Save (writer); - output.WriteLine (); - } - } - - static void ImportDocsForPackage (string package, string ns) - { - string packagePath = new StringBuilder (ProcessingContext.SourceDocumentationRoot.Length + 1 + package.Length + 19) - .Append (ProcessingContext.SourceDocumentationRoot) - .Append (Path.DirectorySeparatorChar) - .Append (package) - .Append (Path.DirectorySeparatorChar) - .Append ("package-summary.html") - .ToString (); - if (!File.Exists (packagePath)) { - Logger.Log (LoggingVerbosity.Warning, Errors.MissingPackagePathToImportDocumentation, "Could not import documentation for package '{0}', as file '{1}' does not exist.", package, packagePath); - return; - } - string nsDocsPath = new StringBuilder (ProcessingContext.DestDocumentationRoot.Length + 1 + ns.Length + 7) - .Append (ProcessingContext.DestDocumentationRoot) - .Append (Path.DirectorySeparatorChar) - .Append ("ns-") - .Append (ns) - .Append (".xml") - .ToString (); - - var source = HtmlLoader.GetJavaDocFile (packagePath); - XElement dest = GetMdocFile (nsDocsPath); - - // new DroidDoc -> JavaDoc - var jdSummaryDiv = source.Descendants ("div") - .Where (d => d.Attribute ("id")?.Value == "jd-content" || HasHtmlClass (d, "jd-descr")) - .FirstOrDefault (); - if (jdSummaryDiv == null) - return; - - var mdRemarks = dest.XPathSelectElement ("Docs/remarks"); - mdRemarks.Value = ""; - // it's somewhat hacky... it's not only for DroidDoc, but hopefully works. - mdRemarks.Add (new DroidDocDocumentElement (new DroidDocMdocHelper (), source).Mdoc.FromHtml (jdSummaryDiv.Nodes ())); - FixupMdoc (mdRemarks); - SetSummaryFromRemarks (dest.Element ("Docs")); - - WriteMdocFile (nsDocsPath, dest); - } - - internal static void FixupMdoc (XElement root) - { - FlattenParas (root); - FlattenTerms (root); - } - - static void FlattenParas (XElement root) - { - foreach (var e in root.Elements ()) { - XNode before = e.NextNode; - XNode after = e; - foreach (var p in e.Descendants ("para").ToList ()) { - Append (p, before, ref after); - } - } - XElement add = null; - foreach (var n in root.Nodes ().ToList ()) { - var e = n as XElement; - if (e != null && e.Name.LocalName == "para") { - add = e.HasElements ? null : e; - continue; - } - if (add != null) { - n.Remove (); - add.Add (n); - } - } - } - - static void Append (XElement node, XNode before, ref XNode after) - { - node.Remove (); - if (before != null) { - before.AddBeforeSelf (node); - return; - } - after.AddAfterSelf (node); - after = node; - } - - static void FlattenTerms (XElement root) - { - foreach (var item in root.Descendants ("list").Elements ("item")) { - XNode before = item.NextNode; - XNode after = item; - foreach (var nestedItem in item.Descendants ("item").ToList ()) { - Append (nestedItem, before, ref after); - } - } - } - } - - - /* This class gives processing methods (namely samples processing) - * some context on what they are currently working on - */ - public class ProcessingContext { - public TextWriter LoggingOutput { get; set; } = Console.Error; - public string CurrentFilePath { get; set; } - public Type CurrentType { get; set; } - - public string SourceDocumentationRoot { get; set; } - public string DestDocumentationRoot { get; set; } - public int MessageLevel { get; set; } - public bool ImportSamples { get; set; } - public string SamplesPath { get; set; } - public IEnumerable Assemblies { get; set; } - public IEnumerable TypesToProcess { get; set; } - public IEnumerable TypesToSkip { get; set; } - } - - static class Errors - { - public const int CouldNotFindSourceJavadoc = 1; - public const int MissingFileForRegeneration = 2; - public const int MissingPackagePathToImportDocumentation = 3; - public const int JavaDocSectionNotFound = 4; - public const int ManagedParameterNotFound = 5; - } -} diff --git a/src/Xamarin.Android.Tools.JavadocImporter/samples.cs b/src/Xamarin.Android.Tools.JavadocImporter/samples.cs deleted file mode 100644 index 40907040e44..00000000000 --- a/src/Xamarin.Android.Tools.JavadocImporter/samples.cs +++ /dev/null @@ -1,240 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using System.Collections.Generic; -using System.Security.Cryptography; -using System.Text; -using System.Xml.Serialization; -using Java.Interop.Tools.JavaCallableWrappers; -using Xamarin.Tools.Zip; - -public struct SampleDesc { - public string ID { get; set; } - public string FullTypeName { get; set; } - public string DocumentationFilePath { get; set; } - public string Language { get; set; } // e.g 'obj-c' when taken from Apple otherwise a value understood by mdoc like 'C#' - - public override string ToString () - { - return string.Format ("{0}: {1} '{2}' in {3}", ID, FullTypeName, DocumentationFilePath, Language); - } -} - -public class SampleRepository -{ - ZipArchive archive; - HashAlgorithm hasher = new Crc64 (); - HashSet validFiles = new HashSet (); - Dictionary index = new Dictionary (); - Dictionary updates = new Dictionary (); - - public SampleRepository (string name) : this (ZipArchive.Open (name.EndsWith (".zip", StringComparison.OrdinalIgnoreCase) ? name : name + ".zip", FileMode.Open)) - { - - } - - protected SampleRepository (ZipArchive archive) - { - this.archive = archive; - if (archive.ContainsEntry ("index.xml")) - using (var stream = new MemoryStream ()) { - archive.First (e => e.FullName.Equals ("index.xml", StringComparison.OrdinalIgnoreCase)).Extract (stream); - stream.Position = 0; - index = ((ICollection)IndexSerializer.Deserialize (stream)).ToDictionary (sd => sd.ID, sd => sd); - } - } - - // Returns an id that can be used to register the sample position in the documentation flow - public string RegisterSample (string source, SampleDesc desc) - { - var hash = StringHash (source); - validFiles.Add (hash); - desc.ID = hash; - - if (!archive.ContainsEntry (hash)) { - updates.Add (hash, source); - archive.AddEntry (hash, source, Encoding.UTF8); - index[hash] = desc; - } - - return hash; - } - - public void OverwriteSample (string hash, string content, SampleDesc newDesc) - { - if (!archive.ContainsEntry (hash)) - return; - - UpdateEntry (archive, hash, content); - index[hash] = newDesc; - } - - void UpdateEntry (ZipArchive archive, string file, string content) - { - var existing = archive.FirstOrDefault (e => e.FullName == file); - if (existing != null) - archive.DeleteEntry (existing); - archive.AddEntry (file, content, Encoding.UTF8); - } - - public string GetSampleFromID (string id, out SampleDesc desc) - { - desc = new SampleDesc (); - - string source; - if (updates.TryGetValue (id, out source)) - return source; - - var entry = archive.FirstOrDefault (e => e.FullName == id); - if (entry == null) - return null; - - desc = index[id]; - using (var stream = new MemoryStream ()) { - entry.Extract (stream); - stream.Position = 0; - return new StreamReader (stream).ReadToEnd (); - } - } - - public string GetSampleFromContent (string content, out SampleDesc desc) - { - return GetSampleFromID (StringHash (content), out desc); - } - - public SampleDesc GetSampleDescFromID (string id) - { - return index[id]; - } - - public static SampleRepository LoadFrom (string file) - { - using (var archive = ZipArchive.Open (file, FileMode.Open)) { - var samples = new SampleRepository (archive); - return samples; - } - } - - public void Close (bool removeOldEntries) - { - // See if we have any stale file - if (removeOldEntries) { - var list = new List (archive); - foreach (var entry in list) { - if (!validFiles.Contains (entry.FullName)) - archive.DeleteEntry (entry); - } - } - // Serialize index - var writer = new StringWriter (); - IndexSerializer.Serialize (writer, new List (index.Values)); - UpdateEntry (archive, "index.xml", writer.ToString ()); - - archive.Close (); - } - - public IEnumerable AllIDs { - get { - return index.Keys; - } - } - - public bool IsValidID (string id) - { - return index.ContainsKey (id); - } - - string StringHash (String input) - { - // TODO: Reuse byte array - return hasher.ComputeHash (Encoding.UTF8.GetBytes (input)).Select (b => String.Format("{0:X2}", b)).Aggregate (string.Concat); - } - - XmlSerializer IndexSerializer { - get { - return new XmlSerializer (typeof (List)); - } - } - -#if STANDALONE_EXPORTER - public static void Main (string[] args) - { - string samplesPath = args[0]; - string outDir = args[1]; - - if (!File.Exists (samplesPath)) { - Console.WriteLine ("Couldn't find samples repository at {0}"); - return; - } - - SampleRepository samples = SampleRepository.LoadFrom (samplesPath); - - if (!Directory.Exists (outDir)) - Directory.CreateDirectory (outDir); - - foreach (var id in samples.AllIDs) { - SampleDesc desc; - var content = samples.GetSampleFromID (id, out desc); - - var type = desc.FullTypeName.Substring (desc.FullTypeName.LastIndexOf ('.') + 1); - var ns = desc.FullTypeName.Substring (0, desc.FullTypeName.LastIndexOf ('.')); - - Console.WriteLine ("Processing {0}::{1}", ns, type); - var path = Path.Combine (outDir, ns, type); - if (!Directory.Exists (path)) - Directory.CreateDirectory (path); - if (!Directory.Exists (path)) - Directory.CreateDirectory (path); - path = Path.Combine (path, id + (desc.Language == "xml" ? ".xml" : ".native")); - - File.WriteAllText (path, content); - } - } -#elif STANDALONE_IMPORTER - public static void Main (string[] args) - { - string samplesPath = args[0]; - string inDir = args[1]; - - if (!File.Exists (samplesPath)) { - Console.WriteLine ("Couldn't find samples repository at {0}"); - return; - } - if (!Directory.Exists (inDir)) { - Console.WriteLine ("Couldn't find input snippet directory"); - return; - } - - var langExtensions = new Dictionary () { - { ".xml", "XML" }, - { ".cs", "C#" } - }; - - SampleRepository samples = SampleRepository.LoadFrom (samplesPath); - - foreach (var file in Directory.EnumerateFiles (inDir, "*", SearchOption.AllDirectories)) { - var extension = Path.GetExtension (file); - var id = Path.GetFileNameWithoutExtension (file); - if (string.IsNullOrEmpty (extension) || string.IsNullOrEmpty (id)) - continue; - - string lang; - if (!langExtensions.TryGetValue (extension, out lang) || !samples.IsValidID (id)) { - Console.WriteLine ("Not processed: {0}", Path.GetFileName (file)); - continue; - } - - SampleDesc oldDesc = samples.GetSampleDescFromID (id); - samples.OverwriteSample (id, File.ReadAllText (file), new SampleDesc { - ID = id, - Language = lang, - DocumentationFilePath = oldDesc.DocumentationFilePath, - FullTypeName = oldDesc.FullTypeName - }); - Console.WriteLine ("Done: {0}", id); - } - - samples.Close (false); - } -#endif -} diff --git a/src/Xamarin.Android.Tools.JavadocImporter/strict.dtd b/src/Xamarin.Android.Tools.JavadocImporter/strict.dtd deleted file mode 100644 index b27455943fc..00000000000 --- a/src/Xamarin.Android.Tools.JavadocImporter/strict.dtd +++ /dev/null @@ -1,870 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -%HTMLlat1; - - -%HTMLsymbol; - - -%HTMLspecial; - - - - - - - - - - - - - -]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tools/javadoc2mdoc/Driver.cs b/tools/javadoc2mdoc/Driver.cs deleted file mode 100644 index 70d6ca4fe59..00000000000 --- a/tools/javadoc2mdoc/Driver.cs +++ /dev/null @@ -1,142 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; - -using Mono.Options; - -namespace Xamarin.Android.Tools.JavaDocToMdoc -{ - - class Driver - { - const string AppName = "javadoc-to-mdoc"; - static bool importSamples = false; - - public static int Main (string [] args) - { - bool show_help = false; - var types = new HashSet (); - var skip = new HashSet (); - string samplesPath = null; - string sourceRoot = null, destinationRoot = null; - int messageLevel = 0; - - var options = new OptionSet () { - { "doc-dir=", - "{DIRECTORY} for the JavaDoc HTML docs to import.\n" + - "Defaults to `SDK-DIR/docs/reference`.", - v => sourceRoot = v }, - { "enum-map=", - "Ignored; obsolete option.", - v => {} }, - { "metadata=", - "Ignored; obsolete option.", - v => {} }, - { "o|out=", - "Directory containing mdoc(5) documentation to import into.", - v => destinationRoot = v }, - { "sdk-dir=", - "{DIRECTORY} for the Android SDK.", - v => sourceRoot = Path.Combine (v, "docs/reference") }, - { "skip-type=", - ".NET {TYPE} to skip doc importfor.\n", - v => skip.Add (v) }, - { "type=", - ".NET {TYPE} to import documentation for.\n" + - "Largely for debugging purposes, so we don't need to import everything.", - v => types.Add (v) }, - { "v|verbose:", - "Increase verbosity of messages, or set verbosity to {LEVEL}.", - (int? v) => messageLevel = v.HasValue ? v.Value : messageLevel + 1}, - { "h|?|help", - "Show this help message and exit.", - v => show_help = v != null }, - { "import-samples", - "If set, the tool will import samples from an external repository", - v => importSamples = true }, - { "samples-repository=", - "Tell where to find the sample .zip repository", - v => samplesPath = v}, - }; - - List assemblies; - try { - assemblies = options.Parse (args); - } catch (Exception e) { - Error (messageLevel == 0 ? e.Message : e.ToString ()); - Console.Error.WriteLine ("See '{0} --help' for more information.", AppName); - return 1; - } - - if (show_help) { - ShowHelp (options); - return 0; - } - - if (string.IsNullOrEmpty (sourceRoot) || !Directory.Exists (sourceRoot)) { - Error ("Missing or invalid --doc-dir=DIR or --sdk-dir=DIR directory."); - return 1; - } - - if (string.IsNullOrEmpty (destinationRoot) || !Directory.Exists (destinationRoot)) { - Error ("Missing or invalid --out=DIR directory."); - return 1; - } - - if (string.IsNullOrEmpty (samplesPath) || !File.Exists (samplesPath)) - samplesPath = Path.Combine (destinationRoot, "samples.zip"); - - if (assemblies.Count == 0) { - ShowHelp (options); - return 1; - } - try { - Application.Run (new ProcessingContext () { - SourceDocumentationRoot = sourceRoot, - DestDocumentationRoot = destinationRoot, - ImportSamples = importSamples, - SamplesPath = samplesPath, - MessageLevel = messageLevel, - Assemblies = assemblies, - TypesToProcess = types, - TypesToSkip = skip - }); - return 0; - } catch (Exception e) { - Error ("{0}", messageLevel == 0 ? e.Message : e.ToString ()); - return 1; - } - } - - internal static void Error (string message) - { - Console.Error.Write (AppName); - Console.Error.Write (" : "); - Console.Error.WriteLine (message); - } - - internal static void Error (string formatMessage, params object [] args) - { - Console.Error.Write (AppName); - Console.Error.Write (" : "); - Console.Error.WriteLine (formatMessage, args); - } - - static void ShowHelp (OptionSet options) - { - Console.WriteLine ("Usage: {0} [OPTIONS]+ ASSEMBLY+", AppName); - Console.WriteLine (); - Console.WriteLine ("JavaDoc to mdoc(5) translation tool."); - Console.WriteLine (); - Console.WriteLine ("Available Options:"); - options.WriteOptionDescriptions (Console.Out); - Console.WriteLine (); - Console.WriteLine ("Either the --doc-dir or the --sdk-dir option must be specified."); - Console.WriteLine ("The --out option is required."); - Console.WriteLine (); - Console.WriteLine ("Copyright (C) 2010, Novell, Inc."); - Console.WriteLine ("Copyright (C) 2015, Xamarin, Inc."); - Console.WriteLine ("Copyright (C) 2017, Microsoft, Inc."); - } - } -} diff --git a/tools/javadoc2mdoc/javadoc2mdoc.csproj b/tools/javadoc2mdoc/javadoc2mdoc.csproj deleted file mode 100644 index e87a01a86c3..00000000000 --- a/tools/javadoc2mdoc/javadoc2mdoc.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - $(DotNetStableTargetFramework) - false - Exe - Xamarin.Android.Tools.JavadocToMDoc - javadoc-to-mdoc - - - - $(XAInstallPrefix)xbuild\Xamarin\Android\ - - - - - \ No newline at end of file