Browse Source

[macro] add haxe.macro.Expr.TypeDefinition.doc field and support printing it with haxe.macro.Printer (#6401)

Dan Korostelev 8 years ago
parent
commit
bfd7db1b46
3 changed files with 9 additions and 1 deletions
  1. 2 1
      src/macro/macroApi.ml
  2. 6 0
      std/haxe/macro/Expr.hx
  3. 1 0
      std/haxe/macro/Printer.hx

+ 2 - 1
src/macro/macroApi.ml

@@ -1369,10 +1369,11 @@ let decode_type_def v =
 	let pos = decode_pos (field v "pos") in
 	let isExtern = decode_opt_bool (field v "isExtern") in
 	let fields = List.map decode_field (decode_array (field v "fields")) in
+	let doc = opt decode_string (field v "doc") in
 	let mk fl dl =
 		{
 			d_name = name;
-			d_doc = None;
+			d_doc = doc;
 			d_params = decode_tparams (field v "params");
 			d_meta = meta;
 			d_flags = fl;

+ 6 - 0
std/haxe/macro/Expr.hx

@@ -808,6 +808,12 @@ typedef TypeDefinition = {
 	**/
 	var name : String;
 
+	/**
+		The documentation of the type, if available. If the type has no
+		documentation, the value is `null`.
+	**/
+	@:optional var doc : Null<String>;
+
 	/**
 		The position to the type definition.
 	**/

+ 1 - 0
std/haxe/macro/Printer.hx

@@ -251,6 +251,7 @@ class Printer {
 
 		var str = t == null ? "#NULL" :
 			(printPackage && t.pack.length > 0 && t.pack[0] != "" ? "package " + t.pack.join(".") + ";\n" : "") +
+			(t.doc != null && t.doc != "" ? "/**\n" + tabString + StringTools.replace(t.doc, "\n", "\n" + tabString) + "\n**/\n" : "") +
 			(t.meta != null && t.meta.length > 0 ? t.meta.map(printMetadata).join(" ") + " " : "") + (t.isExtern ? "extern " : "") + switch (t.kind) {
 				case TDEnum:
 					"enum " + t.name + ((t.params != null && t.params.length > 0) ? "<" + t.params.map(printTypeParamDecl).join(", ") + ">" : "") + " {\n"