Commit c8fc9b33 authored by Christian Kamm's avatar Christian Kamm
Browse files

QmlJS: Clean up idOfObject() and folding text code.



Change-Id: Id3e9d24689c67ce0e12b12b82636177a0344ede1
Reviewed-by: Nicolas Arnaud-Cormos's avatarNicolas Arnaud-Cormos <nicolas@kdab.com>
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@nokia.com>
parent 2ec51f5b
......@@ -96,29 +96,16 @@ SourceLocation QmlJS::fullLocationForQualifiedId(AST::UiQualifiedId *qualifiedId
return locationFromRange(start, end);
}
QString QmlJS::idOfObject(UiObjectDefinition *object, UiScriptBinding **idBinding)
{
if (!object) {
if (idBinding)
*idBinding = 0;
return QString();
}
return idOfObject(object->initializer, idBinding);
}
QString QmlJS::idOfObject(UiObjectBinding *object, UiScriptBinding **idBinding)
{
if (!object) {
if (idBinding)
*idBinding = 0;
return QString();
}
return idOfObject(object->initializer, idBinding);
}
QString QmlJS::idOfObject(UiObjectInitializer *initializer, UiScriptBinding **idBinding)
/*!
\returns the value of the 'id:' binding in \a object
\param idBinding optional out parameter to get the UiScriptBinding for the id binding
*/
QString QmlJS::idOfObject(Node *object, UiScriptBinding **idBinding)
{
if (idBinding)
*idBinding = 0;
UiObjectInitializer *initializer = initializerOfObject(object);
if (!initializer)
return QString();
......@@ -143,11 +130,14 @@ QString QmlJS::idOfObject(UiObjectInitializer *initializer, UiScriptBinding **id
return QString();
}
UiObjectInitializer *QmlJS::initializerOfObject(Node *node)
/*!
\returns the UiObjectInitializer if \a object is a UiObjectDefinition or UiObjectBinding, otherwise 0
*/
UiObjectInitializer *QmlJS::initializerOfObject(Node *object)
{
if (UiObjectDefinition *definition = cast<UiObjectDefinition *>(node))
if (UiObjectDefinition *definition = cast<UiObjectDefinition *>(object))
return definition->initializer;
if (UiObjectBinding *binding = cast<UiObjectBinding *>(node))
if (UiObjectBinding *binding = cast<UiObjectBinding *>(object))
return binding->initializer;
return 0;
}
......
......@@ -18,11 +18,10 @@ QMLJS_EXPORT AST::SourceLocation locationFromRange(const AST::SourceLocation &st
QMLJS_EXPORT AST::SourceLocation fullLocationForQualifiedId(AST::UiQualifiedId *);
QMLJS_EXPORT QString idOfObject(AST::UiObjectDefinition *object, AST::UiScriptBinding **idBinding = 0);
QMLJS_EXPORT QString idOfObject(AST::UiObjectBinding *object, AST::UiScriptBinding **idBinding = 0);
QMLJS_EXPORT QString idOfObject(AST::UiObjectInitializer *initializer, AST::UiScriptBinding **idBinding = 0);
QMLJS_EXPORT QString idOfObject(AST::Node *object, AST::UiScriptBinding **idBinding = 0);
QMLJS_EXPORT AST::UiObjectInitializer *initializerOfObject(AST::Node *object);
QMLJS_EXPORT AST::UiObjectInitializer *initializerOfObject(AST::Node *node);
QMLJS_EXPORT AST::UiQualifiedId *qualifiedTypeNameId(AST::Node *node);
QMLJS_EXPORT bool isValidBuiltinPropertyType(const QString &name);
......
......@@ -1695,27 +1695,15 @@ TextEditor::IAssistInterface *QmlJSTextEditorWidget::createAssistInterface(
QString QmlJSTextEditorWidget::foldReplacementText(const QTextBlock &block) const
{
int curlyIndex = block.text().indexOf(QLatin1Char('{'));
if ((curlyIndex == -1) || !m_semanticInfo.isValid())
return TextEditor::BaseTextEditorWidget::foldReplacementText(block);
int pos = block.position() + curlyIndex;
Node *node = m_semanticInfo.rangeAt(pos);
if (node) {
UiObjectInitializer *objectInitializer = 0;
if (UiObjectDefinition *def = cast<UiObjectDefinition *>(node))
objectInitializer = def->initializer;
else if (UiObjectBinding *binding = cast<UiObjectBinding *>(node))
objectInitializer = binding->initializer;
// Get the id value, if it exists, and display it
if (objectInitializer) {
QString objectId = idOfObject(objectInitializer);
if (!objectId.isEmpty())
return QLatin1String("id: ") + objectId + QLatin1String("...");
}
const int curlyIndex = block.text().indexOf(QLatin1Char('{'));
if (curlyIndex != -1 && m_semanticInfo.isValid()) {
const int pos = block.position() + curlyIndex;
Node *node = m_semanticInfo.rangeAt(pos);
const QString objectId = idOfObject(node);
if (!objectId.isEmpty())
return QLatin1String("id: ") + objectId + QLatin1String("...");
}
return TextEditor::BaseTextEditorWidget::foldReplacementText(block);
......
......@@ -160,7 +160,7 @@ protected:
return true;
QString context = toString(ast->qualifiedTypeNameId);
const QString id = idOfObject(ast->initializer);
const QString id = idOfObject(ast);
if (!id.isEmpty())
context = QString("%1 (%2)").arg(id, context);
accept(ast->initializer, contextString(context));
......@@ -173,7 +173,7 @@ protected:
return true;
QString context = toString(ast->qualifiedTypeNameId);
const QString id = idOfObject(ast->initializer);
const QString id = idOfObject(ast);
if (!id.isEmpty())
context = QString("%1 (%2)").arg(id, context);
accept(ast->initializer, contextString(context));
......
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