12#include <QtCore/QLoggingCategory>
20 : itemCanonicalPath(itCanonicalPath),
item(
it), currentMap(fLoc)
22 DomItem cRegions =
it.field(Fields::comments);
32 qCWarning(writeOutLog) <<
"PendingRegions non empty when closing item"
37 w.lineWriter.endSourceLocation(
it.value());
42 qCWarning(writeOutLog) <<
"PendingComments when closing item "
58 Path itP =
it.canonicalPath();
61 &&
states.last().itemCanonicalPath
62 == itP.mid(0,
states.last().itemCanonicalPath.length())) {
63 int oldL =
states.last().itemCanonicalPath.length();
65 itP.mid(oldL, itP.length() - oldL),
84 state().closeState(*
this);
94 QList<SourceLocation> *cLocs =
95 (updateLocs ? &(fMap->info().preCommentLocations[region]) :
nullptr);
96 state().pendingComments[region].writePre(*
this, cLocs);
107 state().pendingRegions.remove(region);
108 if (
state().pendingComments.contains(region)) {
112 QList<SourceLocation> *cLocs =
113 (updateLocs ? &(fMap->info().postCommentLocations[region]) :
nullptr);
114 state().pendingComments[region].writePost(*
this, cLocs);
116 state().pendingComments.remove(region);
131 codeForRegion = u
"component"_s;
135 codeForRegion = u
":"_s;
138 codeForRegion = u
"import"_s;
141 codeForRegion = u
"as"_s;
144 codeForRegion = u
"on"_s;
147 codeForRegion = u
"id"_s;
150 codeForRegion = u
"{"_s;
153 codeForRegion = u
"}"_s;
156 codeForRegion = u
"["_s;
159 codeForRegion = u
"]"_s;
162 codeForRegion = u
"("_s;
165 codeForRegion = u
")"_s;
168 codeForRegion = u
"enum"_s;
171 codeForRegion = u
"default"_s;
174 codeForRegion = u
"required"_s;
177 codeForRegion = u
"readonly"_s;
180 codeForRegion = u
"property"_s;
183 codeForRegion = u
"function"_s;
186 codeForRegion = u
"signal"_s;
189 codeForRegion = u
"return"_s;
192 codeForRegion = u
"..."_s;
195 codeForRegion = u
"="_s;
198 codeForRegion = u
"pragma"_s;
201 codeForRegion = u
","_s;
204 codeForRegion = u
"for"_s;
207 codeForRegion = u
"else"_s;
210 codeForRegion = u
"do"_s;
213 codeForRegion = u
"while"_s;
216 codeForRegion = u
"try"_s;
219 codeForRegion = u
"catch"_s;
222 codeForRegion = u
"finally"_s;
225 codeForRegion = u
"case"_s;
228 codeForRegion = u
"throw"_s;
231 codeForRegion = u
"continue"_s;
234 codeForRegion = u
"break"_s;
237 codeForRegion = u
"?"_s;
240 codeForRegion = u
";"_s;
243 codeForRegion = u
"if"_s;
246 codeForRegion = u
"switch"_s;
262 Q_ASSERT_X(
false,
"regionToString",
"Using regionToString on a value or an identifier!");
289 switch (fileItem.internalKind()) {
291 return writtenQmlFileItem(fileItem, fileItem.canonicalPath());
293 return writtenJsFileItem(fileItem, fileItem.canonicalPath());
295 qCWarning(writeOutLog) << fileItem.internalKind() <<
" is not supported";
306 auto exprUpdater = [&mutableFile, filePath](
308 if (std::shared_ptr<ScriptExpression> formattedExpr =
t->info().expr) {
311 if (!originalExprItem)
312 qCWarning(writeOutLog) <<
"failed to get" <<
p.mid(filePath.
length()) <<
"from"
313 << mutableFile.canonicalPath();
317 else if (formattedExpr->ast()
320 originalExprItem.setScript(formattedExpr);
322 logScriptExprUpdateSkipped(originalExprItem.item(),
323 originalExprItem.canonicalPath(), formattedExpr);
330 return mutableFile.item();
333DomItem OutWriter::writtenJsFileItem(
const DomItem &fileItem,
const Path &filePath)
340 if (std::shared_ptr<ScriptExpression> formattedExpr =
t->info().expr) {
341 Q_ASSERT(p.mid(0, filePath.length()) == filePath);
342 mutableFile.mutableAs<JsFile>()->setExpression(formattedExpr);
346 return mutableFile.item();
349void OutWriter::logScriptExprUpdateSkipped(
350 const DomItem &exprItem,
const Path &exprPath,
351 const std::shared_ptr<ScriptExpression> &formattedExpr)
353 qCWarning(writeOutLog).noquote() <<
"Skipped update of reformatted ScriptExpression with "
354 "code:\n---------------\n"
355 << formattedExpr->code() <<
"\n---------------\n preCode:" <<
357 <<
"\n postCode: " <<
359 <<
"\n as it failed standalone reparse with errors:" <<
360 [&exprItem, &exprPath, &formattedExpr](
Sink s) {
361 exprItem.copy(formattedExpr, exprPath)
QList< Key > keys() const
Path canonicalPath() const
static void addRegion(const Tree &fLoc, FileLocationRegion region, SourceLocation loc)
std::shared_ptr< AttachedInfoT< FileLocations > > Tree
static Tree ensure(const Tree &base, const Path &basePath, AttachedInfo::PathType pType=AttachedInfo::PathType::Relative)
static void updateFullLocation(const Tree &fLoc, SourceLocation loc)
LineWriter & write(QStringView v, TextAddType tType=TextAddType::Normal)
void endSourceLocation(PendingSourceLocationId)
PendingSourceLocationId startSourceLocation(SourceLocation *)
const LineWriterOptions & options() const
MutableDomItem path(const Path &p)
QMap< FileLocationRegion, PendingSourceLocationId > pendingRegions
void closeState(OutWriter &)
PendingSourceLocationId fullRegionId
QMap< FileLocationRegion, CommentedElement > pendingComments
OutWriterState(const Path &itPath, const DomItem &it, const FileLocations::Tree &fLoc)
void regionStart(FileLocationRegion region)
void regionEnd(FileLocationRegion regino)
void itemStart(const DomItem &it)
UpdatedScriptExpression::Tree reformattedScriptExpressions
void itemEnd(const DomItem &it)
FileLocations::Tree topLocation
OutWriterState & state(int i=0)
OutWriter & writeRegion(FileLocationRegion region, QStringView toWrite)
DomItem restoreWrittenFileItem(const DomItem &fileItem)
std::shared_ptr< AttachedInfoT< UpdatedScriptExpression > > Tree
static bool visitTree(const Tree &base, function_ref< bool(const Path &, const Tree &)> visitor, const Path &basePath=Path())
\macro QT_RESTRICTED_CAST_FROM_ASCII
QSet< QString >::iterator it
void sinkEscaped(const Sink &sink, QStringView s, EscapeOptions options)
dumps a string as quoted string (escaping things like quotes or newlines)
@ FirstSemicolonTokenRegion
@ QuestionMarkTokenRegion
function_ref< void(QStringView)> Sink
Combined button and popup list for selecting options.
#define qCWarning(category,...)
GLfloat GLfloat GLfloat w
[0]
#define Q_ASSERT_X(cond, x, msg)