diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/cppeditor/cppdocumentationcommenthelper.cpp | 7 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppdocumentationcommenthelper.h | 4 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppdoxygen_test.cpp | 41 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppdoxygen_test.h | 10 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppeditor.cpp | 3 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppeditortestcase.h | 4 | ||||
-rw-r--r-- | src/plugins/cpptools/doxygengenerator.cpp | 28 | ||||
-rw-r--r-- | src/plugins/cpptools/doxygengenerator.h | 6 |
8 files changed, 91 insertions, 12 deletions
diff --git a/src/plugins/cppeditor/cppdocumentationcommenthelper.cpp b/src/plugins/cppeditor/cppdocumentationcommenthelper.cpp index 0995d6a5a5..4bdcdd8fbe 100644 --- a/src/plugins/cppeditor/cppdocumentationcommenthelper.cpp +++ b/src/plugins/cppeditor/cppdocumentationcommenthelper.cpp @@ -268,7 +268,8 @@ bool handleDoxygenContinuation(QTextCursor &cursor, namespace CppEditor { namespace Internal { -bool trySplitComment(TextEditor::TextEditorWidget *editorWidget) +bool trySplitComment(TextEditor::TextEditorWidget *editorWidget, + const CPlusPlus::Snapshot &snapshot) { const CommentsSettings &settings = CppToolsSettings::instance()->commentsSettings(); if (!settings.m_enableDoxygen && !settings.m_leadingAsterisks) @@ -310,7 +311,9 @@ bool trySplitComment(TextEditor::TextEditorWidget *editorWidget) } if (!cursor.atEnd()) { - const QString &comment = doxygen.generate(cursor); + const QString &comment = doxygen.generate(cursor, + snapshot, + editorWidget->textDocument()->filePath()); if (!comment.isEmpty()) { cursor.beginEditBlock(); cursor.setPosition(pos); diff --git a/src/plugins/cppeditor/cppdocumentationcommenthelper.h b/src/plugins/cppeditor/cppdocumentationcommenthelper.h index 169323188a..f384968965 100644 --- a/src/plugins/cppeditor/cppdocumentationcommenthelper.h +++ b/src/plugins/cppeditor/cppdocumentationcommenthelper.h @@ -29,11 +29,13 @@ #include "cppeditor_global.h" namespace TextEditor { class TextEditorWidget; } +namespace CPlusPlus { class Snapshot; } namespace CppEditor { namespace Internal { -bool trySplitComment(TextEditor::TextEditorWidget *editorWidget); +bool trySplitComment(TextEditor::TextEditorWidget *editorWidget, + const CPlusPlus::Snapshot &snapshot); } // namespace Internal } // namespace CppEditor diff --git a/src/plugins/cppeditor/cppdoxygen_test.cpp b/src/plugins/cppeditor/cppdoxygen_test.cpp index 91b2207b40..ebbb109af3 100644 --- a/src/plugins/cppeditor/cppdoxygen_test.cpp +++ b/src/plugins/cppeditor/cppdoxygen_test.cpp @@ -281,6 +281,18 @@ void DoxygenTest::testBasic_data() "*foo /*\n" " \n" ); + + QTest::newRow("withMacroFromDocumentBeforeFunction") << _( + "#define API\n" + "/**|\n" + "API void f();\n" + ) << _( + "#define API\n" + "/**\n" + " * @brief f\n" + " */\n" + "API void f();\n" + ); } void DoxygenTest::testBasic() @@ -290,6 +302,25 @@ void DoxygenTest::testBasic() runTest(given, expected); } +void DoxygenTest::testWithMacroFromHeaderBeforeFunction() +{ + const QByteArray given = + "#include \"header.h\"\n" + "/**|\n" + "API void f();\n"; + + const QByteArray expected = + "#include \"header.h\"\n" + "/**\n" + " * @brief f\n" + " */\n" + "API void f();\n"; + + const TestDocument headerDocumentDefiningMacro("header.h", "#define API\n"); + + runTest(given, expected, /*settings=*/ 0, { headerDocumentDefiningMacro }); +} + void DoxygenTest::testNoLeadingAsterisks_data() { QTest::addColumn<QByteArray>("given"); @@ -323,8 +354,10 @@ void DoxygenTest::verifyCleanState() const } /// The '|' in the input denotes the cursor position. -void DoxygenTest::runTest(const QByteArray &original, const QByteArray &expected, - CppTools::CommentsSettings *settings) +void DoxygenTest::runTest(const QByteArray &original, + const QByteArray &expected, + CppTools::CommentsSettings *settings, + const TestDocuments &includedHeaderDocuments) { // Write files to disk CppTools::Tests::TemporaryDir temporaryDir; @@ -334,6 +367,10 @@ void DoxygenTest::runTest(const QByteArray &original, const QByteArray &expected testDocument.m_source.remove(testDocument.m_cursorPosition, 1); testDocument.setBaseDirectory(temporaryDir.path()); QVERIFY(testDocument.writeToDisk()); + foreach (TestDocument testDocument, includedHeaderDocuments) { + testDocument.setBaseDirectory(temporaryDir.path()); + QVERIFY(testDocument.writeToDisk()); + } // Update Code Model QVERIFY(TestCase::parseFiles(testDocument.filePath())); diff --git a/src/plugins/cppeditor/cppdoxygen_test.h b/src/plugins/cppeditor/cppdoxygen_test.h index 65e7672c2a..68f6b2509a 100644 --- a/src/plugins/cppeditor/cppdoxygen_test.h +++ b/src/plugins/cppeditor/cppdoxygen_test.h @@ -26,6 +26,8 @@ #ifndef CPPDOXYGEN_TEST_H #define CPPDOXYGEN_TEST_H +#include "cppeditortestcase.h" + #include <cpptools/commentssettings.h> #include <QObject> @@ -48,13 +50,17 @@ private slots: void testBasic_data(); void testBasic(); + void testWithMacroFromHeaderBeforeFunction(); + void testNoLeadingAsterisks_data(); void testNoLeadingAsterisks(); private: void verifyCleanState() const; - void runTest(const QByteArray &original, const QByteArray &expected, - CppTools::CommentsSettings *settings = 0); + void runTest(const QByteArray &original, + const QByteArray &expected, + CppTools::CommentsSettings *settings = 0, + const TestDocuments &includedHeaderDocuments = TestDocuments()); QScopedPointer<CppTools::CommentsSettings> oldSettings; }; diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index b0c9389b69..8f96ca4256 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -69,6 +69,7 @@ #include <texteditor/refactoroverlay.h> #include <cplusplus/ASTPath.h> +#include <cplusplus/FastPreprocessor.h> #include <utils/qtcassert.h> #include <QAction> @@ -603,7 +604,7 @@ void CppEditorWidget::keyPressEvent(QKeyEvent *e) return; if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) { - if (trySplitComment(this)) { + if (trySplitComment(this, semanticInfo().snapshot)) { e->accept(); return; } diff --git a/src/plugins/cppeditor/cppeditortestcase.h b/src/plugins/cppeditor/cppeditortestcase.h index c93e3a2c9d..4b4239c295 100644 --- a/src/plugins/cppeditor/cppeditortestcase.h +++ b/src/plugins/cppeditor/cppeditortestcase.h @@ -30,6 +30,8 @@ #include <cpptools/cpptoolstestcase.h> +#include <QVector> + namespace CppEditor { namespace Internal { @@ -55,6 +57,8 @@ public: CppEditorWidget *m_editorWidget; }; +using TestDocuments = QVector<TestDocument>; + class TestCase : public CppTools::Tests::TestCase { public: 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); diff --git a/src/plugins/cpptools/doxygengenerator.h b/src/plugins/cpptools/doxygengenerator.h index b19d4e01ef..c816ebfcb9 100644 --- a/src/plugins/cpptools/doxygengenerator.h +++ b/src/plugins/cpptools/doxygengenerator.h @@ -33,6 +33,8 @@ QT_FORWARD_DECLARE_CLASS(QTextCursor) namespace CPlusPlus { class DeclarationAST; } +namespace CPlusPlus { class Snapshot; } +namespace Utils { class FileName; } namespace CppTools { @@ -53,7 +55,9 @@ public: void setGenerateBrief(bool gen); void setAddLeadingAsterisks(bool add); - QString generate(QTextCursor cursor); + QString generate(QTextCursor cursor, + const CPlusPlus::Snapshot &snapshot, + const Utils::FileName &documentFilePath); QString generate(QTextCursor cursor, CPlusPlus::DeclarationAST *decl); private: |