Commit Graph

217 Commits

Author SHA1 Message Date
Christian Kandeler
24eb796231 CppEditor: Fix "Add Definition" quickfix for function parameters
... whose type is a template.

Fixes: QTCREATORBUG-25560
Change-Id: I1d626f9376e8802a87ca1a28099932ccbf744d47
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-04-09 07:43:19 +00:00
Christian Kandeler
b066b3029e CPlusPlus: Improve type name minimization
... for function parameters. These are located in the scope of the
surrounding class or namespace.
This uncovered a bug in the "Insert Virtual Functions of Base Classes"
quickfix, which we also fix here.

Fixes: QTCREATORBUG-8030
Change-Id: I7f11659dc8e252e3819df8178734e8958fa1b496
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-02-22 11:16:49 +00:00
Alessandro Portale
395e7cbfb9 CppEditor: Default to .cpp for QuickFix creation of 1-line setter/getter
Until Qt Creator 4.14, the QuickFix for setter/getter creation for
simple members added the implementation in the .cpp file.

The new QuickFix settings in Qt Creator 4.15 in theory keep the default
like before, but the threshold of 2 lines is usually not reached, which
causes the getter/setter implementations to now land in the header file.

This change sets the default threshold to 1 to restore the previous
default behavior.

Fixes: QTCREATORBUG-25331
Change-Id: I570deaa8b81686dc31254e8261b59ddcf8731f91
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-02-11 16:05:25 +00:00
Christian Kandeler
e740295b8d CplusPlus: Fix minimal name construction
... when creating the constructor implementation for a derived class.
We would erroneously strip off the class name.
Amends aae3ce15aa.

Change-Id: I62c800d490626e8cb9416829633f9ef7b0c666cd
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-02-09 16:56:12 +00:00
Christian Kandeler
33d2d736ea CppEditor: Do not add redundant access specifier
... when inserting a member function declaration for a definition.

Fixes: QTCREATORBUG-5591
Change-Id: Ie85b435a1595832d0085abdcc0a4187d939820e0
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-02-08 15:19:31 +00:00
Leander Schulten
29207e3eeb CppEditor: Add Base Class Support for Generate Constructor QuickFix
Change-Id: Idd92229134609c0ac87aad030a6bb645ff4cce1b
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-02-04 11:40:05 +00:00
Christian Kandeler
feefe3585f CppEditor: Make "Complete switch statement" quickfix more visible
Do not require the cursor to be on the "switch" keyword, but allow it to
be anywhere within the switch construct.

Fixes: QTCREATORBUG-5379
Change-Id: Ic25504237b3ef12958f339d7176dfeeac6bd3466
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-02-04 11:19:53 +00:00
Christian Kandeler
aae3ce15aa CplusPlus: Fix minimal name construction
... when using declarations are involved.
Second attempt.
I have a suspicion that this is not the "correct" approach, however:
    a) It appears to fix the problem.
    b) It does not break any tests.
    c) It's rather high in the call tree, so there's a low likelihood
       of breaking something else.
    d) Considering the hacky-looking pre-existing code dealing with
       using declarations (e.g. LookupContext::lookupByUsing()),
       it seems quite possible that there is no "correct" way with
       the current infrastructure.

Fixes: QTCREATORBUG-14524
Change-Id: I28c6e53137c21ce158bbd03b92b3db39146116d5
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-01-29 14:21:46 +00:00
Christian Kandeler
e5982d9c3d CPlusPlus: Revert name minimization fix
This effetively reverts 87ec0f349f, which had unwanted side effects.

Change-Id: I03438c18f43b07a6560416af746132bc4471fbb7
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-01-29 09:37:34 +00:00
Christian Kandeler
87ec0f349f CplusPlus: Fix minimal name construction
... when using declarations are involved.

Fixes: QTCREATORBUG-14524
Change-Id: I0c391b88628f40973b6f601e60c64263f62a88a0
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-01-28 14:31:49 +00:00
Christian Kandeler
667d50e1bc CppEditor: Fix "add definition" quickfix insertion string
... for the edge case of the insertion location being preceded by a
function whose body is a try-catch clause.

Fixes: QTCREATORBUG-14661
Change-Id: Icc7d5283ead81d644231479317214a8cc177493d
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-01-28 14:30:20 +00:00
Leander Schulten
8192f7f4f4 CppEditor: Make it possible to specify default values in generate constructor quickfix
Change-Id: If73b4bdad1e3878091378d800bec2f1682a55c9f
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-01-19 13:48:46 +00:00
Leander Schulten
1342500fb0 CppEditor: Make it possible to change the order of parameters in the Generate Constructor Quickfix
Change-Id: Iacdf1d660f50a85c18bc48db842bf45ebccf686e
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-01-18 11:46:32 +00:00
Leander Schulten
c960f279e6 CppEditor: Add QuickFix to generate a constructor
Change-Id: Iba2ce3bfa1a1d1a325626a21f46b485d12cbb060
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-01-11 14:59:40 +00:00
Eike Ziller
8d67dd57e8 Merge remote-tracking branch 'origin/4.14'
Change-Id: I5e138bb7883c0436fee14ca6af20e99396676af1
2020-11-20 13:00:37 +01:00
Leander Schulten
993b614d94 CppEditor: Remove using namespace quickfix: Don't insert inline namespaces
Change-Id: If386d31de723ca928d3c50f55e32205c50937b0a
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2020-11-19 18:35:05 +00:00
Eike Ziller
5ca70bdcb3 Merge remote-tracking branch 'origin/4.14'
Change-Id: Iea84f23cf394de13e99a9ed777c8c113e4eff473
2020-11-19 15:38:13 +01:00
Leander Schulten
92667c779c CppEditor: Remove using directive at global scope always in all files
Previously only using directives in the global scope that followed the
quickfixed using directive were removed

Change-Id: I330acfe3236a6845fd1667f9fa699ab6c8fb560d
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2020-11-16 13:55:27 +00:00
Eike Ziller
381c5656e7 Merge remote-tracking branch 'origin/4.14'
Conflicts:
	src/plugins/mesonprojectmanager/project/mesonprojectparser.h

Change-Id: Id38d20ce20981dcdc322fe5d1d7647f4bec89d8a
2020-11-13 16:03:26 +01:00
Christian Kandeler
3cd2e2c445 CppEditor: Improve "definition from declaration" for templates
- Make sure the template parameters are included in the definition.
- Find the correct insertion location when using an already-defined
  template member function as an anchor.

Fixes: QTCREATORBUG-24848
Change-Id: I1272ba36403904e7aed81bcef48745793c5e2217
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-11-13 12:49:51 +00:00
Eike Ziller
724fd58a3b Merge remote-tracking branch 'origin/4.14' into master
Conflicts:
	src/plugins/cppeditor/cppquickfix_test.cpp

Change-Id: I470ee35f54f883244d819531131c172bd25c0e3f
2020-10-29 09:18:31 +01:00
Christian Kandeler
d2ebc16b92 CppEditor: Fix "move definition" quickfix for template member functions
There are a lot more problems in this area (e.g. with nested classes),
but let's tackle them one by one.

Fixes: QTCREATORBUG-24801
Change-Id: I4b3805ea6f8b28373925693650150bbd89508096
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-10-28 12:41:26 +00:00
Christian Kandeler
0ebb004d85 CppEditor: Make "Complete Switch" quickfix work with enum classes
Fixes: QTCREATORBUG-20475
Change-Id: Id21a007ab4b652dcfe49d97bfa4c9fa77bacf8c4
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-10-27 11:40:37 +00:00
Christian Kandeler
f515672ffd CppEditor: Offer class-level quickfixes also when clicking "in class"
That is, allow the cursor to on some "neutral" place in the body of the
declaration, not only strictly on the class name.

Fixes: QTCREATORBUG-15699
Change-Id: I74ad6048c16c19d418446c990178535d878fc630
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-10-23 10:27:49 +00:00
Eike Ziller
9c6108afd1 Merge remote-tracking branch 'origin/4.14' into master
Change-Id: Ib4363db8e71488e1d13e8c1012023abfaf06286b
2020-10-22 14:38:01 +02:00
Christian Kandeler
135e76f965 CppEditor: Offer InsertDefsOperation quickfix for all classes
The check whether there are unimplemented member functions takes quite
long, so Creator would freeze for several seconds when right-clicking on
the name of even a medium-sized class.
Therefore, we offer the operation for all classes with member functions
and move the expensive check into the perform() method.

Change-Id: Ie19958ba8c53493be859f9982d7d5697e6e9d88b
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-10-21 08:19:25 +00:00
Eike Ziller
dbb6201605 Merge remote-tracking branch 'origin/4.14' into master
Change-Id: Id7ad82997873da828456a15c441620d93c6fc7e7
2020-10-21 09:31:01 +02:00
Christian Kandeler
2b5e1ea62e CppEditor: Fix some "convert to camel case" edge cases
Fixes: QTCREATORBUG-16560
Change-Id: I8573ae6c5dce0956c868addc69a921c62f1d571a
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-10-20 13:27:54 +00:00
Eike Ziller
80951d3e59 Merge remote-tracking branch 'origin/4.14' into master
Conflicts:
	src/plugins/cppeditor/cppquickfix_test.cpp

Change-Id: Ib2984a3b3d9d071d11304b6cf132c2f8cef77e1c
2020-10-19 15:22:37 +02:00
Leander Schulten
5b5ae97104 CppEditor: Introduce QuickFix settings and unify getter/setter generation
Introduces a QuickFix settings page where the generation of getters and
setters can be customized. The settings can be saved into a file that can
go into a VCS. All QuickFixes that generate getter/setter/signals/
Q_PROPERTIES now use the same backend. QuickFixes that generate getters/
setters are now extended to also generate signals and Q_PROPERTIES.

Fixes: QTCREATORBUG-1532
Fixes: QTCREATORBUG-17941
Fixes: QTCREATORBUG-12678
Fixes: QTCREATORBUG-15779
Fixes: QTCREATORBUG-11620
Fixes: QTCREATORBUG-22707
Fixes: QTCREATORBUG-20157
Fixes: QTCREATORBUG-21804
Fixes: QTCREATORBUG-19814
Fixes: QTCREATORBUG-14622
Fixes: QTCREATORBUG-19803
Change-Id: I50ed2dad9b4a637fbd87b3e1f2856060ad0ad920
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2020-10-14 10:12:44 +00:00
Leander Schulten
15f39cf37c CppEditor: Fix Typedef Handling with 'Remove Using Directive' QuickFix
Previously, typedefs were ignored and the new code became invalid after
applying the quickfix.

Change-Id: I0d4295e90d02dfacc3edac5ac3f96d9edbeaf662
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2020-10-12 14:34:54 +00:00
Christian Kandeler
023a77ea80 CppEditor: Consider templates in "complete switch" quickfix
Fixes: QTCREATORBUG-24752
Change-Id: I39bc007e5f493a9826adb4575eb210bf9ec21159
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-10-12 09:01:29 +00:00
Leander Schulten
32ee29cb9e CppEditor: Implement remove using namespace Quickfix
Fixes: QTCREATORBUG-24392
Change-Id: Iaf4df4ebf161a4a757f59f22e692e0f9b99cd63c
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2020-08-12 13:32:20 +00:00
Christian Kandeler
d9eb3dc5a4 CppEditor: Do not re-indent existing code
... in "Complete Switch Statement" quickfix.

Fixes: QTCREATORBUG-12445
Change-Id: Ic168f5b434b81d2b5f5a0d344d6c6786a75d07a5
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-08-10 12:02:11 +00:00
Christian Kandeler
537e2e23ff CppEditor: Work around cmake bug
If you mention "Q_OBJECT" in a raw string literal, the cmake build
fails...

Change-Id: I9004184b48dea9a77b9303c3fd871cef747ade4c
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-07-30 13:30:18 +00:00
Christian Kandeler
77d13f08ba CppEditor: Let users create implementations for all member functions
... in one go.

Fixes: QTCREATORBUG-12164
Change-Id: Ifc81c8b1caf4319ce57882375f513d72e4c0ea52
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-07-29 11:56:07 +00:00
Leander Schulten
fdd70d898d CppEditor: Don't create 'namespace xyz{}' if there is 'using namespace xyz'
Change-Id: Idc08de5f44ccac0de8490158199c4e44f7efe79e
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2020-07-28 09:53:48 +00:00
Christian Kandeler
73f3056c3e CppEditor: Add class member from member initialization
That is, if a class member being initialized is not yet declared, offer
to add the declaration.

Fixes: QTCREATORBUG-11842
Change-Id: I1d2a56ab99543e996e220aa26b7923023dd163f7
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-07-23 12:57:29 +00:00
Christian Kandeler
e4100c31fc CppEditor: Fix trailing whitespace after extracting a function
... from a block of code.
We must not insert an empty line into the newly created function,
because it gets indented in the first indent operation, resulting in
trailing characters after the actual code has been inserted later.

Fixes: QTCREATORBUG-12118
Change-Id: If438d4de379cae90baa846c112866f2777b44fce
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-07-23 09:00:44 +00:00
Christian Kandeler
affd4ee658 CppEditor: Extend Q_PROPERTY quickfix
... to also generate the RESET function.

Fixes: QTCREATORBUG-11809
Change-Id: I94789227230a67f074ff5fdc76ad8113d2870dd6
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-07-22 07:46:11 +00:00
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
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
934641f45c TextEditor: Sort indent ranges before applying
It can easily happen that callers insert indent ranges out of order, and
without sorting the indentation done earlier in the file is not
considered for the later parts, leading to inconsistent results.

Fixes: QTCREATORBUG-18929
Change-Id: Ice2abe92d54446bcdd102c6a1f822262a8533543
Reviewed-by: David Schulz <david.schulz@qt.io>
2020-06-15 13:46:11 +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
2262af087a CplusPlus: Fix type information for anonymous enums
Variables declared like this:
    enum { E1, E2 } e;
would not get assigned a proper type.

Task-number: QTCREATORBUG-7487
Change-Id: I4362f22feb0f2e4e1e754e9c623e5576fa31f4bc
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2020-06-04 11:24:56 +00:00
Christian Kandeler
39047fac5b CPlusPlus: Add missing type information for enum variables
Consider these two variable declarations:
  enum EX { EX1, EX2};
  EX ex;
  emum EY { EY1, EY2} ey;
The ex variable would correctly get assigned type EX, but the ey
variable would not have any type.
This is now fixed.

Task-number: QTCREATORBUG-7487
Change-Id: I3e09c5766fdb9e6baf3a8d7bc6f2fc581f2d824b
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2020-06-04 10:23:39 +00:00