Commit f9a0f9ab authored by Thomas Hartmann's avatar Thomas Hartmann Committed by Thomas Hartmann

QmlDesigner: Remove using namespace QmlJS::AST from QMLRewriter

Change-Id: Ife1552a666bbd1b333ce1fa46854d95de252f2a8
Reviewed-by: default avatarTim Jenssen <tim.jenssen@theqtcompany.com>
parent 059c2aaf
......@@ -37,8 +37,6 @@
#include <typeinfo>
using namespace QmlJS;
using namespace QmlJS::AST;
using namespace QmlDesigner::Internal;
QMLRewriter::QMLRewriter(QmlDesigner::TextModifier &textModifier):
......@@ -47,11 +45,11 @@ QMLRewriter::QMLRewriter(QmlDesigner::TextModifier &textModifier):
{
}
bool QMLRewriter::operator()(UiProgram *ast)
bool QMLRewriter::operator()(QmlJS::AST::UiProgram *ast)
{
setDidRewriting(false);
Node::accept(ast, this);
QmlJS::AST::Node::accept(ast, this);
return didRewriting();
}
......@@ -71,12 +69,12 @@ QString QMLRewriter::textBetween(int startPosition, int endPosition) const
return m_textModifier->text().mid(startPosition, endPosition - startPosition);
}
QString QMLRewriter::textAt(const SourceLocation &location) const
QString QMLRewriter::textAt(const QmlJS::AST::SourceLocation &location) const
{
return m_textModifier->text().mid(location.offset, location.length);
}
unsigned QMLRewriter::calculateIndentDepth(const SourceLocation &position) const
unsigned QMLRewriter::calculateIndentDepth(const QmlJS::AST::SourceLocation &position) const
{
QTextDocument *doc = m_textModifier->textDocument();
QTextCursor tc(doc);
......@@ -154,41 +152,41 @@ QString QMLRewriter::removeIndentation(const QString &text, unsigned depth)
return result;
}
SourceLocation QMLRewriter::calculateLocation(UiQualifiedId *id)
QmlJS::AST::SourceLocation QMLRewriter::calculateLocation(QmlJS::AST::UiQualifiedId *id)
{
Q_ASSERT(id != 0);
const SourceLocation startLocation = id->identifierToken;
const QmlJS::AST::SourceLocation startLocation = id->identifierToken;
UiQualifiedId *nextId = id;
QmlJS::AST::UiQualifiedId *nextId = id;
while (nextId->next) {
nextId = nextId->next;
}
const SourceLocation endLocation = nextId->identifierToken;
const QmlJS::AST::SourceLocation endLocation = nextId->identifierToken;
return SourceLocation(startLocation.offset, endLocation.end() - startLocation.offset);
return QmlJS::AST::SourceLocation(startLocation.offset, endLocation.end() - startLocation.offset);
}
bool QMLRewriter::isMissingSemicolon(UiObjectMember *member)
bool QMLRewriter::isMissingSemicolon(QmlJS::AST::UiObjectMember *member)
{
UiScriptBinding *binding = AST::cast<UiScriptBinding *>(member);
QmlJS::AST::UiScriptBinding *binding = QmlJS::AST::cast<QmlJS::AST::UiScriptBinding *>(member);
if (binding)
return isMissingSemicolon(binding->statement);
else
return false;
}
bool QMLRewriter::isMissingSemicolon(Statement *stmt)
bool QMLRewriter::isMissingSemicolon(QmlJS::AST::Statement *stmt)
{
if (ExpressionStatement *eStmt = AST::cast<ExpressionStatement *>(stmt)) {
if (QmlJS::AST::ExpressionStatement *eStmt = QmlJS::AST::cast<QmlJS::AST::ExpressionStatement *>(stmt)) {
return !eStmt->semicolonToken.isValid();
} else if (IfStatement *iStmt = AST::cast<IfStatement *>(stmt)) {
} else if (QmlJS::AST::IfStatement *iStmt = QmlJS::AST::cast<QmlJS::AST::IfStatement *>(stmt)) {
if (iStmt->elseToken.isValid())
return isMissingSemicolon(iStmt->ko);
else
return isMissingSemicolon(iStmt->ok);
} else if (DebuggerStatement *dStmt = AST::cast<DebuggerStatement *>(stmt)) {
} else if (QmlJS::AST::DebuggerStatement *dStmt = QmlJS::AST::cast<QmlJS::AST::DebuggerStatement *>(stmt)) {
return !dStmt->semicolonToken.isValid();
} else {
return false;
......@@ -262,26 +260,26 @@ void QMLRewriter::includeLeadingEmptyLine(int &start) const
}
// FIXME: duplicate code in the QmlJS::Rewriter class, remove this
UiObjectMemberList *QMLRewriter::searchMemberToInsertAfter(UiObjectMemberList *members, const QmlDesigner::PropertyNameList &propertyOrder)
QmlJS::AST::UiObjectMemberList *QMLRewriter::searchMemberToInsertAfter(QmlJS::AST::UiObjectMemberList *members, const QmlDesigner::PropertyNameList &propertyOrder)
{
const int objectDefinitionInsertionPoint = propertyOrder.indexOf(PropertyName()); // XXX ????
UiObjectMemberList *lastObjectDef = 0;
UiObjectMemberList *lastNonObjectDef = 0;
QmlJS::AST::UiObjectMemberList *lastObjectDef = 0;
QmlJS::AST::UiObjectMemberList *lastNonObjectDef = 0;
for (UiObjectMemberList *iter = members; iter; iter = iter->next) {
UiObjectMember *member = iter->member;
for (QmlJS::AST::UiObjectMemberList *iter = members; iter; iter = iter->next) {
QmlJS::AST::UiObjectMember *member = iter->member;
int idx = -1;
if (cast<UiObjectDefinition*>(member))
if (QmlJS::AST::cast<QmlJS::AST::UiObjectDefinition*>(member))
lastObjectDef = iter;
else if (UiArrayBinding *arrayBinding = cast<UiArrayBinding*>(member))
else if (QmlJS::AST::UiArrayBinding *arrayBinding = QmlJS::AST::cast<QmlJS::AST::UiArrayBinding*>(member))
idx = propertyOrder.indexOf(toString(arrayBinding->qualifiedId).toUtf8());
else if (UiObjectBinding *objectBinding = cast<UiObjectBinding*>(member))
else if (QmlJS::AST::UiObjectBinding *objectBinding = QmlJS::AST::cast<QmlJS::AST::UiObjectBinding*>(member))
idx = propertyOrder.indexOf(toString(objectBinding->qualifiedId).toUtf8());
else if (UiScriptBinding *scriptBinding = cast<UiScriptBinding*>(member))
else if (QmlJS::AST::UiScriptBinding *scriptBinding = QmlJS::AST::cast<QmlJS::AST::UiScriptBinding*>(member))
idx = propertyOrder.indexOf(toString(scriptBinding->qualifiedId).toUtf8());
else if (cast<UiPublicMember*>(member))
else if (QmlJS::AST::cast<QmlJS::AST::UiPublicMember*>(member))
idx = propertyOrder.indexOf("property");
if (idx < objectDefinitionInsertionPoint)
......@@ -295,25 +293,27 @@ UiObjectMemberList *QMLRewriter::searchMemberToInsertAfter(UiObjectMemberList *m
}
// FIXME: duplicate code in the QmlJS::Rewriter class, remove this
UiObjectMemberList *QMLRewriter::searchMemberToInsertAfter(UiObjectMemberList *members, const QmlDesigner::PropertyName &propertyName, const QmlDesigner::PropertyNameList &propertyOrder)
QmlJS::AST::UiObjectMemberList *QMLRewriter::searchMemberToInsertAfter(QmlJS::AST::UiObjectMemberList *members,
const QmlDesigner::PropertyName &propertyName,
const QmlDesigner::PropertyNameList &propertyOrder)
{
if (!members)
return 0; // empty members
QHash<QString, UiObjectMemberList *> orderedMembers;
QHash<QString, QmlJS::AST::UiObjectMemberList *> orderedMembers;
for (UiObjectMemberList *iter = members; iter; iter = iter->next) {
UiObjectMember *member = iter->member;
for (QmlJS::AST::UiObjectMemberList *iter = members; iter; iter = iter->next) {
QmlJS::AST::UiObjectMember *member = iter->member;
if (UiArrayBinding *arrayBinding = cast<UiArrayBinding*>(member))
if (QmlJS::AST::UiArrayBinding *arrayBinding = QmlJS::AST::cast<QmlJS::AST::UiArrayBinding*>(member))
orderedMembers[toString(arrayBinding->qualifiedId)] = iter;
else if (UiObjectBinding *objectBinding = cast<UiObjectBinding*>(member))
else if (QmlJS::AST::UiObjectBinding *objectBinding = QmlJS::AST::cast<QmlJS::AST::UiObjectBinding*>(member))
orderedMembers[toString(objectBinding->qualifiedId)] = iter;
else if (cast<UiObjectDefinition*>(member))
else if (QmlJS::AST::cast<QmlJS::AST::UiObjectDefinition*>(member))
orderedMembers[QString::null] = iter;
else if (UiScriptBinding *scriptBinding = cast<UiScriptBinding*>(member))
else if (QmlJS::AST::UiScriptBinding *scriptBinding = QmlJS::AST::cast<QmlJS::AST::UiScriptBinding*>(member))
orderedMembers[toString(scriptBinding->qualifiedId)] = iter;
else if (cast<UiPublicMember*>(member))
else if (QmlJS::AST::cast<QmlJS::AST::UiPublicMember*>(member))
orderedMembers[QStringLiteral("property")] = iter;
}
......@@ -325,7 +325,7 @@ UiObjectMemberList *QMLRewriter::searchMemberToInsertAfter(UiObjectMemberList *m
for (; idx > 0; --idx) {
const QString prop = propertyOrder.at(idx - 1);
UiObjectMemberList *candidate = orderedMembers.value(prop, 0);
QmlJS::AST::UiObjectMemberList *candidate = orderedMembers.value(prop, 0);
if (candidate != 0)
return candidate;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment