Commit Graph

285 Commits

Author SHA1 Message Date
Christian Stenger
1e0b82e77d CppEditor: Fix possible wrong location for function definitions
Having no namespace when inserting generated functions may insert
explicitly at the end of a header which is not always desired as we
need to take care of e.g. header guards as well.

Change-Id: I3b154ae936a96f2f8e7e34cda6b5bcdfcbc83faf
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-07-16 11:11:58 +00:00
Christian Kandeler
9fa1286faf CppEditor: Ensure "inline" specifier
... when creating functions in header files. Otherwise, we will likely
cause linker failures in non-trivial projects.

Fixes: QTCREATORBUG-15052
Change-Id: Ic0fff8779ba924f8b9943ab233a0cda409e73e9d
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-07-15 08:04:43 +00:00
Christian Kandeler
bfd49fe5ce CppEditor: Ensure proper namespace for new getter/setter functions
If the class is in a namespace and the cpp file does not yet have any
implementations in that namespace, then we would erroneously put the
getters in the global namespace.

Fixes: QTCREATORBUG-14886
Change-Id: I836537abddfdd92ced783d60e1226b082bbc238e
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-07-14 14:32:40 +00:00
hjk
5937fa009f CppEditor: Avoid a use of QCharRef to make it compile with Qt6
Task-number: QTCREATORBUG-24098
Change-Id: If857b6e473f7df7303621695ffc0a66ad777bd7c
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
2020-07-14 05:56:45 +00:00
Christian Kandeler
e210bcf3eb CppEditor: Offer to create getters and setters for all class members
Fixes: QTCREATORBUG-14504
Change-Id: I12c687492b12c6997064eb7f137b6ccb189d2009
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-07-10 08:07:16 +00:00
Christian Kandeler
5b3aece387 CppEditor: Make "Add curly braces" quickfix more robust
Anchor the opening brace at the closing parenthesis, rather than at the
statement. This way, we won't get troubled by macro weirdness in the
statement part.

Fixes: QTCREATORBUG-13921
Change-Id: I05af24d1642e6b62c78bb2f47a1ef0b1fea326d0
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-07-07 14:13:37 +00:00
Christian Kandeler
11a7ccb865 CppEditor: Relax soft assert
The look-up results are ordered by precedence and we can just use the
first one; there doesn't seem to be a reason that additional results
should stop the operation.

Fixes: QTCREATORBUG-14531
Change-Id: Ibe12f975f87ae0d526299219ff54492bef34065c
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-07-06 08:42:51 +00:00
Christian Kandeler
e100939ba7 CppEditor: Extend "Add Include" quickfix
... so it works for all kinds of symbols, not just Qt classes.

Fixes: QTCREATORBUG-21
Change-Id: I2d329c09b64cd8f7eef8cce7d9f022aca8586c0d
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-06-05 14:56:21 +00:00
Christian Kandeler
d811e7773f CppEditor: Do not treat friend declaration as member function
... when trying to create definitions from declarations.
Instead, we completely ignore friends in this context, arguing that the
respective function normally should have a proper declaration somewhere
else.

Fixes: QTCREATORBUG-7164
Change-Id: I3ddb89cefecbc494f9c7e63600b65fd6288b7169
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2020-06-05 14:51:18 +00:00
Christian Kandeler
9e08ecb816 CppEditor: Fix access to dangling pointer
Found by coverity.

Change-Id: I4b73af9b22b80953b4ba6c1004884862c9bdd3b8
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2020-06-04 07:20:50 +00:00
Christian Kandeler
c8d7c074f5 CppEditor: Consider namespaces in "extract function" quickfix
Fixes: QTCREATORBUG-23256
Change-Id: I99b1271907767c3607e35adb49bd4109f3eca18c
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2020-05-29 09:02:49 +00:00
Christian Kandeler
6c4b8b10b7 CppEditor: Add quickfix for creating a forward declaration
In header files, a forward declaration is often preferable to including
another header file, so let's offer this as a quickfix.

Fixes: QTCREATORBUG-23444
Change-Id: Ib50550abb5337098e4122e65e2af42a66742d6f6
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2020-05-27 13:25:19 +00:00
Eike Ziller
0f30adcc8c Merge remote-tracking branch 'origin/4.11'
Change-Id: I949f4f63abe12e11c4598c98295bfccc82e0ebdb
2020-01-09 11:18:44 +01:00
David Schulz
1ab9dc9464 CppEditor: generate valid code via "Convert to Pointer/Stack Variable"
Adding a "= new <TypeName>" after converting a stack variable without
assignment or initializer to pointer.
Also remove the assignment when converting from pointer to stack
variable as this works better with explicit constructors.

Fixes: QTCREATORBUG-23181
Change-Id: I377ec32a1b66cf4b96db14cfcb4b71fb96c80c98
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-01-08 09:21:25 +00:00
hjk
e109b731ad Utils: Rename FilePathList to simply FilePaths
The exact storage type does not really matter here.

Change-Id: Iefec40f0f5909c8e7ba3415db4a11962694e1b38
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2019-12-18 08:43:18 +00:00
Nikolai Kosjar
d337d03ce1 CppEditor: Simplify
bugprone-branch-clone
readability-simplify-boolean-expr

Change-Id: Id30a155e224370713d23b4b534fb82f5e630f36c
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2019-11-01 09:21:29 +00:00
Nikolai Kosjar
c2d36c9387 CppEditor: Fix reference to temporary
Change-Id: I3e2d7cb046e645e03ce5da7f18c48d6ce05fc76a
Reviewed-by: hjk <hjk@qt.io>
2019-08-01 08:14:06 +00:00
Antonio Di Monaco
545b0537ae Skip pure virtual functions in "Insert Definition From Declaration"
Pure virtual functions do not need a definition.

The issue is that, when the codebase is very huge (hundreds of thousands
of files), the match method starts exploring the whole codebase,
searching for an already present definition that will never be found,
so the QuickFix wastes time for nothing and freezes the UI.

Change-Id: Ia17740d740afcb40ec4f1b3237d8b9f5c1e3d54c
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2019-07-29 09:28:02 +00:00
hjk
e3b1106afa Compile fix with recent Qt dev
The reasoning in 1b4766e26c did not take into account that the scope
of QT_NO_JAVA_STYLE_ITERATORS may change over time, as done with
f70905448f6 in Qt base.

Change-Id: Ib1966ff26c4d36d5f62e149d6b45baa4aecf825d
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2019-07-29 08:54:18 +00:00
hjk
7ab6783e24 Standardize on int for line and column values
Recently tons of warnings show up for presumably "problematic"
singned <-> unsigned and size conversions.

The Qt side uses 'int', and that's the biggest 'integration surface'
for us, so instead of establishing some internal boundary between
signed and unsigned areas, push that boundary out of creator core code,
and use 'int' everywhere.

Because it reduces friction further, also do it in libcplusplus.

Change-Id: I84f3b79852c8029713e7ea6f133ffb9ef7030a70
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2019-07-26 09:23:48 +00:00
hjk
0ec860009a Replace uses of QString::sprintf()
There are patches appearing on gerrit for Qt 6 to remove the functions.

Change-Id: Ic189c0a19ddc0f84eb34a56c0861532303de5129
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2019-06-20 12:03:00 +00:00
hjk
473a741c9f Utils: Rename FileName to FilePath
More in line with QFileInfo terminonlogy which appears to be
best-of-breed within Qt.

Change-Id: I1d051ff1c8363ebd4ee56376451df45216c4c9ab
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2019-05-28 12:23:26 +00:00
Nikolai Kosjar
e0c7722441 CppEditor: Modernize
modernize-orgad
modernize-return-braced-init-list
modernize-use-auto
modernize-use-default-member-init
modernize-use-equals-default
modernize-use-nullptr
modernize-use-override
modernize-use-using

Change-Id: Ifa862782fb7b56ed3f93d9f98685c3af616797c2
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
2019-02-08 08:39:58 +00:00
Nikolai Kosjar
55f4c28889 CppEditor: modernize-loop-convert
Change-Id: I80382880a3c35ef0b59729bd222a626bc5c4a32b
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
2019-02-08 07:52:23 +00:00
Nikolai Kosjar
612393889a CppEditor: Fix some clazy level0 warnings
Use leftRef() instead [-Wclazy-qstring-ref]
Use multi-arg instead [-Wclazy-qstring-arg]

Change-Id: I4aa67e0d518060cdec4f96cb7a03a9a499f28f27
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
2019-02-08 07:51:36 +00:00
Alessandro Portale
f5974ad993 Fix warning: "Don't call QVector::first() on temporary QList/QVector"
[-Wclazy-detaching-temporary]

Change-Id: I23f5cbd80bb92d3f9f1bfb5ae07493818958c5b0
Reviewed-by: hjk <hjk@qt.io>
2019-01-28 11:03:39 +00:00
Eike Ziller
3d1d9aae2e Merge remote-tracking branch 'origin/4.8'
Conflicts:
	src/plugins/winrt/winrtdevicefactory.cpp

Change-Id: I33b8697e2ebf2bea051d7f1144449e0743ee16a5
2018-11-19 10:00:18 +01:00
Ivan Donchevskii
8dc566e902 CppTools: Allow to check whether project code style exists
The calling code can anyways fallback to the global style
without extra help if no project style exists.

It is useful when you want to get the project style if it exists
and understand at the same time that it is not a global one.

Change-Id: I265de3f436f90623385427fc8a1abad09c8c3577
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2018-11-12 08:56:20 +00:00
Frank Meerkoetter
ffc070a3f2 Replace call to a long obsolete QtAlgorithms function
Change-Id: I1e07649d7d1153400951ae734c7f78e03ff8fe32
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
2018-10-08 07:47:23 +00:00
Eike Ziller
049291504d Fix function extraction for nested classes
If the function is added to a class inside a class, these must be
prepended before the inner class name.

Fixes: QTCREATORBUG-7271
Change-Id: I07042cdd4927af3b630c6ab1b5587971754e1199
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2018-10-02 13:31:48 +00:00
Eike Ziller
7a7898e2c9 Reduce priority of "Convert to Camel Case" refactoring
Otherwise this is too annoying in case the function is called the way it
should be.

Fixes: QTCREATORBUG-8114
Change-Id: I51063a11e7979e24fc9020344aa5ff800b5064a9
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2018-10-02 13:31:02 +00:00
Frank Meerkoetter
6f56feef29 CppEditor: better detection of the system a numeric literal is in
Fixes:
The literal 1 (or any decimal of length 1) was misdetected as not
already a
decimal literal which resulted in a quickfix "Convert to decimal".

Improves:
More consistent handling of 0. Octal is now handled like the other
cases. The user is offered to turn 0, 0x0, or 0b0 into 00.

Change-Id: I9a559fc328d0b49bfe0e53b933e8b4fee5af27a5
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2018-09-27 07:01:39 +00:00
Frank Meerkoetter
d7be70afd4 CppEditor: binary literal support for ConvertNumericLiteral
Extend the ConvertNumeric literal quickfix to support
C++14 binary literals.

Change-Id: Ia1cf8633e80ddf7d968a881d17ce2a07c5de89d3
Reviewed-by: André Hartmann <aha_1980@gmx.de>
2018-09-20 19:29:03 +00:00
Frank Meerkoetter
17fdb595a0 cppeditor: remove misleading Qt4/Qt5 label in WrapStringLiteral
QStringLiteral and QLatin1String play a different role and have
different properties. QLatin1String isn't strictly Qt4. Qt4 had
QLatin1Literal (for which QLatin1String is nowadays a compat alias).

Change-Id: Ie2a5f7d9d29ad8db735743a9d9579c4c0828cd45
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2018-09-20 07:02:32 +00:00
Marco Bubke
3abaf647d0 Add system include path to HeaderPath and merge ProjectPartHeaderPath
System include paths are appended after other includes by the compiler. So
we should set them as system includes and not as normal includes. Otherwise
we change the include order. Headers in system include paths are not
cluttering the screen with unwanted warning and by the way improve
performance too.

ProjectPartHeaderPath was a dopperganger of HeaderPath, so we merged them.

Change-Id: I7c394b4098b697de79761499ffcd5913cc02d652
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2018-09-10 09:31:32 +00:00
Ivan Donchevskii
ef9c68798d CppTools: Fix getting locator filters from the object pool
They are no longer inside the global object pool.
Get them from CppModelManager instead.

Task-number: QTCREATORBUG-20678
Change-Id: Ifb3221a812295e1dcfe8b59ea693a4b350cbcc2e
Reviewed-by: David Schulz <david.schulz@qt.io>
2018-06-28 07:42:27 +00:00
Orgad Shaneh
eea6a7c3b3 Utils: Purge qtcfallthrough.h
No longer needed.

Change-Id: I9b0bee014df89d4c567f1d2431b5ff9404f5f925
Reviewed-by: hjk <hjk@qt.io>
2018-04-09 09:04:13 +00:00
hjk
289f2b170a CppEditor: Do not add QuickFixFactories to object pool anymore
Not needed anymore.

Also some cleanup, no 'using' in headers etc.

Change-Id: I8c4547d80d0c0ffd989d1efbc74687c9f56096a4
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2018-02-02 12:26:32 +00:00
hjk
0e687d6a4f CppEditor: Normalize WrapStringLiteral and RewriteLogicalAnd interface
Slims down publicly visible interface and could be one step towards
replacing the CppQuickFixFactory derived classes by plain
stand-alone functions.

Change-Id: I9c6a8bcbd8481e14fb21dd41b11a1e6153a35e4b
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2018-01-03 07:36:11 +00:00
hjk
479ab4ef22 TextEditor: Split the global QuickFixFactory list
It's only ever used in the filtered Cpp/QmlJs variants. Splitting
the class simplifies the code and avoids re-doing filtering over
and over again.

Also inline QuickFixFactory::matchingOperations() into callers

Change-Id: I730756315f2e0321649259ef229631233b12fbdd
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-12-18 15:39:51 +00:00
Ivan Donchevskii
74570e833d CppEditor: fix class refactoring crash
... when class contains functions with incorrect AST.

Task-number: QTCREATORBUG-19180
Change-Id: Ie60c27ccec6d664e7ba76b8862326dbb9576a1bb
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2017-11-03 12:12:32 +00:00
Ivan Donchevskii
55a5ffc1ec C++: remove builtin FollowSymbol dependency from CppEditor
Move FollowSymbolUnderCursor to CppTools and
builtin member ownership to internal model manager.

Change-Id: I97a4f744ec1709ccc0b34fb67b58680973ef566f
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2017-09-22 12:59:05 +00:00
Ivan Donchevskii
96ef6c797b CppEditor: split CppEditor and CppEditorWidget
Change-Id: Id3c815184f7f3bace0276e947f6b6f76e61ec6de
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2017-09-12 15:05:38 +00:00
Ulf Hermann
47886969cc Drop unused variables and lambda captures
Also, add context to connect() expressions where we are or were
capturing "this".

Change-Id: I6e006ba6f83d532478018550d148ee93eca59605
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2017-09-08 09:06:53 +00:00
Jochen Becher
91dec7fe7a CppEditor: Minor refactoring quickfix
Change-Id: I978d79f081749cef58ca9be7387892dbca71683c
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2017-07-21 11:54:23 +00:00
Christian Kandeler
be2b3c91ae Add Q_FALLTHROUGH for Qt < 5.8
... and make use of it.
With gcc 7, the new option -Wimplicit-fallthrough is introduced and
added to the -Wextra set, triggering dozens of warnings in our sources.
Therefore, we annotate all obviously intended fall-throughs. The ones
that are still left are unclear and need to be checked by the respective
maintainer.

Change-Id: I44ead33cd42a4b41c28ee5fcb5a31db272710bbc
Reviewed-by: Nikita Baryshnikov <nib952051@gmail.com>
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-07-17 07:51:23 +00:00
Przemyslaw Gorszkowski
c6771c39c1 CppEditor: Fix quickfix for adding include for static functions
Task-number: QTCREATORBUG-14499
Change-Id: Id3e962ed310f43c33b91c7834a1f9ca074519a38
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2017-06-23 11:47:24 +00:00
Nikolai Kosjar
39dea09794 CppEditor: Fix uninitialized value warnings
...from coverity scan.

Change-Id: I1b1fb919e77f1407fe2e4319392c28413a296493
Reviewed-by: Robert Loehning <robert.loehning@qt.io>
2017-06-01 13:33:21 +00:00
Christian Gagneraud
972b48ef24 CppEditor: Use qFuzzyCompare when comparing member variable for qproperty refactoring
For a line like

    Q_PROPERTY(qreal foo READ foo WRITE setFoo NOTIFY fooChanged)

the generated setter will now use "if(qFuzzyCompare(m_foo, foo))" instead of "if (m_foo == foo)"
for types that are supported by qFuzzyCompare (that is: qreal, double and float).

A warning stating that "Floating point comparison needs context sanity check" is as well added
to remind the user to check/fix the generated code.

Change-Id: I8d274d5c072d107f0d04b1e153b5cc183e6317fc
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2017-03-07 23:33:05 +00:00
Nikolai Kosjar
d6e81eb49e CppEditor: Emit member variable for qproperty refactoring
For a line like

    Q_PROPERTY(bool foo READ isFoo WRITE setFoo NOTIFY fooChanged)

the generated setter will now "emit fooChanged(m_foo)" instead of "emit
fooChanged(foo)".

Change-Id: I417607ea614bfde0aafa6de401ffa888daf37c4c
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-02-24 13:57:36 +00:00