Commit c937226d authored by Knut Petter Svendsen's avatar Knut Petter Svendsen Committed by David Schulz

C++: Improved automatic Doxygen comment blocks with CppStyle

Added support for CppStyle for Doxygen block generation when
hitting enter after a /// or //! comment. Previously only
QtStyle and JavaStyle was supported.

Change-Id: Ib010e55ba602127a6842ba02034fbe85994ee2bd
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent 8d2f4060
......@@ -40,7 +40,9 @@
#include <QKeyEvent>
#include <QString>
#include <QTextDocument>
#ifdef WITH_TESTS
#include <QtTest>
#endif
/*!
......@@ -221,3 +223,124 @@ void CppPlugin::test_doxygen_comments_java_style_continuation()
TestCase data(given);
data.run(expected);
}
void CppPlugin::test_doxygen_comments_cpp_styleA()
{
const QByteArray given =
"bool preventFolding;\n"
"///|\n"
"int a;\n"
;
const QByteArray expected =
"bool preventFolding;\n"
"///\n"
"/// \\brief a\n"
"///\n"
"int a;\n"
;
TestCase data(given);
data.run(expected);
}
void CppPlugin::test_doxygen_comments_cpp_styleB()
{
const QByteArray given =
"bool preventFolding;\n"
"//!|\n"
"int a;\n"
;
const QByteArray expected =
"bool preventFolding;\n"
"//!\n"
"//! \\brief a\n"
"//!\n"
"int a;\n"
;
TestCase data(given);
data.run(expected);
}
void CppPlugin::test_doxygen_comments_cpp_styleA_continuation()
{
const QByteArray given =
"bool preventFolding;\n"
"///\n"
"/// \\brief a|\n"
"///\n"
"int a;\n"
;
const QByteArray expected =
"bool preventFolding;\n"
"///\n"
"/// \\brief a\n"
"///\n"
"///\n"
"int a;\n"
;
TestCase data(given);
data.run(expected);
}
/// test cpp style doxygen comment when inside a indented scope
void CppPlugin::test_doxygen_comments_cpp_styleA_indented()
{
const QByteArray given =
" bool preventFolding;\n"
" ///|\n"
" int a;\n"
;
const QByteArray expected =
" bool preventFolding;\n"
" ///\n"
" /// \\brief a\n"
" ///\n"
" int a;\n"
;
TestCase data(given);
data.run(expected);
}
/// test cpp style doxygen comment continuation when inside a indented scope
void CppPlugin::test_doxygen_comments_cpp_styleA_indented_continuation()
{
const QByteArray given =
" bool preventFolding;\n"
" ///\n"
" /// \\brief a|\n"
" ///\n"
" int a;\n"
;
const QByteArray expected =
" bool preventFolding;\n"
" ///\n"
" /// \\brief a\n"
" ///\n"
" ///\n"
" int a;\n"
;
TestCase data(given);
data.run(expected);
}
void CppPlugin::test_doxygen_comments_cpp_styleA_corner_case()
{
const QByteArray given =
"bool preventFolding;\n"
"///\n"
"void d(); ///|\n"
;
const QByteArray expected =
"bool preventFolding;\n"
"///\n"
"void d(); ///\n"
"\n"
;
TestCase data(given);
data.run(expected);
}
This diff is collapsed.
......@@ -285,6 +285,7 @@ private:
QModelIndex indexForPosition(int line, int column, const QModelIndex &rootIndex = QModelIndex()) const;
bool handleDocumentationComment(QKeyEvent *e);
bool isStartOfDoxygenComment(const QTextCursor &cursor) const;
CPlusPlus::CppModelManagerInterface *m_modelManager;
......
......@@ -94,6 +94,12 @@ private slots:
void test_doxygen_comments_qt_style_continuation();
void test_doxygen_comments_java_style();
void test_doxygen_comments_java_style_continuation();
void test_doxygen_comments_cpp_styleA();
void test_doxygen_comments_cpp_styleB();
void test_doxygen_comments_cpp_styleA_indented();
void test_doxygen_comments_cpp_styleA_continuation();
void test_doxygen_comments_cpp_styleA_indented_continuation();
void test_doxygen_comments_cpp_styleA_corner_case();
void test_quickfix_GenerateGetterSetter_basicGetterWithPrefix();
void test_quickfix_GenerateGetterSetter_basicGetterWithoutPrefix();
......
......@@ -245,7 +245,7 @@
<item>
<widget class="QCheckBox" name="leadingAsterisksCheckBox">
<property name="toolTip">
<string>Add leading asterisks when continuing comments on new lines</string>
<string>Add leading asterisks when continuing Qt (/*!) and Java (/**) style comments on new lines</string>
</property>
<property name="text">
<string>Add leading asterisks</string>
......
......@@ -238,7 +238,7 @@ QChar DoxygenGenerator::startMark() const
QChar DoxygenGenerator::styleMark() const
{
if (m_style == QtStyle)
if (m_style == QtStyle || m_style == CppStyleA || m_style == CppStyleB)
return QLatin1Char('\\');
return QLatin1Char('@');
}
......@@ -256,17 +256,31 @@ QString DoxygenGenerator::commandSpelling(Command command)
void DoxygenGenerator::writeStart(QString *comment) const
{
comment->append(offsetString() % QLatin1String("/*") % startMark());
if (m_style == CppStyleA)
comment->append(QLatin1String("///"));
if (m_style == CppStyleB)
comment->append(QLatin1String("//!"));
else
comment->append(offsetString() % QLatin1String("/*") % startMark());
}
void DoxygenGenerator::writeEnd(QString *comment) const
{
comment->append(offsetString() % QLatin1String(" */"));
if (m_style == CppStyleA)
comment->append(QLatin1String("///"));
else if (m_style == CppStyleB)
comment->append(QLatin1String("//!"));
else
comment->append(offsetString() % QLatin1String(" */"));
}
void DoxygenGenerator::writeContinuation(QString *comment) const
{
if (m_addLeadingAsterisks)
if (m_style == CppStyleA)
comment->append(offsetString() % QLatin1String("///"));
else if (m_style == CppStyleB)
comment->append(offsetString() % QLatin1String("//!"));
else if (m_addLeadingAsterisks)
comment->append(offsetString() % QLatin1String(" *"));
else
comment->append(offsetString() % QLatin1String(" "));
......
......@@ -49,8 +49,10 @@ public:
DoxygenGenerator();
enum DocumentationStyle {
JavaStyle,
QtStyle
JavaStyle, ///< JavaStyle comment: /**
QtStyle, ///< QtStyle comment: /*!
CppStyleA, ///< CppStyle comment variant A: ///
CppStyleB ///< CppStyle comment variant B: //!
};
void setStyle(DocumentationStyle style);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment