Skip to content

Commit 3c4f408

Browse files
atsushienojonpryor
authored andcommitted
[class-parse] fix Java8 javadoc regex matches and parameter name retrieval. (#126)
It was using String.Split(char[]) instead of .Split(string[]) which means that with "&nbsp;" the input can be split by any of '&', n,b,s,p and ';'. Also, Javadoc8 parameters can contain <a> tags, which need to be removed.
1 parent 0671930 commit 3c4f408

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,21 @@ public Java8DocScraper (string dir)
119119
ShouldAlterArraySpec = true;
120120
ShouldEliminateGenericArguments = true;
121121
}
122+
123+
protected override string StripTagsFromParameters (string value)
124+
{
125+
// Java8 javadoc contains possibly linked types with <a> tags, so remove all of them.
126+
while (value.IndexOf ('<') >= 0 && value.IndexOf ('>') > value.IndexOf ('<'))
127+
value = value.Substring (0, value.IndexOf ('<')) + value.Substring (value.IndexOf ('>') + 1);
128+
return value;
129+
}
122130
}
123131

124132
public abstract class AndroidDocScraper : IAndroidDocScraper
125133
{
126134
readonly String pattern_head;
127135
readonly String reset_pattern_head;
128-
readonly char [] parameter_pair_splitter;
136+
readonly string [] parameter_pair_splitter;
129137
readonly bool continuous_param_lines;
130138
readonly String open_method;
131139
readonly String param_sep;
@@ -145,7 +153,7 @@ protected AndroidDocScraper (string dir, String patternHead, String resetPattern
145153

146154
pattern_head = patternHead;
147155
reset_pattern_head = resetPatternHead;
148-
parameter_pair_splitter = (parameterPairSplitter != null ? parameterPairSplitter : "\\s+").ToCharArray ();
156+
parameter_pair_splitter = new string [] { (parameterPairSplitter != null ? parameterPairSplitter : "\\s+") };
149157
continuous_param_lines = continuousParamLines;
150158
open_method = openMethod;
151159
param_sep = paramSep;
@@ -178,6 +186,11 @@ protected virtual bool ShouldResetMatchBuffer (string text)
178186
// I *know* this is a hack.
179187
return reset_pattern_head == null || text.EndsWith (">", StringComparison.Ordinal) || !continuous_param_lines && !text.StartsWith (reset_pattern_head, StringComparison.Ordinal);
180188
}
189+
190+
protected virtual string StripTagsFromParameters (string value)
191+
{
192+
return value;
193+
}
181194

182195
public virtual String[] GetParameterNames (string package, string type, string method, string[] ptypes, bool isVarArgs)
183196
{
@@ -223,14 +236,14 @@ public virtual String[] GetParameterNames (string package, string type, string m
223236
var matcher = pattern.Match (text);
224237
if (matcher.Success) {
225238
var plist = matcher.Groups [1];
226-
String[] parms = plist.Value.Split (new string [] {", "}, StringSplitOptions.RemoveEmptyEntries);
239+
String[] parms = StripTagsFromParameters (plist.Value).Split (new string [] { ", " }, StringSplitOptions.RemoveEmptyEntries);
227240
if (parms.Length != ptypes.Length) {
228241
Log.Warning (1, "failed matching {0} (expected {1} params, got {2} params)", buffer, ptypes.Length, parms.Length);
229242
return null;
230243
}
231244
String[] result = new String [ptypes.Length];
232245
for (int i = 0; i < ptypes.Length; i++) {
233-
String[] toks = parms [i].Split (parameter_pair_splitter);
246+
String[] toks = parms [i].Split (parameter_pair_splitter, StringSplitOptions.RemoveEmptyEntries);
234247
result [i] = toks [toks.Length - 1];
235248
}
236249
return result;

0 commit comments

Comments
 (0)