From e2ea5a842161ab8ebed414bda85ad949a5312873 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Mon, 4 Jul 2011 09:46:10 +0200 Subject: [PATCH] QmlJS: Rename range-related functions. astPath -> rangePath To make it more explicit that it does not return the full ast path. declaringMember -> rangeAt Since things like function expressions and declarations and grouped property bindings are also ranges and returned by this function. Change-Id: I70cc99f21635b21dd6f3088a6e5782d84f6f108a Reviewed-on: http://codereview.qt.nokia.com/1045 Reviewed-by: Fawzi Mohamed --- .../qmljseditor/qmljscompletionassist.cpp | 2 +- .../qmljscomponentfromobjectdef.cpp | 2 +- src/plugins/qmljseditor/qmljseditor.cpp | 40 ++++++++++--------- src/plugins/qmljseditor/qmljseditor.h | 4 +- src/plugins/qmljseditor/qmljshoverhandler.cpp | 2 +- src/plugins/qmljseditor/qmljsquickfixes.cpp | 2 +- src/plugins/qmljseditor/qmloutlinemodel.cpp | 2 +- 7 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/plugins/qmljseditor/qmljscompletionassist.cpp b/src/plugins/qmljseditor/qmljscompletionassist.cpp index 48e1aa2e65f..bda56d06c35 100644 --- a/src/plugins/qmljseditor/qmljscompletionassist.cpp +++ b/src/plugins/qmljseditor/qmljscompletionassist.cpp @@ -419,7 +419,7 @@ IAssistProposal *QmlJSCompletionAssistProcessor::perform(const IAssistInterface if (currentFileInfo.suffix() == QLatin1String("qml")) isQmlFile = true; - const QList path = semanticInfo.astPath(m_interface->position()); + const QList path = semanticInfo.rangePath(m_interface->position()); LookupContext::Ptr lookupContext = semanticInfo.lookupContext(path); const Interpreter::Context *context = lookupContext->context(); diff --git a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp index a85e4b0e0f8..bf78bed93d9 100644 --- a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp +++ b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp @@ -165,7 +165,7 @@ QList ComponentFromObjectDef::match( { const int pos = interface->currentFile().cursor().position(); - QList path = interface->semanticInfo().astPath(pos); + QList path = interface->semanticInfo().rangePath(pos); for (int i = path.size() - 1; i >= 0; --i) { Node *node = path.at(i); if (UiObjectDefinition *objDef = cast(node)) { diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index 20f5ade3ef0..0b2101dc74e 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -409,29 +409,30 @@ protected: Range createRange(AST::UiObjectMember *member, AST::UiObjectInitializer *ast) { - Range range; - - range.ast = member; - - range.begin = QTextCursor(_textDocument); - range.begin.setPosition(member->firstSourceLocation().begin()); - - range.end = QTextCursor(_textDocument); - range.end.setPosition(ast->rbraceToken.end()); - return range; + return createRange(member, member->firstSourceLocation(), ast->rbraceToken); } Range createRange(AST::FunctionExpression *ast) + { + return createRange(ast, ast->lbraceToken, ast->rbraceToken); + } + + Range createRange(AST::UiScriptBinding *ast, AST::Block *block) + { + return createRange(ast, block->lbraceToken, block->rbraceToken); + } + + Range createRange(AST::Node *ast, AST::SourceLocation start, AST::SourceLocation end) { Range range; range.ast = ast; range.begin = QTextCursor(_textDocument); - range.begin.setPosition(ast->lbraceToken.begin()); + range.begin.setPosition(start.begin()); range.end = QTextCursor(_textDocument); - range.end.setPosition(ast->rbraceToken.end()); + range.end.setPosition(end.end()); return range; } @@ -477,7 +478,7 @@ protected: } // end of anonymous namespace -AST::Node *SemanticInfo::declaringMember(int cursorPosition) const +AST::Node *SemanticInfo::rangeAt(int cursorPosition) const { AST::Node *declaringMember = 0; @@ -495,25 +496,26 @@ AST::Node *SemanticInfo::declaringMember(int cursorPosition) const return declaringMember; } +// ### the name and behavior of this function is dubious QmlJS::AST::Node *SemanticInfo::declaringMemberNoProperties(int cursorPosition) const { - AST::Node *node = declaringMember(cursorPosition); + AST::Node *node = rangeAt(cursorPosition); if (UiObjectDefinition *objectDefinition = cast(node)) { QString name = objectDefinition->qualifiedTypeNameId->name->asString(); if (!name.isNull() && name.at(0).isLower()) { - QList path = astPath(cursorPosition); + QList path = rangePath(cursorPosition); if (path.size() > 1) return path.at(path.size() - 2); } else if (name.contains("GradientStop")) { - QList path = astPath(cursorPosition); + QList path = rangePath(cursorPosition); if (path.size() > 2) return path.at(path.size() - 3); } } else if (UiObjectBinding *objectBinding = cast(node)) { QString name = objectBinding->qualifiedTypeNameId->name->asString(); if (name.contains("Gradient")) { - QList path = astPath(cursorPosition); + QList path = rangePath(cursorPosition); if (path.size() > 1) return path.at(path.size() - 2); } @@ -522,7 +524,7 @@ QmlJS::AST::Node *SemanticInfo::declaringMemberNoProperties(int cursorPosition) return node; } -QList SemanticInfo::astPath(int cursorPosition) const +QList SemanticInfo::rangePath(int cursorPosition) const { QList path; @@ -1275,7 +1277,7 @@ TextEditor::BaseTextEditorWidget::Link QmlJSTextEditorWidget::findLinkAt(const Q return Link(); } - LookupContext::Ptr lookupContext = semanticInfo.lookupContext(semanticInfo.astPath(cursorPosition)); + LookupContext::Ptr lookupContext = semanticInfo.lookupContext(semanticInfo.rangePath(cursorPosition)); Evaluate evaluator(lookupContext->context()); const Interpreter::Value *value = evaluator.reference(node); diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h index 3240ecd4e95..eab40676167 100644 --- a/src/plugins/qmljseditor/qmljseditor.h +++ b/src/plugins/qmljseditor/qmljseditor.h @@ -108,14 +108,14 @@ public: int revision() const; // Returns the declaring member - QmlJS::AST::Node *declaringMember(int cursorPosition) const; + QmlJS::AST::Node *rangeAt(int cursorPosition) const; QmlJS::AST::Node *declaringMemberNoProperties(int cursorPosition) const; // Returns the AST node under cursor QmlJS::AST::Node *nodeUnderCursor(int cursorPosition) const; // Returns the list of nodes that enclose the given position. - QList astPath(int cursorPosition) const; + QList rangePath(int cursorPosition) const; // Returns a context for the given path QSharedPointer lookupContext(const QList &path = QList()) const; diff --git a/src/plugins/qmljseditor/qmljshoverhandler.cpp b/src/plugins/qmljseditor/qmljshoverhandler.cpp index eb1f664229a..ee7a17deb13 100644 --- a/src/plugins/qmljseditor/qmljshoverhandler.cpp +++ b/src/plugins/qmljseditor/qmljshoverhandler.cpp @@ -120,7 +120,7 @@ void HoverHandler::identifyMatch(TextEditor::ITextEditor *editor, int pos) if (! semanticInfo.isValid() || semanticInfo.revision() != qmlEditor->editorRevision()) return; - QList astPath = semanticInfo.astPath(pos); + QList astPath = semanticInfo.rangePath(pos); const Document::Ptr qmlDocument = semanticInfo.document; LookupContext::Ptr lookupContext = semanticInfo.lookupContext(astPath); diff --git a/src/plugins/qmljseditor/qmljsquickfixes.cpp b/src/plugins/qmljseditor/qmljsquickfixes.cpp index 54c6820c3c0..84fd0de6fe8 100644 --- a/src/plugins/qmljseditor/qmljsquickfixes.cpp +++ b/src/plugins/qmljseditor/qmljsquickfixes.cpp @@ -72,7 +72,7 @@ public: const int pos = interface->currentFile().cursor().position(); - if (QmlJS::AST::Node *member = interface->semanticInfo().declaringMember(pos)) { + if (QmlJS::AST::Node *member = interface->semanticInfo().rangeAt(pos)) { if (QmlJS::AST::UiObjectBinding *b = QmlJS::AST::cast(member)) { if (b->initializer->lbraceToken.startLine == b->initializer->rbraceToken.startLine) objectInitializer = b->initializer; diff --git a/src/plugins/qmljseditor/qmloutlinemodel.cpp b/src/plugins/qmljseditor/qmloutlinemodel.cpp index 0b50232e908..862852db1f3 100644 --- a/src/plugins/qmljseditor/qmloutlinemodel.cpp +++ b/src/plugins/qmljseditor/qmloutlinemodel.cpp @@ -71,7 +71,7 @@ QVariant QmlOutlineItem::data(int role) const if (!uiQualifiedId || !location.isValid() || !m_outlineModel->m_semanticInfo.isValid()) return QVariant(); - QList astPath = m_outlineModel->m_semanticInfo.astPath(location.begin()); + QList astPath = m_outlineModel->m_semanticInfo.rangePath(location.begin()); LookupContext::Ptr lookupContext = m_outlineModel->m_semanticInfo.lookupContext(astPath); const Interpreter::Value *value = lookupContext->evaluate(uiQualifiedId);