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

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

View File

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

View File

@@ -30,15 +30,12 @@
#include "qmljseditor.h"
#include "qmlexpressionundercursor.h"
#include "qmlhoverhandler.h"
#include "qmllookupcontext.h"
#include "qmlresolveexpression.h"
#include <coreplugin/icore.h>
#include <coreplugin/uniqueidmanager.h>
#include <coreplugin/editormanager/editormanager.h>
#include <debugger/debuggerconstants.h>
#include <extensionsystem/pluginmanager.h>
#include <qmljs/qmljssymbol.h>
#include <qmljs/qmljsbind.h>
#include <qmljs/qmljscheck.h>
#include <qmljs/qmljsinterpreter.h>
@@ -131,16 +128,6 @@ void QmlHoverHandler::updateContextHelpId(TextEditor::ITextEditor *editor, int p
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)
{
m_helpId.clear();

View File

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

View File

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

View File

@@ -20,10 +20,8 @@ HEADERS += \
qmlfilewizard.h \
qmlhighlighter.h \
qmlhoverhandler.h \
qmllookupcontext.h \
qmlmodelmanager.h \
qmlmodelmanagerinterface.h \
qmlresolveexpression.h
qmlmodelmanagerinterface.h
SOURCES += \
qmlcodecompletion.cpp \
@@ -35,10 +33,8 @@ SOURCES += \
qmlfilewizard.cpp \
qmlhighlighter.cpp \
qmlhoverhandler.cpp \
qmllookupcontext.cpp \
qmlmodelmanager.cpp \
qmlmodelmanagerinterface.cpp \
qmlresolveexpression.cpp
qmlmodelmanagerinterface.cpp
RESOURCES += qmljseditor.qrc
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);
addAutoReleasedObject(m_modelManager);
QmlJS::TypeSystem *typeSystem = new QmlJS::TypeSystem;
addAutoReleasedObject(typeSystem);
QList<int> context;
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);
contextMenu->addAction(cmd);
m_completion = new QmlCodeCompletion(m_modelManager, typeSystem);
m_completion = new QmlCodeCompletion(m_modelManager);
addAutoReleasedObject(m_completion);
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 <qmljs/qmljsdocument.h>
#include <qmljs/qmljstypesystem.h>
#include <QObject>
#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