From f191ede6ef22c35bcaaee0f6b65354df349b0516 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Sat, 11 Feb 2017 03:03:05 +0900 Subject: [PATCH 1/3] [class-parse] really support Java8 and other various doclet types. ClassPath class had a red-herring property named "DocletType", which was NEVER assigned and therefore never worked. Its existence is optimistic so that it premised that any consuming code knows which doclet type its argument javadoc is generated with. So, just kill it and implement working code here. Now that we get a working doclet parser, a handful of Java8 scraper issues were discovered, so fixed them all. Namely: - Arrays are replaced as :A, not mere []. - the new DroidDoc actually uses [] as is, and I believe it used to be so too in Javadocs. On the other hand, [] may show up only within droiddocs, so skip that string.Replace() for Java8. - Java8 doc parsers simply passed '-' which actually needed to be escaped. It caused errors when argument names were simple like 'x-y' (which was treated as character range specification in regex). - regex matching for "anything except for '('" should actually be "... except for '(' and ')'" and then they should have been escaped too. --- .../ClassPath.cs | 23 ++++++++++++++--- .../JavaDocumentScraper.cs | 25 ++++++++++--------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/Xamarin.Android.Tools.Bytecode/ClassPath.cs b/src/Xamarin.Android.Tools.Bytecode/ClassPath.cs index aee01e485..af8a117a4 100644 --- a/src/Xamarin.Android.Tools.Bytecode/ClassPath.cs +++ b/src/Xamarin.Android.Tools.Bytecode/ClassPath.cs @@ -26,8 +26,6 @@ public class ClassPath { public string ApiSource { get; set; } - public JavaDocletType DocletType { get; set; } - public IEnumerable DocumentationPaths { get; set; } public bool AutoRename { get; set; } @@ -224,9 +222,28 @@ void FixupParametersFromDocs (XElement api) } } + JavaDocletType GetDocletType (string path) + { + var kind = JavaDocletType.DroidDoc; + char [] buf = new char [500]; + string packagesHtml = Path.Combine (path, "packages.html"); + if (File.Exists (packagesHtml) && File.ReadAllText (packagesHtml).Contains ("") { + ShouldEscapeBrackets = true; } string prev_path; @@ -115,13 +109,14 @@ public Java7DocScraper (string dir) class Java8DocScraper : AndroidDocScraper { - const String pattern_head_javadoc = " GetContentLines (string path) { return File.ReadAllText (path).Split ('\n'); @@ -199,9 +197,12 @@ public virtual String[] GetParameterNames (string package, string type, string m buffer.Append (param_sep); buffer.Append (ptypes [i].Replace ('$', '.')); } - buffer.Replace ("[", "\\[").Replace ("]", "\\]"); + if (ShouldEscapeBrackets) + buffer.Replace ("[", "\\[").Replace ("]", "\\]"); + if (ShouldAlterArraySpec) + buffer.Replace ("[]", ":A"); buffer.Append (close_method); - buffer.Append ("\".*\\(([^(]*)\\)"); + buffer.Append ("\".*\\(([^\\(\\)]*)\\)"); buffer.Append (post_close_method_parens); buffer.Replace ("?", "\\?"); Regex pattern = new Regex (buffer.ToString (), RegexOptions.Multiline); From 01e25c2dd5b54d3a528816dd2f7d5b34c4ee3256 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Sat, 11 Feb 2017 03:16:10 +0900 Subject: [PATCH 2/3] [class-parse] bring back JavaDocletType (only for getting unit tests working) As described in the previous change, this property doesn't make sense at all, but it is too annoying to alter existing tests as well as removing it from class-parse.exe (Program.cs), so just make it nullable and bring back. --- src/Xamarin.Android.Tools.Bytecode/ClassPath.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Tools.Bytecode/ClassPath.cs b/src/Xamarin.Android.Tools.Bytecode/ClassPath.cs index af8a117a4..03429747b 100644 --- a/src/Xamarin.Android.Tools.Bytecode/ClassPath.cs +++ b/src/Xamarin.Android.Tools.Bytecode/ClassPath.cs @@ -26,6 +26,8 @@ public class ClassPath { public string ApiSource { get; set; } + public JavaDocletType? DocletType { get; set; } + public IEnumerable DocumentationPaths { get; set; } public bool AutoRename { get; set; } @@ -243,7 +245,7 @@ JavaDocletType GetDocletType (string path) IAndroidDocScraper CreateDocScraper (string src) { - switch (GetDocletType (src)) { + switch (DocletType ?? GetDocletType (src)) { default: return new DroidDoc2Scraper (src); case JavaDocletType.DroidDoc: return new DroidDocScraper (src); case JavaDocletType.Java6: return new JavaDocScraper (src); From 5c5b7e96b5eb4ebafcb7a20602719a2596a4964b Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Tue, 14 Feb 2017 21:07:50 +0900 Subject: [PATCH 3/3] [class-parse] Java8 doc scraper needs to eliminate generic args from searches. --- src/Xamarin.Android.Tools.Bytecode/JavaDocumentScraper.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Tools.Bytecode/JavaDocumentScraper.cs b/src/Xamarin.Android.Tools.Bytecode/JavaDocumentScraper.cs index ae9c8ac84..1b2a91900 100644 --- a/src/Xamarin.Android.Tools.Bytecode/JavaDocumentScraper.cs +++ b/src/Xamarin.Android.Tools.Bytecode/JavaDocumentScraper.cs @@ -117,6 +117,7 @@ public Java8DocScraper (string dir) : base (dir, pattern_head_javadoc, reset_pattern_head_javadoc, parameter_pair_splitter_javadoc, true, "\\-", "\\-", "\\-", null) { ShouldAlterArraySpec = true; + ShouldEliminateGenericArguments = true; } } @@ -164,6 +165,7 @@ protected AndroidDocScraper (string dir, String patternHead, String resetPattern protected bool ShouldEscapeBrackets { get; set; } protected bool ShouldAlterArraySpec { get; set; } + protected bool ShouldEliminateGenericArguments { get; set; } protected virtual IEnumerable GetContentLines (string path) { @@ -195,7 +197,11 @@ public virtual String[] GetParameterNames (string package, string type, string m for (int i = 0; i < ptypes.Length; i++) { if (i != 0) buffer.Append (param_sep); - buffer.Append (ptypes [i].Replace ('$', '.')); + var ptype = ptypes [i]; + if (ShouldEliminateGenericArguments) + while (ptype.IndexOf ('<') > 0 && ptype.IndexOf ('>') > ptype.IndexOf ('<')) + ptype = ptype.Substring (0, ptype.IndexOf ('<')) + ptype.Substring (ptype.IndexOf ('>') + 1); + buffer.Append (ptype.Replace ('$', '.')); } if (ShouldEscapeBrackets) buffer.Replace ("[", "\\[").Replace ("]", "\\]");