Commit f4aa5156 authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

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: default avatarFawzi Mohamed <fawzi.mohamed@digia.com>
parent efe2f64e
......@@ -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);
......
......@@ -41,6 +41,8 @@
namespace QmlJS {
class Imports;
class QMLJS_EXPORT Check: protected AST::Visitor
{
Q_DECLARE_TR_FUNCTIONS(QmlJS::Check)
......@@ -115,6 +117,8 @@ private:
void scanCommentsForAnnotations();
void warnAboutUnnecessarySuppressions();
bool isQtQuick2() const;
AST::Node *parent(int distance = 0);
Document::Ptr _doc;
......@@ -143,6 +147,8 @@ private:
bool _importsOk;
bool _inStatementBinding;
const Imports *_imports;
bool _isQtQuick2;
};
} // namespace QmlJS
......
......@@ -219,6 +219,8 @@ StaticAnalysisMessages::StaticAnalysisMessages()
"and might not show up in Qt Quick Designer as expected."));
newMsg(WarnStatesOnlyInRootItemForVisualDesigner, Error,
tr("Qt Quick Designer only supports states in the root item."));
newMsg(WarnAboutQtQuick1InsteadQtQuick2, Warning,
tr("Using Qt Quick 1 code model instead of Qt Quick 2."));
}
} // anonymous namespace
......
......@@ -120,7 +120,8 @@ enum Type
ErrInvalidStringValuePattern = 320,
ErrLongerStringValueExpected = 321,
ErrShorterStringValueExpected = 322,
ErrInvalidArrayValueLength = 323
ErrInvalidArrayValueLength = 323,
WarnAboutQtQuick1InsteadQtQuick2 = 324
};
class QMLJS_EXPORT PrototypeMessageData {
......
Markdown is supported
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