diff --git a/duchain/declarationbuilder.cpp b/duchain/declarationbuilder.cpp --- a/duchain/declarationbuilder.cpp +++ b/duchain/declarationbuilder.cpp @@ -920,10 +920,12 @@ v.lastDeclaration()->setType(container); } }; - - foreach ( const QString& key, items.keys() ) { - if ( Helper::docstringContainsHint(function.data(), key, &args) ) { - items[key](); + auto docstring = function->comment(); + if ( ! docstring.isEmpty() ) { + foreach ( const auto& key, items.keys() ) { + if ( Helper::docstringContainsHint(docstring, key, &args) ) { + items[key](); + } } } } @@ -1345,24 +1347,25 @@ dec->clearBaseClasses(); dec->setClassType(ClassDeclarationData::Class); - dec->setComment(getDocstring(node->body)); - - // check whether this is a type container (list, dict, ...) or just a "normal" class - if ( Helper::docstringContainsHint(dec, "TypeContainer") ) { - ListType* container = nullptr; - if ( Helper::docstringContainsHint(dec, "hasTypedKeys") ) { - container = new MapType(); + auto docstring = getDocstring(node->body); + dec->setComment(docstring); + if ( ! docstring.isEmpty() ) { + // check whether this is a type container (list, dict, ...) or just a "normal" class + if ( Helper::docstringContainsHint(docstring, "TypeContainer") ) { + ListType* container = nullptr; + if ( Helper::docstringContainsHint(docstring, "hasTypedKeys") ) { + container = new MapType(); + } + else { + container = new ListType(); + } + type = StructureType::Ptr(container); } - else { - container = new ListType(); + if ( Helper::docstringContainsHint(docstring, "IndexedTypeContainer") ) { + IndexedContainer* container = new IndexedContainer(); + type = StructureType::Ptr(container); } - type = StructureType::Ptr(container); } - if ( Helper::docstringContainsHint(dec, "IndexedTypeContainer") ) { - IndexedContainer* container = new IndexedContainer(); - type = StructureType::Ptr(container); - } - lock.unlock(); foreach ( ExpressionAst* c, node->baseClasses ) { // Iterate over all the base classes, and add them to the duchain. diff --git a/duchain/expressionvisitor.cpp b/duchain/expressionvisitor.cpp --- a/duchain/expressionvisitor.cpp +++ b/duchain/expressionvisitor.cpp @@ -314,15 +314,18 @@ return false; }; - foreach ( const QString& currentHint, knownDecoratorHints.keys() ) { - QStringList arguments; - if ( ! Helper::docstringContainsHint(funcDecl, currentHint, &arguments) ) { - continue; - } - // If the hint word appears in the docstring, run the evaluation function. - if ( knownDecoratorHints[currentHint](arguments, currentHint) ) { - // We indeed found something, so we're done. - return; + auto docstring = funcDecl->comment(); + if ( ! docstring.isEmpty() ) { + foreach ( const QString& currentHint, knownDecoratorHints.keys() ) { + QStringList arguments; + if ( ! Helper::docstringContainsHint(docstring, currentHint, &arguments) ) { + continue; + } + // If the hint word appears in the docstring, run the evaluation function. + if ( knownDecoratorHints[currentHint](arguments, currentHint) ) { + // We indeed found something, so we're done. + return; + } } } diff --git a/duchain/helpers.h b/duchain/helpers.h --- a/duchain/helpers.h +++ b/duchain/helpers.h @@ -159,9 +159,8 @@ return 0; }; - static bool docstringContainsHint(Declaration* declaration, const QString& hintName, QStringList* args = 0) { + static bool docstringContainsHint(const QString& comment, const QString& hintName, QStringList* args = 0) { // TODO cache types! this is horribly inefficient - const QString& comment = declaration->comment(); const QString search = "! " + hintName + " !"; int index = comment.indexOf(search); if ( index >= 0 ) {