forked from qt-creator/qt-creator
QmlJS: Move commonly used functions to qmlutils.h.
Change-Id: I22376d96fe575bc00a55094c06af80e32a5587e6 Reviewed-on: http://codereview.qt-project.org/6238 Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/qmljsdocument.h>
|
||||
#include <qmljs/qmljsutils.h>
|
||||
#include <qmljstools/qmljsrefactoringchanges.h>
|
||||
|
||||
#include <QtCore/QCoreApplication>
|
||||
@@ -51,43 +52,6 @@ using namespace QmlJSTools;
|
||||
|
||||
namespace {
|
||||
|
||||
static QString toString(Statement *statement)
|
||||
{
|
||||
ExpressionStatement *expStmt = cast<ExpressionStatement *>(statement);
|
||||
if (!expStmt)
|
||||
return QString();
|
||||
if (IdentifierExpression *idExp = cast<IdentifierExpression *>(expStmt->expression)) {
|
||||
return idExp->name.toString();
|
||||
} else if (StringLiteral *strExp = cast<StringLiteral *>(expStmt->expression)) {
|
||||
return strExp->value.toString();
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
static QString getIdProperty(UiObjectDefinition *def)
|
||||
{
|
||||
QString objectName;
|
||||
|
||||
if (def && def->initializer) {
|
||||
for (UiObjectMemberList *iter = def->initializer->members; iter; iter = iter->next) {
|
||||
if (UiScriptBinding *script = cast<UiScriptBinding*>(iter->member)) {
|
||||
if (!script->qualifiedId)
|
||||
continue;
|
||||
if (script->qualifiedId->next)
|
||||
continue;
|
||||
if (!script->qualifiedId->name.isEmpty()) {
|
||||
if (script->qualifiedId->name == QLatin1String("id"))
|
||||
return toString(script->statement);
|
||||
if (script->qualifiedId->name == QLatin1String("objectName"))
|
||||
objectName = toString(script->statement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return objectName;
|
||||
}
|
||||
|
||||
class Operation: public QmlJSQuickFixOperation
|
||||
{
|
||||
UiObjectDefinition *m_objDef;
|
||||
@@ -101,7 +65,7 @@ public:
|
||||
{
|
||||
Q_ASSERT(m_objDef != 0);
|
||||
|
||||
m_idName = getIdProperty(m_objDef);
|
||||
m_idName = idOfObject(m_objDef);
|
||||
|
||||
if (m_idName.isEmpty()) {
|
||||
setDescription(QCoreApplication::translate("QmlJSEditor::ComponentFromObjectDef",
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
#include <qmljs/qmljsicontextpane.h>
|
||||
#include <qmljs/qmljsmodelmanagerinterface.h>
|
||||
#include <qmljs/qmljsscopebuilder.h>
|
||||
#include <qmljs/qmljsutils.h>
|
||||
#include <qmljs/parser/qmljsastvisitor_p.h>
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsengine_p.h>
|
||||
@@ -944,15 +945,6 @@ void QmlJSTextEditorWidget::updateOutlineIndexNow()
|
||||
}
|
||||
}
|
||||
|
||||
static UiQualifiedId *qualifiedTypeNameId(Node *m)
|
||||
{
|
||||
if (UiObjectDefinition *def = cast<UiObjectDefinition *>(m))
|
||||
return def->qualifiedTypeNameId;
|
||||
else if (UiObjectBinding *binding = cast<UiObjectBinding *>(m))
|
||||
return binding->qualifiedTypeNameId;
|
||||
return 0;
|
||||
}
|
||||
|
||||
class QtQuickToolbarMarker {};
|
||||
Q_DECLARE_METATYPE(QtQuickToolbarMarker)
|
||||
|
||||
@@ -1078,12 +1070,7 @@ protected:
|
||||
|
||||
bool isSelectable(UiObjectMember *member) const
|
||||
{
|
||||
UiQualifiedId *id = 0;
|
||||
if (UiObjectDefinition *def = cast<UiObjectDefinition *>(member))
|
||||
id = def->qualifiedTypeNameId;
|
||||
else if (UiObjectBinding *binding = cast<UiObjectBinding *>(member))
|
||||
id = binding->qualifiedTypeNameId;
|
||||
|
||||
UiQualifiedId *id = qualifiedTypeNameId(member);
|
||||
if (id) {
|
||||
const QStringRef &name = id->name;
|
||||
if (!name.isEmpty() && name.at(0).isUpper()) {
|
||||
@@ -1094,15 +1081,6 @@ protected:
|
||||
return false;
|
||||
}
|
||||
|
||||
inline UiObjectInitializer *initializer(UiObjectMember *member) const
|
||||
{
|
||||
if (UiObjectDefinition *def = cast<UiObjectDefinition *>(member))
|
||||
return def->initializer;
|
||||
else if (UiObjectBinding *binding = cast<UiObjectBinding *>(member))
|
||||
return binding->initializer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline bool isIdBinding(UiObjectMember *member) const
|
||||
{
|
||||
if (UiScriptBinding *script = cast<UiScriptBinding *>(member)) {
|
||||
@@ -1149,7 +1127,7 @@ protected:
|
||||
if ((isRangeSelected() && intersectsCursor(begin, end))
|
||||
|| (!isRangeSelected() && containsCursor(begin, end)))
|
||||
{
|
||||
if (initializer(member) && isSelectable(member)) {
|
||||
if (initializerOfObject(member) && isSelectable(member)) {
|
||||
m_selectedMembers << member;
|
||||
// move start towards end; this facilitates multiselection so that root is usually ignored.
|
||||
m_cursorPositionStart = qMin(end, m_cursorPositionEnd);
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
#include <qmljs/qmljsinterpreter.h>
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsastfwd_p.h>
|
||||
#include <qmljs/qmljscheck.h>
|
||||
#include <qmljs/qmljsutils.h>
|
||||
#include <texteditor/itexteditor.h>
|
||||
#include <texteditor/basetexteditor.h>
|
||||
#include <texteditor/helpitem.h>
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
#include <qmljs/qmljsevaluate.h>
|
||||
#include <qmljs/qmljscontext.h>
|
||||
#include <qmljs/qmljsbind.h>
|
||||
#include <qmljs/qmljscheck.h>
|
||||
#include <qmljs/qmljsutils.h>
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsastvisitor_p.h>
|
||||
#include <texteditor/syntaxhighlighter.h>
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include <qmljs/qmljsbind.h>
|
||||
#include <qmljs/qmljsscopebuilder.h>
|
||||
#include <qmljs/qmljsevaluate.h>
|
||||
#include <qmljs/qmljsutils.h>
|
||||
#include <texteditor/basetexteditor.h>
|
||||
#include <texteditor/tabsettings.h>
|
||||
#include <coreplugin/icore.h>
|
||||
@@ -66,11 +67,7 @@ static inline QString textAt(const Document* doc,
|
||||
|
||||
static inline const ObjectValue * getPropertyChangesTarget(Node *node, const ScopeChain &scopeChain)
|
||||
{
|
||||
UiObjectInitializer *initializer = 0;
|
||||
if (UiObjectDefinition *definition = cast<UiObjectDefinition *>(node))
|
||||
initializer = definition->initializer;
|
||||
if (UiObjectBinding *binding = cast<UiObjectBinding *>(node))
|
||||
initializer = binding->initializer;
|
||||
UiObjectInitializer *initializer = initializerOfObject(node);
|
||||
if (initializer) {
|
||||
for (UiObjectMemberList *members = initializer->members; members; members = members->next) {
|
||||
if (UiScriptBinding *scriptBinding = cast<UiScriptBinding *>(members->member)) {
|
||||
|
||||
Reference in New Issue
Block a user