diff options
Diffstat (limited to 'editor/doc_tools.cpp')
-rw-r--r-- | editor/doc_tools.cpp | 149 |
1 files changed, 111 insertions, 38 deletions
diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp index ec9a744e57..85adc312f2 100644 --- a/editor/doc_tools.cpp +++ b/editor/doc_tools.cpp @@ -1,32 +1,32 @@ -/*************************************************************************/ -/* doc_tools.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ +/**************************************************************************/ +/* doc_tools.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ #include "doc_tools.h" @@ -85,6 +85,9 @@ void DocTools::merge_from(const DocTools &p_data) { const DocData::ClassDoc &cf = p_data.class_list[c.name]; + c.is_deprecated = cf.is_deprecated; + c.is_experimental = cf.is_experimental; + c.description = cf.description; c.brief_description = cf.brief_description; c.tutorials = cf.tutorials; @@ -133,6 +136,8 @@ void DocTools::merge_from(const DocTools &p_data) { const DocData::MethodDoc &mf = cf.constructors[j]; m.description = mf.description; + m.is_deprecated = mf.is_deprecated; + m.is_experimental = mf.is_experimental; break; } } @@ -148,6 +153,8 @@ void DocTools::merge_from(const DocTools &p_data) { const DocData::MethodDoc &mf = cf.methods[j]; m.description = mf.description; + m.is_deprecated = mf.is_deprecated; + m.is_experimental = mf.is_experimental; break; } } @@ -162,6 +169,8 @@ void DocTools::merge_from(const DocTools &p_data) { const DocData::MethodDoc &mf = cf.signals[j]; m.description = mf.description; + m.is_deprecated = mf.is_deprecated; + m.is_experimental = mf.is_experimental; break; } } @@ -176,6 +185,8 @@ void DocTools::merge_from(const DocTools &p_data) { const DocData::ConstantDoc &mf = cf.constants[j]; m.description = mf.description; + m.is_deprecated = mf.is_deprecated; + m.is_experimental = mf.is_experimental; break; } } @@ -190,6 +201,8 @@ void DocTools::merge_from(const DocTools &p_data) { const DocData::MethodDoc &mf = cf.annotations[j]; m.description = mf.description; + m.is_deprecated = mf.is_deprecated; + m.is_experimental = mf.is_experimental; break; } } @@ -204,6 +217,8 @@ void DocTools::merge_from(const DocTools &p_data) { const DocData::PropertyDoc &pf = cf.properties[j]; p.description = pf.description; + p.is_deprecated = pf.is_deprecated; + p.is_experimental = pf.is_experimental; break; } } @@ -266,6 +281,8 @@ void DocTools::merge_from(const DocTools &p_data) { const DocData::MethodDoc &mf = cf.operators[j]; m.description = mf.description; + m.is_deprecated = mf.is_deprecated; + m.is_experimental = mf.is_experimental; break; } } @@ -318,7 +335,7 @@ static Variant get_documentation_default_value(const StringName &p_class_name, c Variant default_value = Variant(); r_default_value_valid = false; - if (ClassDB::can_instantiate(p_class_name)) { + if (ClassDB::can_instantiate(p_class_name) && !ClassDB::is_virtual(p_class_name)) { // Keep this condition in sync with ClassDB::class_get_default_property_value. default_value = ClassDB::class_get_default_property_value(p_class_name, p_property_name, &r_default_value_valid); } else { // Cannot get default value of classes that can't be instantiated @@ -684,7 +701,7 @@ void DocTools::generate(bool p_basic_types) { if (rt != Variant::NIL) { // Has operator. // Skip String % operator as it's registered separately for each Variant arg type, // we'll add it manually below. - if (i == Variant::STRING && Variant::Operator(j) == Variant::OP_MODULE) { + if ((i == Variant::STRING || i == Variant::STRING_NAME) && Variant::Operator(j) == Variant::OP_MODULE) { continue; } MethodInfo mi; @@ -701,7 +718,7 @@ void DocTools::generate(bool p_basic_types) { } } - if (i == Variant::STRING) { + if (i == Variant::STRING || i == Variant::STRING_NAME) { // We skipped % operator above, and we register it manually once for Variant arg type here. MethodInfo mi; mi.name = "operator %"; @@ -828,6 +845,7 @@ void DocTools::generate(bool p_basic_types) { for (int i = 0; i < CoreConstants::get_global_constant_count(); i++) { DocData::ConstantDoc cd; cd.name = CoreConstants::get_global_constant_name(i); + cd.is_bitfield = CoreConstants::is_global_constant_bitfield(i); if (!CoreConstants::get_ignore_value_in_docs(i)) { cd.value = itos(CoreConstants::get_global_constant_value(i)); cd.is_value_valid = true; @@ -1007,6 +1025,12 @@ static Error _parse_methods(Ref<XMLParser> &parser, Vector<DocData::MethodDoc> & if (parser->has_attribute("qualifiers")) { method.qualifiers = parser->get_attribute_value("qualifiers"); } + if (parser->has_attribute("is_deprecated")) { + method.is_deprecated = parser->get_attribute_value("is_deprecated").to_lower() == "true"; + } + if (parser->has_attribute("is_experimental")) { + method.is_experimental = parser->get_attribute_value("is_experimental").to_lower() == "true"; + } while (parser->read() == OK) { if (parser->get_node_type() == XMLParser::NODE_ELEMENT) { @@ -1138,6 +1162,14 @@ Error DocTools::_load(Ref<XMLParser> parser) { c.inherits = parser->get_attribute_value("inherits"); } + if (parser->has_attribute("is_deprecated")) { + c.is_deprecated = parser->get_attribute_value("is_deprecated").to_lower() == "true"; + } + + if (parser->has_attribute("is_experimental")) { + c.is_experimental = parser->get_attribute_value("is_experimental").to_lower() == "true"; + } + while (parser->read() == OK) { if (parser->get_node_type() == XMLParser::NODE_ELEMENT) { String name2 = parser->get_node_name(); @@ -1211,6 +1243,12 @@ Error DocTools::_load(Ref<XMLParser> parser) { if (parser->has_attribute("enum")) { prop2.enumeration = parser->get_attribute_value("enum"); } + if (parser->has_attribute("is_deprecated")) { + prop2.is_deprecated = parser->get_attribute_value("is_deprecated").to_lower() == "true"; + } + if (parser->has_attribute("is_experimental")) { + prop2.is_experimental = parser->get_attribute_value("is_experimental").to_lower() == "true"; + } if (!parser->is_empty()) { parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) { @@ -1275,6 +1313,12 @@ Error DocTools::_load(Ref<XMLParser> parser) { if (parser->has_attribute("is_bitfield")) { constant2.is_bitfield = parser->get_attribute_value("is_bitfield").to_lower() == "true"; } + if (parser->has_attribute("is_deprecated")) { + constant2.is_deprecated = parser->get_attribute_value("is_deprecated").to_lower() == "true"; + } + if (parser->has_attribute("is_experimental")) { + constant2.is_experimental = parser->get_attribute_value("is_experimental").to_lower() == "true"; + } if (!parser->is_empty()) { parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) { @@ -1327,7 +1371,15 @@ static void _write_method_doc(Ref<FileAccess> f, const String &p_name, Vector<Do qualifiers += " qualifiers=\"" + m.qualifiers.xml_escape() + "\""; } - _write_string(f, 2, "<" + p_name + " name=\"" + m.name.xml_escape() + "\"" + qualifiers + ">"); + String additional_attributes; + if (m.is_deprecated) { + additional_attributes += " is_deprecated=\"true\""; + } + if (m.is_experimental) { + additional_attributes += " is_experimental=\"true\""; + } + + _write_string(f, 2, "<" + p_name + " name=\"" + m.name.xml_escape() + "\"" + qualifiers + additional_attributes + ">"); if (!m.return_type.is_empty()) { String enum_text; @@ -1390,6 +1442,12 @@ Error DocTools::save_classes(const String &p_default_path, const HashMap<String, String header = "<class name=\"" + c.name + "\""; if (!c.inherits.is_empty()) { header += " inherits=\"" + c.inherits + "\""; + if (c.is_deprecated) { + header += " is_deprecated=\"true\""; + } + if (c.is_experimental) { + header += " is_experimental=\"true\""; + } } header += String(" version=\"") + VERSION_BRANCH + "\""; // Reference the XML schema so editors can provide error checking. @@ -1433,6 +1491,12 @@ Error DocTools::save_classes(const String &p_default_path, const HashMap<String, if (!c.properties[i].default_value.is_empty()) { additional_attributes += " default=\"" + c.properties[i].default_value.xml_escape(true) + "\""; } + if (c.properties[i].is_deprecated) { + additional_attributes += " is_deprecated=\"true\""; + } + if (c.properties[i].is_experimental) { + additional_attributes += " is_experimental=\"true\""; + } const DocData::PropertyDoc &p = c.properties[i]; @@ -1453,21 +1517,30 @@ Error DocTools::save_classes(const String &p_default_path, const HashMap<String, _write_string(f, 1, "<constants>"); for (int i = 0; i < c.constants.size(); i++) { const DocData::ConstantDoc &k = c.constants[i]; + + String additional_attributes; + if (c.constants[i].is_deprecated) { + additional_attributes += " is_deprecated=\"true\""; + } + if (c.constants[i].is_experimental) { + additional_attributes += " is_experimental=\"true\""; + } + if (k.is_value_valid) { if (!k.enumeration.is_empty()) { if (k.is_bitfield) { - _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\" enum=\"" + k.enumeration + "\" is_bitfield=\"true\">"); + _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\" enum=\"" + k.enumeration + "\" is_bitfield=\"true\"" + additional_attributes + ">"); } else { - _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\" enum=\"" + k.enumeration + "\">"); + _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\" enum=\"" + k.enumeration + "\"" + additional_attributes + ">"); } } else { - _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\">"); + _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\"" + additional_attributes + ">"); } } else { if (!k.enumeration.is_empty()) { - _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"platform-dependent\" enum=\"" + k.enumeration + "\">"); + _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"platform-dependent\" enum=\"" + k.enumeration + "\"" + additional_attributes + ">"); } else { - _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"platform-dependent\">"); + _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"platform-dependent\"" + additional_attributes + ">"); } } _write_string(f, 3, _translate_doc_string(k.description).strip_edges().xml_escape()); |