diff options
Diffstat (limited to 'editor/doc_tools.cpp')
-rw-r--r-- | editor/doc_tools.cpp | 135 |
1 files changed, 81 insertions, 54 deletions
diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp index e6cd1e0b48..a819458417 100644 --- a/editor/doc_tools.cpp +++ b/editor/doc_tools.cpp @@ -39,6 +39,7 @@ #include "core/object/script_language.h" #include "core/string/translation.h" #include "core/version.h" +#include "editor/editor_settings.h" #include "scene/resources/theme.h" // Used for a hack preserving Mono properties on non-Mono builds. @@ -178,6 +179,20 @@ void DocTools::merge_from(const DocTools &p_data) { } } + for (int i = 0; i < c.annotations.size(); i++) { + DocData::MethodDoc &m = c.annotations.write[i]; + + for (int j = 0; j < cf.annotations.size(); j++) { + if (cf.annotations[j].name != m.name) { + continue; + } + const DocData::MethodDoc &mf = cf.annotations[j]; + + m.description = mf.description; + break; + } + } + for (int i = 0; i < c.properties.size(); i++) { DocData::PropertyDoc &p = c.properties.write[i]; @@ -349,8 +364,15 @@ void DocTools::generate(bool p_basic_types) { List<PropertyInfo> properties; List<PropertyInfo> own_properties; - if (name == "ProjectSettings") { - // Special case for project settings, so settings can be documented. + + // Special case for editor and project settings, so they can be documented. + if (name == "EditorSettings") { + // We don't create the full blown EditorSettings (+ config file) with `create()`, + // instead we just make a local instance to get default values. + Ref<EditorSettings> edset = memnew(EditorSettings); + edset->get_property_list(&properties); + own_properties = properties; + } else if (name == "ProjectSettings") { ProjectSettings::get_singleton()->get_property_list(&properties); own_properties = properties; } else { @@ -388,6 +410,13 @@ void DocTools::generate(bool p_basic_types) { bool default_value_valid = false; Variant default_value; + if (name == "EditorSettings") { + if (E.name == "resource_local_to_scene" || E.name == "resource_name" || E.name == "resource_path" || E.name == "script") { + // Don't include spurious properties in the generated EditorSettings class reference. + continue; + } + } + if (name == "ProjectSettings") { // Special case for project settings, so that settings are not taken from the current project's settings if (E.name == "script" || !ProjectSettings::get_singleton()->is_builtin_setting(E.name)) { @@ -410,8 +439,6 @@ void DocTools::generate(bool p_basic_types) { } } - //used to track uninitialized values using valgrind - //print_line("getting default value for " + String(name) + "." + String(E.name)); if (default_value_valid && default_value.get_type() != Variant::OBJECT) { prop.default_value = default_value.get_construct_string().replace("\n", " "); } @@ -429,7 +456,7 @@ void DocTools::generate(bool p_basic_types) { PropertyInfo retinfo = mb->get_return_info(); found_type = true; - if (retinfo.type == Variant::INT && retinfo.usage & PROPERTY_USAGE_CLASS_IS_ENUM) { + if (retinfo.type == Variant::INT && retinfo.usage & (PROPERTY_USAGE_CLASS_IS_ENUM | PROPERTY_USAGE_CLASS_IS_BITFIELD)) { prop.enumeration = retinfo.class_name; prop.type = "int"; } else if (retinfo.class_name != StringName()) { @@ -484,53 +511,7 @@ void DocTools::generate(bool p_basic_types) { } DocData::MethodDoc method; - - method.name = E.name; - - if (E.flags & METHOD_FLAG_VIRTUAL) { - method.qualifiers = "virtual"; - } - - if (E.flags & METHOD_FLAG_CONST) { - if (!method.qualifiers.is_empty()) { - method.qualifiers += " "; - } - method.qualifiers += "const"; - } - - if (E.flags & METHOD_FLAG_VARARG) { - if (!method.qualifiers.is_empty()) { - method.qualifiers += " "; - } - method.qualifiers += "vararg"; - } - - if (E.flags & METHOD_FLAG_STATIC) { - if (!method.qualifiers.is_empty()) { - method.qualifiers += " "; - } - method.qualifiers += "static"; - } - - for (int i = -1; i < E.arguments.size(); i++) { - if (i == -1) { -#ifdef DEBUG_METHODS_ENABLED - DocData::return_doc_from_retinfo(method, E.return_val); -#endif - } else { - const PropertyInfo &arginfo = E.arguments[i]; - DocData::ArgumentDoc argument; - DocData::argument_doc_from_arginfo(argument, arginfo); - - int darg_idx = i - (E.arguments.size() - E.default_arguments.size()); - if (darg_idx >= 0) { - Variant default_arg = E.default_arguments[darg_idx]; - argument.default_value = default_arg.get_construct_string().replace("\n", " "); - } - - method.arguments.push_back(argument); - } - } + DocData::method_doc_from_methodinfo(method, E, ""); Vector<Error> errs = ClassDB::get_method_error_return_values(name, E.name); if (errs.size()) { @@ -575,6 +556,7 @@ void DocTools::generate(bool p_basic_types) { constant.value = itos(ClassDB::get_integer_constant(name, E)); constant.is_value_valid = true; constant.enumeration = ClassDB::get_integer_constant_enum(name, E); + constant.is_bitfield = ClassDB::is_enum_bitfield(name, constant.enumeration); c.constants.push_back(constant); } @@ -959,8 +941,41 @@ void DocTools::generate(bool p_basic_types) { c.constants.push_back(cd); } + // Get annotations. + List<MethodInfo> ainfo; + lang->get_public_annotations(&ainfo); + + for (const MethodInfo &ai : ainfo) { + DocData::MethodDoc atd; + atd.name = ai.name; + + if (ai.flags & METHOD_FLAG_VARARG) { + if (!atd.qualifiers.is_empty()) { + atd.qualifiers += " "; + } + atd.qualifiers += "vararg"; + } + + DocData::return_doc_from_retinfo(atd, ai.return_val); + + for (int j = 0; j < ai.arguments.size(); j++) { + DocData::ArgumentDoc ad; + DocData::argument_doc_from_arginfo(ad, ai.arguments[j]); + + int darg_idx = j - (ai.arguments.size() - ai.default_arguments.size()); + if (darg_idx >= 0) { + Variant default_arg = ai.default_arguments[darg_idx]; + ad.default_value = default_arg.get_construct_string().replace("\n", " "); + } + + atd.arguments.push_back(ad); + } + + c.annotations.push_back(atd); + } + // Skip adding the lang if it doesn't expose anything (e.g. C#). - if (c.methods.is_empty() && c.constants.is_empty()) { + if (c.methods.is_empty() && c.constants.is_empty() && c.annotations.is_empty()) { continue; } @@ -1162,6 +1177,9 @@ Error DocTools::_load(Ref<XMLParser> parser) { } else if (name2 == "signals") { Error err2 = _parse_methods(parser, c.signals); ERR_FAIL_COND_V(err2, err2); + } else if (name2 == "annotations") { + Error err2 = _parse_methods(parser, c.annotations); + ERR_FAIL_COND_V(err2, err2); } else if (name2 == "members") { while (parser->read() == OK) { if (parser->get_node_type() == XMLParser::NODE_ELEMENT) { @@ -1244,6 +1262,9 @@ Error DocTools::_load(Ref<XMLParser> parser) { if (parser->has_attribute("enum")) { constant2.enumeration = parser->get_attribute_value("enum"); } + if (parser->has_attribute("is_bitfield")) { + constant2.is_bitfield = parser->get_attribute_value("is_bitfield").to_lower() == "true"; + } if (!parser->is_empty()) { parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) { @@ -1424,7 +1445,11 @@ Error DocTools::save_classes(const String &p_default_path, const HashMap<String, const DocData::ConstantDoc &k = c.constants[i]; if (k.is_value_valid) { if (!k.enumeration.is_empty()) { - _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\" enum=\"" + k.enumeration + "\">"); + if (k.is_bitfield) { + _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\" enum=\"" + k.enumeration + "\" is_bitfield=\"true\">"); + } else { + _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\" enum=\"" + k.enumeration + "\">"); + } } else { _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\">"); } @@ -1442,6 +1467,8 @@ Error DocTools::save_classes(const String &p_default_path, const HashMap<String, _write_string(f, 1, "</constants>"); } + _write_method_doc(f, "annotation", c.annotations); + if (!c.theme_properties.is_empty()) { c.theme_properties.sort(); |