From a53032d6a597779bc98a5c4d0bff34338dd6395e Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Mon, 25 Feb 2019 22:39:22 +0200 Subject: [PATCH] CppTools: Move code style snippets to a separate header Include it only where used. Resolves many "unused static variable" warnings. Change-Id: Ie1e578d9b9511f963e359d87f7740b4981975dbd Reviewed-by: Christian Stenger --- .../clangformat/clangformatconfigwidget.cpp | 2 +- .../cpptools/cppcodestylesettingspage.cpp | 1 + src/plugins/cpptools/cppcodestylesnippets.h | 190 ++++++++++++++++++ src/plugins/cpptools/cpptools.pro | 1 + src/plugins/cpptools/cpptools.qbs | 1 + src/plugins/cpptools/cpptoolsconstants.h | 158 --------------- 6 files changed, 194 insertions(+), 159 deletions(-) create mode 100644 src/plugins/cpptools/cppcodestylesnippets.h diff --git a/src/plugins/clangformat/clangformatconfigwidget.cpp b/src/plugins/clangformat/clangformatconfigwidget.cpp index 6aa14b9a71a..faaf6d937ff 100644 --- a/src/plugins/clangformat/clangformatconfigwidget.cpp +++ b/src/plugins/clangformat/clangformatconfigwidget.cpp @@ -35,7 +35,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/plugins/cpptools/cppcodestylesettingspage.cpp b/src/plugins/cpptools/cppcodestylesettingspage.cpp index 981a0bda617..ef62ad1fa32 100644 --- a/src/plugins/cpptools/cppcodestylesettingspage.cpp +++ b/src/plugins/cpptools/cppcodestylesettingspage.cpp @@ -26,6 +26,7 @@ #include "cppcodestylesettingspage.h" #include "cppcodestylepreferences.h" +#include "cppcodestylesnippets.h" #include "cpppointerdeclarationformatter.h" #include "cppqtstyleindenter.h" #include "cpptoolsconstants.h" diff --git a/src/plugins/cpptools/cppcodestylesnippets.h b/src/plugins/cpptools/cppcodestylesnippets.h new file mode 100644 index 00000000000..b1f8ce199c5 --- /dev/null +++ b/src/plugins/cpptools/cppcodestylesnippets.h @@ -0,0 +1,190 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +namespace CppTools { +namespace Constants { + +static const char *DEFAULT_CODE_STYLE_SNIPPETS[] + = {"#include \n" + "\n" + "class Complex\n" + " {\n" + "public:\n" + " Complex(double re, double im)\n" + " : _re(re), _im(im)\n" + " {}\n" + " double modulus() const\n" + " {\n" + " return sqrt(_re * _re + _im * _im);\n" + " }\n" + "private:\n" + " double _re;\n" + " double _im;\n" + " };\n" + "\n" + "void bar(int i)\n" + " {\n" + " static int counter = 0;\n" + " counter += i;\n" + " }\n" + "\n" + "namespace Foo\n" + " {\n" + " namespace Bar\n" + " {\n" + " void foo(int a, int b)\n" + " {\n" + " for (int i = 0; i < a; i++)\n" + " {\n" + " if (i < b)\n" + " bar(i);\n" + " else\n" + " {\n" + " bar(i);\n" + " bar(b);\n" + " }\n" + " }\n" + " }\n" + " } // namespace Bar\n" + " } // namespace Foo\n", + "#include \n" + "\n" + "class Complex\n" + " {\n" + "public:\n" + " Complex(double re, double im)\n" + " : _re(re), _im(im)\n" + " {}\n" + " double modulus() const\n" + " {\n" + " return sqrt(_re * _re + _im * _im);\n" + " }\n" + "private:\n" + " double _re;\n" + " double _im;\n" + " };\n" + "\n" + "void bar(int i)\n" + " {\n" + " static int counter = 0;\n" + " counter += i;\n" + " }\n" + "\n" + "namespace Foo\n" + " {\n" + " namespace Bar\n" + " {\n" + " void foo(int a, int b)\n" + " {\n" + " for (int i = 0; i < a; i++)\n" + " {\n" + " if (i < b)\n" + " bar(i);\n" + " else\n" + " {\n" + " bar(i);\n" + " bar(b);\n" + " }\n" + " }\n" + " }\n" + " } // namespace Bar\n" + " } // namespace Foo\n", + "namespace Foo\n" + "{\n" + "namespace Bar\n" + "{\n" + "class FooBar\n" + " {\n" + "public:\n" + " FooBar(int a)\n" + " : _a(a)\n" + " {}\n" + " int calculate() const\n" + " {\n" + " if (a > 10)\n" + " {\n" + " int b = 2 * a;\n" + " return a * b;\n" + " }\n" + " return -a;\n" + " }\n" + "private:\n" + " int _a;\n" + " };\n" + "}\n" + "}\n", + "#include \"bar.h\"\n" + "\n" + "int foo(int a)\n" + " {\n" + " switch (a)\n" + " {\n" + " case 1:\n" + " bar(1);\n" + " break;\n" + " case 2:\n" + " {\n" + " bar(2);\n" + " break;\n" + " }\n" + " case 3:\n" + " default:\n" + " bar(3);\n" + " break;\n" + " }\n" + " return 0;\n" + " }\n", + "void foo() {\n" + " if (a &&\n" + " b)\n" + " c;\n" + "\n" + " while (a ||\n" + " b)\n" + " break;\n" + " a = b +\n" + " c;\n" + " myInstance.longMemberName +=\n" + " foo;\n" + " myInstance.longMemberName += bar +\n" + " foo;\n" + "}\n", + "int *foo(const Bar &b1, Bar &&b2, int*, int *&rpi)\n" + "{\n" + " int*pi = 0;\n" + " int*const*const cpcpi = π\n" + " int*const*pcpi = π\n" + " int**const cppi = π\n" + "\n" + " void (*foo)(char *s) = 0;\n" + " int (*bar)[] = 0;\n" + "\n" + " return pi;\n" + "}\n"}; + +} // namespace Constants +} // namespace CppTools diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro index a55e805af4e..04b7ce1adcc 100644 --- a/src/plugins/cpptools/cpptools.pro +++ b/src/plugins/cpptools/cpptools.pro @@ -26,6 +26,7 @@ HEADERS += \ cppcodestylepreferencesfactory.h \ cppcodestylesettings.h \ cppcodestylesettingspage.h \ + cppcodestylesnippets.h \ cppcompletionassist.h \ cppcompletionassistprocessor.h \ cppcompletionassistprovider.h \ diff --git a/src/plugins/cpptools/cpptools.qbs b/src/plugins/cpptools/cpptools.qbs index 89062d3a21c..85e086ddf92 100644 --- a/src/plugins/cpptools/cpptools.qbs +++ b/src/plugins/cpptools/cpptools.qbs @@ -82,6 +82,7 @@ Project { "cppcodestylesettingspage.cpp", "cppcodestylesettingspage.h", "cppcodestylesettingspage.ui", + "cppcodestylesnippets.h", "cppcompletionassist.cpp", "cppcompletionassist.h", "cppcompletionassistprocessor.cpp", diff --git a/src/plugins/cpptools/cpptoolsconstants.h b/src/plugins/cpptools/cpptoolsconstants.h index 781f5ebdf89..2e1aebfd432 100644 --- a/src/plugins/cpptools/cpptoolsconstants.h +++ b/src/plugins/cpptools/cpptoolsconstants.h @@ -105,163 +105,5 @@ constexpr const char TIDY_DOCUMENTATION_URL_TEMPLATE[] constexpr const char CLAZY_DOCUMENTATION_URL_TEMPLATE[] = "https://github.com/KDE/clazy/blob/master/docs/checks/README-%1.md"; -static const char *DEFAULT_CODE_STYLE_SNIPPETS[] - = {"#include \n" - "\n" - "class Complex\n" - " {\n" - "public:\n" - " Complex(double re, double im)\n" - " : _re(re), _im(im)\n" - " {}\n" - " double modulus() const\n" - " {\n" - " return sqrt(_re * _re + _im * _im);\n" - " }\n" - "private:\n" - " double _re;\n" - " double _im;\n" - " };\n" - "\n" - "void bar(int i)\n" - " {\n" - " static int counter = 0;\n" - " counter += i;\n" - " }\n" - "\n" - "namespace Foo\n" - " {\n" - " namespace Bar\n" - " {\n" - " void foo(int a, int b)\n" - " {\n" - " for (int i = 0; i < a; i++)\n" - " {\n" - " if (i < b)\n" - " bar(i);\n" - " else\n" - " {\n" - " bar(i);\n" - " bar(b);\n" - " }\n" - " }\n" - " }\n" - " } // namespace Bar\n" - " } // namespace Foo\n", - "#include \n" - "\n" - "class Complex\n" - " {\n" - "public:\n" - " Complex(double re, double im)\n" - " : _re(re), _im(im)\n" - " {}\n" - " double modulus() const\n" - " {\n" - " return sqrt(_re * _re + _im * _im);\n" - " }\n" - "private:\n" - " double _re;\n" - " double _im;\n" - " };\n" - "\n" - "void bar(int i)\n" - " {\n" - " static int counter = 0;\n" - " counter += i;\n" - " }\n" - "\n" - "namespace Foo\n" - " {\n" - " namespace Bar\n" - " {\n" - " void foo(int a, int b)\n" - " {\n" - " for (int i = 0; i < a; i++)\n" - " {\n" - " if (i < b)\n" - " bar(i);\n" - " else\n" - " {\n" - " bar(i);\n" - " bar(b);\n" - " }\n" - " }\n" - " }\n" - " } // namespace Bar\n" - " } // namespace Foo\n", - "namespace Foo\n" - "{\n" - "namespace Bar\n" - "{\n" - "class FooBar\n" - " {\n" - "public:\n" - " FooBar(int a)\n" - " : _a(a)\n" - " {}\n" - " int calculate() const\n" - " {\n" - " if (a > 10)\n" - " {\n" - " int b = 2 * a;\n" - " return a * b;\n" - " }\n" - " return -a;\n" - " }\n" - "private:\n" - " int _a;\n" - " };\n" - "}\n" - "}\n", - "#include \"bar.h\"\n" - "\n" - "int foo(int a)\n" - " {\n" - " switch (a)\n" - " {\n" - " case 1:\n" - " bar(1);\n" - " break;\n" - " case 2:\n" - " {\n" - " bar(2);\n" - " break;\n" - " }\n" - " case 3:\n" - " default:\n" - " bar(3);\n" - " break;\n" - " }\n" - " return 0;\n" - " }\n", - "void foo() {\n" - " if (a &&\n" - " b)\n" - " c;\n" - "\n" - " while (a ||\n" - " b)\n" - " break;\n" - " a = b +\n" - " c;\n" - " myInstance.longMemberName +=\n" - " foo;\n" - " myInstance.longMemberName += bar +\n" - " foo;\n" - "}\n", - "int *foo(const Bar &b1, Bar &&b2, int*, int *&rpi)\n" - "{\n" - " int*pi = 0;\n" - " int*const*const cpcpi = π\n" - " int*const*pcpi = π\n" - " int**const cppi = π\n" - "\n" - " void (*foo)(char *s) = 0;\n" - " int (*bar)[] = 0;\n" - "\n" - " return pi;\n" - "}\n"}; - } // namespace Constants } // namespace CppTools