forked from qt-creator/qt-creator
QmlJS: Remove LookupContext.
Use Context or ScopeChain instead. Change-Id: I2489477eac08774ba41710ee81876aab11b5af24 Reviewed-on: http://codereview.qt.nokia.com/1699 Reviewed-by: Fawzi Mohamed <fawzi.mohamed@nokia.com>
This commit is contained in:
@@ -18,7 +18,6 @@ HEADERS += \
|
||||
$$PWD/qmljslink.h \
|
||||
$$PWD/qmljscheck.h \
|
||||
$$PWD/qmljsscopebuilder.h \
|
||||
$$PWD/qmljslookupcontext.h \
|
||||
$$PWD/qmljslineinfo.h \
|
||||
$$PWD/qmljscompletioncontextfinder.h \
|
||||
$$PWD/qmljsmodelmanagerinterface.h \
|
||||
@@ -42,7 +41,6 @@ SOURCES += \
|
||||
$$PWD/qmljslink.cpp \
|
||||
$$PWD/qmljscheck.cpp \
|
||||
$$PWD/qmljsscopebuilder.cpp \
|
||||
$$PWD/qmljslookupcontext.cpp \
|
||||
$$PWD/qmljslineinfo.cpp \
|
||||
$$PWD/qmljscompletioncontextfinder.cpp \
|
||||
$$PWD/qmljsmodelmanagerinterface.cpp \
|
||||
|
@@ -37,8 +37,8 @@
|
||||
|
||||
#include "qmljs_global.h"
|
||||
|
||||
#include <qmljs/qmljsdocument.h>
|
||||
#include <qmljs/parser/qmljsastfwd_p.h>
|
||||
#include <qmljs/qmljslookupcontext.h>
|
||||
|
||||
namespace TextEditor {
|
||||
class BaseTextEditor;
|
||||
@@ -46,6 +46,10 @@ class BaseTextEditor;
|
||||
|
||||
namespace QmlJS {
|
||||
|
||||
namespace Interpreter {
|
||||
class ScopeChain;
|
||||
}
|
||||
|
||||
class QMLJS_EXPORT IContextPane : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -53,7 +57,7 @@ class QMLJS_EXPORT IContextPane : public QObject
|
||||
public:
|
||||
IContextPane(QObject *parent = 0) : QObject(parent) {}
|
||||
virtual ~IContextPane() {}
|
||||
virtual void apply(TextEditor::BaseTextEditor *editor, Document::Ptr document, LookupContext::Ptr lookupContext, AST::Node *node, bool update, bool force = false) = 0;
|
||||
virtual void apply(TextEditor::BaseTextEditor *editor, Document::Ptr document, const Interpreter::ScopeChain *scopeChain, AST::Node *node, bool update, bool force = false) = 0;
|
||||
virtual void setEnabled(bool) = 0;
|
||||
virtual bool isAvailable(TextEditor::BaseTextEditor *editor, Document::Ptr document, AST::Node *node) = 0;
|
||||
virtual QWidget* widget() = 0;
|
||||
|
@@ -1,135 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (info@qt.nokia.com)
|
||||
**
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
||||
** Please review the following information to ensure the GNU Lesser General
|
||||
** Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** Other Usage
|
||||
**
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at info@qt.nokia.com.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "qmljslookupcontext.h"
|
||||
#include "qmljscontext.h"
|
||||
#include "qmljslink.h"
|
||||
#include "qmljsscopebuilder.h"
|
||||
#include "qmljsmodelmanagerinterface.h"
|
||||
#include "qmljsevaluate.h"
|
||||
#include "qmljsscopechain.h"
|
||||
#include "qmljscontext.h"
|
||||
|
||||
using namespace QmlJS;
|
||||
|
||||
class QmlJS::LookupContextData
|
||||
{
|
||||
public:
|
||||
LookupContextData(Document::Ptr doc, const Snapshot &snapshot, const QList<AST::Node *> &path)
|
||||
: doc(doc)
|
||||
, context(Link(snapshot,
|
||||
ModelManagerInterface::instance()->importPaths(),
|
||||
ModelManagerInterface::instance()->builtins(doc))())
|
||||
, scopeChain(doc, context)
|
||||
{
|
||||
ScopeBuilder scopeBuilder(&scopeChain);
|
||||
scopeBuilder.push(path);
|
||||
}
|
||||
|
||||
LookupContextData(Document::Ptr doc,
|
||||
const Interpreter::ContextPtr &context,
|
||||
const QList<AST::Node *> &path)
|
||||
: doc(doc)
|
||||
, context(context)
|
||||
, scopeChain(doc, context)
|
||||
{
|
||||
ScopeBuilder scopeBuilder(&scopeChain);
|
||||
scopeBuilder.push(path);
|
||||
}
|
||||
|
||||
Document::Ptr doc;
|
||||
Interpreter::ContextPtr context;
|
||||
Interpreter::ScopeChain scopeChain;
|
||||
};
|
||||
|
||||
LookupContext::LookupContext(Document::Ptr doc, const Snapshot &snapshot, const QList<AST::Node *> &path)
|
||||
: d(new LookupContextData(doc, snapshot, path))
|
||||
{
|
||||
}
|
||||
|
||||
LookupContext::LookupContext(const Document::Ptr doc,
|
||||
const Interpreter::ContextPtr &context,
|
||||
const QList<AST::Node *> &path)
|
||||
: d(new LookupContextData(doc, context, path))
|
||||
{
|
||||
}
|
||||
|
||||
LookupContext::~LookupContext()
|
||||
{
|
||||
}
|
||||
|
||||
LookupContext::Ptr LookupContext::create(Document::Ptr doc, const Snapshot &snapshot, const QList<AST::Node *> &path)
|
||||
{
|
||||
Ptr ptr(new LookupContext(doc, snapshot, path));
|
||||
return ptr;
|
||||
}
|
||||
|
||||
LookupContext::Ptr LookupContext::create(const Document::Ptr doc,
|
||||
const Interpreter::ContextPtr &context,
|
||||
const QList<AST::Node *> &path)
|
||||
{
|
||||
Ptr ptr(new LookupContext(doc, context, path));
|
||||
return ptr;
|
||||
}
|
||||
|
||||
const Interpreter::Value *LookupContext::evaluate(AST::Node *node) const
|
||||
{
|
||||
Evaluate check(&d->scopeChain);
|
||||
return check(node);
|
||||
}
|
||||
|
||||
Document::Ptr LookupContext::document() const
|
||||
{
|
||||
return d->doc;
|
||||
}
|
||||
|
||||
Snapshot LookupContext::snapshot() const
|
||||
{
|
||||
return d->context->snapshot();
|
||||
}
|
||||
|
||||
// the engine is only guaranteed to live as long as the LookupContext
|
||||
Interpreter::ValueOwner *LookupContext::valueOwner() const
|
||||
{
|
||||
return d->context->valueOwner();
|
||||
}
|
||||
|
||||
// the context is only guaranteed to live as long as the LookupContext
|
||||
const Interpreter::ContextPtr &LookupContext::context() const
|
||||
{
|
||||
return d->context;
|
||||
}
|
||||
|
||||
const Interpreter::ScopeChain &LookupContext::scopeChain() const
|
||||
{
|
||||
return d->scopeChain;
|
||||
}
|
@@ -1,90 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (info@qt.nokia.com)
|
||||
**
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
||||
** Please review the following information to ensure the GNU Lesser General
|
||||
** Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** Other Usage
|
||||
**
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at info@qt.nokia.com.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef QMLJSLOOKUPCONTEXT_H
|
||||
#define QMLJSLOOKUPCONTEXT_H
|
||||
|
||||
#include "qmljsdocument.h"
|
||||
#include "parser/qmljsastfwd_p.h"
|
||||
|
||||
#include <QtCore/QSharedPointer>
|
||||
#include <QtCore/QScopedPointer>
|
||||
|
||||
namespace QmlJS {
|
||||
|
||||
class LookupContextData;
|
||||
|
||||
namespace Interpreter {
|
||||
class Value;
|
||||
class Context;
|
||||
typedef QSharedPointer<const Context> ContextPtr;
|
||||
class ValueOwner;
|
||||
class ScopeChain;
|
||||
}
|
||||
|
||||
class QMLJS_EXPORT LookupContext
|
||||
{
|
||||
Q_DISABLE_COPY(LookupContext)
|
||||
|
||||
LookupContext(const Document::Ptr doc, const Snapshot &snapshot, const QList<AST::Node *> &path);
|
||||
LookupContext(const Document::Ptr doc,
|
||||
const Interpreter::ContextPtr &context,
|
||||
const QList<AST::Node *> &path);
|
||||
|
||||
public:
|
||||
~LookupContext();
|
||||
|
||||
typedef QSharedPointer<LookupContext> Ptr;
|
||||
|
||||
// consider using SemanticInfo::lookupContext instead, it's faster
|
||||
static Ptr create(const Document::Ptr doc, const Snapshot &snapshot,
|
||||
const QList<AST::Node *> &path);
|
||||
static Ptr create(const Document::Ptr doc,
|
||||
const Interpreter::ContextPtr &context,
|
||||
const QList<AST::Node *> &path);
|
||||
|
||||
const Interpreter::Value *evaluate(AST::Node *node) const;
|
||||
|
||||
Document::Ptr document() const;
|
||||
Snapshot snapshot() const;
|
||||
Interpreter::ValueOwner *valueOwner() const;
|
||||
const Interpreter::ContextPtr &context() const;
|
||||
const Interpreter::ScopeChain &scopeChain() const;
|
||||
|
||||
private:
|
||||
QScopedPointer<LookupContextData> d;
|
||||
};
|
||||
|
||||
} // namespace QmlJS
|
||||
|
||||
#endif // QMLJSLOOKUPCONTEXT_H
|
||||
|
@@ -32,6 +32,7 @@
|
||||
|
||||
#include "qmljsscopechain.h"
|
||||
#include "qmljsbind.h"
|
||||
#include "qmljsevaluate.h"
|
||||
|
||||
using namespace QmlJS;
|
||||
using namespace QmlJS::Interpreter;
|
||||
@@ -101,6 +102,12 @@ const Value * ScopeChain::lookup(const QString &name, const ObjectValue **foundI
|
||||
return m_context->valueOwner()->undefinedValue();
|
||||
}
|
||||
|
||||
const Value *ScopeChain::evaluate(AST::Node *node) const
|
||||
{
|
||||
Evaluate evaluator(this);
|
||||
return evaluator(node);
|
||||
}
|
||||
|
||||
const ObjectValue *ScopeChain::globalScope() const
|
||||
{
|
||||
return m_globalScope;
|
||||
|
@@ -79,6 +79,7 @@ public:
|
||||
const ContextPtr &context() const;
|
||||
|
||||
const Value *lookup(const QString &name, const ObjectValue **foundInScope = 0) const;
|
||||
const Value *evaluate(AST::Node *node) const;
|
||||
|
||||
const ObjectValue *globalScope() const;
|
||||
void setGlobalScope(const ObjectValue *globalScope);
|
||||
|
@@ -51,6 +51,9 @@ namespace QmlJS {
|
||||
class DiagnosticMessage;
|
||||
class LookupContext;
|
||||
class Document;
|
||||
namespace Interpreter {
|
||||
class ScopeChain;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -186,7 +189,7 @@ public:
|
||||
|
||||
bool renameId(const QString& oldId, const QString& newId);
|
||||
|
||||
QmlJS::LookupContext *lookupContext() const;
|
||||
const QmlJS::Interpreter::ScopeChain &scopeChain() const;
|
||||
QmlJS::Document *document() const;
|
||||
|
||||
QString convertTypeToImportAlias(const QString &type) const;
|
||||
|
@@ -46,10 +46,10 @@
|
||||
#include <QDeclarativeEngine>
|
||||
#include <QDeclarativeComponent>
|
||||
|
||||
#include <qmljs/qmljslookupcontext.h>
|
||||
#include <qmljs/qmljsdocument.h>
|
||||
#include <qmljs/qmljscontext.h>
|
||||
#include <qmljs/qmljsbind.h>
|
||||
#include <qmljs/qmljsscopechain.h>
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <languageutils/fakemetaobject.h>
|
||||
#include <private/qdeclarativemetatype_p.h>
|
||||
@@ -135,7 +135,7 @@ static inline bool isValueType(const QString &type)
|
||||
return objectValuesList.contains(type);
|
||||
}
|
||||
|
||||
const Interpreter::QmlObjectValue *findQmlPrototype(const Interpreter::ObjectValue *ov, LookupContext *context)
|
||||
const Interpreter::QmlObjectValue *findQmlPrototype(const Interpreter::ObjectValue *ov, const Interpreter::ContextPtr &context)
|
||||
{
|
||||
if (!ov)
|
||||
return 0;
|
||||
@@ -144,15 +144,15 @@ const Interpreter::QmlObjectValue *findQmlPrototype(const Interpreter::ObjectVal
|
||||
if (qmlValue)
|
||||
return qmlValue;
|
||||
|
||||
return findQmlPrototype(ov->prototype(context->context()), context);
|
||||
return findQmlPrototype(ov->prototype(context), context);
|
||||
}
|
||||
|
||||
QStringList prototypes(const Interpreter::ObjectValue *ov, LookupContext::Ptr context, bool versions = false)
|
||||
QStringList prototypes(const Interpreter::ObjectValue *ov, const Interpreter::ContextPtr &context, bool versions = false)
|
||||
{
|
||||
QStringList list;
|
||||
if (!ov)
|
||||
return list;
|
||||
ov = ov->prototype(context->context());
|
||||
ov = ov->prototype(context);
|
||||
while (ov) {
|
||||
const Interpreter::QmlObjectValue * qmlValue = dynamic_cast<const Interpreter::QmlObjectValue *>(ov);
|
||||
if (qmlValue) {
|
||||
@@ -170,14 +170,14 @@ QStringList prototypes(const Interpreter::ObjectValue *ov, LookupContext::Ptr co
|
||||
list << ov->className();
|
||||
}
|
||||
}
|
||||
ov = ov->prototype(context->context());
|
||||
ov = ov->prototype(context);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<PropertyInfo> getObjectTypes(const Interpreter::ObjectValue *ov, LookupContext *context, bool local = false);
|
||||
QList<PropertyInfo> getObjectTypes(const Interpreter::ObjectValue *ov, const Interpreter::ContextPtr &context, bool local = false);
|
||||
|
||||
QList<PropertyInfo> getQmlTypes(const Interpreter::QmlObjectValue *ov, LookupContext *context, bool local = false)
|
||||
QList<PropertyInfo> getQmlTypes(const Interpreter::QmlObjectValue *ov, const Interpreter::ContextPtr &context, bool local = false)
|
||||
{
|
||||
QList<PropertyInfo> list;
|
||||
if (!ov)
|
||||
@@ -192,7 +192,7 @@ QList<PropertyInfo> getQmlTypes(const Interpreter::QmlObjectValue *ov, LookupCon
|
||||
QString name = property.first;
|
||||
if (!ov->isWritable(name) && ov->isPointer(name)) {
|
||||
//dot property
|
||||
const Interpreter::QmlObjectValue * qmlValue = dynamic_cast<const Interpreter::QmlObjectValue *>(ov->lookupMember(name, context->context()));
|
||||
const Interpreter::QmlObjectValue * qmlValue = dynamic_cast<const Interpreter::QmlObjectValue *>(ov->lookupMember(name, context));
|
||||
if (qmlValue) {
|
||||
QList<PropertyInfo> dotProperties = getQmlTypes(qmlValue, context);
|
||||
foreach (const PropertyInfo &propertyInfo, dotProperties) {
|
||||
@@ -204,7 +204,7 @@ QList<PropertyInfo> getQmlTypes(const Interpreter::QmlObjectValue *ov, LookupCon
|
||||
}
|
||||
}
|
||||
if (isValueType(ov->propertyType(name))) {
|
||||
const Interpreter::ObjectValue *dotObjectValue = dynamic_cast<const Interpreter::ObjectValue *>(ov->lookupMember(name, context->context()));
|
||||
const Interpreter::ObjectValue *dotObjectValue = dynamic_cast<const Interpreter::ObjectValue *>(ov->lookupMember(name, context));
|
||||
if (dotObjectValue) {
|
||||
QList<PropertyInfo> dotProperties = getObjectTypes(dotObjectValue, context);
|
||||
foreach (const PropertyInfo &propertyInfo, dotProperties) {
|
||||
@@ -222,7 +222,7 @@ QList<PropertyInfo> getQmlTypes(const Interpreter::QmlObjectValue *ov, LookupCon
|
||||
}
|
||||
|
||||
if (!local) {
|
||||
const Interpreter::ObjectValue* prototype = ov->prototype(context->context());
|
||||
const Interpreter::ObjectValue* prototype = ov->prototype(context);
|
||||
|
||||
const Interpreter::QmlObjectValue * qmlObjectValue = dynamic_cast<const Interpreter::QmlObjectValue *>(prototype);
|
||||
|
||||
@@ -236,7 +236,7 @@ QList<PropertyInfo> getQmlTypes(const Interpreter::QmlObjectValue *ov, LookupCon
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<PropertyInfo> getTypes(const Interpreter::ObjectValue *ov, LookupContext *context, bool local = false)
|
||||
QList<PropertyInfo> getTypes(const Interpreter::ObjectValue *ov, const Interpreter::ContextPtr &context, bool local = false)
|
||||
{
|
||||
QList<PropertyInfo> list;
|
||||
|
||||
@@ -251,7 +251,7 @@ QList<PropertyInfo> getTypes(const Interpreter::ObjectValue *ov, LookupContext *
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<PropertyInfo> getObjectTypes(const Interpreter::ObjectValue *ov, LookupContext *context, bool local)
|
||||
QList<PropertyInfo> getObjectTypes(const Interpreter::ObjectValue *ov, const Interpreter::ContextPtr &context, bool local)
|
||||
{
|
||||
QList<PropertyInfo> list;
|
||||
if (!ov)
|
||||
@@ -262,7 +262,7 @@ QList<PropertyInfo> getObjectTypes(const Interpreter::ObjectValue *ov, LookupCon
|
||||
list << processor.properties();
|
||||
|
||||
if (!local) {
|
||||
const Interpreter::ObjectValue* prototype = ov->prototype(context->context());
|
||||
const Interpreter::ObjectValue* prototype = ov->prototype(context);
|
||||
|
||||
const Interpreter::QmlObjectValue * qmlObjectValue = dynamic_cast<const Interpreter::QmlObjectValue *>(prototype);
|
||||
|
||||
@@ -381,7 +381,7 @@ private:
|
||||
QSet<QString> m_prototypeCacheNegatives;
|
||||
|
||||
//storing the pointer would not be save
|
||||
QmlJS::LookupContext *lookupContext() const;
|
||||
QmlJS::Interpreter::ContextPtr context() const;
|
||||
QmlJS::Document *document() const;
|
||||
|
||||
QPointer<Model> m_model;
|
||||
@@ -423,11 +423,11 @@ NodeMetaInfoPrivate::NodeMetaInfoPrivate(Model *model, QString type, int maj, in
|
||||
m_minorVersion(min), m_isValid(false), m_isComponent(false),
|
||||
m_model(model)
|
||||
{
|
||||
if (lookupContext()) {
|
||||
if (context()) {
|
||||
const Interpreter::QmlObjectValue *objectValue = getQmlObjectValue();
|
||||
if (objectValue) {
|
||||
setupPropertyInfo(getTypes(objectValue, lookupContext()));
|
||||
setupLocalPropertyInfo(getTypes(objectValue, lookupContext(), true));
|
||||
setupPropertyInfo(getTypes(objectValue, context()));
|
||||
setupLocalPropertyInfo(getTypes(objectValue, context(), true));
|
||||
m_defaultPropertyName = objectValue->defaultPropertyName();
|
||||
setupPrototypes();
|
||||
m_isValid = true;
|
||||
@@ -442,9 +442,9 @@ NodeMetaInfoPrivate::NodeMetaInfoPrivate(Model *model, QString type, int maj, in
|
||||
} else {
|
||||
m_isComponent = true;
|
||||
}
|
||||
setupPropertyInfo(getTypes(objectValue, lookupContext()));
|
||||
setupLocalPropertyInfo(getTypes(objectValue, lookupContext(), true));
|
||||
m_defaultPropertyName = lookupContext()->context()->defaultPropertyName(objectValue);
|
||||
setupPropertyInfo(getTypes(objectValue, context()));
|
||||
setupLocalPropertyInfo(getTypes(objectValue, context(), true));
|
||||
m_defaultPropertyName = context()->defaultPropertyName(objectValue);
|
||||
setupPrototypes();
|
||||
m_isValid = true;
|
||||
}
|
||||
@@ -466,7 +466,7 @@ static inline QString getUrlFromType(const QString& typeName)
|
||||
|
||||
const QmlJS::Interpreter::QmlObjectValue *NodeMetaInfoPrivate::getQmlObjectValue() const
|
||||
{
|
||||
QmlJS::Interpreter::QmlObjectValue * value = lookupContext()->valueOwner()->cppQmlTypes().typeByQualifiedName(lookupName());
|
||||
QmlJS::Interpreter::QmlObjectValue * value = context()->valueOwner()->cppQmlTypes().typeByQualifiedName(lookupName());
|
||||
if (value)
|
||||
return value;
|
||||
|
||||
@@ -490,14 +490,12 @@ const QmlJS::Interpreter::QmlObjectValue *NodeMetaInfoPrivate::getQmlObjectValue
|
||||
|
||||
LanguageUtils::ComponentVersion version(9999, 9999);
|
||||
//get the correct version
|
||||
Document::Ptr doc = lookupContext()->document();
|
||||
const Interpreter::Context *context = lookupContext()->context().data();
|
||||
Interpreter::ImportInfo importInfo = context->imports(doc.data())->info(fullQualifiedImportAliasType(), context);
|
||||
Interpreter::ImportInfo importInfo = context()->imports(document())->info(fullQualifiedImportAliasType(), context().data());
|
||||
|
||||
if (importInfo.isValid())
|
||||
version = importInfo.version();
|
||||
|
||||
QList<Interpreter::QmlObjectValue *> qmlObjectValues = lookupContext()->valueOwner()->cppQmlTypes().typesForImport(package, version);
|
||||
QList<Interpreter::QmlObjectValue *> qmlObjectValues = context()->valueOwner()->cppQmlTypes().typesForImport(package, version);
|
||||
const Interpreter::QmlObjectValue *qmlValue = 0;
|
||||
foreach (Interpreter::QmlObjectValue *value, qmlObjectValues) {
|
||||
if (value->className() == type)
|
||||
@@ -525,15 +523,15 @@ const QmlJS::Interpreter::QmlObjectValue *NodeMetaInfoPrivate::getQmlObjectValue
|
||||
|
||||
const QmlJS::Interpreter::ObjectValue *NodeMetaInfoPrivate::getObjectValue() const
|
||||
{
|
||||
return lookupContext()->context()->lookupType(document(), lookupNameComponent());
|
||||
return context()->lookupType(document(), lookupNameComponent());
|
||||
}
|
||||
|
||||
QmlJS::LookupContext *NodeMetaInfoPrivate::lookupContext() const
|
||||
QmlJS::Interpreter::ContextPtr NodeMetaInfoPrivate::context() const
|
||||
{
|
||||
if (m_model && m_model->rewriterView()) {
|
||||
return m_model->rewriterView()->lookupContext();
|
||||
return m_model->rewriterView()->scopeChain().context();
|
||||
}
|
||||
return 0;
|
||||
return QmlJS::Interpreter::ContextPtr(0);
|
||||
}
|
||||
|
||||
QmlJS::Document *NodeMetaInfoPrivate::document() const
|
||||
@@ -670,7 +668,7 @@ bool NodeMetaInfoPrivate::isPropertyEnum(const QString &propertyName) const
|
||||
}
|
||||
|
||||
QList<const Interpreter::ObjectValue *> objects;
|
||||
objects = Interpreter::PrototypeIterator(getNearestQmlObjectValue(), lookupContext()->context()).all();
|
||||
objects = Interpreter::PrototypeIterator(getNearestQmlObjectValue(), context()).all();
|
||||
|
||||
//We have to run the prototype chain
|
||||
foreach (const Interpreter::ObjectValue *ov, objects) {
|
||||
@@ -706,7 +704,7 @@ QString NodeMetaInfoPrivate::propertyEnumScope(const QString &propertyName) cons
|
||||
}
|
||||
|
||||
QList<const Interpreter::ObjectValue *> objects;
|
||||
objects = Interpreter::PrototypeIterator(getNearestQmlObjectValue(), lookupContext()->context()).all();
|
||||
objects = Interpreter::PrototypeIterator(getNearestQmlObjectValue(), context()).all();
|
||||
|
||||
//We have to run the prototype chain
|
||||
foreach (const Interpreter::ObjectValue *ov, objects) {
|
||||
@@ -849,7 +847,7 @@ QStringList NodeMetaInfoPrivate::lookupNameComponent() const
|
||||
|
||||
bool NodeMetaInfoPrivate::isValid() const
|
||||
{
|
||||
return m_isValid && lookupContext() && document();
|
||||
return m_isValid && context() && document();
|
||||
}
|
||||
|
||||
QString NodeMetaInfoPrivate::propertyType(const QString &propertyName) const
|
||||
@@ -863,9 +861,9 @@ void NodeMetaInfoPrivate::setupPrototypes()
|
||||
{
|
||||
QList<const Interpreter::ObjectValue *> objects;
|
||||
if (m_isComponent)
|
||||
objects = Interpreter::PrototypeIterator(getObjectValue(), lookupContext()->context()).all();
|
||||
objects = Interpreter::PrototypeIterator(getObjectValue(), context()).all();
|
||||
else
|
||||
objects = Interpreter::PrototypeIterator(getQmlObjectValue(), lookupContext()->context()).all();
|
||||
objects = Interpreter::PrototypeIterator(getQmlObjectValue(), context()).all();
|
||||
foreach (const Interpreter::ObjectValue *ov, objects) {
|
||||
TypeDescription description;
|
||||
description.className = ov->className();
|
||||
@@ -878,7 +876,7 @@ void NodeMetaInfoPrivate::setupPrototypes()
|
||||
description.className = qmlValue->packageName() + '.' + description.className;
|
||||
m_prototypes.append(description);
|
||||
} else {
|
||||
if (lookupContext()->context()->lookupType(document(), QStringList() << ov->className()))
|
||||
if (context()->lookupType(document(), QStringList() << ov->className()))
|
||||
m_prototypes.append(description);
|
||||
}
|
||||
}
|
||||
@@ -893,7 +891,7 @@ QList<TypeDescription> NodeMetaInfoPrivate::prototypes() const
|
||||
const QmlJS::Interpreter::QmlObjectValue *NodeMetaInfoPrivate::getNearestQmlObjectValue() const
|
||||
{
|
||||
if (m_isComponent)
|
||||
return findQmlPrototype(getObjectValue(), lookupContext());
|
||||
return findQmlPrototype(getObjectValue(), context());
|
||||
return getQmlObjectValue();
|
||||
}
|
||||
|
||||
|
@@ -624,9 +624,9 @@ bool RewriterView::renameId(const QString& oldId, const QString& newId)
|
||||
return false;
|
||||
}
|
||||
|
||||
QmlJS::LookupContext *RewriterView::lookupContext() const
|
||||
const QmlJS::Interpreter::ScopeChain &RewriterView::scopeChain() const
|
||||
{
|
||||
return textToModelMerger()->lookupContext();
|
||||
return textToModelMerger()->scopeChain();
|
||||
}
|
||||
|
||||
QmlJS::Document *RewriterView::document() const
|
||||
|
@@ -340,7 +340,6 @@ public:
|
||||
, m_scopeChain(doc, m_context)
|
||||
, m_scopeBuilder(&m_scopeChain)
|
||||
{
|
||||
m_lookupContext = LookupContext::create(doc, m_context, QList<AST::Node*>());
|
||||
}
|
||||
|
||||
~ReadingContext()
|
||||
@@ -384,7 +383,7 @@ public:
|
||||
majorVersion = ComponentVersion::NoVersion;
|
||||
minorVersion = ComponentVersion::NoVersion;
|
||||
|
||||
const Interpreter::Imports *imports = m_lookupContext->context()->imports(m_lookupContext->document().data());
|
||||
const Interpreter::Imports *imports = m_context->imports(m_doc.data());
|
||||
Interpreter::ImportInfo importInfo = imports->info(fullTypeName, m_context.data());
|
||||
if (importInfo.isValid() && importInfo.type() == Interpreter::ImportInfo::LibraryImport) {
|
||||
QString name = importInfo.name().replace("\\", ".");
|
||||
@@ -621,8 +620,8 @@ public:
|
||||
}
|
||||
|
||||
|
||||
LookupContext::Ptr lookupContext() const
|
||||
{ return m_lookupContext; }
|
||||
const Interpreter::ScopeChain &scopeChain() const
|
||||
{ return m_scopeChain; }
|
||||
|
||||
QList<DiagnosticMessage> diagnosticLinkMessages() const
|
||||
{ return m_diagnosticLinkMessages; }
|
||||
@@ -633,7 +632,6 @@ private:
|
||||
Link m_link;
|
||||
QList<DiagnosticMessage> m_diagnosticLinkMessages;
|
||||
Interpreter::ContextPtr m_context;
|
||||
LookupContext::Ptr m_lookupContext;
|
||||
Interpreter::ScopeChain m_scopeChain;
|
||||
ScopeBuilder m_scopeBuilder;
|
||||
};
|
||||
@@ -766,7 +764,8 @@ bool TextToModelMerger::load(const QString &data, DifferenceHandler &differenceH
|
||||
}
|
||||
snapshot.insert(doc);
|
||||
ReadingContext ctxt(snapshot, doc, importPaths);
|
||||
m_lookupContext = ctxt.lookupContext();
|
||||
m_scopeChain = QSharedPointer<const Interpreter::ScopeChain>(
|
||||
new Interpreter::ScopeChain(ctxt.scopeChain()));
|
||||
m_document = doc;
|
||||
|
||||
QList<RewriterView::Error> errors;
|
||||
@@ -783,7 +782,7 @@ bool TextToModelMerger::load(const QString &data, DifferenceHandler &differenceH
|
||||
}
|
||||
|
||||
if (view()->checkSemanticErrors()) {
|
||||
Check check(doc, m_lookupContext->context());
|
||||
Check check(doc, m_scopeChain->context());
|
||||
check.setOptions(check.options() & ~Check::ErrCheckTypeErrors);
|
||||
foreach (const QmlJS::DiagnosticMessage &diagnosticMessage, check()) {
|
||||
if (diagnosticMessage.isError())
|
||||
|
@@ -38,9 +38,8 @@
|
||||
#include "nodelistproperty.h"
|
||||
#include "modelnode.h"
|
||||
|
||||
#include <qmljs/qmljslookupcontext.h>
|
||||
#include <qmljs/qmljsdocument.h>
|
||||
#include <qmljs/qmljslookupcontext.h>
|
||||
#include <qmljs/qmljsscopechain.h>
|
||||
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QTimer>
|
||||
@@ -69,8 +68,8 @@ public:
|
||||
RewriterView *view() const
|
||||
{ return m_rewriterView; }
|
||||
|
||||
QmlJS::LookupContext *lookupContext() const
|
||||
{ return m_lookupContext.data(); }
|
||||
const QmlJS::Interpreter::ScopeChain &scopeChain() const
|
||||
{ return *m_scopeChain; }
|
||||
|
||||
QmlJS::Document *document() const
|
||||
{ return m_document.data(); }
|
||||
@@ -141,7 +140,7 @@ private:
|
||||
private:
|
||||
RewriterView *m_rewriterView;
|
||||
bool m_isActive;
|
||||
QmlJS::LookupContext::Ptr m_lookupContext;
|
||||
QSharedPointer<const QmlJS::Interpreter::ScopeChain> m_scopeChain;
|
||||
QmlJS::Document::Ptr m_document;
|
||||
QTimer m_setupTimer;
|
||||
QSet<ModelNode> m_setupComponentList;
|
||||
|
@@ -49,7 +49,6 @@
|
||||
#include <qmljs/qmljsinterpreter.h>
|
||||
#include <qmljs/qmljscontext.h>
|
||||
#include <qmljs/qmljsscopechain.h>
|
||||
#include <qmljs/qmljslookupcontext.h>
|
||||
#include <qmljs/qmljsscanner.h>
|
||||
#include <qmljs/qmljsbind.h>
|
||||
#include <qmljs/qmljscompletioncontextfinder.h>
|
||||
@@ -421,9 +420,8 @@ IAssistProposal *QmlJSCompletionAssistProcessor::perform(const IAssistInterface
|
||||
isQmlFile = true;
|
||||
|
||||
const QList<AST::Node *> path = semanticInfo.rangePath(m_interface->position());
|
||||
LookupContext::Ptr lookupContext = semanticInfo.lookupContext(path);
|
||||
const Interpreter::ContextPtr &context = lookupContext->context();
|
||||
const Interpreter::ScopeChain &scopeChain = lookupContext->scopeChain();
|
||||
const Interpreter::ContextPtr &context = semanticInfo.context;
|
||||
const Interpreter::ScopeChain &scopeChain = semanticInfo.scopeChain(path);
|
||||
|
||||
// Search for the operator that triggered the completion.
|
||||
QChar completionOperator;
|
||||
@@ -615,9 +613,9 @@ IAssistProposal *QmlJSCompletionAssistProcessor::perform(const IAssistInterface
|
||||
|
||||
if (expression != 0 && ! isLiteral(expression)) {
|
||||
// Evaluate the expression under cursor.
|
||||
Interpreter::ValueOwner *interp = lookupContext->valueOwner();
|
||||
Interpreter::ValueOwner *interp = context->valueOwner();
|
||||
const Interpreter::Value *value =
|
||||
interp->convertToObject(lookupContext->evaluate(expression));
|
||||
interp->convertToObject(scopeChain.evaluate(expression));
|
||||
//qDebug() << "type:" << interp->typeId(value);
|
||||
|
||||
if (value && completionOperator == QLatin1Char('.')) { // member completion
|
||||
|
@@ -46,8 +46,8 @@
|
||||
#include <qmljs/qmljsevaluate.h>
|
||||
#include <qmljs/qmljsdocument.h>
|
||||
#include <qmljs/qmljsicontextpane.h>
|
||||
#include <qmljs/qmljslookupcontext.h>
|
||||
#include <qmljs/qmljsmodelmanagerinterface.h>
|
||||
#include <qmljs/qmljsscopebuilder.h>
|
||||
#include <qmljs/parser/qmljsastvisitor_p.h>
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsengine_p.h>
|
||||
@@ -547,14 +547,17 @@ QList<AST::Node *> SemanticInfo::rangePath(int cursorPosition) const
|
||||
return path;
|
||||
}
|
||||
|
||||
LookupContext::Ptr SemanticInfo::lookupContext(const QList<QmlJS::AST::Node *> &path) const
|
||||
Interpreter::ScopeChain SemanticInfo::scopeChain(const QList<QmlJS::AST::Node *> &path) const
|
||||
{
|
||||
Q_ASSERT(! m_context.isNull());
|
||||
Q_ASSERT(m_rootScopeChain);
|
||||
|
||||
if (m_context.isNull())
|
||||
return LookupContext::create(document, snapshot, path);
|
||||
if (path.isEmpty())
|
||||
return *m_rootScopeChain;
|
||||
|
||||
return LookupContext::create(document, m_context, path);
|
||||
Interpreter::ScopeChain scope = *m_rootScopeChain;
|
||||
ScopeBuilder builder(&scope);
|
||||
builder.push(path);
|
||||
return scope;
|
||||
}
|
||||
|
||||
static bool importContainsCursor(UiImport *importAst, unsigned cursorPosition)
|
||||
@@ -602,7 +605,7 @@ AST::Node *SemanticInfo::nodeUnderCursor(int pos) const
|
||||
|
||||
bool SemanticInfo::isValid() const
|
||||
{
|
||||
if (document && m_context)
|
||||
if (document && context && m_rootScopeChain)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@@ -924,7 +927,7 @@ void QmlJSTextEditorWidget::updateCursorPositionNow()
|
||||
Node *oldNode = m_semanticInfo.declaringMemberNoProperties(m_oldCursorPosition);
|
||||
Node *newNode = m_semanticInfo.declaringMemberNoProperties(position());
|
||||
if (oldNode != newNode && m_oldCursorPosition != -1)
|
||||
m_contextPane->apply(editor(), semanticInfo().document, LookupContext::Ptr(),newNode, false);
|
||||
m_contextPane->apply(editor(), semanticInfo().document, 0, newNode, false);
|
||||
if (m_contextPane->isAvailable(editor(), semanticInfo().document, newNode) &&
|
||||
!m_contextPane->widget()->isVisible()) {
|
||||
QList<TextEditor::RefactorMarker> markers;
|
||||
@@ -1009,19 +1012,17 @@ class SelectedElement: protected Visitor
|
||||
unsigned m_cursorPositionStart;
|
||||
unsigned m_cursorPositionEnd;
|
||||
QList<UiObjectMember *> m_selectedMembers;
|
||||
LookupContext::Ptr m_lookupContext;
|
||||
|
||||
public:
|
||||
SelectedElement()
|
||||
: m_cursorPositionStart(0), m_cursorPositionEnd(0) {}
|
||||
|
||||
QList<UiObjectMember *> operator()(LookupContext::Ptr lookupContext, unsigned startPosition, unsigned endPosition)
|
||||
QList<UiObjectMember *> operator()(const Document::Ptr &doc, unsigned startPosition, unsigned endPosition)
|
||||
{
|
||||
m_lookupContext = lookupContext;
|
||||
m_cursorPositionStart = startPosition;
|
||||
m_cursorPositionEnd = endPosition;
|
||||
m_selectedMembers.clear();
|
||||
Node::accept(lookupContext->document()->qmlProgram(), this);
|
||||
Node::accept(doc->qmlProgram(), this);
|
||||
return m_selectedMembers;
|
||||
}
|
||||
|
||||
@@ -1135,7 +1136,7 @@ void QmlJSTextEditorWidget::setSelectedElements()
|
||||
|
||||
if (m_semanticInfo.isValid()) {
|
||||
SelectedElement selectedMembers;
|
||||
QList<UiObjectMember *> members = selectedMembers(m_semanticInfo.lookupContext(),
|
||||
QList<UiObjectMember *> members = selectedMembers(m_semanticInfo.document,
|
||||
startPos, endPos);
|
||||
if (!members.isEmpty()) {
|
||||
foreach(UiObjectMember *m, members) {
|
||||
@@ -1259,8 +1260,8 @@ TextEditor::BaseTextEditorWidget::Link QmlJSTextEditorWidget::findLinkAt(const Q
|
||||
return Link();
|
||||
}
|
||||
|
||||
LookupContext::Ptr lookupContext = semanticInfo.lookupContext(semanticInfo.rangePath(cursorPosition));
|
||||
Evaluate evaluator(&lookupContext->scopeChain());
|
||||
const Interpreter::ScopeChain scopeChain = semanticInfo.scopeChain(semanticInfo.rangePath(cursorPosition));
|
||||
Evaluate evaluator(&scopeChain);
|
||||
const Interpreter::Value *value = evaluator.reference(node);
|
||||
|
||||
QString fileName;
|
||||
@@ -1316,7 +1317,10 @@ void QmlJSTextEditorWidget::showContextPane()
|
||||
{
|
||||
if (m_contextPane && m_semanticInfo.isValid()) {
|
||||
Node *newNode = m_semanticInfo.declaringMemberNoProperties(position());
|
||||
m_contextPane->apply(editor(), m_semanticInfo.document, m_semanticInfo.lookupContext(), newNode, false, true);
|
||||
Interpreter::ScopeChain scopeChain = m_semanticInfo.scopeChain(m_semanticInfo.rangePath(position()));
|
||||
m_contextPane->apply(editor(), m_semanticInfo.document,
|
||||
&scopeChain,
|
||||
newNode, false, true);
|
||||
m_oldCursorPosition = position();
|
||||
QList<TextEditor::RefactorMarker> markers;
|
||||
setRefactorMarkers(markers);
|
||||
@@ -1412,10 +1416,7 @@ void QmlJSTextEditorWidget::wheelEvent(QWheelEvent *event)
|
||||
BaseTextEditorWidget::wheelEvent(event);
|
||||
|
||||
if (visible) {
|
||||
LookupContext::Ptr lookupContext;
|
||||
if (m_semanticInfo.isValid())
|
||||
lookupContext = m_semanticInfo.lookupContext();
|
||||
m_contextPane->apply(editor(), semanticInfo().document, QmlJS::LookupContext::Ptr(), m_semanticInfo.declaringMemberNoProperties(m_oldCursorPosition), false, true);
|
||||
m_contextPane->apply(editor(), semanticInfo().document, 0, m_semanticInfo.declaringMemberNoProperties(m_oldCursorPosition), false, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1486,7 +1487,7 @@ void QmlJSTextEditorWidget::updateSemanticInfo(const SemanticInfo &semanticInfo)
|
||||
if (m_contextPane) {
|
||||
Node *newNode = m_semanticInfo.declaringMemberNoProperties(position());
|
||||
if (newNode) {
|
||||
m_contextPane->apply(editor(), semanticInfo.document, LookupContext::Ptr(), newNode, true);
|
||||
m_contextPane->apply(editor(), semanticInfo.document, 0, newNode, true);
|
||||
m_cursorPositionTimer->start(); //update text marker
|
||||
}
|
||||
}
|
||||
@@ -1539,7 +1540,7 @@ bool QmlJSTextEditorWidget::hideContextPane()
|
||||
{
|
||||
bool b = (m_contextPane) && m_contextPane->widget()->isVisible();
|
||||
if (b) {
|
||||
m_contextPane->apply(editor(), semanticInfo().document, LookupContext::Ptr(), 0, false);
|
||||
m_contextPane->apply(editor(), semanticInfo().document, 0, 0, false);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
@@ -37,7 +37,7 @@
|
||||
|
||||
#include <qmljs/qmljsdocument.h>
|
||||
#include <qmljs/qmljsscanner.h>
|
||||
#include <qmljs/qmljscontext.h>
|
||||
#include <qmljs/qmljsscopechain.h>
|
||||
#include <texteditor/basetexteditor.h>
|
||||
#include <texteditor/quickfix.h>
|
||||
|
||||
@@ -117,12 +117,13 @@ public:
|
||||
// Returns the list of nodes that enclose the given position.
|
||||
QList<QmlJS::AST::Node *> rangePath(int cursorPosition) const;
|
||||
|
||||
// Returns a context for the given path
|
||||
QSharedPointer<QmlJS::LookupContext> lookupContext(const QList<QmlJS::AST::Node *> &path = QList<QmlJS::AST::Node *>()) const;
|
||||
// Returns a scopeChain for the given path
|
||||
QmlJS::Interpreter::ScopeChain scopeChain(const QList<QmlJS::AST::Node *> &path = QList<QmlJS::AST::Node *>()) const;
|
||||
|
||||
public: // attributes
|
||||
QmlJS::Document::Ptr document;
|
||||
QmlJS::Snapshot snapshot;
|
||||
QmlJS::Interpreter::ContextPtr context;
|
||||
QList<Range> ranges;
|
||||
QHash<QString, QList<QmlJS::AST::SourceLocation> > idLocations;
|
||||
QList<Declaration> declarations;
|
||||
@@ -131,7 +132,7 @@ public: // attributes
|
||||
QList<QmlJS::DiagnosticMessage> semanticMessages;
|
||||
|
||||
private:
|
||||
QmlJS::Interpreter::ContextPtr m_context;
|
||||
QSharedPointer<const QmlJS::Interpreter::ScopeChain> m_rootScopeChain;
|
||||
|
||||
friend class Internal::SemanticHighlighter;
|
||||
};
|
||||
|
@@ -40,7 +40,6 @@
|
||||
#include <QtCore/QFutureWatcher>
|
||||
#include <utils/filesearch.h>
|
||||
#include <qmljs/qmljsdocument.h>
|
||||
#include <qmljs/qmljslookupcontext.h>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QTimer)
|
||||
|
||||
|
@@ -40,6 +40,7 @@
|
||||
#include <coreplugin/helpmanager.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <qmljs/qmljscontext.h>
|
||||
#include <qmljs/qmljsscopechain.h>
|
||||
#include <qmljs/qmljsinterpreter.h>
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsastfwd_p.h>
|
||||
@@ -54,6 +55,7 @@
|
||||
|
||||
using namespace Core;
|
||||
using namespace QmlJS;
|
||||
using namespace QmlJS::Interpreter;
|
||||
using namespace QmlJSEditor;
|
||||
using namespace QmlJSEditor::Internal;
|
||||
|
||||
@@ -123,20 +125,20 @@ void HoverHandler::identifyMatch(TextEditor::ITextEditor *editor, int pos)
|
||||
QList<AST::Node *> astPath = semanticInfo.rangePath(pos);
|
||||
|
||||
const Document::Ptr qmlDocument = semanticInfo.document;
|
||||
LookupContext::Ptr lookupContext = semanticInfo.lookupContext(astPath);
|
||||
ScopeChain scopeChain = semanticInfo.scopeChain(astPath);
|
||||
|
||||
AST::Node *node = semanticInfo.nodeUnderCursor(pos);
|
||||
if (astPath.isEmpty()) {
|
||||
if (AST::UiImport *import = AST::cast<AST::UiImport *>(node))
|
||||
handleImport(lookupContext, import);
|
||||
handleImport(scopeChain, import);
|
||||
return;
|
||||
}
|
||||
if (matchColorItem(lookupContext, qmlDocument, astPath, pos))
|
||||
if (matchColorItem(scopeChain, qmlDocument, astPath, pos))
|
||||
return;
|
||||
|
||||
handleOrdinaryMatch(lookupContext, node);
|
||||
handleOrdinaryMatch(scopeChain, node);
|
||||
|
||||
TextEditor::HelpItem helpItem = qmlHelpItem(lookupContext, node);
|
||||
TextEditor::HelpItem helpItem = qmlHelpItem(scopeChain, node);
|
||||
if (!helpItem.helpId().isEmpty())
|
||||
setLastHelpItemIdentified(helpItem);
|
||||
}
|
||||
@@ -153,7 +155,7 @@ bool HoverHandler::matchDiagnosticMessage(QmlJSEditor::QmlJSTextEditorWidget *qm
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HoverHandler::matchColorItem(const LookupContext::Ptr &lookupContext,
|
||||
bool HoverHandler::matchColorItem(const ScopeChain &scopeChain,
|
||||
const Document::Ptr &qmlDocument,
|
||||
const QList<AST::Node *> &astPath,
|
||||
unsigned pos)
|
||||
@@ -176,7 +178,7 @@ bool HoverHandler::matchColorItem(const LookupContext::Ptr &lookupContext,
|
||||
const Interpreter::Value *value = 0;
|
||||
if (const AST::UiScriptBinding *binding = AST::cast<const AST::UiScriptBinding *>(member)) {
|
||||
if (binding->qualifiedId && posIsInSource(pos, binding->statement)) {
|
||||
value = lookupContext->evaluate(binding->qualifiedId);
|
||||
value = scopeChain.evaluate(binding->qualifiedId);
|
||||
if (value && value->asColorValue()) {
|
||||
color = textAt(qmlDocument,
|
||||
binding->statement->firstSourceLocation(),
|
||||
@@ -186,9 +188,9 @@ bool HoverHandler::matchColorItem(const LookupContext::Ptr &lookupContext,
|
||||
} else if (const AST::UiPublicMember *publicMember =
|
||||
AST::cast<const AST::UiPublicMember *>(member)) {
|
||||
if (publicMember->name && posIsInSource(pos, publicMember->statement)) {
|
||||
value = lookupContext->scopeChain().lookup(publicMember->name->asString());
|
||||
value = scopeChain.lookup(publicMember->name->asString());
|
||||
if (const Interpreter::Reference *ref = value->asReference())
|
||||
value = lookupContext->context()->lookupReference(ref);
|
||||
value = scopeChain.context()->lookupReference(ref);
|
||||
color = textAt(qmlDocument,
|
||||
publicMember->statement->firstSourceLocation(),
|
||||
publicMember->statement->lastSourceLocation());
|
||||
@@ -209,18 +211,18 @@ bool HoverHandler::matchColorItem(const LookupContext::Ptr &lookupContext,
|
||||
return false;
|
||||
}
|
||||
|
||||
void HoverHandler::handleOrdinaryMatch(const LookupContext::Ptr &lookupContext, AST::Node *node)
|
||||
void HoverHandler::handleOrdinaryMatch(const ScopeChain &scopeChain, AST::Node *node)
|
||||
{
|
||||
if (node && !(AST::cast<AST::StringLiteral *>(node) != 0 ||
|
||||
AST::cast<AST::NumericLiteral *>(node) != 0)) {
|
||||
const Interpreter::Value *value = lookupContext->evaluate(node);
|
||||
prettyPrintTooltip(value, lookupContext->context());
|
||||
const Interpreter::Value *value = scopeChain.evaluate(node);
|
||||
prettyPrintTooltip(value, scopeChain.context());
|
||||
}
|
||||
}
|
||||
|
||||
void HoverHandler::handleImport(const LookupContext::Ptr &lookupContext, AST::UiImport *node)
|
||||
void HoverHandler::handleImport(const ScopeChain &scopeChain, AST::UiImport *node)
|
||||
{
|
||||
const Interpreter::Imports *imports = lookupContext->context()->imports(lookupContext->document().data());
|
||||
const Interpreter::Imports *imports = scopeChain.context()->imports(scopeChain.document().data());
|
||||
if (!imports)
|
||||
return;
|
||||
|
||||
@@ -229,7 +231,7 @@ void HoverHandler::handleImport(const LookupContext::Ptr &lookupContext, AST::Ui
|
||||
if (import.info.type() == Interpreter::ImportInfo::LibraryImport
|
||||
&& !import.libraryPath.isEmpty()) {
|
||||
QString msg = tr("Library at %1").arg(import.libraryPath);
|
||||
const LibraryInfo &libraryInfo = lookupContext->snapshot().libraryInfo(import.libraryPath);
|
||||
const LibraryInfo &libraryInfo = scopeChain.context()->snapshot().libraryInfo(import.libraryPath);
|
||||
if (libraryInfo.pluginTypeInfoStatus() == LibraryInfo::DumpDone) {
|
||||
msg += QLatin1Char('\n');
|
||||
msg += tr("Dumped plugins successfully.");
|
||||
@@ -298,7 +300,7 @@ void HoverHandler::prettyPrintTooltip(const QmlJS::Interpreter::Value *value,
|
||||
}
|
||||
|
||||
// if node refers to a property, its name and defining object are returned - otherwise zero
|
||||
static const Interpreter::ObjectValue *isMember(const LookupContext::Ptr &lookupContext,
|
||||
static const Interpreter::ObjectValue *isMember(const ScopeChain &scopeChain,
|
||||
AST::Node *node, QString *name)
|
||||
{
|
||||
const Interpreter::ObjectValue *owningObject = 0;
|
||||
@@ -306,22 +308,22 @@ static const Interpreter::ObjectValue *isMember(const LookupContext::Ptr &lookup
|
||||
if (!identExp->name)
|
||||
return 0;
|
||||
*name = identExp->name->asString();
|
||||
lookupContext->scopeChain().lookup(*name, &owningObject);
|
||||
scopeChain.lookup(*name, &owningObject);
|
||||
} else if (AST::FieldMemberExpression *fme = AST::cast<AST::FieldMemberExpression *>(node)) {
|
||||
if (!fme->base || !fme->name)
|
||||
return 0;
|
||||
*name = fme->name->asString();
|
||||
const Interpreter::Value *base = lookupContext->evaluate(fme->base);
|
||||
const Interpreter::Value *base = scopeChain.evaluate(fme->base);
|
||||
if (!base)
|
||||
return 0;
|
||||
owningObject = base->asObjectValue();
|
||||
if (owningObject)
|
||||
owningObject->lookupMember(*name, lookupContext->context(), &owningObject);
|
||||
owningObject->lookupMember(*name, scopeChain.context(), &owningObject);
|
||||
} else if (AST::UiQualifiedId *qid = AST::cast<AST::UiQualifiedId *>(node)) {
|
||||
if (!qid->name)
|
||||
return 0;
|
||||
*name = qid->name->asString();
|
||||
const Interpreter::Value *value = lookupContext->scopeChain().lookup(*name, &owningObject);
|
||||
const Interpreter::Value *value = scopeChain.lookup(*name, &owningObject);
|
||||
for (AST::UiQualifiedId *it = qid->next; it; it = it->next) {
|
||||
if (!value)
|
||||
return 0;
|
||||
@@ -329,17 +331,17 @@ static const Interpreter::ObjectValue *isMember(const LookupContext::Ptr &lookup
|
||||
if (!next || !it->name)
|
||||
return 0;
|
||||
*name = it->name->asString();
|
||||
value = next->lookupMember(*name, lookupContext->context(), &owningObject);
|
||||
value = next->lookupMember(*name, scopeChain.context(), &owningObject);
|
||||
}
|
||||
}
|
||||
return owningObject;
|
||||
}
|
||||
|
||||
TextEditor::HelpItem HoverHandler::qmlHelpItem(const LookupContext::Ptr &lookupContext,
|
||||
TextEditor::HelpItem HoverHandler::qmlHelpItem(const ScopeChain &scopeChain,
|
||||
AST::Node *node) const
|
||||
{
|
||||
QString name;
|
||||
if (const Interpreter::ObjectValue *scope = isMember(lookupContext, node, &name)) {
|
||||
if (const Interpreter::ObjectValue *scope = isMember(scopeChain, node, &name)) {
|
||||
// maybe it's a type?
|
||||
if (!name.isEmpty() && name.at(0).isUpper()) {
|
||||
const QString maybeHelpId(QLatin1String("QML.") + name);
|
||||
@@ -349,8 +351,8 @@ TextEditor::HelpItem HoverHandler::qmlHelpItem(const LookupContext::Ptr &lookupC
|
||||
|
||||
// otherwise, it's probably a property
|
||||
const Interpreter::ObjectValue *lastScope;
|
||||
scope->lookupMember(name, lookupContext->context(), &lastScope);
|
||||
Interpreter::PrototypeIterator iter(scope, lookupContext->context());
|
||||
scope->lookupMember(name, scopeChain.context(), &lastScope);
|
||||
Interpreter::PrototypeIterator iter(scope, scopeChain.context());
|
||||
while (iter.hasNext()) {
|
||||
const Interpreter::ObjectValue *cur = iter.next();
|
||||
|
||||
|
@@ -34,7 +34,6 @@
|
||||
#define QMLJSHOVERHANDLER_H
|
||||
|
||||
#include <qmljs/qmljsmodelmanagerinterface.h>
|
||||
#include <qmljs/qmljslookupcontext.h>
|
||||
#include <texteditor/basehoverhandler.h>
|
||||
|
||||
#include <QtGui/QColor>
|
||||
@@ -51,6 +50,15 @@ namespace TextEditor {
|
||||
class ITextEditor;
|
||||
}
|
||||
|
||||
namespace QmlJS {
|
||||
namespace Interpreter {
|
||||
class ScopeChain;
|
||||
class Context;
|
||||
typedef QSharedPointer<const Context> ContextPtr;
|
||||
class Value;
|
||||
}
|
||||
}
|
||||
|
||||
namespace QmlJSEditor {
|
||||
class QmlJSTextEditorWidget;
|
||||
|
||||
@@ -70,19 +78,19 @@ private:
|
||||
virtual void operateTooltip(TextEditor::ITextEditor *editor, const QPoint &point);
|
||||
|
||||
bool matchDiagnosticMessage(QmlJSEditor::QmlJSTextEditorWidget *qmlEditor, int pos);
|
||||
bool matchColorItem(const QmlJS::LookupContext::Ptr &lookupContext,
|
||||
bool matchColorItem(const QmlJS::Interpreter::ScopeChain &lookupContext,
|
||||
const QmlJS::Document::Ptr &qmlDocument,
|
||||
const QList<QmlJS::AST::Node *> &astPath,
|
||||
unsigned pos);
|
||||
void handleOrdinaryMatch(const QmlJS::LookupContext::Ptr &lookupContext,
|
||||
void handleOrdinaryMatch(const QmlJS::Interpreter::ScopeChain &lookupContext,
|
||||
QmlJS::AST::Node *node);
|
||||
void handleImport(const QmlJS::LookupContext::Ptr &lookupContext,
|
||||
void handleImport(const QmlJS::Interpreter::ScopeChain &lookupContext,
|
||||
QmlJS::AST::UiImport *node);
|
||||
|
||||
void prettyPrintTooltip(const QmlJS::Interpreter::Value *value,
|
||||
const QmlJS::Interpreter::ContextPtr &context);
|
||||
|
||||
TextEditor::HelpItem qmlHelpItem(const QmlJS::LookupContext::Ptr &lookupContext,
|
||||
TextEditor::HelpItem qmlHelpItem(const QmlJS::Interpreter::ScopeChain &lookupContext,
|
||||
QmlJS::AST::Node *node) const;
|
||||
|
||||
QmlJS::ModelManagerInterface *m_modelManager;
|
||||
|
@@ -135,10 +135,12 @@ SemanticInfo SemanticHighlighter::semanticInfo(const SemanticHighlighterSource &
|
||||
QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance();
|
||||
|
||||
QmlJS::Link link(snapshot, modelManager->importPaths(), modelManager->builtins(doc));
|
||||
QmlJS::Interpreter::ContextPtr ctx = link(doc, &semanticInfo.semanticMessages);
|
||||
semanticInfo.m_context = QSharedPointer<const QmlJS::Interpreter::Context>(ctx);
|
||||
semanticInfo.context = link(doc, &semanticInfo.semanticMessages);
|
||||
|
||||
QmlJS::Check checker(doc, ctx);
|
||||
QmlJS::Interpreter::ScopeChain *scopeChain = new QmlJS::Interpreter::ScopeChain(doc, semanticInfo.context);
|
||||
semanticInfo.m_rootScopeChain = QSharedPointer<const QmlJS::Interpreter::ScopeChain>(scopeChain);
|
||||
|
||||
QmlJS::Check checker(doc, semanticInfo.context);
|
||||
semanticInfo.semanticMessages.append(checker());
|
||||
|
||||
return semanticInfo;
|
||||
|
@@ -35,7 +35,7 @@
|
||||
|
||||
#include <qmljs/parser/qmljsastvisitor_p.h>
|
||||
#include <qmljs/qmljscontext.h>
|
||||
#include <qmljs/qmljslookupcontext.h>
|
||||
#include <qmljs/qmljsscopechain.h>
|
||||
#include <qmljs/qmljsmodelmanagerinterface.h>
|
||||
#include <qmljs/qmljsrewriter.h>
|
||||
#include <qmljstools/qmljsrefactoringchanges.h>
|
||||
@@ -72,10 +72,10 @@ QVariant QmlOutlineItem::data(int role) const
|
||||
return QVariant();
|
||||
|
||||
QList<AST::Node *> astPath = m_outlineModel->m_semanticInfo.rangePath(location.begin());
|
||||
LookupContext::Ptr lookupContext = m_outlineModel->m_semanticInfo.lookupContext(astPath);
|
||||
const Interpreter::Value *value = lookupContext->evaluate(uiQualifiedId);
|
||||
Interpreter::ScopeChain scopeChain = m_outlineModel->m_semanticInfo.scopeChain(astPath);
|
||||
const Interpreter::Value *value = scopeChain.evaluate(uiQualifiedId);
|
||||
|
||||
return prettyPrint(value, lookupContext->context());
|
||||
return prettyPrint(value, scopeChain.context());
|
||||
}
|
||||
|
||||
if (role == Qt::DecorationRole) {
|
||||
|
@@ -37,7 +37,6 @@
|
||||
#include <utils/changeset.h>
|
||||
#include <qmljs/qmljsdocument.h>
|
||||
#include <qmljs/qmljsicons.h>
|
||||
#include <qmljs/qmljslookupcontext.h>
|
||||
|
||||
#include <QtGui/QStandardItemModel>
|
||||
|
||||
|
@@ -40,7 +40,6 @@
|
||||
#include <qmljs/qmljspropertyreader.h>
|
||||
#include <qmljs/qmljsrewriter.h>
|
||||
#include <qmljs/qmljsindenter.h>
|
||||
#include <qmljs/qmljslookupcontext.h>
|
||||
#include <qmljs/qmljscontext.h>
|
||||
#include <qmljs/qmljsbind.h>
|
||||
#include <qmljs/qmljsscopebuilder.h>
|
||||
@@ -65,7 +64,7 @@ static inline QString textAt(const Document* doc,
|
||||
return doc->source().mid(from.offset, to.end() - from.begin());
|
||||
}
|
||||
|
||||
static inline const Interpreter::ObjectValue * getPropertyChangesTarget(Node *node, LookupContext::Ptr lookupContext)
|
||||
static inline const Interpreter::ObjectValue * getPropertyChangesTarget(Node *node, const Interpreter::ScopeChain &scopeChain)
|
||||
{
|
||||
UiObjectInitializer *initializer = 0;
|
||||
if (UiObjectDefinition *definition = cast<UiObjectDefinition *>(node))
|
||||
@@ -78,7 +77,7 @@ static inline const Interpreter::ObjectValue * getPropertyChangesTarget(Node *no
|
||||
if (scriptBinding->qualifiedId
|
||||
&& scriptBinding->qualifiedId->name->asString() == QLatin1String("target")
|
||||
&& ! scriptBinding->qualifiedId->next) {
|
||||
Evaluate evaluator(&lookupContext->scopeChain());
|
||||
Evaluate evaluator(&scopeChain);
|
||||
const Interpreter::Value *targetValue = evaluator(scriptBinding->statement);
|
||||
if (const Interpreter::ObjectValue *targetObject = Interpreter::value_cast<const Interpreter::ObjectValue *>(targetValue)) {
|
||||
return targetObject;
|
||||
@@ -132,7 +131,7 @@ QuickToolBar::~QuickToolBar()
|
||||
m_widget.clear();
|
||||
}
|
||||
|
||||
void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr document, LookupContext::Ptr lookupContext, AST::Node *node, bool update, bool force)
|
||||
void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr document, const Interpreter::ScopeChain *scopeChain, AST::Node *node, bool update, bool force)
|
||||
{
|
||||
if (!QuickToolBarSettings::get().enableContextPane && !force && !update) {
|
||||
contextWidget()->hide();
|
||||
@@ -151,20 +150,20 @@ void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr docum
|
||||
|
||||
bool isPropertyChanges = false;
|
||||
|
||||
if (!lookupContext.isNull() && scopeObject) {
|
||||
if (scopeChain && scopeObject) {
|
||||
m_prototypes.clear();
|
||||
foreach (const Interpreter::ObjectValue *object,
|
||||
Interpreter::PrototypeIterator(scopeObject, lookupContext->context()).all()) {
|
||||
Interpreter::PrototypeIterator(scopeObject, scopeChain->context()).all()) {
|
||||
m_prototypes.append(object->className());
|
||||
}
|
||||
|
||||
if (m_prototypes.contains("PropertyChanges")) {
|
||||
isPropertyChanges = true;
|
||||
const Interpreter::ObjectValue *targetObject = getPropertyChangesTarget(node, lookupContext);
|
||||
const Interpreter::ObjectValue *targetObject = getPropertyChangesTarget(node, *scopeChain);
|
||||
m_prototypes.clear();
|
||||
if (targetObject) {
|
||||
foreach (const Interpreter::ObjectValue *object,
|
||||
Interpreter::PrototypeIterator(targetObject, lookupContext->context()).all()) {
|
||||
Interpreter::PrototypeIterator(targetObject, scopeChain->context()).all()) {
|
||||
m_prototypes.append(object->className());
|
||||
}
|
||||
}
|
||||
@@ -196,7 +195,7 @@ void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr docum
|
||||
end = objectBinding->lastSourceLocation().end();
|
||||
}
|
||||
|
||||
if (lookupContext.isNull()) {
|
||||
if (!scopeChain) {
|
||||
if (name != m_oldType)
|
||||
m_prototypes.clear();
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@ class QuickToolBar : public QmlJS::IContextPane
|
||||
public:
|
||||
QuickToolBar(QObject *parent = 0);
|
||||
~QuickToolBar();
|
||||
void apply(TextEditor::BaseTextEditor *editor, QmlJS::Document::Ptr document, QmlJS::LookupContext::Ptr lookupContext, QmlJS::AST::Node *node, bool update, bool force = false);
|
||||
void apply(TextEditor::BaseTextEditor *editor, QmlJS::Document::Ptr document, const QmlJS::Interpreter::ScopeChain *scopeChain, QmlJS::AST::Node *node, bool update, bool force = false);
|
||||
bool isAvailable(TextEditor::BaseTextEditor *editor, QmlJS::Document::Ptr document, QmlJS::AST::Node *node);
|
||||
void setProperty(const QString &propertyName, const QVariant &value);
|
||||
void removeProperty(const QString &propertyName);
|
||||
|
Reference in New Issue
Block a user