diff options
author | Christian Kamm <christian.d.kamm@nokia.com> | 2011-07-04 09:46:10 +0200 |
---|---|---|
committer | Christian Kamm <christian.d.kamm@nokia.com> | 2011-07-05 11:52:57 +0200 |
commit | e2ea5a842161ab8ebed414bda85ad949a5312873 (patch) | |
tree | 4d5492916d6062103e1d6fbb0ef3343267e10f12 | |
parent | eec591ff1c9394a7ffdc103f4d4337ccd708de11 (diff) | |
download | qt-creator-e2ea5a842161ab8ebed414bda85ad949a5312873.tar.gz |
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 <fawzi.mohamed@nokia.com>
-rw-r--r-- | src/plugins/qmljseditor/qmljscompletionassist.cpp | 2 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp | 2 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmljseditor.cpp | 38 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmljseditor.h | 4 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmljshoverhandler.cpp | 2 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmljsquickfixes.cpp | 2 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmloutlinemodel.cpp | 2 |
7 files changed, 27 insertions, 25 deletions
diff --git a/src/plugins/qmljseditor/qmljscompletionassist.cpp b/src/plugins/qmljseditor/qmljscompletionassist.cpp index 48e1aa2e65..bda56d06c3 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<AST::Node *> path = semanticInfo.astPath(m_interface->position()); + const QList<AST::Node *> 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 a85e4b0e0f..bf78bed93d 100644 --- a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp +++ b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp @@ -165,7 +165,7 @@ QList<QmlJSQuickFixOperation::Ptr> ComponentFromObjectDef::match( { const int pos = interface->currentFile().cursor().position(); - QList<Node *> path = interface->semanticInfo().astPath(pos); + QList<Node *> path = interface->semanticInfo().rangePath(pos); for (int i = path.size() - 1; i >= 0; --i) { Node *node = path.at(i); if (UiObjectDefinition *objDef = cast<UiObjectDefinition *>(node)) { diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index 20f5ade3ef..0b2101dc74 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; + return createRange(member, member->firstSourceLocation(), ast->rbraceToken); + } - range.begin = QTextCursor(_textDocument); - range.begin.setPosition(member->firstSourceLocation().begin()); + Range createRange(AST::FunctionExpression *ast) + { + return createRange(ast, ast->lbraceToken, ast->rbraceToken); + } - range.end = QTextCursor(_textDocument); - range.end.setPosition(ast->rbraceToken.end()); - return range; + Range createRange(AST::UiScriptBinding *ast, AST::Block *block) + { + return createRange(ast, block->lbraceToken, block->rbraceToken); } - Range createRange(AST::FunctionExpression *ast) + 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<UiObjectDefinition*>(node)) { QString name = objectDefinition->qualifiedTypeNameId->name->asString(); if (!name.isNull() && name.at(0).isLower()) { - QList<AST::Node *> path = astPath(cursorPosition); + QList<AST::Node *> path = rangePath(cursorPosition); if (path.size() > 1) return path.at(path.size() - 2); } else if (name.contains("GradientStop")) { - QList<AST::Node *> path = astPath(cursorPosition); + QList<AST::Node *> path = rangePath(cursorPosition); if (path.size() > 2) return path.at(path.size() - 3); } } else if (UiObjectBinding *objectBinding = cast<UiObjectBinding*>(node)) { QString name = objectBinding->qualifiedTypeNameId->name->asString(); if (name.contains("Gradient")) { - QList<AST::Node *> path = astPath(cursorPosition); + QList<AST::Node *> 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<AST::Node *> SemanticInfo::astPath(int cursorPosition) const +QList<AST::Node *> SemanticInfo::rangePath(int cursorPosition) const { QList<AST::Node *> 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 3240ecd4e9..eab4067616 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<QmlJS::AST::Node *> astPath(int cursorPosition) const; + QList<QmlJS::AST::Node *> rangePath(int cursorPosition) const; // Returns a context for the given path QSharedPointer<QmlJS::LookupContext> lookupContext(const QList<QmlJS::AST::Node *> &path = QList<QmlJS::AST::Node *>()) const; diff --git a/src/plugins/qmljseditor/qmljshoverhandler.cpp b/src/plugins/qmljseditor/qmljshoverhandler.cpp index eb1f664229..ee7a17deb1 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<AST::Node *> astPath = semanticInfo.astPath(pos); + QList<AST::Node *> 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 54c6820c3c..84fd0de6fe 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<QmlJS::AST::UiObjectBinding *>(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 0b50232e90..862852db1f 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<AST::Node *> astPath = m_outlineModel->m_semanticInfo.astPath(location.begin()); + QList<AST::Node *> astPath = m_outlineModel->m_semanticInfo.rangePath(location.begin()); LookupContext::Ptr lookupContext = m_outlineModel->m_semanticInfo.lookupContext(astPath); const Interpreter::Value *value = lookupContext->evaluate(uiQualifiedId); |