qmljs: use SourceLocation::length in reformatter instead of isValid

isValid becomes more strict in Qt6.2, meaning invalid (default
initialized) SourceLocation.
Reformatter used it to check for absent (i.e. 0 length) tokens, which
might still be valid (according to the new definition) as they mark
the start or end of an AST element.
Thus use length != 0 instead of isValid() in these places.

Change-Id: I4fbc1466ccef6b4b4e2c1d6b5169189b34dc6ae3
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Fawzi Mohamed
2021-07-19 14:05:01 +02:00
parent 42fe70b93e
commit dc654cfcba

View File

@@ -210,7 +210,7 @@ protected:
if (_hasOpenComment) { if (_hasOpenComment) {
newLine(); newLine();
} }
if (lastLoc.isValid()) { if (lastLoc.length != 0) {
QList<SourceLocation> comments = _doc->engine()->comments(); QList<SourceLocation> comments = _doc->engine()->comments();
for (; _nextComment < comments.size(); ++_nextComment) { for (; _nextComment < comments.size(); ++_nextComment) {
SourceLocation commentLoc = comments.at(_nextComment); SourceLocation commentLoc = comments.at(_nextComment);
@@ -237,7 +237,7 @@ protected:
void out(const SourceLocation &loc) void out(const SourceLocation &loc)
{ {
if (!loc.isValid()) if (loc.length == 0)
return; return;
out(toString(loc), loc); out(toString(loc), loc);
} }
@@ -489,7 +489,7 @@ protected:
else if (UiImport *import = cast<UiImport *>(ast)) else if (UiImport *import = cast<UiImport *>(ast))
firstLoc = import->firstSourceLocation(); firstLoc = import->firstSourceLocation();
if (firstLoc.isValid() && int(firstLoc.offset) != _lastNewlineOffset) { if (firstLoc.length != 0 && int(firstLoc.offset) != _lastNewlineOffset) {
_lastNewlineOffset = firstLoc.offset; _lastNewlineOffset = firstLoc.offset;
if (precededByEmptyLine(firstLoc) && !_result.endsWith(QLatin1String("\n\n"))) if (precededByEmptyLine(firstLoc) && !_result.endsWith(QLatin1String("\n\n")))
@@ -511,7 +511,7 @@ protected:
else if (UiImport *import = cast<UiImport *>(ast)) else if (UiImport *import = cast<UiImport *>(ast))
lastLoc = import->lastSourceLocation(); lastLoc = import->lastSourceLocation();
if (lastLoc.isValid()) { if (lastLoc.length != 0) {
const QList<SourceLocation> &comments = _doc->engine()->comments(); const QList<SourceLocation> &comments = _doc->engine()->comments();
// preserve trailing comments // preserve trailing comments
@@ -566,7 +566,7 @@ protected:
{ {
for (UiEnumMemberList *it = list; it; it = it->next) { for (UiEnumMemberList *it = list; it; it = it->next) {
out(it->memberToken); out(it->memberToken);
if (it->valueToken.isValid()) { if (it->valueToken.length != 0) {
out(" = "); out(" = ");
out(it->valueToken); out(it->valueToken);
} }
@@ -1136,7 +1136,7 @@ protected:
{ {
out(ast->returnToken); out(ast->returnToken);
if (ast->expression) { if (ast->expression) {
if (ast->returnToken.isValid()) if (ast->returnToken.length != 0)
out(" "); out(" ");
accept(ast->expression); accept(ast->expression);
} }
@@ -1277,7 +1277,7 @@ protected:
out("=> "); out("=> ");
out(ast->lbraceToken); out(ast->lbraceToken);
if (ast->body) { if (ast->body) {
if (ast->body->next || ast->lbraceToken.isValid()) { if (ast->body->next || ast->lbraceToken.length != 0) {
lnAcceptIndented(ast->body); lnAcceptIndented(ast->body);
newLine(); newLine();
} else { } else {