Line data Source code
1 : // SPDX-FileCopyrightText: 2013-2025 Paul Colby <git@colby.id.au>
2 : // SPDX-License-Identifier: LGPL-3.0-or-later
3 :
4 : #include <QtGlobal> // \todo Remove if/when dropping support for Qt 6.0.x.
5 : #if (QT_VERSION_CHECK(6, 0, 0) <= QT_VERSION) && (QT_VERSION < QT_VERSION_CHECK(6, 1, 0))
6 : #include <limits> // https://bugreports.qt.io/browse/QTBUG-89977
7 : #endif
8 :
9 : #include <QCoreApplication>
10 : #include <QDir>
11 : #include <QJsonObject>
12 : #include <QLoggingCategory>
13 :
14 : namespace smithy {
15 : class Model;
16 : class Shape;
17 : }
18 : class Renderer;
19 :
20 0 : class Generator
21 : {
22 0 : Q_DECLARE_TR_FUNCTIONS(Generator);
23 :
24 : public:
25 : enum class ClobberMode {
26 : Prompt,
27 : Overwrite,
28 : Skip,
29 : };
30 :
31 : Generator(const smithy::Model * const model, Renderer * const renderer);
32 :
33 : int expectedFileCount() const;
34 :
35 : bool generate(const QString &outputDir, ClobberMode clobberMode);
36 :
37 : QStringList renderedFiles() const;
38 : QStringList skippedFiles() const;
39 :
40 : protected:
41 : enum class Capitalisation {
42 : NoChange = 0,
43 : lowercase = 1,
44 : camelCase = 2,
45 : CamelCase = 3,
46 : UPPERCASE = 4,
47 : };
48 :
49 : bool renderService(const smithy::Shape &service,
50 : const QStringList &serviceTemplateNames,
51 : const QStringList &operationTemplateNames,
52 : const QString &outputDir, ClobberMode &clobberMode);
53 :
54 : bool renderOperation(const smithy::Shape &operation, const QVariantHash serviceContext,
55 : const QStringList &templateNames, const QString &outputDir,
56 : ClobberMode &clobberMode);
57 :
58 : bool render(const QString &templateName, const QString &outputPathName,
59 : ClobberMode &clobberMode);
60 :
61 : QVariantHash toContext(const smithy::Shape &shape) const;
62 :
63 : static const QString canonicalServiceId(const QString &sdkId);
64 :
65 : static bool promptToOverwrite(const QString &pathName, ClobberMode &clobberMode);
66 :
67 : static Capitalisation getCase(const QString &first, const QString &second);
68 : static QString makeCase(const QString &string, const Capitalisation &capitalisation);
69 : static QString makeOutputPathName(const QString &templateName, const QRegularExpression &pattern,
70 : const QHash<QString,QString> &ids,
71 : const QString &outputDir = QString{});
72 :
73 : static QStringList formatHtmlDocumentation(const QString &html);
74 :
75 : private:
76 : const smithy::Model * const model;
77 : Renderer * const renderer;
78 : QStringList renderedPathNames;
79 : QStringList skippedPathNames;
80 :
81 : static const QRegularExpression servicePattern;
82 : static const QRegularExpression operationPattern;
83 0 : static Q_LOGGING_CATEGORY(lc, "smithy.Generator", QtInfoMsg); ///< Logging category for Generator.
84 : };
|