Bug 397664

Summary: C++ importer does not correctly detect generalization in template classes
Product: [Applications] umbrello Reporter: Thomas Jansen <mithi>
Component: generalAssignee: Umbrello Development Group <umbrello-devel>
Status: RESOLVED FIXED    
Severity: normal CC: ralf.habacker
Priority: NOR    
Version: Git   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 2.26.1 (KDE Applications 18.08.1)
Attachments: Initial patch

Description Thomas Jansen 2018-08-20 16:08:10 UTC
Created attachment 114517 [details]
Initial patch

Umbrello does not correctly parse existing C++ code that uses template classes when trying to detect a generalization. I debugged the code and found that in CppTree2Uml::parseBaseClause the baseName contains the template parameters as  part of the name which does not match the name of the class (that has only the name of the class without any template parameters).

By stripping the template parameters from baseName the generalization is detected.

The attached patch works for my needs and can be used as a starting point.

Test Cases:

Generalization detection works when not using template classes:
class u1 {
public:
  u1() {}
  ~u1() {}
};

class u2: public u1 {
public:
  u2() {}
  ~u2() {}
};

It does not work when using template classes:
template <class T>
class t1 {
public:
  t1() {}
  ~t1() {}
};

template <class T>
class t2: public t1<T> {
public:
  t2() {}
  ~t2() {}
};
Comment 1 Ralf Habacker 2018-08-21 09:19:54 UTC
Git commit f7c4d22cf3663d134656055226c7207c88bbef97 by Ralf Habacker.
Committed on 21/08/2018 at 09:19.
Pushed by habacker into branch 'Applications/18.08'.

Fix 'C++ importer does not correctly detect generalization in template classes'

With this commit a related test case has been added.
FIXED-IN:2.26.1 (KDE Applications 18.08.1)

A  +13   -0    test/import/cxx/templates.h     [License: UNKNOWN]  *
M  +10   -0    umbrello/codeimport/kdevcppparser/cpptree2uml.cpp

The files marked with a * at the end have a non valid license. Please read: https://community.kde.org/Policies/Licensing_Policy and use the headers which are listed at that page.


https://commits.kde.org/umbrello/f7c4d22cf3663d134656055226c7207c88bbef97
Comment 2 Ralf Habacker 2018-08-21 09:20:06 UTC
Thanks for your contribution
Comment 3 Ralf Habacker 2018-08-22 11:40:53 UTC
Git commit fc7dd9e1578d289a322de12cc33eabf91405b4a2 by Ralf Habacker.
Committed on 22/08/2018 at 11:40.
Pushed by habacker into branch 'Applications/18.08'.

More robust determination of the name of the base class with template parameters using the abstract syntax tree

This should also work with multiple template parameters.

M  +8    -14   umbrello/codeimport/kdevcppparser/cpptree2uml.cpp

https://commits.kde.org/umbrello/fc7dd9e1578d289a322de12cc33eabf91405b4a2
Comment 4 Ralf Habacker 2018-08-22 11:47:12 UTC
Git commit 2d3369b2252b1f6255f9a4afc0d607a5c067c858 by Ralf Habacker.
Committed on 22/08/2018 at 11:46.
Pushed by habacker into branch 'Applications/18.08'.

Adding a C++ test case with multiple template parameters

M  +14   -0    test/import/cxx/templates.h

https://commits.kde.org/umbrello/2d3369b2252b1f6255f9a4afc0d607a5c067c858