forked from qt-creator/qt-creator
QmlJsEditor: Remove foreach / Q_FOREACH usage
Task-number: QTCREATORBUG-27464 Change-Id: I77741a639d8585d1e0ad04d7c5e6588852202e4a Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -101,7 +101,7 @@ static void addCompletions(QList<AssistProposalItemInterface *> *completions,
|
||||
const QIcon &icon,
|
||||
int order)
|
||||
{
|
||||
foreach (const QString &text, newCompletions)
|
||||
for (const QString &text : newCompletions)
|
||||
addCompletion(completions, text, icon, order);
|
||||
}
|
||||
|
||||
@@ -226,7 +226,8 @@ public:
|
||||
_processed.clear();
|
||||
_propertyProcessor = processor;
|
||||
|
||||
foreach (const ObjectValue *scope, _scopeChain->all())
|
||||
const QList<const ObjectValue *> scopes = _scopeChain->all();
|
||||
for (const ObjectValue *scope : scopes)
|
||||
processProperties(scope);
|
||||
}
|
||||
|
||||
@@ -302,7 +303,7 @@ const Value *getPropertyValue(const ObjectValue *object,
|
||||
return nullptr;
|
||||
|
||||
const Value *value = object;
|
||||
foreach (const QString &name, propertyNames) {
|
||||
for (const QString &name : propertyNames) {
|
||||
if (const ObjectValue *objectValue = value->asObjectValue()) {
|
||||
value = objectValue->lookupMember(name, context);
|
||||
if (!value)
|
||||
@@ -687,7 +688,7 @@ IAssistProposal *QmlJSCompletionAssistProcessor::perform(const AssistInterface *
|
||||
QStringList nCompletions;
|
||||
QString prefix(libVersion.left(toSkip));
|
||||
nCompletions.reserve(completions.size());
|
||||
foreach (const QString &completion, completions)
|
||||
for (const QString &completion : qAsConst(completions))
|
||||
if (completion.startsWith(prefix))
|
||||
nCompletions.append(completion.right(completion.size()-toSkip));
|
||||
completions = nCompletions;
|
||||
@@ -800,7 +801,8 @@ IAssistProposal *QmlJSCompletionAssistProcessor::perform(const AssistInterface *
|
||||
if (const QmlEnumValue *enumValue =
|
||||
value_cast<QmlEnumValue>(value)) {
|
||||
const QString &name = context->imports(document.data())->nameForImportedObject(enumValue->owner(), context.data());
|
||||
foreach (const QString &key, enumValue->keys()) {
|
||||
const QStringList keys = enumValue->keys();
|
||||
for (const QString &key : keys) {
|
||||
QString completion;
|
||||
if (name.isEmpty())
|
||||
completion = QString::fromLatin1("\"%1\"").arg(key);
|
||||
@@ -910,7 +912,7 @@ bool QmlJSCompletionAssistProcessor::acceptsIdleEditor() const
|
||||
Scanner scanner;
|
||||
const QList<Token> tokens = scanner(blockText, blockState);
|
||||
const int column = block.position() - m_interface->position();
|
||||
foreach (const Token &tk, tokens) {
|
||||
for (const Token &tk : tokens) {
|
||||
if (column >= tk.begin() && column <= tk.end()) {
|
||||
if (charBeforeCursor == QLatin1Char('/') && tk.is(Token::String))
|
||||
return true; // path completion inside string literals
|
||||
@@ -1051,7 +1053,7 @@ void QmlJSAssistProposalModel::filter(const QString &prefix)
|
||||
return;
|
||||
QList<AssistProposalItemInterface *> newCurrentItems;
|
||||
newCurrentItems.reserve(m_currentItems.size());
|
||||
foreach (AssistProposalItemInterface *item, m_currentItems)
|
||||
for (AssistProposalItemInterface *item : qAsConst(m_currentItems))
|
||||
if (!item->text().startsWith(QLatin1String("__")))
|
||||
newCurrentItems << item;
|
||||
m_currentItems = newCurrentItems;
|
||||
|
@@ -123,13 +123,14 @@ public:
|
||||
|
||||
QStringList sortedPropertiesWithoutId;
|
||||
|
||||
foreach (const QString &property, propertyReader.properties())
|
||||
const QStringList properties = propertyReader.properties();
|
||||
for (const QString &property : properties)
|
||||
if (property != QLatin1String("id"))
|
||||
sortedPropertiesWithoutId.append(property);
|
||||
|
||||
sortedPropertiesWithoutId.sort();
|
||||
|
||||
foreach (const QString &property, sortedPropertiesWithoutId)
|
||||
for (const QString &property : qAsConst(sortedPropertiesWithoutId))
|
||||
sourcePreview.append(QLatin1String(" ") + property + QLatin1String(": ") + propertyReader.readAstValue(property));
|
||||
|
||||
const bool confirm = ComponentNameDialog::go(&componentName, &path, &suffix,
|
||||
@@ -178,7 +179,7 @@ public:
|
||||
if (program->members)
|
||||
astRootNode = program->members->member;
|
||||
|
||||
foreach (const QString &property, result)
|
||||
for (const QString &property : qAsConst(result))
|
||||
rewriter.removeBindingByName(initializerOfObject(astRootNode), property);
|
||||
} else {
|
||||
qWarning() << Q_FUNC_INFO << "parsing failed:" << newComponentSource;
|
||||
@@ -208,7 +209,7 @@ public:
|
||||
if (!m_idName.isEmpty())
|
||||
replacement += QLatin1String("id: ") + m_idName + QLatin1Char('\n');
|
||||
|
||||
foreach (const QString &property, result)
|
||||
for (const QString &property : qAsConst(result))
|
||||
replacement += property + QLatin1String(": ") + propertyReader.readAstValue(property) + QLatin1Char('\n');
|
||||
|
||||
Utils::ChangeSet changes;
|
||||
|
@@ -189,7 +189,7 @@ static void appendExtraSelectionsForMessages(
|
||||
const QList<DiagnosticMessage> &messages,
|
||||
const QTextDocument *document)
|
||||
{
|
||||
foreach (const DiagnosticMessage &d, messages) {
|
||||
for (const DiagnosticMessage &d : messages) {
|
||||
const int line = d.loc.startLine;
|
||||
const int column = qMax(1U, d.loc.startColumn);
|
||||
|
||||
@@ -511,10 +511,10 @@ void QmlJSEditorWidget::setSelectedElements()
|
||||
|
||||
if (m_qmlJsEditorDocument->semanticInfo().isValid()) {
|
||||
SelectedElement selectedMembers;
|
||||
QList<UiObjectMember *> members
|
||||
= selectedMembers(m_qmlJsEditorDocument->semanticInfo().document, startPos, endPos);
|
||||
const QList<UiObjectMember *> members
|
||||
= selectedMembers(m_qmlJsEditorDocument->semanticInfo().document, startPos, endPos);
|
||||
if (!members.isEmpty()) {
|
||||
foreach (UiObjectMember *m, members) {
|
||||
for (UiObjectMember *m : members) {
|
||||
offsets << m;
|
||||
}
|
||||
}
|
||||
@@ -768,7 +768,8 @@ void QmlJSEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
|
||||
if (auto importAst = cast<const AST::UiImport *>(node)) {
|
||||
// if it's a file import, link to the file
|
||||
foreach (const ImportInfo &import, semanticInfo.document->bind()->imports()) {
|
||||
const QList<ImportInfo> imports = semanticInfo.document->bind()->imports();
|
||||
for (const ImportInfo &import : imports) {
|
||||
if (import.ast() == importAst && import.type() == ImportType::File) {
|
||||
Utils::Link link(Utils::FilePath::fromString(import.path()));
|
||||
link.linkTextStart = importAst->firstSourceLocation().begin();
|
||||
@@ -896,7 +897,8 @@ void QmlJSEditorWidget::contextMenuEvent(QContextMenuEvent *e)
|
||||
|
||||
if (ActionContainer *mcontext = ActionManager::actionContainer(Constants::M_CONTEXT)) {
|
||||
QMenu *contextMenu = mcontext->menu();
|
||||
foreach (QAction *action, contextMenu->actions()) {
|
||||
const QList<QAction *> actions = contextMenu->actions();
|
||||
for (QAction *action : actions) {
|
||||
menu->addAction(action);
|
||||
if (action->objectName() == QLatin1String(Constants::M_REFACTORING_MENU_INSERTION_POINT))
|
||||
menu->addMenu(refactoringMenu);
|
||||
|
@@ -260,7 +260,8 @@ private:
|
||||
if (root && root->lookupMember(_name, _scopeChain.context()))
|
||||
return check(root);
|
||||
|
||||
foreach (const QmlComponentChain *parent, chain->instantiatingComponents()) {
|
||||
const QList<const QmlComponentChain *> parents = chain->instantiatingComponents();
|
||||
for (const QmlComponentChain *parent : parents) {
|
||||
if (contains(parent))
|
||||
return true;
|
||||
}
|
||||
@@ -278,7 +279,8 @@ private:
|
||||
|
||||
bool checkQmlScope()
|
||||
{
|
||||
foreach (const ObjectValue *s, _scopeChain.qmlScopeObjects()) {
|
||||
const QList<const ObjectValue *> scopes = _scopeChain.qmlScopeObjects();
|
||||
for (const ObjectValue *s : scopes) {
|
||||
if (check(s))
|
||||
return true;
|
||||
}
|
||||
@@ -749,8 +751,8 @@ public:
|
||||
|
||||
// find all idenfifier expressions, try to resolve them and check if the result is in scope
|
||||
FindUsages findUsages(doc, context);
|
||||
FindUsages::Result results = findUsages(name, scope);
|
||||
foreach (const SourceLocation &loc, results)
|
||||
const FindUsages::Result results = findUsages(name, scope);
|
||||
for (const SourceLocation &loc : results)
|
||||
usages.append(Usage(fileName, matchingLine(loc.offset, doc->source()), loc.startLine, loc.startColumn - 1, loc.length));
|
||||
if (future->isPaused())
|
||||
future->waitForResume();
|
||||
@@ -791,8 +793,8 @@ public:
|
||||
|
||||
// find all idenfifier expressions, try to resolve them and check if the result is in scope
|
||||
FindTypeUsages findUsages(doc, context);
|
||||
FindTypeUsages::Result results = findUsages(name, scope);
|
||||
foreach (const SourceLocation &loc, results)
|
||||
const FindTypeUsages::Result results = findUsages(name, scope);
|
||||
for (const SourceLocation &loc : results)
|
||||
usages.append(Usage(fileName, matchingLine(loc.offset, doc->source()), loc.startLine, loc.startColumn - 1, loc.length));
|
||||
if (future->isPaused())
|
||||
future->waitForResume();
|
||||
@@ -815,7 +817,7 @@ public:
|
||||
|
||||
void operator()(QList<Usage> &, const QList<Usage> &usages)
|
||||
{
|
||||
foreach (const Usage &u, usages)
|
||||
for (const Usage &u : usages)
|
||||
future->reportResult(u);
|
||||
|
||||
future->setProgressValue(future->progressValue() + 1);
|
||||
@@ -892,7 +894,7 @@ static void find_helper(QFutureInterface<FindReferences::Usage> &future,
|
||||
replacement = name;
|
||||
|
||||
QStringList files;
|
||||
foreach (const Document::Ptr &doc, snapshot) {
|
||||
for (const Document::Ptr &doc : qAsConst(snapshot)) {
|
||||
// ### skip files that don't contain the name token
|
||||
files.append(doc->fileName());
|
||||
}
|
||||
@@ -974,10 +976,10 @@ QList<FindReferences::Usage> FindReferences::findUsageOfType(const QString &file
|
||||
|
||||
QmlJS::Snapshot snapshot = modelManager->snapshot();
|
||||
|
||||
foreach (const QmlJS::Document::Ptr &doc, snapshot) {
|
||||
for (const QmlJS::Document::Ptr &doc : qAsConst(snapshot)) {
|
||||
FindTypeUsages findUsages(doc, context);
|
||||
FindTypeUsages::Result results = findUsages(typeName, targetValue);
|
||||
foreach (const SourceLocation &loc, results) {
|
||||
const FindTypeUsages::Result results = findUsages(typeName, targetValue);
|
||||
for (const SourceLocation &loc : results) {
|
||||
usages.append(Usage(doc->fileName(), matchingLine(loc.offset, doc->source()), loc.startLine, loc.startColumn - 1, loc.length));
|
||||
}
|
||||
}
|
||||
|
@@ -268,15 +268,17 @@ void QmlJSHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos, R
|
||||
|
||||
bool QmlJSHoverHandler::matchDiagnosticMessage(QmlJSEditorWidget *qmlEditor, int pos)
|
||||
{
|
||||
foreach (const QTextEdit::ExtraSelection &sel,
|
||||
qmlEditor->extraSelections(TextEditorWidget::CodeWarningsSelection)) {
|
||||
const QList<QTextEdit::ExtraSelection> selections =
|
||||
qmlEditor->extraSelections(TextEditorWidget::CodeWarningsSelection);
|
||||
for (const QTextEdit::ExtraSelection &sel : selections) {
|
||||
if (pos >= sel.cursor.selectionStart() && pos <= sel.cursor.selectionEnd()) {
|
||||
setToolTip(sel.format.toolTip());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
foreach (const QTextLayout::FormatRange &range,
|
||||
qmlEditor->qmlJsEditorDocument()->diagnosticRanges()) {
|
||||
const QVector<QTextLayout::FormatRange> ranges =
|
||||
qmlEditor->qmlJsEditorDocument()->diagnosticRanges();
|
||||
for (const QTextLayout::FormatRange &range : ranges) {
|
||||
if (pos >= range.start && pos < range.start+range.length) {
|
||||
setToolTip(range.format.toolTip());
|
||||
return true;
|
||||
@@ -357,7 +359,8 @@ void QmlJSHoverHandler::handleImport(const ScopeChain &scopeChain, AST::UiImport
|
||||
if (!imports)
|
||||
return;
|
||||
|
||||
foreach (const Import &import, imports->all()) {
|
||||
const QList<Import> importList = imports->all();
|
||||
for (const Import &import : importList) {
|
||||
if (import.info.ast() == node) {
|
||||
if (import.info.type() == ImportType::Library
|
||||
&& !import.libraryPath.isEmpty()) {
|
||||
|
@@ -154,7 +154,7 @@ void matchAddAnalysisMessageSuppressionCommentQuickFix(const QmlJSQuickFixInterf
|
||||
{
|
||||
const QList<StaticAnalysis::Message> &messages = interface->semanticInfo().staticAnalysisMessages;
|
||||
|
||||
foreach (const StaticAnalysis::Message &message, messages) {
|
||||
for (const StaticAnalysis::Message &message : messages) {
|
||||
if (interface->currentFile()->isCursorOn(message.location)) {
|
||||
result << new AnalysizeMessageSuppressionOperation(interface, message);
|
||||
return;
|
||||
|
@@ -59,7 +59,7 @@ namespace {
|
||||
|
||||
static bool isIdScope(const ObjectValue *scope, const QList<const QmlComponentChain *> &chain)
|
||||
{
|
||||
foreach (const QmlComponentChain *c, chain) {
|
||||
for (const QmlComponentChain *c : chain) {
|
||||
if (c->idScope() == scope)
|
||||
return true;
|
||||
if (isIdScope(scope, c->instantiatingComponents()))
|
||||
@@ -391,7 +391,7 @@ protected:
|
||||
void addMessages(QList<DiagnosticMessage> messages,
|
||||
const Document::Ptr &doc)
|
||||
{
|
||||
foreach (const DiagnosticMessage &d, messages) {
|
||||
for (const DiagnosticMessage &d : messages) {
|
||||
int line = d.loc.startLine;
|
||||
int column = qMax(1U, d.loc.startColumn);
|
||||
int length = d.loc.length;
|
||||
@@ -426,7 +426,7 @@ protected:
|
||||
void addMessages(const QList<StaticAnalysis::Message> &messages,
|
||||
const Document::Ptr &doc)
|
||||
{
|
||||
foreach (const StaticAnalysis::Message &d, messages) {
|
||||
for (const StaticAnalysis::Message &d : messages) {
|
||||
int line = d.location.startLine;
|
||||
int column = qMax(1U, d.location.startColumn);
|
||||
int length = d.location.length;
|
||||
|
@@ -400,7 +400,7 @@ bool QmlOutlineModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
|
||||
stream >> rowPath;
|
||||
|
||||
QModelIndex index;
|
||||
foreach (int row, rowPath) {
|
||||
for (int row : qAsConst(rowPath)) {
|
||||
index = this->index(row, 0, index);
|
||||
if (!index.isValid())
|
||||
continue;
|
||||
@@ -883,7 +883,7 @@ void QmlOutlineModel::reparentNodes(QmlOutlineItem *targetItem, int row, QList<Q
|
||||
TextEditor::RefactoringFilePtr file = refactoring.file(
|
||||
Utils::FilePath::fromString(m_semanticInfo.document->fileName()));
|
||||
file->setChangeSet(changeSet);
|
||||
foreach (const Utils::ChangeSet::Range &range, changedRanges) {
|
||||
for (const Utils::ChangeSet::Range &range : qAsConst(changedRanges)) {
|
||||
file->appendIndentRange(range);
|
||||
}
|
||||
file->apply();
|
||||
|
@@ -63,7 +63,7 @@ QmlTaskManager::QmlTaskManager()
|
||||
static Tasks convertToTasks(const QList<DiagnosticMessage> &messages, const FilePath &fileName, Utils::Id category)
|
||||
{
|
||||
Tasks result;
|
||||
foreach (const DiagnosticMessage &msg, messages) {
|
||||
for (const DiagnosticMessage &msg : messages) {
|
||||
Task::TaskType type = msg.isError() ? Task::Error : Task::Warning;
|
||||
Task task(type, msg.message, fileName, msg.loc.startLine, category);
|
||||
result += task;
|
||||
@@ -74,17 +74,18 @@ static Tasks convertToTasks(const QList<DiagnosticMessage> &messages, const File
|
||||
static Tasks convertToTasks(const QList<StaticAnalysis::Message> &messages, const FilePath &fileName, Utils::Id category)
|
||||
{
|
||||
QList<DiagnosticMessage> diagnostics;
|
||||
foreach (const StaticAnalysis::Message &msg, messages)
|
||||
for (const StaticAnalysis::Message &msg : messages)
|
||||
diagnostics += msg.toDiagnosticMessage();
|
||||
return convertToTasks(diagnostics, fileName, category);
|
||||
}
|
||||
|
||||
void QmlTaskManager::collectMessages(
|
||||
QFutureInterface<FileErrorMessages> &future,
|
||||
Snapshot snapshot, QList<ModelManagerInterface::ProjectInfo> projectInfos,
|
||||
ViewerContext vContext, bool updateSemantic)
|
||||
void QmlTaskManager::collectMessages(QFutureInterface<FileErrorMessages> &future,
|
||||
Snapshot snapshot,
|
||||
const QList<ModelManagerInterface::ProjectInfo> &projectInfos,
|
||||
ViewerContext vContext,
|
||||
bool updateSemantic)
|
||||
{
|
||||
foreach (const ModelManagerInterface::ProjectInfo &info, projectInfos) {
|
||||
for (const ModelManagerInterface::ProjectInfo &info : projectInfos) {
|
||||
QHash<QString, QList<DiagnosticMessage> > linkMessages;
|
||||
ContextPtr context;
|
||||
if (updateSemantic) {
|
||||
@@ -92,7 +93,7 @@ void QmlTaskManager::collectMessages(
|
||||
context = link(&linkMessages);
|
||||
}
|
||||
|
||||
foreach (const QString &fileName, info.sourceFiles) {
|
||||
for (const QString &fileName : qAsConst(info.sourceFiles)) {
|
||||
Document::Ptr document = snapshot.document(fileName);
|
||||
if (!document)
|
||||
continue;
|
||||
@@ -157,15 +158,15 @@ void QmlTaskManager::updateMessagesNow(bool updateSemantic)
|
||||
|
||||
void QmlTaskManager::documentsRemoved(const QStringList &path)
|
||||
{
|
||||
foreach (const QString &item, path)
|
||||
for (const QString &item : path)
|
||||
removeTasksForFile(item);
|
||||
}
|
||||
|
||||
void QmlTaskManager::displayResults(int begin, int end)
|
||||
{
|
||||
for (int i = begin; i < end; ++i) {
|
||||
FileErrorMessages result = m_messageCollector.resultAt(i);
|
||||
foreach (const Task &task, result.tasks) {
|
||||
const ProjectExplorer::Tasks tasks = m_messageCollector.resultAt(i).tasks;
|
||||
for (const Task &task : tasks) {
|
||||
insertTask(task);
|
||||
}
|
||||
}
|
||||
@@ -189,7 +190,7 @@ void QmlTaskManager::removeTasksForFile(const QString &fileName)
|
||||
{
|
||||
if (m_docsWithTasks.contains(fileName)) {
|
||||
const Tasks tasks = m_docsWithTasks.value(fileName);
|
||||
foreach (const Task &task, tasks)
|
||||
for (const Task &task : tasks)
|
||||
TaskHub::removeTask(task);
|
||||
m_docsWithTasks.remove(fileName);
|
||||
}
|
||||
|
@@ -69,7 +69,7 @@ private:
|
||||
};
|
||||
static void collectMessages(QFutureInterface<FileErrorMessages> &future,
|
||||
QmlJS::Snapshot snapshot,
|
||||
QList<QmlJS::ModelManagerInterface::ProjectInfo> projectInfos,
|
||||
const QList<QmlJS::ModelManagerInterface::ProjectInfo> &projectInfos,
|
||||
QmlJS::ViewerContext vContext,
|
||||
bool updateSemantic);
|
||||
|
||||
|
@@ -129,20 +129,20 @@ void QuickToolBar::apply(TextEditor::TextEditorWidget *editorWidget, Document::P
|
||||
|
||||
if (scopeChain && scopeObject) {
|
||||
m_prototypes.clear();
|
||||
foreach (const ObjectValue *object,
|
||||
PrototypeIterator(scopeObject, scopeChain->context()).all()) {
|
||||
const QList<const ObjectValue *> objects
|
||||
= PrototypeIterator(scopeObject, scopeChain->context()).all();
|
||||
for (const ObjectValue *object : objects)
|
||||
m_prototypes.append(object->className());
|
||||
}
|
||||
|
||||
if (m_prototypes.contains(QLatin1String("PropertyChanges"))) {
|
||||
isPropertyChanges = true;
|
||||
const ObjectValue *targetObject = getPropertyChangesTarget(node, *scopeChain);
|
||||
m_prototypes.clear();
|
||||
if (targetObject) {
|
||||
foreach (const ObjectValue *object,
|
||||
PrototypeIterator(targetObject, scopeChain->context()).all()) {
|
||||
const QList<const ObjectValue *> objects
|
||||
= PrototypeIterator(targetObject, scopeChain->context()).all();
|
||||
for (const ObjectValue *object : objects)
|
||||
m_prototypes.append(object->className());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user