Getter/Setter generation

Milian Wolff mail at milianw.de
Sun Oct 4 10:57:03 UTC 2015


On Sonntag, 4. Oktober 2015 12:12:53 CEST Felix Mauch wrote:
> Hej Milian,

Hey Felix,

please keep the mailing list in the loop. More people can help you there.

> Is languages/cpp/codecompletion the right place to start? Writing a
> class that inherits from KDevelop::CompletionTreeItem? Then, there's
> still the question how it gets triggered.

No, that's the old cpp plugin which is deprecated. We are nowadays working on 
the clang based plugin in the kdev-clang repository [1]. There, look at 
codecompletion/context.cpp, e.g. OverrideItem and how it's used. You'll need 
to do some special processing of the AST to find viable items to add. Also 
look at the completionhelper.cpp file - maybe that's a good place to add the 
logic.

What you want to do:

- find direct data members of the current class context
- check if there are setters/getters for that data member
- if not, add code completion items for them

If you have more questions on how to do that, just ask (on the mailing list).

Good luck! Note that I'll be unavailable the next three days. Starting from 
Thu I'll attend the KDev sprint and will have a lot of time for this. I can 
then also guide you through the process, e.g. via IRC (#kdevelop on freenode).

Cheers

[1]: ssh://git@git.kde.org/kdev-clang

> On 10/01/2015 02:30 PM, Milian Wolff wrote:
> > On Dienstag, 29. September 2015 09:00:36 CEST Felix Mauch wrote:
> >> Hey there,
> >> 
> >> I've been using QtCreator for a while now and recently switched to
> >> KDevelop because of its awesome code navigation and its ability to
> >> change the UI to my needs.
> >> However, I was shocked when I didn't find a way to automatically create
> >> getter and setter methods (in C++). Did I just miss it or does this
> >> feature not exist?
> >> 
> >> I found an old review request on
> >> https://git.reviewboard.kde.org/r/103613/ which seems like it never got
> >> merged.
> >> 
> >> Is there any way I can achieve this? Otherwise I guess, I should try to
> >> implement something myself...
> >> Personally I'd prefer a refactoring-entry: "Create Get- and Set-methods"
> >> in the context menu over a full blown GUI for this purpose. Maybe that's
> >> doable via a lightweigt plugin?
> > 
> > It really isn't implemented yet, and I totally agree that we should come
> > up
> > with a solution here. The existing patches we got where always far too
> > dialog centric and - imo - got too much into the way.
> > 
> > What I'd love to see is someone taking our feedback into account and
> > creating a new solution. Something like:
> > 
> > - detect that there is a member called m_foo
> > - during code completion in the header, offer to add a getter/setter for
> > foo when it's not there yet
> > - outside the class, we can reuse the existing "implement function" code
> > to
> > then create the declaration.
> > 
> > That sounds doable to me, and is much better than having a complicated
> > dialog which you need to open in order to create a getter/setter.
> > 
> > It would be sufficient to add a simple implementation first, and then
> > later
> > add per-project config options that allow you to specify the style of the
> > getter/setter. I.e. prefixes, suffixes, return style, ...
> > 
> > Bye

-- 
Milian Wolff
mail at milianw.de
http://milianw.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20151004/638e6ab8/attachment.sig>


More information about the KDevelop-devel mailing list