Merge pull request #76065 from dalexeev/gds-check-tool-and-icon
GDScript: Add some checks for `@tool` and `@icon`
This commit is contained in:
commit
a1d2396ab9
5 changed files with 30 additions and 0 deletions
|
@ -3686,6 +3686,12 @@ bool GDScriptParser::validate_annotation_arguments(AnnotationNode *p_annotation)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GDScriptParser::tool_annotation(const AnnotationNode *p_annotation, Node *p_node) {
|
bool GDScriptParser::tool_annotation(const AnnotationNode *p_annotation, Node *p_node) {
|
||||||
|
#ifdef DEBUG_ENABLED
|
||||||
|
if (this->_is_tool) {
|
||||||
|
push_error(R"("@tool" annotation can only be used once.)", p_annotation);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif // DEBUG_ENABLED
|
||||||
this->_is_tool = true;
|
this->_is_tool = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -3694,6 +3700,16 @@ bool GDScriptParser::icon_annotation(const AnnotationNode *p_annotation, Node *p
|
||||||
ERR_FAIL_COND_V_MSG(p_node->type != Node::CLASS, false, R"("@icon" annotation can only be applied to classes.)");
|
ERR_FAIL_COND_V_MSG(p_node->type != Node::CLASS, false, R"("@icon" annotation can only be applied to classes.)");
|
||||||
ERR_FAIL_COND_V(p_annotation->resolved_arguments.is_empty(), false);
|
ERR_FAIL_COND_V(p_annotation->resolved_arguments.is_empty(), false);
|
||||||
ClassNode *p_class = static_cast<ClassNode *>(p_node);
|
ClassNode *p_class = static_cast<ClassNode *>(p_node);
|
||||||
|
#ifdef DEBUG_ENABLED
|
||||||
|
if (!p_class->icon_path.is_empty()) {
|
||||||
|
push_error(R"("@icon" annotation can only be used once.)", p_annotation);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (String(p_annotation->resolved_arguments[0]).is_empty()) {
|
||||||
|
push_error(R"("@icon" annotation argument must contain the path to the icon.)", p_annotation->arguments[0]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif // DEBUG_ENABLED
|
||||||
p_class->icon_path = p_annotation->resolved_arguments[0];
|
p_class->icon_path = p_annotation->resolved_arguments[0];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
@icon("res://1.png")
|
||||||
|
@icon("res://1.png")
|
||||||
|
|
||||||
|
func test():
|
||||||
|
pass
|
|
@ -0,0 +1,2 @@
|
||||||
|
GDTEST_PARSER_ERROR
|
||||||
|
"@icon" annotation can only be used once.
|
|
@ -0,0 +1,5 @@
|
||||||
|
@tool
|
||||||
|
@tool
|
||||||
|
|
||||||
|
func test():
|
||||||
|
pass
|
|
@ -0,0 +1,2 @@
|
||||||
|
GDTEST_ANALYZER_ERROR
|
||||||
|
"@tool" annotation can only be used once.
|
Loading…
Reference in a new issue