Bug 355356 - Function "Adapt signature" doesn't work correct (renaming argument) for constructor of class
Summary: Function "Adapt signature" doesn't work correct (renaming argument) for const...
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: CPP (Clang-based) (show other bugs)
Version: git master
Platform: Mageia RPMs Linux
: NOR normal
Target Milestone: 5.0.0
Assignee: kdevelop-bugs-null
URL:
Keywords: release_blocker
Depends on:
Blocks:
 
Reported: 2015-11-14 21:49 UTC by Piotr Mierzwinski
Modified: 2016-01-30 21:15 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Simple C++ project containing only one class with one constructor (1.33 KB, application/x-xz)
2015-11-14 21:52 UTC, Piotr Mierzwinski
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Piotr Mierzwinski 2015-11-14 21:49:17 UTC
I attached exampled simple project. When I rename first parameter in constructor I get broken its definition. Looking like this:
void MyClass::MyClass(int* nPointer, const QString& string)

Please take a look on the class declaration (located in header file):
#include <QString>

class MyClass
{
public:
	/** This function something do.
	 * @param pointer some pointer
	 * @param string some string
	 */
	MyClass( int *pointer, const QString &string );

// 	void foo();

};

#endif // MYCLASS_H

and class declaration (located in cpp file):
#include "myclass.h"

MyClass::MyClass( int *pointer, const QString &string )
{
	int *localPointer = pointer;
	QString localString = string;
}

/*
void MyClass::foo()
{

}
*/


Reproducible: Always

Steps to Reproduce:
1. Run KDevelop and open attached project (or create your own and put there mentioned above code)
2. In declaration of constructor please rename its first argument: "pointer" to "nPointer"
3. When helper "Adapt Signature" pop out then please choose option "1" (Update definition of signature)
4. Please switch editor to cpp file

Actual Results:  
void MyClass::MyClass(int* nPointer, const QString& string)

Additionally as you can see the format of arguments (spaces and * and & location) is lost and I have to restore all to the original. This is really annoying :/. I can report separate bug report for this if this is necessary. This also happened in KDevelop 4.

Expected Results:  
MyClass::MyClass( int *nPointer, const QString &string )


KTextEditor, Kate, KDevelop, KDevplatform cloned at 14.11.2015, where KDevelop, KDevplatform come from 5.0 branch

Would be nice if after this operation also argument in doxygen documentation would be updated. Now is only highlighted by Problem reporter.
Comment 1 Piotr Mierzwinski 2015-11-14 21:52:05 UTC
Created attachment 95504 [details]
Simple C++ project containing only one class with one constructor
Comment 2 Milian Wolff 2015-11-15 13:44:44 UTC
Haven't tried this explicit example, but I've seen odd behavior of the signature assistant myself.

Regarding the syntax formatting: Have you configured that properly? KDevelop settings -> Source Formatter. There, use e.g. astyle and configure it to your likings. It should then be used by the assistants. If not, open a new bug report for that please.
Comment 3 Milian Wolff 2016-01-30 15:51:39 UTC
Git commit 95e7dd4e07adcd3cd29a2d998fb4076b80746c11 by Milian Wolff.
Committed on 30/01/2016 at 15:51.
Pushed by mwolff into branch '5.0'.

Do not add return type to constructors in signature assistant.

M  +6    -4    languages/clang/codegen/adaptsignatureaction.cpp
M  +11   -3    languages/clang/codegen/adaptsignatureassistant.cpp
M  +8    -0    languages/clang/tests/test_assistants.cpp

http://commits.kde.org/kdevelop/95e7dd4e07adcd3cd29a2d998fb4076b80746c11
Comment 4 Milian Wolff 2016-01-30 15:52:19 UTC
@ Piotr: Regarding the whitespace changes, when you have setup the source formatter, it should use the correct style. If that is not the case, please report a new bug for that.

Thanks
Comment 5 Piotr Mierzwinski 2016-01-30 20:49:14 UTC
@Milian: Yes. Some times ago I configured "Source formatter" with my own formatter. You mentioned me about this when I reported different bug. I found some bug related with this function and soon I'm going to report it.
Comment 6 Piotr Mierzwinski 2016-01-30 21:15:33 UTC
And BTW. I'm not sure if this is correct approach to use "Source formatter" in functions: "Adapt signature" or/and "Update declaration signature". Here I was confused, because I thought that "Source formatter" is used only in options: "Edit->Reformat source" and "Edit->Reformat line" :-/.

What if I would like to have different formatting in header of function declaration and different in code (body of function). For example I would like to format default parameter in header of function declaration like this: "void foo( bool param=true)", and in body of function I like such format: "bool localParam = false". As you can see padding is different in both places. Now when I  use option: "Edit->Reformat source" then one of them will be broken :-(. In this moment I have to use same formatting every where. I like such format: "void foo( bool param=true)", because this takes less space in row. This if of course is not problem when I have wide monitor or break line on every parameter.