Commit Graph

248 Commits

Author SHA1 Message Date
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
Nikolai Kosjar
1aaf840f3f CppEditor: Remove superfluous "..." for qproperty refactoring
Change-Id: I79229b47514f0a420c13351673f018bbf564ae56
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-02-24 13:57:31 +00:00
Montel Laurent
cb8d0f0678 Remove last Q_NULLPTR usage
Change-Id: I8a55a9f1927e6db979d61eb4702f2ebde8d27572
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-02-22 10:27:26 +00:00
Tobias Hunger
78ced14c4c CppEditor: Remove dead code
Change-Id: If65f43e232c83924a746bcbb30ced5db57dd547b
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2016-11-30 09:48:59 +00:00
Tobias Hunger
81401ace26 CppEditor: Fix possible use of uninitialized values
Change-Id: I138309e5e85c839250f5f93448530b9e12c5f6af
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2016-11-29 15:13:26 +00:00
Friedemann Kleint
3b1308bb43 TextEditor: Remove exported class QuickFixOperations
Define an operator << that accepts a raw pointer for the list of
QuickFixOperation::Ptr instead.

Fixes MSVC 17 warnings

src/corelib/tools/qlist.h(423): warning C4661: 'QVector<T> QList<T>::toVector(void) const': no suitable definition provided for explicit template instantiation request        ]
src/corelib/tools/qlist.h(389): note: see declaration of 'QList<TextEditor::QuickFixOperation::Ptr>::toVector'
src/corelib/tools/qlist.h(423): warning C4661: 'QSet<T> QList<T>::toSet(void) const': no suitable definition provided for explicit template instantiation request
src/corelib/tools/qlist.h(390): note: see declaration of 'QList<TextEditor::QuickFixOperation::Ptr>::toSet'
src/corelib/tools/qlist.h(423): warning C4661: 'QList<TextEditor::QuickFixOperation::Ptr> QList<TextEditor::QuickFixOperation::Ptr>::fromVector(const QVector<T> &)': no suitable definition provided for explicit template instantiation request
...

Task-number: QTBUG-57086
Change-Id: I879511656c39eb7a3eae54ea7daca3eca8ebe8d7
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
2016-11-18 11:47:59 +00:00
Nikolai Kosjar
745fc30277 CppEditor: Fix null pointer access
Task-number: QTCREATORBUG-17253
Change-Id: Ide3d15508a2e310c307fef68457848e869c4d2de
Reviewed-by: David Schulz <david.schulz@qt.io>
2016-11-15 11:21:25 +00:00
Lorenz Haas
49c6710b42 CppEditor: Fix GenerateGetterSetter for reference types
Change-Id: Iad332cf023c6bff0c7f5ae46fb56f0393c9c7b29
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2016-10-31 16:00:17 +00:00
Orgad Shaneh
34baa3ec47 CppEditor: Add enclosing template on "Move Definition Outside"
The template id for the class name is missing, but it's better than
nothing.

For example:

template<class T>
class Foo
{
    void func() {} // Move Definition Outside Class
};

// The following lines are added
template<class T>
void Foo::func() {} // Should be Foo<T>::func

Task-number: QTCREATORBUG-16649
Change-Id: Icb560e0b87f563cbda18f4742f44bb8ef4d8a900
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2016-09-06 13:23:18 +00:00
Orgad Shaneh
d0d1f43e8f CppEditor: Add enclosing template on "Add Definition"
The template id for the class name is missing, but it's better than
nothing.

For example:

template<class T>
class Foo
{
  void func(); // Add Definition
};

// The following lines are added
template<class T>
void Foo::func() // Should be Foo<T>::func
{
}

Change-Id: I60a0cbd348985def3dfb7037067786e942278593
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2016-09-06 13:23:12 +00:00
Orgad Shaneh
39aff55d8a C++: Enable showEnclosingTemplate also for function type
Do not require directly passing the enclosing template.

Change-Id: Ie03bc58338fe003677a5f5311d86d70f499373ee
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2016-09-06 09:33:48 +00:00
Orgad Shaneh
5a40bddf08 CppEditor: Add template enclosing scope on "Insert Declaration"
Change-Id: Iff4893193b56c2ed86b4b9515a1a1df847528369
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2016-08-19 14:41:25 +00:00
Orgad Shaneh
2890966ec3 CppEditor: Prevent "Add Declaration" for existing template functions
class Foo
{
    template<class T>
    void func();
};

template<class T>
void Foo::func() {} // Add Declaration should not be triggered at all

Change-Id: Ifff733d8381177300dae017ae419200cfdf5c425
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2016-08-19 14:41:17 +00:00
Orgad Shaneh
65dc6d0fc2 CppEditor: Fix "Move Definition to Class" for template member functions
class Foo
{
    template<class T>
    void func();
};

template<class T>
void Foo::func() {} // Move to class

It currently doesn't trigger at all.

Change-Id: I63d561771a8dd455f01e99dd836abbd23eec71b7
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2016-08-19 14:41:11 +00:00
Orgad Shaneh
e920921f27 CppEditor: Fix "Move Definition to Class" for function in template class
template<class T>
class Foo { void func(); };

template<class T>
void Foo<T>::func() {} // Move to class

Prior to this change, this currently leaves behind `template<class T>`
where the definition used to be:

template<class T>
class Foo { void func() {} };

template<class T>

Task-number: QTCREATORBUG-14354
Change-Id: I8e1f75a3ae50619a7bae9c63d3798b16bcfea545
Reviewed-by: Lorenz Haas <lorenz.haas@histomatics.de>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2016-08-19 13:00:42 +00:00
Nikolai Kosjar
1ea6404337 CppTools: Allow prefering getter names with "get" prefix
We default to "foo()" for e.g. a member variable "m_foo", but other
coding styles require "getFoo()".

Task-number: QTCREATORBUG-16452
Change-Id: I9ccfdf88e4c469bc1c06fde855ad754faf2bd238
Reviewed-by: André Hartmann <aha_1980@gmx.de>
2016-06-22 12:22:57 +00:00
Nikolai Kosjar
b928a1ce46 CppEditor: Extract determineGetterSetterNames()
...and make it a bit more readable since we are going to make some
changes there.

Change-Id: Ic1d0c47a36ef4547a4842508c2404e9fc12f5220
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
2016-06-22 12:20:25 +00:00
Tobias Hunger
397e7f4843 Update License according to agreement with Free Qt Foundation
* Update files in src/plugins

Change-Id: Ia5d77fad7d19d4bb3498e78661982f68729adb22
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
2016-01-19 15:57:01 +00:00
Marco Bubke
2b4cadf1fe CppTools: Move ProjectPart in its own header file
Also extracting inline HeaderPath class and change projects list in vector
because the size is  larger than a pointer.

Change-Id: I885fdff3fe9bccc877634d1615249755f5b674fd
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2016-01-13 14:46:56 +00:00
Marco Bubke
6fe9b0ccc4 CppTools: Add CppToolsBridge
We broke the dependency of
BaseEditorDocumentProcessor *BaseEditorDocumentProcessor::get(const QString &filePath)

It's hiding static calls and it is much easier to do it that way than to
provide a reference to every user. It's also possible to exchange it with
different implementations for different test cases.

Change-Id: Ic74699b45948e8b48f7efb6a1b295ba2641b8951
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2016-01-12 10:21:30 +00:00
Orgad Shaneh
e99aaf23b9 CppEditor: Fix ConvertQt4Connect for different namespace
Change-Id: I152d7cda02bb034bf817eeeb4b467667e1188b2f
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-12-15 10:49:49 +00:00
Nikolai Kosjar
0498fb68ff C++: Revert lookup to 3.4.2
...which was least buggy.

The bugs fixed by the changes we revert here (highlighting/completion
for code involving templates) were minor compared to ones we currently
have. Those bugs will be addressed by the clang code model anyway.

Relevant commits were collected via:

  $ cd ${QTC}/src/libs/cplusplus
  $ git log \
   --no-merges \
   --format=oneline \
   v3.4.2..HEAD \
   -- LookupContext.* ResolveExpression.* TypeResolver.* TypeOfExpression.* \
      ../../plugins/cpptools/cppcompletion_test.cpp

From this list the following were skipped due to irrelevance:

  88c5b47e53 # CppTools: Minor cleanup in completion tests
  e5255a1f5c # CppTools: Add a test for ObjC not replacing dot with arrow
  5b12c8d63a # CppTools: Support ObjC in member access operator tests
  9fef4fb9ca # CPlusPlus: Fix warnings about overriding visit(...) methods

There were only minor conflicts while reverting those.

This changes touches so many files because there were quite some
cleanups and renames after the 3.4.2 release.

Task-number: QTCREATORBUG-14889
Task-number: QTCREATORBUG-15211
Task-number: QTCREATORBUG-15213
Task-number: QTCREATORBUG-15257
Task-number: QTCREATORBUG-15264
Task-number: QTCREATORBUG-15291
Task-number: QTCREATORBUG-15329
Change-Id: I01f759f8f35ecb4228928a4f22086e279c1a5435
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-11-19 14:48:38 +00:00
Nikolai Kosjar
a7928b4b0b Clang: Integrate clang's fixits as refactoring actions
They are invokable by the usual means (Alt+Enter, editor's context menu
> Refactor) plus by the context menu of the editor's left margin for the
related line.

The fixit text comes directly from libclang and is thus not translated.
We modify the text slighty by stripping the diagnostic category prefix
("note:", "error:", ...) and capitalizing the first letter.

A follow-up change should properly indicate available refactorings with
a refactoring icon in the editor's left margin.

Task-number: QTCREATORBUG-14868
Change-Id: I86157c9f824d2a9dedf19087476d02ad1e6cc854
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-09-29 11:39:21 +00:00
Robert Loehning
02972e5844 CppEditor: Assign parent to "Extract Function" dialog
Change-Id: I37bdafe640cca00211f1c558f2f2afc5d12d8357
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-09-04 09:05:43 +00:00
Robert Loehning
f1b9f56c69 CppEditor: Fix whitespace
Change-Id: I5b1f9268e2bc37344fba2ffec6098ae787cb327f
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-08-18 10:02:51 +00:00
Nikolai Kosjar
45778539d8 CppEditor: Fix crash with invalid switch/case statement
Task-number: QTCREATORBUG-14925
Change-Id: Iea2cf17070d9db48924e76f6c7febca0d52e4686
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
2015-08-18 09:44:40 +00:00
Nikolai Kosjar
0f00e08422 C++: Fix null pointer access for invalid code
The code snippet provided in the bug report could not be parsed
properly, thus Bind did not generate all expected symbols/names.

The chunk in onConnectOrDisconnectCall() fixes the crash. The other
chunks address triggered QTC_ASSERTs.

Change-Id: Idf508b91b70659d38e59064d4922600f7b31daf8
Task-number: QTCREATORBUG-14709
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-07-13 10:30:52 +00:00
Lorenz Haas
85d1f0cda4 CppEditor: Improve ExtractFunction's input dialog
Use FancyLineEdit and validate the function name before accepting the
dialog.

Change-Id: I1634ac757127d3cb39674eeed79388e720d570fa
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-06-11 11:33:10 +00:00
Lorenz Haas
7389f46959 CppEditor: ExtractFunction quick fix asks for access specifier
Task-number: QTCREATORBUG-12127
Change-Id: Ifb6ff22282f0f181e49a260e57307ec937f5dfb2
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-06-09 11:17:20 +00:00
Lorenz Haas
7879aa5fae CppEditor: Fix added newlines for GenerateGetterSetter quick fix
As a nice side effect superfluous new lines - introduced by quick fixes
that are using InsertionPointLocator::methodDefinition - vanished.

Task-number: QTCREATORBUG-13872
Change-Id: Ib3df2b2acbc22449f16f4444092a57ae93d53d35
Reviewed-by: Jochen Becher <jochen_becher@gmx.de>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-06-09 10:11:56 +00:00
Tobias Hunger
a1b8e94f0b cppeditor: s/Q_DECL_OVERRIDE/override/g
Change-Id: Ie0b75ea64ec3927732b484983311990c8ca0d057
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-06-04 12:25:58 +00:00
Joerg Bornemann
4b5315bd7c CppEditor: fix "Convert to Stack Variable" for empty initializer lists
The "Convert to Stack Variable" quick fix generated invalid code for
the following snippet: QString s = new QString();

Task-number: QTCREATORBUG-14279
Change-Id: I1f5e33d2089bc2d5713eae1e9f4dc5986523112c
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-04-20 16:14:43 +00:00
Orgad Shaneh
cb350bfeb2 C++: Rename ClassOrNamespace -> LookupScope
Change-Id: Ide74482b133dd1fec40a725d9aa81bd749385f37
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-04-20 14:51:56 +00:00
Lorenz Haas
0ea753ad63 CppEditor: Respect current getter coding style
With a simple check GenerateGetterSetter looks for symbols starting with
"get". If such symbols are found it is most likely that the current
class uses "getFoo" for getters and thus the quick fix uses this coding
style for generating the getter name.

Change-Id: I9ff8ef8bb936572abaaf9e671b8985553c1018f1
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-03-24 16:08:01 +00:00
Lorenz Haas
0913eb8660 CppEditor: GenerateGetterSetter now ignores symbols in Q_PROPERTY
Since the Q_PROPERTY's name equals the typical getter name the "Generate
Getter" quick fix was not offered.

Q_PROPERTY(int a ...) // <-- a is "recognized" as "int a();"
int m_a;

Task-number: QTCREATORBUG-14166
Change-Id: I35709a1b6492b68309d02427d60251df4fd76cfa
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-03-24 16:07:27 +00:00
Nikolai Kosjar
6a94f7e355 CppEditor: Add basic test for ExtractFunction
Change-Id: I44f2edb2905e202669630ab5da85066011491fae
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
2015-03-13 13:41:37 +00:00
Orgad Shaneh
dbb9891f43 CppEditor: Support implicit pointers in Qt5 connect conversion
Task-number: QTCREATORBUG-14104
Change-Id: I157dbcb0e06ed1bf49d2df01bdbad215e35a4c3a
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-03-09 13:27:12 +00:00
Orgad Shaneh
683540bee7 CppEditor: Expand templates for Qt5 connect conversion
Fixes at least explicit data() calls for templated pointers:

QPointer<QAction> action;
connect(action.data(), SIGNAL(triggered()), this, SLOT(slot()));

Change-Id: I7f76c1f556c0f271936728d611751424969916a7
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-03-09 13:16:06 +00:00