cpppointerdeclarationformatter_test.cpp 23.5 KB
Newer Older
1 2
/****************************************************************************
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/

30
#include "cpppointerdeclarationformatter.h"
31
#include "cpptoolsplugin.h"
32 33
#include "cpptoolsplugin.h"
#include "cpptoolstestcase.h"
34

35 36 37
#include <coreplugin/coreconstants.h>

#include <texteditor/basetexteditor.h>
38
#include <texteditor/plaintexteditorfactory.h>
39

40 41
#include <utils/fileutils.h>

42 43
#include <cplusplus/pp.h>

44 45 46 47 48 49 50 51 52 53 54 55
#include <QDebug>
#include <QDir>
#include <QTextCursor>
#include <QTextDocument>
#include <QtTest>

using namespace CPlusPlus;
using namespace CppTools;
using namespace CppTools::Internal;

Q_DECLARE_METATYPE(Overview)

56 57 58
namespace {

QString stripCursor(const QString &source)
59 60 61 62 63 64 65 66 67 68
{
    QString copy(source);
    const int pos = copy.indexOf(QLatin1Char('@'));
    if (pos != -1)
        copy.remove(pos, 1);
    else
        qDebug() << Q_FUNC_INFO << "Warning: No cursor marker to strip.";
    return copy;
}

69
class PointerDeclarationFormatterTestCase : public CppTools::Tests::TestCase
70
{
71
public:
72 73 74 75
    PointerDeclarationFormatterTestCase(const QByteArray &source,
                                        const QString &expectedSource,
                                        Document::ParseMode parseMode,
                                        PointerDeclarationFormatter::CursorHandling cursorHandling)
76
    {
77 78
        QVERIFY(succeededSoFar());

79 80 81 82 83 84 85 86 87 88 89
        // Find cursor position and remove cursor marker '@'
        int cursorPosition = 0;
        QString sourceWithoutCursorMarker = QLatin1String(source);
        const int pos = sourceWithoutCursorMarker.indexOf(QLatin1Char('@'));
        if (pos != -1) {
            sourceWithoutCursorMarker.remove(pos, 1);
            cursorPosition = pos;
        }

        // Write source to temprorary file
        const QString filePath = QDir::tempPath() + QLatin1String("/file.h");
90
        Document::Ptr document = Document::create(filePath);
91
        QVERIFY(writeFile(document->fileName(), sourceWithoutCursorMarker.toUtf8()));
92 93

        // Preprocess source
94 95
        Environment env;
        Preprocessor preprocess(0, &env);
96 97
        const QByteArray preprocessedSource = preprocess.run(filePath, sourceWithoutCursorMarker);

98 99 100
        document->setUtf8Source(preprocessedSource);
        document->parse(parseMode);
        document->check();
101
        QVERIFY(document->diagnosticMessages().isEmpty());
102 103 104 105
        AST *ast = document->translationUnit()->ast();
        QVERIFY(ast);

        // Open file
106
        TextEditor::BaseTextEditor *editor = TextEditor::PlainTextEditorFactory::createPlainTextEditor();
107
        QString error;
108
        editor->open(&error, document->fileName(), document->fileName());
109
        QVERIFY(error.isEmpty());
110 111

        // Set cursor position
112
        QTextCursor cursor = editor->textCursor();
113
        cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, cursorPosition);
114
        editor->setTextCursor(cursor);
115

116
        QTextDocument *qtextDocument = editor->qdocument();
117
        CppRefactoringFilePtr cppRefactoringFile
118
            = CppRefactoringChanges::file(editor->editorWidget(), document);
119

120
        // Prepare for formatting
121 122 123 124 125 126
        Overview overview;
        overview.showReturnTypes = true;
        overview.showArgumentNames = true;
        overview.starBindFlags = Overview::StarBindFlags(0);

        // Run the formatter
127
        PointerDeclarationFormatter formatter(cppRefactoringFile, overview, cursorHandling);
Orgad Shaneh's avatar
Orgad Shaneh committed
128
        Utils::ChangeSet change = formatter.format(ast); // ChangeSet may be empty.
129 130

        // Apply change
131
        QTextCursor changeCursor(qtextDocument);
132
        change.apply(&changeCursor);
133

134
        // Compare
135
        QCOMPARE(qtextDocument->toPlainText(), expectedSource);
136
    }
137 138
};

139 140
} // anonymous namespace

141 142 143 144 145
void CppToolsPlugin::test_format_pointerdeclaration_in_simpledeclarations()
{
    QFETCH(QString, source);
    QFETCH(QString, reformattedSource);

146
    PointerDeclarationFormatterTestCase(source.toUtf8(),
147 148 149
                                        reformattedSource,
                                        Document::ParseDeclaration,
                                        PointerDeclarationFormatter::RespectCursor);
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
}

void CppToolsPlugin::test_format_pointerdeclaration_in_simpledeclarations_data()
{
    QTest::addColumn<QString>("source");
    QTest::addColumn<QString>("reformattedSource");

    QString source;

    //
    // Naming scheme for the test cases: <description>_(in|out)-(start|middle|end)
    //   in/out:
    //      Denotes whether the cursor is in or out of the quickfix activation range
    //   start/middle/end:
    //      Denotes whether is cursor is near to the range start, middle or end
    //

    QTest::newRow("basic_in-start")
        << "@char *s;"
        << "char * s;";

    source = QLatin1String("char *s;@");
    QTest::newRow("basic_out-end")
        << source << stripCursor(source);

    QTest::newRow("basic_in-end")
        << "char *s@;"
        << "char * s;";

    QTest::newRow("basic-with-ws_in-start")
        << "\n  @char *s;  " // Add some whitespace to check position detection.
        << "\n  char * s;  ";

    source = QLatin1String("\n @ char *s;  ");
    QTest::newRow("basic-with-ws_out-start")
        << source << stripCursor(source);

    QTest::newRow("basic-with-const_in-start")
        << "@const char *s;"
        << "const char * s;";

    QTest::newRow("basic-with-const-and-init-value_in-end")
        << "const char *s@ = 0;"
        << "const char * s = 0;";

    source = QLatin1String("const char *s @= 0;");
    QTest::newRow("basic-with-const-and-init-value_out-end")
        << source << stripCursor(source);

    QTest::newRow("first-declarator_in-start")
        << "@const char *s, *t;"
        << "const char * s, *t;";

    QTest::newRow("first-declarator_in-end")
        << "const char *s@, *t;"
        << "const char * s, *t;";

    source = QLatin1String("const char *s,@ *t;");
    QTest::newRow("first-declarator_out-end")
        << source << stripCursor(source);

    QTest::newRow("function-declaration-param_in-start")
        << "int f(@char *s);"
        << "int f(char * s);";

    QTest::newRow("function-declaration-param_in-end")
        << "int f(char *s@);"
        << "int f(char * s);";

    QTest::newRow("function-declaration-param_in-end")
        << "int f(char *s@ = 0);"
        << "int f(char * s = 0);";

    QTest::newRow("function-declaration-param-multiple-params_in-end")
        << "int f(char *s@, int);"
        << "int f(char * s, int);";

    source = QLatin1String("int f(char *s)@;");
    QTest::newRow("function-declaration-param_out-end")
        << source << stripCursor(source);

    source = QLatin1String("int f@(char *s);");
    QTest::newRow("function-declaration-param_out-start")
        << source << stripCursor(source);

    source = QLatin1String("int f(char *s =@ 0);");
    QTest::newRow("function-declaration-param_out-end")
        << source << stripCursor(source);

    // Function definitions are handled by the same code as function
    // declarations, so just check a minimal example.
    QTest::newRow("function-definition-param_in-middle")
        << "int f(char @*s) {}"
        << "int f(char * s) {}";

    QTest::newRow("function-declaration-returntype_in-start")
        << "@char *f();"
        << "char * f();";

    QTest::newRow("function-declaration-returntype_in-end")
        << "char *f@();"
        << "char * f();";

    source = QLatin1String("char *f(@);");
    QTest::newRow("function-declaration-returntype_out-end")
        << source << stripCursor(source);

    QTest::newRow("function-definition-returntype_in-end")
        << "char *f@() {}"
        << "char * f() {}";

    QTest::newRow("function-definition-returntype_in-start")
        << "@char *f() {}"
        << "char * f() {}";

    source = QLatin1String("char *f(@) {}");
    QTest::newRow("function-definition-returntype_out-end")
        << source << stripCursor(source);

    source = QLatin1String("inline@ char *f() {}");
    QTest::newRow("function-definition-returntype-inline_out-start")
        << source << stripCursor(source);

    // Same code is also used for for other specifiers like virtual, inline, friend, ...
    QTest::newRow("function-definition-returntype-static-inline_in-start")
        << "static inline @char *f() {}"
        << "static inline char * f() {}";

    QTest::newRow("function-declaration-returntype-static-inline_in-start")
        << "static inline @char *f();"
        << "static inline char * f();";

    source = QLatin1String("static inline@ char *f() {}");
    QTest::newRow("function-definition-returntype-static-inline_out-start")
        << source << stripCursor(source);

    QTest::newRow("function-declaration-returntype-static-custom-type_in-start")
        << "static @CustomType *f();"
        << "static CustomType * f();";

    source = QLatin1String("static@ CustomType *f();");
    QTest::newRow("function-declaration-returntype-static-custom-type_out-start")
        << source << stripCursor(source);

    QTest::newRow("function-declaration-returntype-symbolvisibilityattributes_in-start")
        << "__attribute__((visibility(\"default\"))) @char *f();"
        << "__attribute__((visibility(\"default\"))) char * f();";

    source = QLatin1String("@__attribute__((visibility(\"default\"))) char *f();");
    QTest::newRow("function-declaration-returntype-symbolvisibilityattributes_out-start")
        << source << stripCursor(source);

    // The following two are not supported at the moment.
    source = QLatin1String("@char * __attribute__((visibility(\"default\"))) f();");
    QTest::newRow("function-declaration-returntype-symbolvisibilityattributes_out-start")
        << source << stripCursor(source);

    source = QLatin1String("@char * __attribute__((visibility(\"default\"))) f() {}");
    QTest::newRow("function-definition-returntype-symbolvisibilityattributes_out-start")
        << source << stripCursor(source);

    // NOTE: Since __declspec() is not parsed (but defined to nothing),
    // we can't detect it properly. Therefore, we fail on code with
    // FOO_EXPORT macros with __declspec() for pointer return types;

    QTest::newRow("typedef_in-start")
        << "typedef @char *s;"
        << "typedef char * s;";

    source = QLatin1String("@typedef char *s;");
    QTest::newRow("typedef_out-start")
        << source << stripCursor(source);

    QTest::newRow("static_in-start")
        << "static @char *s;"
        << "static char * s;";

    QTest::newRow("pointerToFunction_in-start")
        << "int (*bar)(@char *s);"
        << "int (*bar)(char * s);";

    source = QLatin1String("int (@*bar)();");
    QTest::newRow("pointerToFunction_in-start")
        << source << stripCursor(source);

    source = QLatin1String("int (@*bar)[] = 0;");
    QTest::newRow("pointerToArray_in-start")
        << source << stripCursor(source);

    //
    // Additional test cases that does not fit into the naming scheme
    //

    // The following case is a side effect of the reformatting. Though
    // the pointer type is according to the overview, the double space
    // before 'char' gets corrected.
    QTest::newRow("remove-extra-whitespace")
        << "@const  char * s = 0;"
        << "const char * s = 0;";

    // Nothing to pretty print since no pointer or references are involved.
    source = QLatin1String("@char  bla;"); // Two spaces to get sure nothing is reformatted.
    QTest::newRow("precondition-fail-no-pointer")
        << source << stripCursor(source);
354 355

    // Respect white space within operator names
356
    QTest::newRow("operators1")
357 358
        << "class C { C@&operator = (const C &); };"
        << "class C { C & operator = (const C &); };";
359 360 361 362

    QTest::newRow("operators2")
        << "C &C::operator = (const C &) {}"
        << "C & C::operator = (const C &) {}";
363 364 365 366 367 368 369
}

void CppToolsPlugin::test_format_pointerdeclaration_in_controlflowstatements()
{
    QFETCH(QString, source);
    QFETCH(QString, reformattedSource);

370
    PointerDeclarationFormatterTestCase(source.toUtf8(),
371 372 373
                                        reformattedSource,
                                        Document::ParseStatement,
                                        PointerDeclarationFormatter::RespectCursor);
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
}

void CppToolsPlugin::test_format_pointerdeclaration_in_controlflowstatements_data()
{
    QTest::addColumn<QString>("source");
    QTest::addColumn<QString>("reformattedSource");

    QString source;

    //
    // Same naming scheme as in test_format_pointerdeclaration_in_simpledeclarations_data()
    //

    QTest::newRow("if_in-start")
        << "if (@char *s = 0);"
        << "if (char * s = 0);";

    source = QLatin1String("if @(char *s = 0);");
    QTest::newRow("if_out-start")
        << source << stripCursor(source);

    QTest::newRow("if_in-end")
        << "if (char *s@ = 0);"
        << "if (char * s = 0);";

    source = QLatin1String("if (char *s @= 0);");
    QTest::newRow("if_out-end")
        << source << stripCursor(source);

    // if and for statements are handled by the same code, so just
    // check minimal examples for these
    QTest::newRow("while")
        << "while (@char *s = 0);"
        << "while (char * s = 0);";

    QTest::newRow("for")
        << "for (;@char *s = 0;);"
        << "for (;char * s = 0;);";

    // Should also work since it's a simple declaration
    // for (char *s = 0; true;);

    QTest::newRow("foreach_in-start")
        << "foreach (@char *s, list);"
        << "foreach (char * s, list);";

    source = QLatin1String("foreach @(char *s, list);");
    QTest::newRow("foreach-out-start")
        << source << stripCursor(source);

    QTest::newRow("foreach_in_end")
        << "foreach (const char *s@, list);"
        << "foreach (const char * s, list);";

    source = QLatin1String("foreach (const char *s,@ list);");
    QTest::newRow("foreach_out_end")
        << source << stripCursor(source);

    //
    // Additional test cases that does not fit into the naming scheme
    //

    source = QLatin1String("@if (char  s = 0);"); // Two spaces to get sure nothing is reformatted.
    QTest::newRow("precondition-fail-no-pointer") << source << stripCursor(source);
}

void CppToolsPlugin::test_format_pointerdeclaration_multiple_declarators()
{
    QFETCH(QString, source);
    QFETCH(QString, reformattedSource);

445
    PointerDeclarationFormatterTestCase(source.toUtf8(),
446 447 448
                                        reformattedSource,
                                        Document::ParseDeclaration,
                                        PointerDeclarationFormatter::RespectCursor);
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
}

void CppToolsPlugin::test_format_pointerdeclaration_multiple_declarators_data()
{
    QTest::addColumn<QString>("source");
    QTest::addColumn<QString>("reformattedSource");

    QString source;

    QTest::newRow("function-declaration_in-start")
        << "char *s = 0, @*f(int i) = 0;"
        << "char *s = 0, * f(int i) = 0;";

    QTest::newRow("non-pointer-before_in-start")
        << "char c, @*t;"
        << "char c, * t;";

    QTest::newRow("pointer-before_in-start")
        << "char *s, @*t;"
        << "char *s, * t;";

    QTest::newRow("pointer-before_in-end")
        << "char *s, *t@;"
        << "char *s, * t;";

    source = QLatin1String("char *s,@ *t;");
    QTest::newRow("md1-out_start")
        << source << stripCursor(source);

    source = QLatin1String("char *s, *t;@");
    QTest::newRow("md1-out_end")
        << source << stripCursor(source);

    QTest::newRow("non-pointer-after_in-start")
        << "char c, @*t, d;"
        << "char c, * t, d;";

    QTest::newRow("pointer-after_in-start")
        << "char c, @*t, *d;"
        << "char c, * t, *d;";

    QTest::newRow("function-pointer_in-start")
        << "char *s, @*(*foo)(char *s) = 0;"
        << "char *s, *(*foo)(char * s) = 0;";
}

void CppToolsPlugin::test_format_pointerdeclaration_multiple_matches()
{
    QFETCH(QString, source);
    QFETCH(QString, reformattedSource);

500
    PointerDeclarationFormatterTestCase(source.toUtf8(),
501 502 503
                                        reformattedSource,
                                        Document::ParseTranlationUnit,
                                        PointerDeclarationFormatter::IgnoreCursor);
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
}

void CppToolsPlugin::test_format_pointerdeclaration_multiple_matches_data()
{
    QTest::addColumn<QString>("source");
    QTest::addColumn<QString>("reformattedSource");

    QTest::newRow("rvalue-reference")
        << "int g(Bar&&c) {}"
        << "int g(Bar && c) {}";

    QTest::newRow("if2")
        << "int g() { if (char *s = 0) { char *t = 0; } }"
        << "int g() { if (char * s = 0) { char * t = 0; } }";

    QTest::newRow("if1")
        << "int g() { if (int i = 0) { char *t = 0; } }"
        << "int g() { if (int i = 0) { char * t = 0; } }";

    QTest::newRow("for1")
        << "int g() { for (char *s = 0; char *t = 0; s++); }"
        << "int g() { for (char * s = 0; char * t = 0; s++); }";

    QTest::newRow("for2")
        << "int g() { for (char *s = 0; char *t = 0; s++) { char *u = 0; } }"
        << "int g() { for (char * s = 0; char * t = 0; s++) { char * u = 0; } }";

    QTest::newRow("for3")
        << "int g() { for (char *s; char *t = 0; s++) { char *u = 0; } }"
        << "int g() { for (char * s; char * t = 0; s++) { char * u = 0; } }";

    QTest::newRow("multiple-declarators")
        << "const char c, *s, *(*foo)(char *s) = 0;"
        << "const char c, * s, *(*foo)(char * s) = 0;";

    QTest::newRow("complex")
        <<
            "int *foo(const int &b, int*, int *&rpi)\n"
            "{\n"
            "    int*pi = 0;\n"
            "    int*const*const cpcpi = &pi;\n"
            "    int*const*pcpi = &pi;\n"
            "    int**const cppi = &pi;\n"
            "\n"
            "    void (*foo)(char *s) = 0;\n"
            "    int (*bar)[] = 0;\n"
            "\n"
            "    char *s = 0, *f(int i) = 0;\n"
            "    const char c, *s, *(*foo)(char *s) = 0;"
            "\n"
            "    for (char *s; char *t = 0; s++) { char *u = 0; }"
            "\n"
            "    return 0;\n"
            "}\n"
        <<
           "int * foo(const int & b, int *, int *& rpi)\n"
           "{\n"
           "    int * pi = 0;\n"
           "    int * const * const cpcpi = &pi;\n"
           "    int * const * pcpi = &pi;\n"
           "    int ** const cppi = &pi;\n"
           "\n"
           "    void (*foo)(char * s) = 0;\n"
           "    int (*bar)[] = 0;\n"
           "\n"
           "    char * s = 0, * f(int i) = 0;\n"
           "    const char c, * s, *(*foo)(char * s) = 0;"
           "\n"
           "    for (char * s; char * t = 0; s++) { char * u = 0; }"
           "\n"
           "    return 0;\n"
           "}\n";
}
577 578 579 580 581 582

void CppToolsPlugin::test_format_pointerdeclaration_macros()
{
    QFETCH(QString, source);
    QFETCH(QString, reformattedSource);

583
    PointerDeclarationFormatterTestCase(source.toUtf8(),
584 585 586
                                        reformattedSource,
                                        Document::ParseTranlationUnit,
                                        PointerDeclarationFormatter::RespectCursor);
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
}

void CppToolsPlugin::test_format_pointerdeclaration_macros_data()
{
    QTest::addColumn<QString>("source");
    QTest::addColumn<QString>("reformattedSource");

    QString source;

    source = QLatin1String(
        "#define FOO int*\n"
        "FOO @bla;\n");
    QTest::newRow("macro-in-simple-declaration")
        << source << stripCursor(source);

    source = QLatin1String(
        "#define FOO int*\n"
        "FOO @f();\n");
    QTest::newRow("macro-in-function-declaration-returntype")
        << source << stripCursor(source);

    source = QLatin1String(
        "#define FOO int*\n"
        "int f(@FOO a);\n");
    QTest::newRow("macro-in-function-declaration-param")
        << source << stripCursor(source);

    source = QLatin1String(
        "#define FOO int*\n"
616
        "FOO @f() {}\n");
617 618 619 620 621
    QTest::newRow("macro-in-function-definition-returntype")
        << source << stripCursor(source);

    source = QLatin1String(
        "#define FOO int*\n"
622
        "int f(FOO @a) {}\n");
623 624 625 626 627
    QTest::newRow("macro-in-function-definition-param")
        << source << stripCursor(source);

    source = QLatin1String(
        "#define FOO int*\n"
628
        "void f() { while (FOO @s = 0) {} }\n");
629 630 631 632 633
    QTest::newRow("macro-in-if-while-for")
        << source << stripCursor(source);

    source = QLatin1String(
        "#define FOO int*\n"
634
        "void f() { foreach (FOO @s, list) {} }\n");
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
    QTest::newRow("macro-in-foreach")
        << source << stripCursor(source);

    // The bug was that we got "Reformat to 'QMetaObject staticMetaObject'"
    // at the cursor position below, which was completelty wrong.
    QTest::newRow("wrong-reformat-suggestion")
        <<
           "#define Q_OBJECT \\\n"
           "public: \\\n"
           "    template <typename T> inline void qt_check_for_QOBJECT_macro(T &_q_argument) \\\n"
           "        { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i; } \\\n"
           "    QMetaObject staticMetaObject; \\\n"
           "    void *qt_metacast(const char *); \\\n"
           "    static inline QString tr(const char *s, const char *f = 0); \\\n"
           " \n"
           "class KitInformation\n"
           "{\n"
           "    Q_OBJECT\n"
           "public:\n"
           "    typedef QPair<QString, QString> Item;\n"
           " \n"
           "    Core::Id dataId(); // the higher the closer to top.\n"
           " \n"
           "    unsigned int priority() = 0;\n"
           " \n"
           "    QVariant defaultValue(Kit@*) = 0;\n"
           "};\n"
        <<
           "#define Q_OBJECT \\\n"
           "public: \\\n"
           "    template <typename T> inline void qt_check_for_QOBJECT_macro(T &_q_argument) \\\n"
           "        { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i; } \\\n"
           "    QMetaObject staticMetaObject; \\\n"
           "    void *qt_metacast(const char *); \\\n"
           "    static inline QString tr(const char *s, const char *f = 0); \\\n"
           " \n"
           "class KitInformation\n"
           "{\n"
           "    Q_OBJECT\n"
           "public:\n"
           "    typedef QPair<QString, QString> Item;\n"
           " \n"
           "    Core::Id dataId(); // the higher the closer to top.\n"
           " \n"
           "    unsigned int priority() = 0;\n"
           " \n"
           "    QVariant defaultValue(Kit *) = 0;\n"
           "};\n";
}