From 996692d529b9b2e5fbef1c46b11c3de446519050 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Wed, 6 Jan 2021 11:47:08 -0500 Subject: [PATCH] [Xamarin.Android.Tools.Bytecode] Relax _ApiXml check Context: https://github.com/xamarin/java.interop/issues/767 Context: https://github.com/xamarin/xamarin-android/blob/a7413a2389886082c3d3422c50a7e6cc84f43d8f/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Bindings.ClassParse.targets#L23 Commit 69e1b80a added `java-source-utils.jar`, which can parse Java source code to extract parameter names, storing them into a "`class-parse`-like XML file". A benefit to a "`class-parse`-like XML file" is that it should be possible to use this same file with `class-parse --docspath`, overriding parameter names present in Java bytecode (which typically *isn't* present, as `javac -parameters` is rarely used). Unfortunately, this doesn't work: if you attempt to use `java-source-utils.jar` output w/ `class-parse --docspath`, it fails: System.Exception: Directory 'example.xml' does not exist at Xamarin.Android.Tools.Bytecode.AndroidDocScraper..ctor (System.String dir, System.String patternHead, System.String resetPatternHead, System.String parameterPairSplitter, System.Boolean continuousParamLines, System.String openMethod, System.String paramSep, System.String closeMethod, System.String postCloseMethodParens) [0x00093] in :0 at Xamarin.Android.Tools.Bytecode.AndroidDocScraper..ctor (System.String dir, System.String patternHead, System.String resetPatternHead, System.String parameterPairSplitter, System.Boolean continuousParamLines) [0x00000] in :0 at Xamarin.Android.Tools.Bytecode.DroidDocScraper..ctor (System.String dir) [0x00000] in :0 at Xamarin.Android.Tools.Bytecode.ClassPath.CreateDocScraper (System.String src) [0x00037] in :0 The problem is that we shouldn't be creating a `DroidDocScraper` for `java-source-utils.jar` output, it should be creating a `ApiXmlDocScraper`! We're creating the wrong `*Scraper` type because `JavaMethodParameterNameProvider.GetDocletType()` doesn't detect `java-source-utils.jar` output as being `JavaDocletType._ApiXml`; instead, it treats it as the default of `JavaDocletType.DroidDoc`. `JavaMethodParameterNameProvider.GetDocletType()` doesn't detect `java-source-utils.jar` output as being `JavaDocletType._ApiXml`, because it requires that the XML contain: while `java-source-utils.jar` instead emits: Relax `JavaMethodParameterNameProvider.GetDocletType()` to instead check for `") && rawXML.Contains ("