From 90b36d88e20b9620802c6e52e1c63c8f739889d3 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Tue, 6 Jun 2023 11:00:37 +0200 Subject: [PATCH] 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 Reviewed-by: --- src/libs/qmljs/qmljsreformatter.cpp | 27 +++++++++++++++++++++- tests/auto/qml/reformatter/annotations.qml | 22 ++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/auto/qml/reformatter/annotations.qml diff --git a/src/libs/qmljs/qmljsreformatter.cpp b/src/libs/qmljs/qmljsreformatter.cpp index 232c0361a1a..d2891451e95 100644 --- a/src/libs/qmljs/qmljsreformatter.cpp +++ b/src/libs/qmljs/qmljsreformatter.cpp @@ -590,14 +590,35 @@ protected: return true; } - bool visit(UiObjectDefinition *ast) override + bool visit(UiAnnotation *ast) override { + out("@"); accept(ast->qualifiedTypeNameId); out(" "); accept(ast->initializer); 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 { out(ast->lbraceToken); @@ -687,9 +708,12 @@ protected: bool visit(UiScriptBinding *ast) override { + accept(ast->annotations); + accept(ast->qualifiedId); out(": ", ast->colonToken); accept(ast->statement); + return false; } @@ -1290,6 +1314,7 @@ protected: { for (UiObjectMemberList *it = ast; it; it = it->next) { accept(it->member); + if (it->next) newLine(); } diff --git a/tests/auto/qml/reformatter/annotations.qml b/tests/auto/qml/reformatter/annotations.qml new file mode 100644 index 00000000000..ee3d1fb45ca --- /dev/null +++ b/tests/auto/qml/reformatter/annotations.qml @@ -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 + } +}