Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqmldomerrormessage_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef ERRORMESSAGE_H
5#define ERRORMESSAGE_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qqmldom_global.h"
20#include "qqmldompath_p.h"
21
22#include <QtQml/private/qqmljsast_p.h>
23#include <QtCore/QCoreApplication>
24#include <QtCore/QString>
25#include <QtCore/QCborArray>
26#include <QtCore/QCborMap>
27#include <QtCore/QLoggingCategory>
28#include <QtQml/private/qqmljsdiagnosticmessage_p.h>
29
31
32namespace QQmlJS {
33namespace Dom {
34
36
38
39class ErrorGroups;
40class DomItem;
41using std::function;
42
43#define NewErrorGroup(name) QQmlJS::Dom::ErrorGroup(QT_TRANSLATE_NOOP("ErrorGroup", name))
44
48public:
49 constexpr ErrorGroup(const char *groupId):
50 m_groupId(groupId)
51 {}
52
53
54 void dump(const Sink &sink) const;
55 void dumpId(const Sink &sink) const;
56
57 QLatin1String groupId() const;
58 QString groupName() const;
59 private:
60 const char *m_groupId;
61};
62
65public:
66 void dump(const Sink &sink) const;
67 void dumpId(const Sink &sink) const;
68 QCborArray toCbor() const;
69
70 [[nodiscard]] ErrorMessage errorMessage(
71 const Dumper &msg, ErrorLevel level, const Path &element = Path(),
72 const QString &canonicalFilePath = QString(), SourceLocation location = SourceLocation()) const;
73 [[nodiscard]] ErrorMessage errorMessage(
74 const DiagnosticMessage &msg, const Path &element = Path(),
75 const QString &canonicalFilePath = QString()) const;
76
77 void fatal(const Dumper &msg, const Path &element = Path(), QStringView canonicalFilePath = u"",
79
80 [[nodiscard]] ErrorMessage debug(const QString &message) const;
81 [[nodiscard]] ErrorMessage debug(const Dumper &message) const;
82 [[nodiscard]] ErrorMessage info(const QString &message) const;
83 [[nodiscard]] ErrorMessage info(const Dumper &message) const;
84 [[nodiscard]] ErrorMessage warning(const QString &message) const;
85 [[nodiscard]] ErrorMessage warning(const Dumper &message) const;
86 [[nodiscard]] ErrorMessage error(const QString &message) const;
87 [[nodiscard]] ErrorMessage error(const Dumper &message) const;
88
89 static int cmp(const ErrorGroups &g1, const ErrorGroups &g2);
90
91 QVector<ErrorGroup> groups;
92};
93
94inline bool operator==(const ErrorGroups& lhs, const ErrorGroups& rhs){ return ErrorGroups::cmp(lhs,rhs) == 0; }
95inline bool operator!=(const ErrorGroups& lhs, const ErrorGroups& rhs){ return ErrorGroups::cmp(lhs,rhs) != 0; }
96inline bool operator< (const ErrorGroups& lhs, const ErrorGroups& rhs){ return ErrorGroups::cmp(lhs,rhs) < 0; }
97inline bool operator> (const ErrorGroups& lhs, const ErrorGroups& rhs){ return ErrorGroups::cmp(lhs,rhs) > 0; }
98inline bool operator<=(const ErrorGroups& lhs, const ErrorGroups& rhs){ return ErrorGroups::cmp(lhs,rhs) <= 0; }
99inline bool operator>=(const ErrorGroups& lhs, const ErrorGroups& rhs){ return ErrorGroups::cmp(lhs,rhs) >= 0; }
100
101class QMLDOM_EXPORT ErrorMessage { // reuse Some of the other DiagnosticMessages?
104public:
106 // error registry (usage is optional)
107 static QLatin1String msg(const char *errorId, ErrorMessage &&err);
108 static QLatin1String msg(QLatin1String errorId, ErrorMessage &&err);
109 static void visitRegisteredMessages(function_ref<bool (const ErrorMessage &)> visitor);
110 [[nodiscard]] static ErrorMessage load(QLatin1String errorId);
111 [[nodiscard]] static ErrorMessage load(const char *errorId);
112 template<typename... T>
113 [[nodiscard]] static ErrorMessage load(QLatin1String errorId, T... args){
114 ErrorMessage res = load(errorId);
115 res.message = res.message.arg(args...);
116 return res;
117 }
118
120 const QString &message, const ErrorGroups &errorGroups, Level level = Level::Warning,
121 const Path &path = Path(), const QString &file = QString(),
124 const ErrorGroups &errorGroups, const DiagnosticMessage &msg, const Path &path = Path(),
125 const QString &file = QString(), QLatin1String errorId = QLatin1String(""));
126
127 [[nodiscard]] ErrorMessage &withErrorId(QLatin1String errorId);
128 [[nodiscard]] ErrorMessage &withPath(const Path &);
129 [[nodiscard]] ErrorMessage &withFile(const QString &);
130 [[nodiscard]] ErrorMessage &withFile(QStringView);
131 [[nodiscard]] ErrorMessage &withLocation(SourceLocation);
132 [[nodiscard]] ErrorMessage &withItem(const DomItem &);
133
134 ErrorMessage handle(const ErrorHandler &errorHandler=nullptr);
135
136 void dump(const Sink &s) const;
137 QString toString() const;
138 QCborMap toCbor() const;
139 friend int compare(const ErrorMessage &msg1, const ErrorMessage &msg2)
140 {
141 int c;
142 c = msg1.location.offset - msg2.location.offset;
143 if (c != 0)
144 return c;
145 c = msg1.location.startLine - msg2.location.startLine;
146 if (c != 0)
147 return c;
148 c = msg1.errorId.compare(msg2.errorId);
149 if (c != 0)
150 return c;
151 if (!msg1.errorId.isEmpty())
152 return 0;
153 c = msg1.message.compare(msg2.message);
154 if (c != 0)
155 return c;
156 c = msg1.file.compare(msg2.file);
157 if (c != 0)
158 return c;
159 c = Path::cmp(msg1.path, msg2.path);
160 if (c != 0)
161 return c;
162 c = int(msg1.level) - int(msg2.level);
163 if (c != 0)
164 return c;
165 c = int(msg1.errorGroups.groups.size() - msg2.errorGroups.groups.size());
166 if (c != 0)
167 return c;
168 for (qsizetype i = 0; i < msg1.errorGroups.groups.size(); ++i) {
169 c = msg1.errorGroups.groups[i].groupId().compare(msg2.errorGroups.groups[i].groupId());
170 if (c != 0)
171 return c;
172 }
173 c = msg1.location.length - msg2.location.length;
174 if (c != 0)
175 return c;
176 c = msg1.location.startColumn - msg2.location.startColumn;
177 return c;
178 }
179
187};
188
189inline bool operator !=(const ErrorMessage &e1, const ErrorMessage &e2) {
190 return compare(e1, e2) != 0;
191}
192inline bool operator ==(const ErrorMessage &e1, const ErrorMessage &e2) {
193 return compare(e1, e2) == 0;
194}
195inline bool operator<(const ErrorMessage &e1, const ErrorMessage &e2)
196{
197 return compare(e1, e2) < 0;
198}
199inline bool operator<=(const ErrorMessage &e1, const ErrorMessage &e2)
200{
201 return compare(e1, e2) <= 0;
202}
203inline bool operator>(const ErrorMessage &e1, const ErrorMessage &e2)
204{
205 return compare(e1, e2) > 0;
206}
207inline bool operator>=(const ErrorMessage &e1, const ErrorMessage &e2)
208{
209 return compare(e1, e2) >= 0;
210}
211
214
217
218} // end namespace Dom
219} // end namespace QQmlJS
221#endif // ERRORMESSAGE_H
\inmodule QtCore\reentrant
Definition qcborarray.h:20
\inmodule QtCore\reentrant
Definition qcbormap.h:21
A Sink is a function that accepts a QStringView as input.
convenience macro creating a new ErrorGroup and registering its groupId as translatable string
constexpr ErrorGroup(const char *groupId)
Represents a set of tags grouping a set of related error messages.
QVector< ErrorGroup > groups
static int cmp(const ErrorGroups &g1, const ErrorGroups &g2)
Represents an error message connected to the dom.
static ErrorMessage load(QLatin1String errorId, T... args)
friend int compare(const ErrorMessage &msg1, const ErrorMessage &msg2)
\inmodule QtCore
Definition qstringview.h:78
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
p1 load("image.bmp")
bool operator!=(const Version &v1, const Version &v2)
void silentError(const ErrorMessage &)
Error handler that ignores all errors (excluding fatal ones)
void errorToQDebug(const ErrorMessage &error)
writes an ErrorMessage to QDebug
ErrorLevel errorLevelFromQtMsgType(QtMsgType msgType)
void defaultErrorHandler(const ErrorMessage &error)
Calls the default error handler (by default errorToQDebug)
void setDefaultErrorHandler(const ErrorHandler &h)
Sets the default error handler.
bool operator>(const Version &v1, const Version &v2)
std::function< void(const ErrorMessage &)> ErrorHandler
bool operator>=(const Version &v1, const Version &v2)
bool operator==(const Version &v1, const Version &v2)
bool operator<=(const Version &v1, const Version &v2)
bool operator<(const Version &v1, const Version &v2)
Combined button and popup list for selecting options.
#define Q_DECLARE_TR_FUNCTIONS(context)
DBusConnection const char DBusError * error
QtMsgType
Definition qlogging.h:29
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLint location
GLuint64 GLenum void * handle
GLenum GLuint GLint level
GLuint GLsizei const GLchar * message
GLfloat GLfloat GLfloat GLfloat h
GLdouble s
[6]
Definition qopenglext.h:235
GLuint res
const GLubyte * c
GLsizei const GLchar *const * path
GLsizei GLenum GLboolean sink
#define QMLDOM_EXPORT
QDebug warning(QAnyStringView fileName, int lineNumber)
static QString dump(const QByteArray &)
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define Q_GADGET
static int compare(quint64 a, quint64 b)
ptrdiff_t qsizetype
Definition qtypes.h:165
static QString errorMessage(QUrlPrivate::ErrorCode errorCode, const QString &errorSource, qsizetype errorPosition)
Definition qurl.cpp:3517
QFile file
[0]
QHostInfo info
[0]
char * toString(const MyType &t)
[31]
QJSValueList args