Removed obsolete code

Done with: Erik
This commit is contained in:
Roberto Raggi
2010-01-27 14:37:24 +01:00
parent d89b7ecb73
commit 39c2575ab3
27 changed files with 8 additions and 1855 deletions

View File

@@ -16,36 +16,19 @@ HEADERS += \
$$PWD/qmljsbind.h \ $$PWD/qmljsbind.h \
$$PWD/qmljscheck.h \ $$PWD/qmljscheck.h \
$$PWD/qmljsdocument.h \ $$PWD/qmljsdocument.h \
$$PWD/qmljsidcollector.h \
$$PWD/qmljsmetatypebackend.h \
$$PWD/qmljspackageinfo.h \
$$PWD/qmljsscanner.h \ $$PWD/qmljsscanner.h \
$$PWD/qmljssymbol.h \ $$PWD/qmljsinterpreter.h
$$PWD/qmljstypesystem.h \
$$PWD/qmljsinterpreter.h \
$$PWD/qmljsmetatypesystem.h
SOURCES += \ SOURCES += \
$$PWD/qmljsbind.cpp \ $$PWD/qmljsbind.cpp \
$$PWD/qmljscheck.cpp \ $$PWD/qmljscheck.cpp \
$$PWD/qmljsdocument.cpp \ $$PWD/qmljsdocument.cpp \
$$PWD/qmljsidcollector.cpp \
$$PWD/qmljsmetatypebackend.cpp \
$$PWD/qmljspackageinfo.cpp \
$$PWD/qmljsscanner.cpp \ $$PWD/qmljsscanner.cpp \
$$PWD/qmljssymbol.cpp \
$$PWD/qmljstypesystem.cpp \
$$PWD/qmljsinterpreter.cpp \ $$PWD/qmljsinterpreter.cpp \
$$PWD/qmljsmetatypesystem.cpp $$PWD/qmljsmetatypesystem.cpp
contains(QT_CONFIG, declarative) { contains(QT_CONFIG, declarative) {
QT += declarative QT += declarative
HEADERS += \
$$PWD/qtdeclarativemetatypebackend.h
SOURCES += \
$$PWD/qtdeclarativemetatypebackend.cpp
} else { } else {
DEFINES += NO_DECLARATIVE_BACKEND DEFINES += NO_DECLARATIVE_BACKEND
} }

View File

@@ -27,7 +27,6 @@
** **
**************************************************************************/ **************************************************************************/
#include "qmljsidcollector.h"
#include "qmljsdocument.h" #include "qmljsdocument.h"
#include <qmljs/parser/qmljsast_p.h> #include <qmljs/parser/qmljsast_p.h>
#include <qmljs/parser/qmljslexer_p.h> #include <qmljs/parser/qmljslexer_p.h>
@@ -70,8 +69,6 @@ Document::~Document()
if (_pool) if (_pool)
delete _pool; delete _pool;
qDeleteAll(_symbols);
} }
Document::Ptr Document::create(const QString &fileName) Document::Ptr Document::create(const QString &fileName)
@@ -136,7 +133,6 @@ bool Document::parseQml()
_engine = new Engine(); _engine = new Engine();
_pool = new NodePool(_fileName, _engine); _pool = new NodePool(_fileName, _engine);
_ids.clear();
Lexer lexer(_engine); Lexer lexer(_engine);
Parser parser(_engine); Parser parser(_engine);
@@ -147,17 +143,6 @@ bool Document::parseQml()
_ast = parser.ast(); _ast = parser.ast();
_diagnosticMessages = parser.diagnosticMessages(); _diagnosticMessages = parser.diagnosticMessages();
if (qmlProgram()) {
for (QmlJS::AST::UiObjectMemberList *iter = qmlProgram()->members; iter; iter = iter->next)
if (iter->member)
_symbols.append(new SymbolFromFile(_fileName, iter->member));
Internal::IdCollector collect;
_ids = collect(*this);
if (_diagnosticMessages.isEmpty())
_diagnosticMessages = collect.diagnosticMessages();
}
return _parsedCorrectly; return _parsedCorrectly;
} }
@@ -169,7 +154,6 @@ bool Document::parseJavaScript()
_engine = new Engine(); _engine = new Engine();
_pool = new NodePool(_fileName, _engine); _pool = new NodePool(_fileName, _engine);
_ids.clear();
Lexer lexer(_engine); Lexer lexer(_engine);
Parser parser(_engine); Parser parser(_engine);
@@ -191,7 +175,6 @@ bool Document::parseExpression()
_engine = new Engine(); _engine = new Engine();
_pool = new NodePool(_fileName, _engine); _pool = new NodePool(_fileName, _engine);
_ids.clear();
Lexer lexer(_engine); Lexer lexer(_engine);
Parser parser(_engine); Parser parser(_engine);
@@ -207,16 +190,6 @@ bool Document::parseExpression()
return _parsedCorrectly; return _parsedCorrectly;
} }
SymbolFromFile *Document::findSymbol(QmlJS::AST::Node *node) const
{
foreach (Symbol *symbol, _symbols)
if (symbol->isSymbolFromFile())
if (symbol->asSymbolFromFile()->node() == node)
return symbol->asSymbolFromFile();
return 0;
}
Snapshot::Snapshot() Snapshot::Snapshot()
{ {
} }

View File

@@ -37,7 +37,6 @@
#include "parser/qmljsengine_p.h" #include "parser/qmljsengine_p.h"
#include "qmljs_global.h" #include "qmljs_global.h"
#include "qmljssymbol.h"
namespace QmlJS { namespace QmlJS {
@@ -46,7 +45,6 @@ class QMLJS_EXPORT Document
public: public:
typedef QSharedPointer<Document> Ptr; typedef QSharedPointer<Document> Ptr;
typedef QList<Document::Ptr> PtrList; typedef QList<Document::Ptr> PtrList;
typedef QMap<QString, IdSymbol*> IdTable;
protected: protected:
Document(const QString &fileName); Document(const QString &fileName);
@@ -76,16 +74,10 @@ public:
int documentRevision() const; int documentRevision() const;
void setDocumentRevision(int documentRevision); void setDocumentRevision(int documentRevision);
IdTable ids() const { return _ids; }
QString fileName() const { return _fileName; } QString fileName() const { return _fileName; }
QString path() const { return _path; } QString path() const { return _path; }
QString componentName() const { return _componentName; } QString componentName() const { return _componentName; }
QmlJS::SymbolFromFile *findSymbol(QmlJS::AST::Node *node) const;
QmlJS::Symbol::List symbols() const
{ return _symbols; }
private: private:
QmlJS::Engine *_engine; QmlJS::Engine *_engine;
QmlJS::NodePool *_pool; QmlJS::NodePool *_pool;
@@ -97,8 +89,6 @@ private:
QString _path; QString _path;
QString _componentName; QString _componentName;
QString _source; QString _source;
IdTable _ids;
QmlJS::Symbol::List _symbols;
}; };
class QMLJS_EXPORT Snapshot class QMLJS_EXPORT Snapshot

View File

@@ -1,121 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include <QDebug>
#include <qmljs/parser/qmljsast_p.h>
#include "qmljsidcollector.h"
using namespace QmlJS;
using namespace QmlJS::AST;
using namespace QmlJS;
using namespace QmlJS::Internal;
QMap<QString, IdSymbol*> IdCollector::operator()(QmlJS::Document &doc)
{
_doc = &doc;
_ids.clear();
_currentSymbol = 0;
Node::accept(doc.qmlProgram(), this);
return _ids;
}
bool IdCollector::visit(UiArrayBinding *ast)
{
SymbolFromFile *oldSymbol = switchSymbol(ast);
Node::accept(ast->members, this);
_currentSymbol = oldSymbol;
return false;
}
bool IdCollector::visit(QmlJS::AST::UiObjectBinding *ast)
{
SymbolFromFile *oldSymbol = switchSymbol(ast);
Node::accept(ast->initializer, this);
_currentSymbol = oldSymbol;
return false;
}
bool IdCollector::visit(QmlJS::AST::UiObjectDefinition *ast)
{
SymbolFromFile *oldSymbol = switchSymbol(ast);
Node::accept(ast->initializer, this);
_currentSymbol = oldSymbol;
return false;
}
bool IdCollector::visit(QmlJS::AST::UiScriptBinding *ast)
{
if (!(ast->qualifiedId->next) && ast->qualifiedId->name->asString() == "id")
if (ExpressionStatement *e = cast<ExpressionStatement*>(ast->statement))
if (IdentifierExpression *i = cast<IdentifierExpression*>(e->expression))
if (i->name)
addId(i->name->asString(), ast);
return false;
}
SymbolFromFile *IdCollector::switchSymbol(QmlJS::AST::UiObjectMember *node)
{
SymbolFromFile *newSymbol = 0;
if (_currentSymbol == 0) {
newSymbol = _doc->findSymbol(node);
} else {
newSymbol = _currentSymbol->findMember(node);
}
SymbolFromFile *oldSymbol = _currentSymbol;
if (newSymbol) {
_currentSymbol = newSymbol;
} else {
QString filename = _doc->fileName();
qWarning() << "Scope without symbol @"<<filename<<":"<<node->firstSourceLocation().startLine<<":"<<node->firstSourceLocation().startColumn;
}
return oldSymbol;
}
void IdCollector::addId(const QString &id, QmlJS::AST::UiScriptBinding *ast)
{
if (!_currentSymbol)
return;
if (_ids.contains(id)) {
_diagnosticMessages.append(DiagnosticMessage(DiagnosticMessage::Warning, ast->statement->firstSourceLocation(), "Duplicate ID"));
} else {
if (SymbolFromFile *symbol = _currentSymbol->findMember(ast))
if (IdSymbol *idSymbol = symbol->asIdSymbol())
_ids[id] = idSymbol;
}
}

View File

@@ -1,74 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef QMLIDCOLLECTOR_H
#define QMLIDCOLLECTOR_H
#include <qmljs/parser/qmljsastvisitor_p.h>
#include <qmljs/parser/qmljsengine_p.h>
#include <qmljs/qmljsdocument.h>
#include <qmljs/qmljssymbol.h>
#include <QMap>
#include <QPair>
#include <QStack>
#include <QString>
namespace QmlJS {
namespace Internal {
class QMLJS_EXPORT IdCollector: protected AST::Visitor
{
public:
QMap<QString, IdSymbol*> operator()(Document &doc);
QList<DiagnosticMessage> diagnosticMessages()
{ return _diagnosticMessages; }
protected:
virtual bool visit(AST::UiArrayBinding *ast);
virtual bool visit(AST::UiObjectBinding *ast);
virtual bool visit(AST::UiObjectDefinition *ast);
virtual bool visit(AST::UiScriptBinding *ast);
private:
SymbolFromFile *switchSymbol(AST::UiObjectMember *node);
void addId(const QString &id, AST::UiScriptBinding *ast);
private:
Document *_doc;
QMap<QString, IdSymbol*> _ids;
SymbolFromFile *_currentSymbol;
QList<DiagnosticMessage> _diagnosticMessages;
};
} // namespace Internal
} // namespace Qml
#endif // QMLIDCOLLECTOR_H

View File

@@ -1,43 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "qmljsmetatypebackend.h"
#include "qmljstypesystem.h"
using namespace QmlJS;
MetaTypeBackend::MetaTypeBackend(TypeSystem *typeSystem):
m_typeSystem(typeSystem)
{
Q_ASSERT(typeSystem);
}
MetaTypeBackend::~MetaTypeBackend()
{
}

View File

@@ -1,60 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef QMLMETATYPEBACKEND_H
#define QMLMETATYPEBACKEND_H
#include <qmljs/qmljs_global.h>
#include <qmljs/qmljspackageinfo.h>
#include <qmljs/qmljssymbol.h>
namespace QmlJS {
class TypeSystem;
class QMLJS_EXPORT MetaTypeBackend
{
public:
MetaTypeBackend(TypeSystem *typeSystem);
virtual ~MetaTypeBackend() = 0;
virtual QList<Symbol *> availableTypes(const QString &package, int majorVersion, int minorVersion) = 0;
virtual Symbol *resolve(const QString &typeName, const QList<PackageInfo> &packages) = 0;
protected:
TypeSystem *typeSystem() const
{ return m_typeSystem; }
private:
TypeSystem *m_typeSystem;
};
} // namespace Qml
#endif // QMLMETATYPEBACKEND_H

View File

@@ -1,39 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "qmljspackageinfo.h"
using namespace QmlJS;
PackageInfo::PackageInfo(const QString &name, int majorVersion, int minorVersion):
m_name(name),
m_majorVersion(majorVersion),
m_minorVersion(minorVersion)
{
}

View File

@@ -1,61 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef PACKAGEINFO_H
#define PACKAGEINFO_H
#include <qmljs/qmljs_global.h>
#include <QtCore/QString>
namespace QmlJS {
class QMLJS_EXPORT PackageInfo
{
public:
PackageInfo(const QString &name, int majorVersion, int minorVersion);
QString name() const
{ return m_name; }
int majorVersion() const
{ return m_majorVersion; }
int minorVersion() const
{ return m_minorVersion; }
private:
QString m_name;
int m_majorVersion;
int m_minorVersion;
};
} // namespace Qml
#endif // PACKAGEINFO_H

View File

@@ -1,234 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "qmljssymbol.h"
#include <qmljs/parser/qmljsast_p.h>
#include <qmljs/parser/qmljsengine_p.h>
using namespace QmlJS;
using namespace QmlJS;
using namespace QmlJS::AST;
Symbol::~Symbol()
{
}
bool Symbol::isBuildInSymbol()
{ return asPrimitiveSymbol() != 0; }
bool Symbol::isSymbolFromFile()
{ return asSymbolFromFile() != 0; }
bool Symbol::isIdSymbol()
{ return asIdSymbol() != 0; }
bool Symbol::isPropertyDefinitionSymbol()
{ return asPropertyDefinitionSymbol() != 0; }
PrimitiveSymbol *Symbol::asPrimitiveSymbol()
{ return 0; }
SymbolFromFile *Symbol::asSymbolFromFile()
{ return 0; }
IdSymbol *Symbol::asIdSymbol()
{ return 0; }
PropertyDefinitionSymbol *Symbol::asPropertyDefinitionSymbol()
{ return 0; }
PrimitiveSymbol::~PrimitiveSymbol()
{}
PrimitiveSymbol *PrimitiveSymbol::asPrimitiveSymbol()
{ return this; }
SymbolWithMembers::~SymbolWithMembers()
{ qDeleteAll(_members); }
const Symbol::List SymbolWithMembers::members()
{ return _members; }
SymbolFromFile::SymbolFromFile(const QString &fileName, QmlJS::AST::UiObjectMember *node):
_fileName(fileName),
_node(node)
{
if (UiObjectBinding *objectBinding = cast<UiObjectBinding*>(_node)) {
if (objectBinding->initializer)
for (UiObjectMemberList *iter = objectBinding->initializer->members; iter; iter = iter->next)
if (iter->member)
todo.append(iter->member);
} else if (UiObjectDefinition *objectDefinition = cast<UiObjectDefinition*>(_node)) {
if (objectDefinition->initializer)
for (UiObjectMemberList *iter = objectDefinition->initializer->members; iter; iter = iter->next)
if (iter->member)
todo.append(iter->member);
} else if (UiArrayBinding *arrayBinding = cast<UiArrayBinding*>(_node)) {
for (UiArrayMemberList *iter = arrayBinding->members; iter; iter = iter->next)
if (iter->member)
todo.append(iter->member);
}
}
SymbolFromFile::~SymbolFromFile()
{}
SymbolFromFile *SymbolFromFile::asSymbolFromFile()
{ return this; }
int SymbolFromFile::line() const
{ return _node->firstSourceLocation().startLine; }
int SymbolFromFile::column() const
{ return _node->firstSourceLocation().startColumn; }
static inline QString toString(UiQualifiedId *qId)
{
QString result;
for (UiQualifiedId *iter = qId; iter; iter = iter->next) {
if (!iter->name)
continue;
result += iter->name->asString();
if (iter->next)
result += '.';
}
return result;
}
const QString SymbolFromFile::name() const
{
if (UiObjectBinding *objectBinding = cast<UiObjectBinding*>(_node))
return toString(objectBinding->qualifiedId);
else if (UiScriptBinding *scriptBinding = cast<UiScriptBinding*>(_node))
return toString(scriptBinding->qualifiedId);
else if (UiArrayBinding *arrayBinding = cast<UiArrayBinding*>(_node))
return toString(arrayBinding->qualifiedId);
else if (UiObjectDefinition *objectDefinition = cast<UiObjectDefinition*>(_node))
return toString(objectDefinition->qualifiedTypeNameId);
else
return QString::null;
}
const Symbol::List SymbolFromFile::members()
{
if (!todo.isEmpty()) {
foreach (Node *todoNode, todo) {
if (UiObjectBinding *objectBinding = cast<UiObjectBinding*>(todoNode))
_members.append(new SymbolFromFile(fileName(), objectBinding));
else if (UiObjectDefinition *objectDefinition = cast<UiObjectDefinition*>(todoNode))
_members.append(new SymbolFromFile(fileName(), objectDefinition));
else if (UiArrayBinding *arrayBinding = cast<UiArrayBinding*>(todoNode))
_members.append(new SymbolFromFile(fileName(), arrayBinding));
else if (UiPublicMember *publicMember = cast<UiPublicMember*>(todoNode))
_members.append(new PropertyDefinitionSymbol(fileName(), publicMember));
else if (UiScriptBinding *scriptBinding = cast<UiScriptBinding*>(todoNode)) {
if (scriptBinding->qualifiedId && scriptBinding->qualifiedId->name && scriptBinding->qualifiedId->name->asString() == QLatin1String("id") && !scriptBinding->qualifiedId->next)
_members.append(new IdSymbol(fileName(), scriptBinding, this));
else
_members.append(new SymbolFromFile(fileName(), scriptBinding));
}
}
todo.clear();
}
return _members;
}
bool SymbolFromFile::isProperty() const
{ return cast<UiObjectDefinition*>(_node) == 0; }
SymbolFromFile *SymbolFromFile::findMember(QmlJS::AST::Node *memberNode)
{
List symbols = members();
foreach (Symbol *symbol, symbols)
if (symbol->isSymbolFromFile())
if (memberNode == symbol->asSymbolFromFile()->node())
return symbol->asSymbolFromFile();
return 0;
}
IdSymbol::IdSymbol(const QString &fileName, QmlJS::AST::UiScriptBinding *idNode, SymbolFromFile *parentNode):
SymbolFromFile(fileName, idNode),
_parentNode(parentNode)
{}
IdSymbol::~IdSymbol()
{}
IdSymbol *IdSymbol::asIdSymbol()
{ return this; }
int IdSymbol::line() const
{ return idNode()->statement->firstSourceLocation().startLine; }
int IdSymbol::column() const
{ return idNode()->statement->firstSourceLocation().startColumn; }
const QString IdSymbol::id() const
{
if (ExpressionStatement *e = cast<ExpressionStatement*>(idNode()->statement))
if (IdentifierExpression *i = cast<IdentifierExpression*>(e->expression))
if (i->name)
return i->name->asString();
return QString();
}
QmlJS::AST::UiScriptBinding *IdSymbol::idNode() const
{ return cast<UiScriptBinding*>(node()); }
PropertyDefinitionSymbol::PropertyDefinitionSymbol(const QString &fileName, QmlJS::AST::UiPublicMember *propertyNode):
SymbolFromFile(fileName, propertyNode)
{}
PropertyDefinitionSymbol::~PropertyDefinitionSymbol()
{}
PropertyDefinitionSymbol *PropertyDefinitionSymbol::asPropertyDefinitionSymbol()
{ return this; }
int PropertyDefinitionSymbol::line() const
{ return propertyNode()->identifierToken.startLine; }
int PropertyDefinitionSymbol::column() const
{ return propertyNode()->identifierToken.startColumn; }
QmlJS::AST::UiPublicMember *PropertyDefinitionSymbol::propertyNode() const
{ return cast<UiPublicMember*>(node()); }
const QString PropertyDefinitionSymbol::name() const
{ return propertyNode()->name->asString(); }

View File

@@ -1,163 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef QMLSYMBOL_H
#define QMLSYMBOL_H
#include <qmljs/parser/qmljsastfwd_p.h>
#include <qmljs/qmljs_global.h>
#include <QList>
#include <QString>
namespace QmlJS {
class QMLJS_EXPORT Symbol
{
public:
typedef QList<Symbol *> List;
public:
virtual ~Symbol() = 0;
virtual const QString name() const = 0;
virtual const List members() = 0;
virtual bool isProperty() const = 0;
bool isBuildInSymbol();
bool isSymbolFromFile();
bool isIdSymbol();
bool isPropertyDefinitionSymbol();
virtual class PrimitiveSymbol *asPrimitiveSymbol();
virtual class SymbolFromFile *asSymbolFromFile();
virtual class IdSymbol *asIdSymbol();
virtual class PropertyDefinitionSymbol *asPropertyDefinitionSymbol();
};
class QMLJS_EXPORT PrimitiveSymbol: public Symbol
{
public:
virtual ~PrimitiveSymbol() = 0;
virtual PrimitiveSymbol *asPrimitiveSymbol();
virtual PrimitiveSymbol *type() const = 0;
using Symbol::members;
virtual List members(bool includeBaseClassMembers) = 0;
};
class QMLJS_EXPORT SymbolWithMembers: public Symbol
{
public:
virtual ~SymbolWithMembers() = 0;
virtual const List members();
protected:
List _members;
};
class QMLJS_EXPORT SymbolFromFile: public SymbolWithMembers
{
public:
SymbolFromFile(const QString &fileName, QmlJS::AST::UiObjectMember *node);
virtual ~SymbolFromFile();
virtual SymbolFromFile *asSymbolFromFile();
QString fileName() const
{ return _fileName; }
virtual int line() const;
virtual int column() const;
QmlJS::AST::UiObjectMember *node() const
{ return _node; }
virtual const QString name() const;
virtual const List members();
virtual bool isProperty() const;
virtual SymbolFromFile *findMember(QmlJS::AST::Node *memberNode);
private:
void fillTodo(QmlJS::AST::UiObjectMemberList *members);
private:
QString _fileName;
QmlJS::AST::UiObjectMember *_node;
QList<QmlJS::AST::Node*> todo;
};
class QMLJS_EXPORT IdSymbol: public SymbolFromFile
{
public:
IdSymbol(const QString &fileName, QmlJS::AST::UiScriptBinding *idNode, SymbolFromFile *parentNode);
virtual ~IdSymbol();
IdSymbol *asIdSymbol();
virtual int line() const;
virtual int column() const;
SymbolFromFile *parentNode() const
{ return _parentNode; }
virtual const QString name() const
{ return "id"; }
virtual const QString id() const;
private:
QmlJS::AST::UiScriptBinding *idNode() const;
private:
SymbolFromFile *_parentNode;
};
class QMLJS_EXPORT PropertyDefinitionSymbol: public SymbolFromFile
{
public:
PropertyDefinitionSymbol(const QString &fileName, QmlJS::AST::UiPublicMember *propertyNode);
virtual ~PropertyDefinitionSymbol();
PropertyDefinitionSymbol *asPropertyDefinitionSymbol();
virtual int line() const;
virtual int column() const;
virtual const QString name() const;
private:
QmlJS::AST::UiPublicMember *propertyNode() const;
};
} // namespace Qml
#endif // QMLSYMBOL_H

View File

@@ -1,70 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "qmljsmetatypebackend.h"
#include "qmljstypesystem.h"
#ifndef NO_DECLARATIVE_BACKEND
# include "qtdeclarativemetatypebackend.h"
#endif // NO_DECLARATIVE_BACKEND
#include <QDebug>
using namespace QmlJS;
TypeSystem::TypeSystem()
{
#ifndef NO_DECLARATIVE_BACKEND
backends.append(new Internal::QtDeclarativeMetaTypeBackend(this));
#endif // NO_DECLARATIVE_BACKEND
}
TypeSystem::~TypeSystem()
{
qDeleteAll(backends);
}
QList<Symbol *> TypeSystem::availableTypes(const QString &package, int majorVersion, int minorVersion)
{
QList<Symbol *> results;
foreach (MetaTypeBackend *backend, backends)
results.append(backend->availableTypes(package, majorVersion, minorVersion));
return results;
}
Symbol *TypeSystem::resolve(const QString &typeName, const QList<PackageInfo> &packages)
{
foreach (MetaTypeBackend *backend, backends)
if (Symbol *symbol = backend->resolve(typeName, packages))
return symbol;
return 0;
}

View File

@@ -1,61 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef QMLTYPESYSTEM_H
#define QMLTYPESYSTEM_H
#include <qmljs/qmljs_global.h>
#include <qmljs/qmljspackageinfo.h>
#include <qmljs/qmljssymbol.h>
#include <QtCore/QList>
#include <QtCore/QObject>
namespace QmlJS {
class MetaTypeBackend;
class QMLJS_EXPORT TypeSystem: public QObject
{
Q_OBJECT
public:
TypeSystem();
virtual ~TypeSystem();
QList<Symbol *> availableTypes(const QString &package, int majorVersion, int minorVersion);
Symbol *resolve(const QString &typeName, const QList<PackageInfo> &packages);
private:
QList<MetaTypeBackend *> backends;
};
} // namespace Qml
#endif // QMLTYPESYSTEM_H

View File

@@ -1,181 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "qtdeclarativemetatypebackend.h"
#include <QDebug>
namespace QmlJS {
namespace Internal {
class DeclarativeSymbol: public PrimitiveSymbol
{
public:
virtual ~DeclarativeSymbol()
{}
protected:
DeclarativeSymbol(QtDeclarativeMetaTypeBackend* backend):
m_backend(backend)
{ Q_ASSERT(backend); }
QtDeclarativeMetaTypeBackend* backend() const
{ return m_backend; }
private:
QtDeclarativeMetaTypeBackend* m_backend;
};
class DeclarativeObjectSymbol: public DeclarativeSymbol
{
DeclarativeObjectSymbol(const DeclarativeObjectSymbol &);
DeclarativeObjectSymbol &operator=(const DeclarativeObjectSymbol &);
public:
DeclarativeObjectSymbol(QtDeclarativeMetaTypeBackend* backend):
DeclarativeSymbol(backend)
{
}
virtual ~DeclarativeObjectSymbol()
{ qDeleteAll(m_members); }
virtual const QString name() const
{ return m_name; }
virtual PrimitiveSymbol *type() const
{ return 0; }
virtual const List members()
{
return m_members;
}
virtual List members(bool includeBaseClassMembers)
{
List result = members();
return result;
}
virtual bool isProperty() const
{ return false; }
public:
static QString key(const QString &typeNameWithPackage, int majorVersion, int minorVersion)
{
return QString(typeNameWithPackage)
+ QLatin1Char('@')
+ QString::number(majorVersion)
+ QLatin1Char('.')
+ QString::number(minorVersion);
}
static QString key(const QString &packageName, const QString &typeName, int majorVersion, int minorVersion)
{
return packageName
+ QLatin1Char('/')
+ typeName
+ QLatin1Char('@')
+ QString::number(majorVersion)
+ QLatin1Char('.')
+ QString::number(minorVersion);
}
private:
QString m_name;
bool m_membersToBeDone;
List m_members;
};
class DeclarativePropertySymbol: public DeclarativeSymbol
{
DeclarativePropertySymbol(const DeclarativePropertySymbol &);
DeclarativePropertySymbol &operator=(const DeclarativePropertySymbol &);
public:
DeclarativePropertySymbol(QtDeclarativeMetaTypeBackend* backend):
DeclarativeSymbol(backend)
{
}
virtual ~DeclarativePropertySymbol()
{}
virtual const QString name() const
{ return QString(); }
virtual PrimitiveSymbol *type() const
{ return 0; }
virtual const List members()
{
return List();
}
virtual List members(bool /*includeBaseClassMembers*/)
{
return members();
}
virtual bool isProperty() const
{ return true; }
private:
};
} // namespace Internal
} // namespace Qml
using namespace QmlJS;
using namespace QmlJS::Internal;
QtDeclarativeMetaTypeBackend::QtDeclarativeMetaTypeBackend(TypeSystem *typeSystem):
MetaTypeBackend(typeSystem)
{
}
QtDeclarativeMetaTypeBackend::~QtDeclarativeMetaTypeBackend()
{
}
QList<Symbol *> QtDeclarativeMetaTypeBackend::availableTypes(const QString &package, int majorVersion, int minorVersion)
{
QList<Symbol *> result;
return result;
}
Symbol *QtDeclarativeMetaTypeBackend::resolve(const QString &typeName, const QList<PackageInfo> &packages)
{
QList<Symbol *> result;
return 0;
}

View File

@@ -1,72 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef QTDECLARATIVEMETATYPEBACKEND_H
#define QTDECLARATIVEMETATYPEBACKEND_H
#include <qmljs/qmljsmetatypebackend.h>
#include <QtCore/QList>
namespace QmlJS {
namespace Internal {
class DeclarativeSymbol;
class DeclarativeObjectSymbol;
class DeclarativePropertySymbol;
class QtDeclarativeMetaTypeBackend: public MetaTypeBackend
{
friend class DeclarativeSymbol;
friend class DeclarativeObjectSymbol;
friend class DeclarativePropertySymbol;
public:
QtDeclarativeMetaTypeBackend(TypeSystem *typeSystem);
~QtDeclarativeMetaTypeBackend();
virtual QList<Symbol *> availableTypes(const QString &package, int majorVersion, int minorVersion);
virtual Symbol *resolve(const QString &typeName, const QList<PackageInfo> &packages);
protected:
// QList<QmlSymbol *> members(const QmlJS::NodeMetaInfo &metaInfo);
// QList<QmlSymbol *> inheritedMembers(const QmlJS::NodeMetaInfo &metaInfo);
// QmlDeclarativeSymbol *typeOf(const QmlJS::PropertyMetaInfo &metaInfo);
private:
// QmlDeclarativeSymbol *getSymbol(const QmlJS::NodeMetaInfo &metaInfo);
private:
// QMap<QString, QmlDeclarativeSymbol*> m_symbols;
};
} // namespace Internal
} // namespace Qml
#endif // QTDECLARATIVEMETATYPEBACKEND_H

View File

@@ -31,12 +31,10 @@
#include "qmlexpressionundercursor.h" #include "qmlexpressionundercursor.h"
#include "qmljseditor.h" #include "qmljseditor.h"
#include "qmlmodelmanagerinterface.h" #include "qmlmodelmanagerinterface.h"
#include "qmllookupcontext.h"
#include <qmljs/parser/qmljsast_p.h> #include <qmljs/parser/qmljsast_p.h>
#include <qmljs/qmljsbind.h> #include <qmljs/qmljsbind.h>
#include <qmljs/qmljsinterpreter.h> #include <qmljs/qmljsinterpreter.h>
#include <qmljs/qmljssymbol.h>
#include <qmljs/qmljsscanner.h> #include <qmljs/qmljsscanner.h>
#include <qmljs/qmljscheck.h> #include <qmljs/qmljscheck.h>
@@ -448,16 +446,14 @@ void FunctionArgumentWidget::updateHintText()
} } // end of namespace QmlJSEditor::Internal } } // end of namespace QmlJSEditor::Internal
QmlCodeCompletion::QmlCodeCompletion(QmlModelManagerInterface *modelManager, QmlJS::TypeSystem *typeSystem, QObject *parent) QmlCodeCompletion::QmlCodeCompletion(QmlModelManagerInterface *modelManager, QObject *parent)
: TextEditor::ICompletionCollector(parent), : TextEditor::ICompletionCollector(parent),
m_modelManager(modelManager), m_modelManager(modelManager),
m_editor(0), m_editor(0),
m_startPosition(0), m_startPosition(0),
m_caseSensitivity(Qt::CaseSensitive), m_caseSensitivity(Qt::CaseSensitive)
m_typeSystem(typeSystem)
{ {
Q_ASSERT(modelManager); Q_ASSERT(modelManager);
Q_ASSERT(typeSystem);
} }
QmlCodeCompletion::~QmlCodeCompletion() QmlCodeCompletion::~QmlCodeCompletion()

View File

@@ -30,7 +30,6 @@
#ifndef QMLCODECOMPLETION_H #ifndef QMLCODECOMPLETION_H
#define QMLCODECOMPLETION_H #define QMLCODECOMPLETION_H
#include <qmljs/qmljstypesystem.h>
#include <qmljs/qmljsdocument.h> #include <qmljs/qmljsdocument.h>
#include <texteditor/icompletioncollector.h> #include <texteditor/icompletioncollector.h>
#include <QtCore/QDateTime> #include <QtCore/QDateTime>
@@ -53,7 +52,7 @@ class QmlCodeCompletion: public TextEditor::ICompletionCollector
Q_OBJECT Q_OBJECT
public: public:
QmlCodeCompletion(QmlModelManagerInterface *modelManager, QmlJS::TypeSystem *typeSystem, QObject *parent = 0); QmlCodeCompletion(QmlModelManagerInterface *modelManager, QObject *parent = 0);
virtual ~QmlCodeCompletion(); virtual ~QmlCodeCompletion();
Qt::CaseSensitivity caseSensitivity() const; Qt::CaseSensitivity caseSensitivity() const;
@@ -82,7 +81,6 @@ private:
int m_startPosition; int m_startPosition;
QList<TextEditor::CompletionItem> m_completions; QList<TextEditor::CompletionItem> m_completions;
Qt::CaseSensitivity m_caseSensitivity; Qt::CaseSensitivity m_caseSensitivity;
QmlJS::TypeSystem *m_typeSystem;
QList<TextEditor::CompletionItem> m_snippets; QList<TextEditor::CompletionItem> m_snippets;
QDateTime m_snippetFileLastModified; QDateTime m_snippetFileLastModified;

View File

@@ -30,15 +30,12 @@
#include "qmljseditor.h" #include "qmljseditor.h"
#include "qmlexpressionundercursor.h" #include "qmlexpressionundercursor.h"
#include "qmlhoverhandler.h" #include "qmlhoverhandler.h"
#include "qmllookupcontext.h"
#include "qmlresolveexpression.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/uniqueidmanager.h> #include <coreplugin/uniqueidmanager.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <debugger/debuggerconstants.h> #include <debugger/debuggerconstants.h>
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <qmljs/qmljssymbol.h>
#include <qmljs/qmljsbind.h> #include <qmljs/qmljsbind.h>
#include <qmljs/qmljscheck.h> #include <qmljs/qmljscheck.h>
#include <qmljs/qmljsinterpreter.h> #include <qmljs/qmljsinterpreter.h>
@@ -131,16 +128,6 @@ void QmlHoverHandler::updateContextHelpId(TextEditor::ITextEditor *editor, int p
updateHelpIdAndTooltip(editor, pos); updateHelpIdAndTooltip(editor, pos);
} }
static QString buildHelpId(Symbol *symbol)
{
if (!symbol)
return QString();
const QString idTemplate(QLatin1String("QML.%1"));
return idTemplate.arg(symbol->name());
}
void QmlHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, int pos) void QmlHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, int pos)
{ {
m_helpId.clear(); m_helpId.clear();

View File

@@ -34,17 +34,13 @@
#include "qmlmodelmanager.h" #include "qmlmodelmanager.h"
#include "qmlexpressionundercursor.h" #include "qmlexpressionundercursor.h"
#include "qmllookupcontext.h"
#include "qmlresolveexpression.h"
#include <qmljs/qmljsindenter.h> #include <qmljs/qmljsindenter.h>
#include <qmljs/qmljstypesystem.h>
#include <qmljs/parser/qmljsastvisitor_p.h> #include <qmljs/parser/qmljsastvisitor_p.h>
#include <qmljs/parser/qmljsast_p.h> #include <qmljs/parser/qmljsast_p.h>
#include <qmljs/parser/qmljsengine_p.h> #include <qmljs/parser/qmljsengine_p.h>
#include <qmljs/qmljsdocument.h> #include <qmljs/qmljsdocument.h>
#include <qmljs/qmljsidcollector.h>
#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
@@ -449,8 +445,7 @@ QmlJSEditorEditable::QmlJSEditorEditable(QmlJSTextEditor *editor)
QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) : QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) :
TextEditor::BaseTextEditor(parent), TextEditor::BaseTextEditor(parent),
m_methodCombo(0), m_methodCombo(0),
m_modelManager(0), m_modelManager(0)
m_typeSystem(0)
{ {
setParenthesesMatchingEnabled(true); setParenthesesMatchingEnabled(true);
setMarksVisible(true); setMarksVisible(true);
@@ -473,7 +468,6 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) :
baseTextDocument()->setSyntaxHighlighter(new QmlHighlighter); baseTextDocument()->setSyntaxHighlighter(new QmlHighlighter);
m_modelManager = ExtensionSystem::PluginManager::instance()->getObject<QmlModelManagerInterface>(); m_modelManager = ExtensionSystem::PluginManager::instance()->getObject<QmlModelManagerInterface>();
m_typeSystem = ExtensionSystem::PluginManager::instance()->getObject<QmlJS::TypeSystem>();
if (m_modelManager) { if (m_modelManager) {
connect(m_modelManager, SIGNAL(documentUpdated(QmlJS::Document::Ptr)), connect(m_modelManager, SIGNAL(documentUpdated(QmlJS::Document::Ptr)),

View File

@@ -43,10 +43,6 @@ namespace Core {
class ICore; class ICore;
} }
namespace QmlJS {
class TypeSystem;
}
namespace QmlJSEditor { namespace QmlJSEditor {
class QmlModelManagerInterface; class QmlModelManagerInterface;
@@ -174,7 +170,6 @@ private:
QTimer *m_updateUsesTimer; QTimer *m_updateUsesTimer;
QComboBox *m_methodCombo; QComboBox *m_methodCombo;
QmlModelManagerInterface *m_modelManager; QmlModelManagerInterface *m_modelManager;
QmlJS::TypeSystem *m_typeSystem;
QTextCharFormat m_occurrencesFormat; QTextCharFormat m_occurrencesFormat;
SemanticInfo m_semanticInfo; SemanticInfo m_semanticInfo;

View File

@@ -20,10 +20,8 @@ HEADERS += \
qmlfilewizard.h \ qmlfilewizard.h \
qmlhighlighter.h \ qmlhighlighter.h \
qmlhoverhandler.h \ qmlhoverhandler.h \
qmllookupcontext.h \
qmlmodelmanager.h \ qmlmodelmanager.h \
qmlmodelmanagerinterface.h \ qmlmodelmanagerinterface.h
qmlresolveexpression.h
SOURCES += \ SOURCES += \
qmlcodecompletion.cpp \ qmlcodecompletion.cpp \
@@ -35,10 +33,8 @@ SOURCES += \
qmlfilewizard.cpp \ qmlfilewizard.cpp \
qmlhighlighter.cpp \ qmlhighlighter.cpp \
qmlhoverhandler.cpp \ qmlhoverhandler.cpp \
qmllookupcontext.cpp \
qmlmodelmanager.cpp \ qmlmodelmanager.cpp \
qmlmodelmanagerinterface.cpp \ qmlmodelmanagerinterface.cpp
qmlresolveexpression.cpp
RESOURCES += qmljseditor.qrc RESOURCES += qmljseditor.qrc
OTHER_FILES += QmlJSEditor.pluginspec QmlJSEditor.mimetypes.xml OTHER_FILES += QmlJSEditor.pluginspec QmlJSEditor.mimetypes.xml

View File

@@ -92,8 +92,6 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
m_modelManager = new QmlModelManager(this); m_modelManager = new QmlModelManager(this);
addAutoReleasedObject(m_modelManager); addAutoReleasedObject(m_modelManager);
QmlJS::TypeSystem *typeSystem = new QmlJS::TypeSystem;
addAutoReleasedObject(typeSystem);
QList<int> context; QList<int> context;
context<< core->uniqueIDManager()->uniqueIdentifier(QmlJSEditor::Constants::C_QMLJSEDITOR_ID); context<< core->uniqueIDManager()->uniqueIdentifier(QmlJSEditor::Constants::C_QMLJSEDITOR_ID);
@@ -122,7 +120,7 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
cmd = am->command(TextEditor::Constants::UN_COMMENT_SELECTION); cmd = am->command(TextEditor::Constants::UN_COMMENT_SELECTION);
contextMenu->addAction(cmd); contextMenu->addAction(cmd);
m_completion = new QmlCodeCompletion(m_modelManager, typeSystem); m_completion = new QmlCodeCompletion(m_modelManager);
addAutoReleasedObject(m_completion); addAutoReleasedObject(m_completion);
addAutoReleasedObject(new QmlHoverHandler()); addAutoReleasedObject(new QmlHoverHandler());

View File

@@ -1,298 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "qmlexpressionundercursor.h"
#include "qmllookupcontext.h"
#include "qmlresolveexpression.h"
#include <qmljs/parser/qmljsast_p.h>
#include <qmljs/parser/qmljsengine_p.h>
#include <qmljs/qmljstypesystem.h>
#include <QDebug>
using namespace QmlJS;
using namespace QmlJSEditor;
using namespace QmlJSEditor::Internal;
using namespace QmlJS::AST;
QmlLookupContext::QmlLookupContext(const QStack<Symbol *> &scopes,
const Document::Ptr &doc,
const Snapshot &snapshot,
TypeSystem *typeSystem):
_scopes(scopes),
_doc(doc),
_snapshot(snapshot),
m_typeSystem(typeSystem)
{
Q_ASSERT(typeSystem != 0);
}
static inline int findFirstQmlObjectScope(const QStack<Symbol*> &scopes, int startIdx)
{
if (startIdx < 0 || startIdx >= scopes.size())
return -1;
for (int i = startIdx; i >= 0; --i) {
Symbol *current = scopes.at(i);
if (current->isSymbolFromFile()) {
Node *node = current->asSymbolFromFile()->node();
if (cast<UiObjectBinding*>(node) || cast<UiObjectDefinition*>(node)) {
return i;
}
}
}
return -1;
}
static inline Symbol *resolveParent(const QStack<Symbol*> &scopes)
{
int idx = findFirstQmlObjectScope(scopes, scopes.size() - 1);
if (idx < 1)
return 0;
idx = findFirstQmlObjectScope(scopes, idx - 1);
if (idx < 0)
return 0;
else
return scopes.at(idx);
}
Symbol *QmlLookupContext::resolve(const QString &name)
{
// find element type names
if (Symbol *type = resolveType(name))
return type;
// find ids
const Document::IdTable ids = _doc->ids();
if (ids.contains(name))
return ids[name];
if (name == "parent") {
return resolveParent(_scopes);
}
// find script methods
// ### TODO
// find properties of the scope object
int scopeObjectIndex = findFirstQmlObjectScope(_scopes, _scopes.size() - 1);
if (scopeObjectIndex != -1)
if (Symbol *propertySymbol = resolveProperty(name, _scopes.at(scopeObjectIndex), _doc->fileName()))
return propertySymbol;
// find properties of the component's root object
if (!_doc->symbols().isEmpty())
if (Symbol *propertySymbol = resolveProperty(name, _doc->symbols()[0], _doc->fileName()))
return propertySymbol;
// component chain
// ### TODO: Might lead to ambiguity.
// context chain
// ### TODO: ?
// global object
// ### TODO
return 0;
}
Symbol *QmlLookupContext::resolveType(const QString &name, const QString &fileName)
{
// TODO: handle import-as.
Document::Ptr document = _snapshot.document(fileName);
if (document.isNull())
return 0;
UiProgram *prog = document->qmlProgram();
if (!prog)
return 0;
UiImportList *imports = prog->imports;
if (!imports)
return 0;
for (UiImportList *iter = imports; iter; iter = iter->next) {
UiImport *import = iter->import;
if (!import)
continue;
// TODO: handle Qt imports
if (!(import->fileName))
continue;
const QString path = import->fileName->asString();
const QMap<QString, Document::Ptr> importedTypes = _snapshot.componentsDefinedByImportedDocuments(document, path);
if (importedTypes.contains(name)) {
Document::Ptr importedDoc = importedTypes.value(name);
return importedDoc->symbols().at(0);
}
}
// TODO: handle Qt imports, hack for now:
return resolveBuildinType(name);
}
Symbol *QmlLookupContext::resolveBuildinType(const QString &name)
{
QList<QmlJS::PackageInfo> packages;
// FIXME:
packages.append(PackageInfo("Qt", 4, 6));
return m_typeSystem->resolve(name, packages);
}
Symbol *QmlLookupContext::resolveProperty(const QString &name, Symbol *scope, const QString &fileName)
{
foreach (Symbol *symbol, scope->members())
if (symbol->isProperty() && symbol->name() == name)
return symbol;
UiQualifiedId *typeName = 0;
if (scope->isSymbolFromFile()) {
Node *ast = scope->asSymbolFromFile()->node();
if (UiObjectBinding *binding = cast<UiObjectBinding*>(ast)) {
typeName = binding->qualifiedTypeNameId;
} else if (UiObjectDefinition *definition = cast<UiObjectDefinition*>(ast)) {
typeName = definition->qualifiedTypeNameId;
} // TODO: extend this to handle (JavaScript) block scopes.
}
if (typeName == 0)
return 0;
Symbol *typeSymbol = resolveType(toString(typeName), fileName);
if (!typeSymbol)
return 0;
if (typeSymbol->isSymbolFromFile()) {
return resolveProperty(name, typeSymbol->asSymbolFromFile(), typeSymbol->asSymbolFromFile()->fileName());
} else if (PrimitiveSymbol *builtinSymbol = typeSymbol->asPrimitiveSymbol()) {
foreach (Symbol *member, builtinSymbol->members(true)) {
if (member->isProperty() && member->name() == name)
return member;
}
}
return 0;
}
QString QmlLookupContext::toString(UiQualifiedId *id)
{
QString str;
for (UiQualifiedId *iter = id; iter; iter = iter->next) {
if (!(iter->name))
continue;
str.append(iter->name->asString());
if (iter->next)
str.append('.');
}
return str;
}
QList<Symbol*> QmlLookupContext::visibleSymbolsInScope()
{
QList<Symbol*> result;
if (!_scopes.isEmpty()) {
Symbol *scope = _scopes.top();
// add members defined in this symbol:
result.append(scope->members());
// add the members of the type of this scope (= object):
result.append(expandType(scope));
}
return result;
}
QList<Symbol*> QmlLookupContext::visibleTypes()
{
QList<Symbol*> result;
UiProgram *program = _doc->qmlProgram();
if (!program)
return result;
for (UiImportList *iter = program->imports; iter; iter = iter->next) {
UiImport *import = iter->import;
if (!import)
continue;
if (!(import->fileName))
continue;
const QString path = import->fileName->asString();
// TODO: handle "import as".
const QMap<QString, Document::Ptr> types = _snapshot.componentsDefinedByImportedDocuments(_doc, path);
foreach (const Document::Ptr typeDoc, types) {
result.append(typeDoc->symbols().at(0));
}
}
result.append(m_typeSystem->availableTypes("Qt", 4, 6));
return result;
}
QList<Symbol*> QmlLookupContext::expandType(QmlJS::Symbol *symbol)
{
if (symbol == 0) {
return QList<Symbol*>();
} else if (PrimitiveSymbol *buildInSymbol = symbol->asPrimitiveSymbol()) {
return buildInSymbol->members(true);
} else if (SymbolFromFile *symbolFromFile = symbol->asSymbolFromFile()){
QList<Symbol*> result;
if (Symbol *superTypeSymbol = resolveType(symbolFromFile->name(), symbolFromFile->fileName())) {
result.append(superTypeSymbol->members());
result.append(expandType(superTypeSymbol));
}
return result;
} else {
return QList<Symbol*>();
}
}

View File

@@ -1,82 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef QMLLOOKUPCONTEXT_H
#define QMLLOOKUPCONTEXT_H
#include <qmljs/qmljstypesystem.h>
#include <qmljs/parser/qmljsastvisitor_p.h>
#include <qmljs/qmljsdocument.h>
#include <qmljs/qmljssymbol.h>
#include <QStack>
namespace QmlJSEditor {
namespace Internal {
class QmlLookupContext
{
public:
QmlLookupContext(const QStack<QmlJS::Symbol *> &scopes,
const QmlJS::Document::Ptr &doc,
const QmlJS::Snapshot &snapshot,
QmlJS::TypeSystem *typeSystem);
QmlJS::Symbol *resolve(const QString &name);
QmlJS::Symbol *resolveType(const QString &name)
{ return resolveType(name, _doc->fileName()); }
QmlJS::Symbol *resolveType(QmlJS::AST::UiQualifiedId *name)
{ return resolveType(toString(name), _doc->fileName()); }
QmlJS::Document::Ptr document() const
{ return _doc; }
QList<QmlJS::Symbol*> visibleSymbolsInScope();
QList<QmlJS::Symbol*> visibleTypes();
QList<QmlJS::Symbol*> expandType(QmlJS::Symbol *symbol);
private:
QmlJS::Symbol *resolveType(const QString &name, const QString &fileName);
QmlJS::Symbol *resolveProperty(const QString &name, QmlJS::Symbol *scope, const QString &fileName);
QmlJS::Symbol *resolveBuildinType(const QString &name);
static QString toString(QmlJS::AST::UiQualifiedId *id);
private:
QStack<QmlJS::Symbol *> _scopes;
QmlJS::Document::Ptr _doc;
QmlJS::Snapshot _snapshot;
QmlJS::TypeSystem *m_typeSystem;
};
} // namespace Internal
} // namespace QmlJSEditor
#endif // QMLLOOKUPCONTEXT_H

View File

@@ -33,7 +33,6 @@
#include "qmljseditor_global.h" #include "qmljseditor_global.h"
#include <qmljs/qmljsdocument.h> #include <qmljs/qmljsdocument.h>
#include <qmljs/qmljstypesystem.h>
#include <QObject> #include <QObject>
#include <QStringList> #include <QStringList>

View File

@@ -1,131 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "qmlresolveexpression.h"
#include <qmljs/parser/qmljsast_p.h>
#include <qmljs/parser/qmljsengine_p.h>
using namespace QmlJSEditor;
using namespace QmlJSEditor::Internal;
using namespace QmlJS;
using namespace QmlJS::AST;
QmlResolveExpression::QmlResolveExpression(const QmlLookupContext &context)
: _context(context), _value(0)
{
}
Symbol *QmlResolveExpression::typeOf(Node *node)
{
Symbol *previousValue = switchValue(0);
Node::accept(node, this);
return switchValue(previousValue);
}
QList<Symbol*> QmlResolveExpression::visibleSymbols(Node *node)
{
QList<Symbol*> result;
Symbol *symbol = typeOf(node);
if (symbol) {
if (symbol->isIdSymbol())
symbol = symbol->asIdSymbol()->parentNode();
result.append(symbol->members());
// TODO: also add symbols from super-types
} else {
result.append(_context.visibleTypes());
}
if (node) {
foreach (IdSymbol *idSymbol, _context.document()->ids().values())
result.append(idSymbol);
}
result.append(_context.visibleSymbolsInScope());
return result;
}
Symbol *QmlResolveExpression::switchValue(Symbol *value)
{
Symbol *previousValue = _value;
_value = value;
return previousValue;
}
bool QmlResolveExpression::visit(IdentifierExpression *ast)
{
const QString name = ast->name->asString();
_value = _context.resolve(name);
return false;
}
static inline bool matches(UiQualifiedId *candidate, const QString &wanted)
{
if (!candidate)
return false;
if (!(candidate->name))
return false;
if (candidate->next)
return false; // TODO: verify this!
return wanted == candidate->name->asString();
}
bool QmlResolveExpression::visit(FieldMemberExpression *ast)
{
const QString memberName = ast->name->asString();
Symbol *base = typeOf(ast->base);
if (!base)
return false;
if (base->isIdSymbol())
base = base->asIdSymbol()->parentNode();
if (!base)
return false;
foreach (Symbol *memberSymbol, base->members())
if (memberSymbol->name() == memberName)
_value = memberSymbol;
return false;
}
bool QmlResolveExpression::visit(QmlJS::AST::UiQualifiedId *ast)
{
_value = _context.resolveType(ast);
return false;
}

View File

@@ -1,66 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef QMLRESOLVEEXPRESSION_H
#define QMLRESOLVEEXPRESSION_H
#include "qmllookupcontext.h"
#include <qmljs/parser/qmljsastvisitor_p.h>
#include <qmljs/qmljssymbol.h>
namespace QmlJSEditor {
namespace Internal {
class QmlResolveExpression: protected QmlJS::AST::Visitor
{
public:
QmlResolveExpression(const QmlLookupContext &context);
QmlJS::Symbol *typeOf(QmlJS::AST::Node *node);
QList<QmlJS::Symbol*> visibleSymbols(QmlJS::AST::Node *node);
protected:
using QmlJS::AST::Visitor::visit;
QmlJS::Symbol *switchValue(QmlJS::Symbol *symbol);
virtual bool visit(QmlJS::AST::FieldMemberExpression *ast);
virtual bool visit(QmlJS::AST::IdentifierExpression *ast);
virtual bool visit(QmlJS::AST::UiQualifiedId *ast);
private:
QmlLookupContext _context;
QmlJS::Symbol *_value;
};
} // namespace Internal
} // namespace QmlJSEditor
#endif // QMLRESOLVEEXPRESSION_H