Commit 1d3c58cc authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Added warning for duplicate IDs.

parent a6ad7737
......@@ -117,6 +117,8 @@ bool QmlDocument::parse()
Internal::QmlIdCollector collect;
_ids = collect(*this);
if (_diagnosticMessages.isEmpty())
_diagnosticMessages = collect.diagnosticMessages();
}
return _parsedCorrectly;
......
......@@ -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;
}
}
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment