forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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<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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user