|
3 | 3 | using System.IO;
|
4 | 4 | using System.Linq;
|
5 | 5 | using System.Xml;
|
| 6 | +using System.Xml.Linq; |
6 | 7 | using Mono.Cecil;
|
7 | 8 | using MonoDroid.Generation;
|
8 | 9 | using Xamarin.AndroidTools.AnnotationSupport;
|
@@ -178,6 +179,7 @@ static void Run (CodeGeneratorOptions options, DirectoryAssemblyResolver resolve
|
178 | 179 | SealedProtectedFixups.Fixup (gens);
|
179 | 180 |
|
180 | 181 | GenerateAnnotationAttributes (gens, annotations_zips);
|
| 182 | + AddJavadoc (gens, options.JavadocXmlFiles); |
181 | 183 |
|
182 | 184 | //SymbolTable.Dump ();
|
183 | 185 |
|
@@ -356,6 +358,78 @@ static void GenerateAnnotationAttributes (List<GenBase> gens, IEnumerable<string
|
356 | 358 | }
|
357 | 359 | }
|
358 | 360 |
|
| 361 | + static void AddJavadoc (List<GenBase> gens, IList<string> javadocXmlFiles) |
| 362 | + { |
| 363 | + if (javadocXmlFiles == null) |
| 364 | + return; |
| 365 | + foreach (var path in javadocXmlFiles) { |
| 366 | + if (!File.Exists (path)) |
| 367 | + continue; |
| 368 | + |
| 369 | + XDocument doc = XDocument.Load (path); |
| 370 | + |
| 371 | + foreach (var type in gens) { |
| 372 | + AddJavadoc (type, doc); |
| 373 | + } |
| 374 | + } |
| 375 | + } |
| 376 | + |
| 377 | + static void AddJavadoc (GenBase type, XDocument javadoc) |
| 378 | + { |
| 379 | + var typeJavadoc = javadoc.Elements ("api") |
| 380 | + .Elements ("package") |
| 381 | + .Where (p => type.PackageName == (string) p.Attribute ("name")) |
| 382 | + .Elements () |
| 383 | + .Where (e => type.JniName == (string) e.Attribute ("jni-signature")) |
| 384 | + .FirstOrDefault (); |
| 385 | + if (typeJavadoc == null) |
| 386 | + return; |
| 387 | + |
| 388 | + if (string.IsNullOrEmpty (type.Javadoc)) |
| 389 | + type.Javadoc = typeJavadoc.Element ("javadoc")?.Value; |
| 390 | + |
| 391 | + foreach (var method in type.Methods) { |
| 392 | + if (!string.IsNullOrEmpty (method.Javadoc)) |
| 393 | + continue; |
| 394 | + var methodJavadoc = typeJavadoc |
| 395 | + .Elements ("method") |
| 396 | + .Where (m => method.JavaName == (string) m.Attribute ("name") && method.JniSignature == (string) m.Attribute ("jni-signature")) |
| 397 | + .Elements ("javadoc") |
| 398 | + .FirstOrDefault (); |
| 399 | + if (methodJavadoc == null) |
| 400 | + continue; |
| 401 | + method.Javadoc = methodJavadoc.Value; |
| 402 | + } |
| 403 | + |
| 404 | + foreach (var field in type.Fields) { |
| 405 | + if (!string.IsNullOrEmpty (field.Javadoc)) |
| 406 | + continue; |
| 407 | + var fieldJavadoc = typeJavadoc |
| 408 | + .Elements ("field") |
| 409 | + .Where (m => field.JavaName == (string) m.Attribute ("name") && field.JniSignature == (string) m.Attribute ("jni-signature")) |
| 410 | + .Elements ("javadoc") |
| 411 | + .FirstOrDefault (); |
| 412 | + if (fieldJavadoc == null) |
| 413 | + continue; |
| 414 | + field.Javadoc = fieldJavadoc.Value; |
| 415 | + } |
| 416 | + |
| 417 | + if (type is ClassGen @class) { |
| 418 | + foreach (var ctor in @class.Ctors) { |
| 419 | + if (!string.IsNullOrEmpty (ctor.Javadoc)) |
| 420 | + continue; |
| 421 | + var ctorJavadoc = typeJavadoc |
| 422 | + .Elements ("constructor") |
| 423 | + .Where (c => ctor.JniSignature == (string) c.Attribute ("jni-signature")) |
| 424 | + .Elements ("javadoc") |
| 425 | + .FirstOrDefault (); |
| 426 | + if (ctorJavadoc == null) |
| 427 | + continue; |
| 428 | + ctor.Javadoc = ctorJavadoc.Value; |
| 429 | + } |
| 430 | + } |
| 431 | + } |
| 432 | + |
359 | 433 | static void AddAnnotationTo (AnnotatedItem item, string annotation)
|
360 | 434 | {
|
361 | 435 | if (item.ManagedInfo.PropertyObject != null)
|
|
0 commit comments