[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdev-qmljs] /: Support single-line slots and slots associated with signals having a complex qualifi
From: Denis Steckelmacher <steckdenis () yahoo ! fr>
Date: 2014-06-09 15:05:35
Message-ID: E1Wu18h-0004i4-Sd () scm ! kde ! org
[Download RAW message or body]
Git commit be9f974a0eb00271f0f9a55380e5c8e777f0c99e by Denis Steckelmacher.
Committed on 09/06/2014 at 15:01.
Pushed by dsteckelmacher into branch 'master'.
Support single-line slots and slots associated with signals having a complex qualified identifier
"onWidthChanged: console.log(value)" and "Component.onLoad: doSomething()" are
now both supported.
M +23 -22 duchain/declarationbuilder.cpp
M +8 -5 tests/files/plugins.qml
http://commits.kde.org/kdev-qmljs/be9f974a0eb00271f0f9a55380e5c8e777f0c99e
diff --git a/duchain/declarationbuilder.cpp b/duchain/declarationbuilder.cpp
index 8bd999f..50f37ba 100644
--- a/duchain/declarationbuilder.cpp
+++ b/duchain/declarationbuilder.cpp
@@ -857,31 +857,34 @@ bool DeclarationBuilder::visit(QmlJS::AST::UiScriptBinding* node)
}
}
- // If a Javascript block is used as expression, open a context for it, so
- // that variables declared in one block don't become visible to the other blocks
- auto block = QmlJS::AST::cast<QmlJS::AST::Block*>(node->statement);
+ // Use ExpressionVisitor to find the signal/property bound
+ DeclarationPointer bindingDecl = findType(node->qualifiedId).declaration;
+ DUChainPointer<ClassFunctionDeclaration> signal;
+
+ // If a Javascript block is used as expression or if the script binding is a
+ // slot, open a subcontext so that variables declared in the binding are kept
+ // local, and the signal parameters can be visible to the slot
+ if ((
+ bindingDecl &&
+ (signal = bindingDecl.dynamicCast<ClassFunctionDeclaration>()) &&
+ signal->isSignal()
+ ) ||
+ node->statement->kind == QmlJS::AST::Node::Kind_Block) {
- if (block) {
openContext(
- block,
- m_session->locationsToInnerRange(block->lbraceToken, block->rbraceToken),
+ node->statement,
+ m_session->locationsToInnerRange(
+ node->statement->firstSourceLocation(),
+ node->statement->lastSourceLocation()
+ ),
DUContext::Other
);
// If this script binding is a slot, import the parameters of its signal
- DeclarationPointer bindingDecl = QmlJS::getDeclarationOrSignal(
- QualifiedIdentifier(bindingName),
- currentContext()
- );
-
- if (bindingDecl) {
- auto signal = bindingDecl.dynamicCast<ClassFunctionDeclaration>();
-
- if (signal && signal->isSignal() && signal->internalFunctionContext()) {
- DUChainWriteLocker lock;
+ if (signal && signal->isSignal() && signal->internalFunctionContext()) {
+ DUChainWriteLocker lock;
- currentContext()->addImportedParentContext(signal->internalFunctionContext());
- }
+ currentContext()->addImportedParentContext(signal->internalFunctionContext());
}
}
@@ -892,10 +895,8 @@ void DeclarationBuilder::endVisit(QmlJS::AST::UiScriptBinding* node)
{
QmlJS::AST::Visitor::endVisit(node);
- // If the script binding opened a code block, close it
- auto block = QmlJS::AST::cast<QmlJS::AST::Block*>(node->statement);
-
- if (block) {
+ // If visit(UiScriptBinding) has opened a context, close it
+ if (currentContext()->type() == DUContext::Other) {
closeContext();
}
}
diff --git a/tests/files/plugins.qml b/tests/files/plugins.qml
index b6bfe97..92d52c4 100644
--- a/tests/files/plugins.qml
+++ b/tests/files/plugins.qml
@@ -51,13 +51,14 @@ Module {
}
/**
* "toString" : "void dataChanged (plugins::QModelIndex, plugins::QModelIndex, int)",
- * "useCount" : 1
+ * "useCount" : 2
*/
Signal {
name: "dataChanged"
/**
- * "toString" : "plugins::QModelIndex topLeft"
+ * "toString" : "plugins::QModelIndex topLeft",
+ * "useCount" : 1
*/
Parameter /* */ { name: "topLeft"; type: "QModelIndex" }
@@ -92,9 +93,7 @@ Module {
*/
id: foo
- onDataChanged: {
- return;
- }
+ onDataChanged: console.log(topLeft);
}
/**
@@ -105,5 +104,9 @@ Module {
id: bar
rootItem.childCount: "foo"
+
+ AbstractItemModel.onDataChanged: {
+ return;
+ }
}
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic