Skip to content

Commit a9379f7

Browse files
atsushienojonpryor
authored andcommitted
[class-parse] JavaApiParameterNames use ; for comments (#213)
Change the `JavaDocletType.JavaApiParameterNamesXml` comment character from `#` to `;`. This is because the parameter description file format uses `#ctor` for constructors, which obviously interacts very badly when "`#` until end of line" is a comment. (Constructors can't be expressed!) This issue was uncovered at API Level 26 which started to contain generic constructors.
1 parent f90f006 commit a9379f7

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

build-tools/xamarin-android-docimporter-ng/Xamarin.Android.ApiTools.ParameterNameExtractor/JavaApiParameterNamesExporter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ public static void WriteParameterNamesXml (this JavaApi api, XmlWriter writer)
8080
* The Text Format is:
8181
*
8282
* package {packagename}
83-
* #---------------------------------------
83+
* ;---------------------------------------
8484
* interface {interfacename}{optional_type_parameters} -or-
8585
* class {classname}{optional_type_parameters}
8686
* {optional_type_parameters}{methodname}({parameters})
8787
*
88-
* Anything after # is treated as comment.
88+
* Anything after ; is treated as comment.
8989
*
9090
* optional_type_parameters: "" -or- "<A,B,C>" (no constraints allowed)
9191
* parameters: type1 p0, type2 p1 (pairs of {type} {name}, joined by ", ")
@@ -118,7 +118,7 @@ public static void WriteParameterNamesText (this JavaApi api, TextWriter writer)
118118
foreach (var package in api.Packages) {
119119
writer.WriteLine ();
120120
writer.WriteLine ($"package {package.Name}");
121-
writer.WriteLine ("#---------------------------------------");
121+
writer.WriteLine (";---------------------------------------");
122122

123123
foreach (var type in package.Types) {
124124
if (!type.Members.OfType<JavaMethodBase> ().Any (m => m.Parameters.Any ()))

src/Xamarin.Android.Tools.Bytecode/JavaParameterNamesLoader.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ class Package
4545
* The Text Format is:
4646
*
4747
* package {packagename}
48-
* #---------------------------------------
48+
* ;---------------------------------------
4949
* interface {interfacename}{optional_type_parameters} -or-
5050
* class {classname}{optional_type_parameters}
5151
* {optional_type_parameters}{methodname}({parameters})
5252
*
53-
* Anything after # is treated as comment.
53+
* Anything after ; is treated as comment.
5454
*
5555
* optional_type_parameters: "" -or- "<A,B,C>" (no constraints allowed)
5656
* parameters: type1 p0, type2 p1 (pairs of {type} {name}, joined by ", ")
@@ -74,8 +74,10 @@ List<Package> LoadParameterFixupDescription (string path)
7474
var types = new List<Type> ();
7575
string type = null;
7676
var methods = new List<Method> ();
77+
int currentLine = 0;
7778
foreach (var l in File.ReadAllLines (path)) {
78-
var line = l.IndexOf ('#') >= 0 ? l.Substring (0, l.IndexOf ('#')) : l;
79+
currentLine++;
80+
var line = l.IndexOf (';') >= 0 ? l.Substring (0, l.IndexOf (';')).TrimEnd (' ', '\t') : l;
7981
if (line.Trim ().Length == 0)
8082
continue;
8183
if (line.StartsWith ("package ", StringComparison.Ordinal)) {
@@ -85,6 +87,8 @@ List<Package> LoadParameterFixupDescription (string path)
8587
continue;
8688
} else if (line.StartsWith (" ", StringComparison.Ordinal)) {
8789
int open = line.IndexOf ('(');
90+
if (open < 0)
91+
throw new ArgumentException ($"Unexpected line in {path} line {currentLine}: {line}");
8892
string parameters = line.Substring (open + 1).TrimEnd (')');
8993
string name = line.Substring (4, open - 4);
9094
if (name.FirstOrDefault () == '<') // generic method can begin with type parameters.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
package java.util
1+

2+
; This is a comment line.
3+
package java.util ; Anything after semicolon is comment.
24
class Collection<E>
35
add(E e)
6+
#ctor()

0 commit comments

Comments
 (0)