From c6d326c0bf2e2b1a7987fbf28f4ac0421ff1766f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= <thorbjorn.lindeijer@nokia.com> Date: Fri, 20 Mar 2009 17:01:16 +0100 Subject: [PATCH] Some fixes to the new class wizard code generation * Convert dots in filenames to underscores in header guards * Don't indent closing namespaces in source file * Consistent empty line placement --- src/libs/utils/codegeneration.cpp | 4 +++- src/plugins/cppeditor/cppclasswizard.cpp | 17 ++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/libs/utils/codegeneration.cpp b/src/libs/utils/codegeneration.cpp index 14448ea4b75..7e019b67c22 100644 --- a/src/libs/utils/codegeneration.cpp +++ b/src/libs/utils/codegeneration.cpp @@ -41,11 +41,14 @@ static QString toAlphaNum(const QString &s) QString rc; const int len = s.size(); const QChar underscore = QLatin1Char('_'); + const QChar dot = QLatin1Char('.'); for (int i = 0; i < len; i++) { const QChar c = s.at(i); if (c == underscore || c.isLetterOrNumber()) rc += c; + else if (c == dot) + rc += underscore; } return rc; } @@ -80,7 +83,6 @@ QString writeOpeningNameSpaces(const QStringList &l, const QString &indent, str << rc << "namespace " << l.at(i) << " {\n"; rc += indent; } - str << '\n'; } return rc; } diff --git a/src/plugins/cppeditor/cppclasswizard.cpp b/src/plugins/cppeditor/cppclasswizard.cpp index d56875e213c..ad574af51f1 100644 --- a/src/plugins/cppeditor/cppclasswizard.cpp +++ b/src/plugins/cppeditor/cppclasswizard.cpp @@ -230,19 +230,20 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par // == Header file == QTextStream headerStr(header); headerStr << "#ifndef " << guard - << "\n#define " << guard << '\n' << '\n'; + << "\n#define " << guard << '\n'; const QRegExp qtClassExpr(QLatin1String("^Q[A-Z3].+")); QTC_ASSERT(qtClassExpr.isValid(), /**/); const bool superIsQtClass = qtClassExpr.exactMatch(params.baseClass); if (superIsQtClass) { - Core::Utils::writeIncludeFileDirective(params.baseClass, true, headerStr); headerStr << '\n'; + Core::Utils::writeIncludeFileDirective(params.baseClass, true, headerStr); } - const QString namespaceIndent = Core::Utils::writeOpeningNameSpaces(namespaceList, 0, headerStr); + const QString namespaceIndent = Core::Utils::writeOpeningNameSpaces(namespaceList, QString(), headerStr); // Class declaration + headerStr << '\n'; headerStr << namespaceIndent << "class " << unqualifiedClassName; if (!params.baseClass.isEmpty()) headerStr << " : public " << params.baseClass << "\n"; @@ -251,21 +252,23 @@ bool CppClassWizard::generateHeaderAndSource(const CppClassWizardParameters &par headerStr << namespaceIndent << "{\n"; headerStr << namespaceIndent << "public:\n" << namespaceIndent << indent << unqualifiedClassName << "();\n"; - headerStr << namespaceIndent << "};\n\n"; + headerStr << namespaceIndent << "};\n"; + + Core::Utils::writeClosingNameSpaces(namespaceList, QString(), headerStr); - Core::Utils::writeClosingNameSpaces(namespaceList, 0, headerStr); + headerStr << '\n'; headerStr << "#endif // "<< guard << '\n'; // == Source file == QTextStream sourceStr(source); Core::Utils::writeIncludeFileDirective(params.headerFile, false, sourceStr); - Core::Utils::writeOpeningNameSpaces(namespaceList, 0, sourceStr); + Core::Utils::writeOpeningNameSpaces(namespaceList, QString(), sourceStr); // Constructor sourceStr << '\n' << namespaceIndent << unqualifiedClassName << "::" << unqualifiedClassName << "()\n"; sourceStr << namespaceIndent << "{\n" << namespaceIndent << "}\n"; - Core::Utils::writeClosingNameSpaces(namespaceList, indent, sourceStr); + Core::Utils::writeClosingNameSpaces(namespaceList, QString(), sourceStr); return true; } -- GitLab