QmlJS: Add support for annotations in qmljsreformatter

This fixes that the annotations are removed. The indentation
still has issues.

Change-Id: I6752767e00e0fafe8eb567066db3b9952f0d0a4f
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Thomas Hartmann
2023-06-06 11:00:37 +02:00
parent 5dadc57bc3
commit 90b36d88e2
2 changed files with 48 additions and 1 deletions

View File

@@ -590,14 +590,35 @@ protected:
return true; return true;
} }
bool visit(UiObjectDefinition *ast) override bool visit(UiAnnotation *ast) override
{ {
out("@");
accept(ast->qualifiedTypeNameId); accept(ast->qualifiedTypeNameId);
out(" "); out(" ");
accept(ast->initializer); accept(ast->initializer);
return false; return false;
} }
bool visit(UiAnnotationList *ast) override
{
for (UiAnnotationList *it = ast; it; it = it->next) {
accept(it->annotation);
newLine();
}
return false;
}
bool visit(UiObjectDefinition *ast) override
{
accept(ast->annotations);
accept(ast->qualifiedTypeNameId);
out(" ");
accept(ast->initializer);
return false;
}
bool visit(UiObjectInitializer *ast) override bool visit(UiObjectInitializer *ast) override
{ {
out(ast->lbraceToken); out(ast->lbraceToken);
@@ -687,9 +708,12 @@ protected:
bool visit(UiScriptBinding *ast) override bool visit(UiScriptBinding *ast) override
{ {
accept(ast->annotations);
accept(ast->qualifiedId); accept(ast->qualifiedId);
out(": ", ast->colonToken); out(": ", ast->colonToken);
accept(ast->statement); accept(ast->statement);
return false; return false;
} }
@@ -1290,6 +1314,7 @@ protected:
{ {
for (UiObjectMemberList *it = ast; it; it = it->next) { for (UiObjectMemberList *it = ast; it; it = it->next) {
accept(it->member); accept(it->member);
if (it->next) if (it->next)
newLine(); newLine();
} }

View File

@@ -0,0 +1,22 @@
import QtQuick
@Annotation {}
Item {
// properties
property int foo
property alias bar: x
@Annotation2 {
someproperty: 10
}
id: someId
@Annotation3 {
someproperty: 10
}
Rectangle {
// properties
property int foo
property alias bar: x
id: someId2
}
}