forked from qt-creator/qt-creator
QmlJS: Add warning if we use a Qt Quick 1 code model for Qt Quick 2
In some cases we use a Qt Quick 1 code model for a file with Qt Quick 2 imports. This patch adds a warning for this, since auto completion is incomplete. Change-Id: I60888fd269c02f38da097104f5ecc982dd65573a Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>
This commit is contained in:
@@ -538,10 +538,15 @@ Check::Check(Document::Ptr doc, const ContextPtr &context)
|
||||
, _scopeBuilder(&_scopeChain)
|
||||
, _importsOk(false)
|
||||
, _inStatementBinding(false)
|
||||
, _imports(0)
|
||||
, _isQtQuick2(false)
|
||||
|
||||
{
|
||||
const Imports *imports = context->imports(doc.data());
|
||||
if (imports && !imports->importFailed())
|
||||
_imports = context->imports(doc.data());
|
||||
if (_imports && !_imports->importFailed()) {
|
||||
_importsOk = true;
|
||||
_isQtQuick2 = isQtQuick2();
|
||||
}
|
||||
|
||||
_enabledMessages = Message::allMessageTypes().toSet();
|
||||
disableMessage(HintAnonymousFunctionSpacing);
|
||||
@@ -737,6 +742,13 @@ void Check::visitQmlObject(Node *ast, UiQualifiedId *typeId,
|
||||
if (iter.error() != PrototypeIterator::NoError)
|
||||
typeError = true;
|
||||
const ObjectValue *lastPrototype = prototypes.last();
|
||||
foreach (const ObjectValue *objectValue, prototypes) {
|
||||
if (objectValue->className() == QLatin1String("QGraphicsObject")
|
||||
&& _isQtQuick2) {
|
||||
addMessage(WarnAboutQtQuick1InsteadQtQuick2, typeErrorLocation);
|
||||
}
|
||||
}
|
||||
|
||||
if (iter.error() == PrototypeIterator::ReferenceResolutionError) {
|
||||
if (const QmlPrototypeReference *ref =
|
||||
value_cast<QmlPrototypeReference>(lastPrototype->prototype())) {
|
||||
@@ -1355,6 +1367,16 @@ void Check::warnAboutUnnecessarySuppressions()
|
||||
}
|
||||
}
|
||||
|
||||
bool Check::isQtQuick2() const
|
||||
{
|
||||
foreach (const Import &import, _imports->all()) {
|
||||
if (import.info.name() == QLatin1String("QtQuick")
|
||||
&& import.info.version().majorVersion() == 2)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Check::visit(NewExpression *ast)
|
||||
{
|
||||
checkNewExpression(ast->expression);
|
||||
|
Reference in New Issue
Block a user