diff options
author | Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> | 2016-03-04 12:43:06 +0100 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> | 2016-03-04 14:22:27 +0000 |
commit | 2b2ba298f3cfc17b74ddd476613377f0b325955b (patch) | |
tree | 3ccd65e272d234c0c2b71954884b36776c101d7e /src/plugins/cpptools/doxygengenerator.cpp | |
parent | f99f5dcdc6f1ae26145242712985ca42d724e34d (diff) |
CppEditor: Generate doxygen comments for functions with macros
...at least for object-like macros. This handles the common case where a
macro before the function signature annotates the DLL import/export.
Task-number: QTCREATORBUG-15819
Change-Id: I79f22508188019402fb7345222408aaf90106f20
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
Diffstat (limited to 'src/plugins/cpptools/doxygengenerator.cpp')
-rw-r--r-- | src/plugins/cpptools/doxygengenerator.cpp | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/plugins/cpptools/doxygengenerator.cpp b/src/plugins/cpptools/doxygengenerator.cpp index 6056803bb4..63a252e992 100644 --- a/src/plugins/cpptools/doxygengenerator.cpp +++ b/src/plugins/cpptools/doxygengenerator.cpp @@ -25,15 +25,20 @@ #include "doxygengenerator.h" +#include <texteditor/convenience.h> + #include <cplusplus/BackwardsScanner.h> #include <cplusplus/CppDocument.h> +#include <utils/fileutils.h> #include <utils/qtcassert.h> #include <QStringBuilder> #include <QTextDocument> #include <QDebug> +#include <limits> + using namespace CppTools; using namespace CPlusPlus; @@ -64,8 +69,24 @@ void DoxygenGenerator::setAddLeadingAsterisks(bool add) m_addLeadingAsterisks = add; } -QString DoxygenGenerator::generate(QTextCursor cursor) +static int lineBeforeCursor(const QTextCursor &cursor) +{ + int line, column; + const bool converted = TextEditor::Convenience::convertPosition(cursor.document(), + cursor.position(), + &line, + &column); + QTC_ASSERT(converted, return std::numeric_limits<int>::max()); + + return line - 1; +} + +QString DoxygenGenerator::generate(QTextCursor cursor, + const CPlusPlus::Snapshot &snapshot, + const Utils::FileName &documentFilePath) { + const QTextCursor initialCursor = cursor; + const QChar &c = cursor.document()->characterAt(cursor.position()); if (!c.isLetter() && c != QLatin1Char('_')) return QString(); @@ -100,8 +121,9 @@ QString DoxygenGenerator::generate(QTextCursor cursor) if (declCandidate.endsWith(QLatin1Char('{'))) declCandidate.append(QLatin1Char('}')); - Document::Ptr doc = Document::create(QLatin1String("<doxygen>")); - doc->setUtf8Source(declCandidate.toUtf8()); + Document::Ptr doc = snapshot.preprocessedDocument(declCandidate.toUtf8(), + documentFilePath, + lineBeforeCursor(initialCursor)); doc->parse(Document::ParseDeclaration); doc->check(Document::FastCheck); |