aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cppeditor
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/cppeditor')
-rw-r--r--src/plugins/cppeditor/cppdocumentationcommenthelper.cpp7
-rw-r--r--src/plugins/cppeditor/cppdocumentationcommenthelper.h4
-rw-r--r--src/plugins/cppeditor/cppdoxygen_test.cpp41
-rw-r--r--src/plugins/cppeditor/cppdoxygen_test.h10
-rw-r--r--src/plugins/cppeditor/cppeditor.cpp3
-rw-r--r--src/plugins/cppeditor/cppeditortestcase.h4
6 files changed, 61 insertions, 8 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: