From 1d3c58cca1016338e8434e93a5b8136028d94a5f Mon Sep 17 00:00:00 2001 From: Erik Verbruggen <erik.verbruggen@nokia.com> Date: Thu, 7 Jan 2010 17:33:56 +0100 Subject: [PATCH] Added warning for duplicate IDs. --- src/shared/qml/qmldocument.cpp | 2 ++ src/shared/qml/qmlidcollector.cpp | 13 ++++++++----- src/shared/qml/qmlidcollector.h | 13 +++++++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/shared/qml/qmldocument.cpp b/src/shared/qml/qmldocument.cpp index 06e11626730..95698a21c99 100644 --- a/src/shared/qml/qmldocument.cpp +++ b/src/shared/qml/qmldocument.cpp @@ -117,6 +117,8 @@ bool QmlDocument::parse() Internal::QmlIdCollector collect; _ids = collect(*this); + if (_diagnosticMessages.isEmpty()) + _diagnosticMessages = collect.diagnosticMessages(); } return _parsedCorrectly; diff --git a/src/shared/qml/qmlidcollector.cpp b/src/shared/qml/qmlidcollector.cpp index 2ac5ed95eb9..381af48d280 100644 --- a/src/shared/qml/qmlidcollector.cpp +++ b/src/shared/qml/qmlidcollector.cpp @@ -31,7 +31,6 @@ #include "qmlidcollector.h" #include "qmljsast_p.h" -#include "qmljsengine_p.h" using namespace QmlJS; using namespace QmlJS::AST; @@ -108,10 +107,14 @@ QmlSymbolFromFile *QmlIdCollector::switchSymbol(QmlJS::AST::UiObjectMember *node void QmlIdCollector::addId(const QString &id, QmlJS::AST::UiScriptBinding *ast) { - if (!_ids.contains(id) && _currentSymbol) { - QmlSymbolFromFile *symbol = _currentSymbol->findMember(ast); + if (!_currentSymbol) + return; - if (QmlIdSymbol *idSymbol = symbol->asIdSymbol()) - _ids[id] = idSymbol; + if (_ids.contains(id)) { + _diagnosticMessages.append(DiagnosticMessage(DiagnosticMessage::Warning, ast->statement->firstSourceLocation(), "Duplicate ID")); + } else { + if (QmlSymbolFromFile *symbol = _currentSymbol->findMember(ast)) + if (QmlIdSymbol *idSymbol = symbol->asIdSymbol()) + _ids[id] = idSymbol; } } diff --git a/src/shared/qml/qmlidcollector.h b/src/shared/qml/qmlidcollector.h index 4206ca8ce36..3db91fe4b9d 100644 --- a/src/shared/qml/qmlidcollector.h +++ b/src/shared/qml/qmlidcollector.h @@ -30,15 +30,16 @@ #ifndef QMLIDCOLLECTOR_H #define QMLIDCOLLECTOR_H +#include <qml/parser/qmljsastvisitor_p.h> +#include <qml/parser/qmljsengine_p.h> +#include <qml/qmldocument.h> +#include <qml/qmlsymbol.h> + #include <QMap> #include <QPair> #include <QStack> #include <QString> -#include <qml/parser/qmljsastvisitor_p.h> -#include <qml/qmldocument.h> -#include <qml/qmlsymbol.h> - namespace Qml { namespace Internal { @@ -47,6 +48,9 @@ class QML_EXPORT QmlIdCollector: protected QmlJS::AST::Visitor public: QMap<QString, Qml::QmlIdSymbol*> operator()(QmlEditor::QmlDocument &doc); + QList<QmlJS::DiagnosticMessage> diagnosticMessages() + { return _diagnosticMessages; } + protected: virtual bool visit(QmlJS::AST::UiArrayBinding *ast); virtual bool visit(QmlJS::AST::UiObjectBinding *ast); @@ -61,6 +65,7 @@ private: QmlEditor::QmlDocument *_doc; QMap<QString, Qml::QmlIdSymbol*> _ids; Qml::QmlSymbolFromFile *_currentSymbol; + QList<QmlJS::DiagnosticMessage> _diagnosticMessages; }; } // namespace Internal -- GitLab