Skip to content

Commit

Permalink
Merge pull request #30 from jonpryor/jonp-update-bytecode-from-monodr…
Browse files Browse the repository at this point in the history
…oid/a438c473

[Xamarin.Android.Tools.bytecode] Add JavaDoc importing
  • Loading branch information
radical committed May 3, 2016
2 parents d547120 + 5693c60 commit 13a6be9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
21 changes: 20 additions & 1 deletion src/Xamarin.Android.Tools.Bytecode/ClassPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@

namespace Xamarin.Android.Tools.Bytecode {

public enum JavaDocletType {
DroidDoc,
Java6,
Java7,
Java8,
}

public class ClassPath {

IList<ClassFile> classFiles = new List<ClassFile> ();

public string ApiSource { get; set; }

public JavaDocletType DocletType { get; set; }

public IEnumerable<string> DocumentationPaths { get; set; }

public bool AutoRename { get; set; }
Expand Down Expand Up @@ -213,9 +222,19 @@ void FixupParametersFromDocs (XElement api)
}
}

AndroidDocScraper CreateDocScraper (string dir)
{
switch (DocletType) {
default: return new DroidDocScraper (dir);
case JavaDocletType.Java6: return new JavaDocScraper (dir);
case JavaDocletType.Java7: return new Java7DocScraper (dir);
case JavaDocletType.Java8: return new Java8DocScraper (dir);
}
}

void FixupParametersFromDocs (XElement api, string path)
{
var jdoc = new DroidDocScraper (path);
var jdoc = CreateDocScraper (path);
var elements = api.XPathSelectElements ("./package/class[@visibility = 'public' or @visibility = 'protected']").ToList ();
elements.AddRange (api.XPathSelectElements ("./package/interface[@visibility = 'public' or @visibility = 'protected']"));
foreach (var elem in elements) {
Expand Down
30 changes: 26 additions & 4 deletions tools/class-parse/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ class App {

public static void Main (string[] args)
{
JavaDocletType docsType = 0;

bool dump = false;
bool help = false;
int verbosity = 0;
bool autorename = false;
var outputFile = (string) null;
var docsPath = (string) null;
var docsPaths = new List<string> ();
var p = new OptionSet () {
"usage: class-dump [-dump] FILES",
"",
Expand All @@ -34,8 +36,12 @@ public static void Main (string[] args)
"Write output to {PATH}.",
v => outputFile = v },
{ "docspath=",
"Android documentation path for parameter fixup",
doc => docsPath = doc},
"Documentation {PATH} for parameter fixup",
doc => docsPaths.Add (doc) },
{ "docstype=",
"{TYPE} of the docs within --docspath. Values:\n " +
string.Join ("\n ", JavaDocletTypeMapping.Keys.OrderBy (s => s)),
t => docsType = GetJavaDocletType (t) },
{ "v|verbose:",
"See stack traces on error.",
(int? v) => verbosity = v.HasValue ? v.Value : verbosity + 1 },
Expand All @@ -59,7 +65,8 @@ public static void Main (string[] args)
};
var classPath = new ClassPath () {
ApiSource = "class-parse",
DocumentationPaths = !string.IsNullOrEmpty (docsPath) ? new string[] { docsPath } : null,
DocumentationPaths = docsPaths.Count == 0 ? null : docsPaths,
DocletType = docsType,
AutoRename = autorename
};
foreach (var file in files) {
Expand All @@ -81,6 +88,21 @@ public static void Main (string[] args)
output.Close ();
}

static Dictionary<string, JavaDocletType> JavaDocletTypeMapping = new Dictionary<string, JavaDocletType> {
{ "droiddoc", JavaDocletType.DroidDoc },
{ "java6", JavaDocletType.Java6 },
{ "java7", JavaDocletType.Java7 },
{ "java8", JavaDocletType.Java8 },
};

static JavaDocletType GetJavaDocletType (string value)
{
JavaDocletType type;
if (value != null && JavaDocletTypeMapping.TryGetValue (value.ToLowerInvariant (), out type))
return type;
return JavaDocletType.DroidDoc;
}

static void DumpFileToXml (ClassPath jar, string file)
{
using (var s = File.OpenRead (file)) {
Expand Down

0 comments on commit 13a6be9

Please sign in to comment.