Merge lp:~ubuntu-sdk-team/ubuntu-sdk-api/listsAndNameSpaces into lp:ubuntu-sdk-api

Proposed by Cris Dywan
Status: Merged
Approved by: Benjamin Zeller
Approved revision: 4
Merged at revision: 4
Proposed branch: lp:~ubuntu-sdk-team/ubuntu-sdk-api/listsAndNameSpaces
Merge into: lp:ubuntu-sdk-api
Prerequisite: lp:~ubuntu-sdk-team/ubuntu-sdk-api/privateApiQt5.6
Diff against target: 117 lines (+35/-25)
2 files modified
apicheck/apicheck.cpp (+29/-19)
tests/qml/Extinct.Animals.api (+6/-6)
To merge this branch: bzr merge lp:~ubuntu-sdk-team/ubuntu-sdk-api/listsAndNameSpaces
Reviewer Review Type Date Requested Status
ubuntu-sdk-build-bot continuous-integration Approve
Benjamin Zeller Approve
Review via email: mp+306357@code.launchpad.net

Commit message

More robust list and namespace handling in apicheck

Description of the change

Forward port of the same commit to the apicheck that lives in the toolkit:

https://code.launchpad.net/~ubuntu-sdk-team/ubuntu-ui-toolkit/listsAndNameSpaces/+merge/299048

To post a comment you must log in.
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Benjamin Zeller (zeller-benjamin) wrote :

In the Animals test at the bottom, seems there is information lost
before you had Extinct.Animals.Europe.ModernContinent: Enum and Extinct.Animals.Pangaea.ModernContinent: Enum.
Now you have Extinct.Animals.ModernContinent: Enum twice
The Europe vs Pangaea information is lost.

Also in line 40 of the patch you do : QString newQmlType(QString(types[0]->qmlTypeName()).split("/")[1].toUtf8());.
Are you sure there are always at least 2 items in the list after splitting the string?

review: Needs Fixing
Revision history for this message
Cris Dywan (kalikiana) wrote :

> In the Animals test at the bottom, seems there is information lost
> before you had Extinct.Animals.Europe.ModernContinent: Enum and
> Extinct.Animals.Pangaea.ModernContinent: Enum.
> Now you have Extinct.Animals.ModernContinent: Enum twice
> The Europe vs Pangaea information is lost.

If filed bug 1628129 to keep track of this: basically the upcoming new format will supersede this, and it's generally going to be more robust and universal. So fixing this in the original QML-ish code would only be interesting if real code were to hit it - Ubuntu UI Toolkit, currently the only project relying on this in real life, isn't affected.

> Also in line 40 of the patch you do : QString
> newQmlType(QString(types[0]->qmlTypeName()).split("/")[1].toUtf8());.
> Are you sure there are always at least 2 items in the list after splitting the
> string?

The code has been thoroughly reviewed before with Ubuntu UI Toolkit in mind, in that sense I'm pretty confident it works in production.

Revision history for this message
Benjamin Zeller (zeller-benjamin) wrote :

Ok then

review: Approve
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'apicheck/apicheck.cpp'
2--- apicheck/apicheck.cpp 2016-09-21 16:04:42 +0000
3+++ apicheck/apicheck.cpp 2016-09-21 16:04:42 +0000
4@@ -140,30 +140,37 @@
5 */
6 QByteArray convertToId(const QString &cppName)
7 {
8- QString qmlType(cppName);
9+ QString qmlType(QString(qPrintable(cppName)).replace(QRegExp("(QQmlListProperty|QList)<(.+)>"), "\\2"));
10+ QString typeFormat(qmlType != cppName ? "list<%1>" : "%1");
11+
12+ QList<const QQmlType*>types(qmlTypesByCppName[qPrintable(qmlType)].toList());
13+ std::sort(types.begin(), types.end(), typeNameSort);
14+
15 if (qmlType.contains("::")) {
16 QStringList parts(qmlType.split("::"));
17- return qPrintable(convertToId(parts[0]) + "." + convertToId(parts[1]));
18+ // Enum or Flags
19+ if (parts.length() > 2) {
20+ qmlType = convertToId(parts[0] + "::" + parts[1]) + "." + parts[2];
21+ } else {
22+ // Namespace
23+ qmlType = parts[1];
24+ // FIXME: Namespaces in properties?
25+ if (parts[0] == "Qt" || parts[0] == "RenderTimer")
26+ return qPrintable(typeFormat.arg(parts[0] + "." + qmlType));
27+ }
28 }
29
30- QList<const QQmlType*>types(qmlTypesByCppName[qPrintable(cppName)].toList());
31- std::sort(types.begin(), types.end(), typeNameSort);
32- if (!types.isEmpty())
33- qmlType = QString(types[0]->qmlTypeName()).split("/")[1].toUtf8();
34- else
35- qmlType = cppToId.value(qPrintable(qmlType), qPrintable(cppName));
36+ if (types.isEmpty())
37+ qmlType = cppToId.value(qPrintable(qmlType), qPrintable(qmlType));
38+ else {
39+ // Cache QML type name
40+ QString newQmlType(QString(types[0]->qmlTypeName()).split("/")[1].toUtf8());
41+ cppToId.insert(qPrintable(qmlType), qPrintable(newQmlType));
42+ qmlType = newQmlType;
43+ }
44 // Strip internal _QMLTYPE_xy suffix
45 qmlType = qmlType.split("_")[0];
46- // List type
47- if (qmlType.startsWith("QQmlListProperty<")) {
48- QString subType(qmlType.mid(17, qmlType.size() - 18));
49- qmlType = "list<" + convertToId(subType) + ">";
50- }
51- else if (qmlType.startsWith("QList<")) {
52- QString subType(qmlType.mid(6, qmlType.size() - 7));
53- qmlType = "list<" + convertToId(subType) + ">";
54- }
55- return qPrintable(qmlType.replace("QTestRootObject", "QtObject"));
56+ return qPrintable(typeFormat.arg(qmlType));
57 }
58
59 QByteArray convertToId(const QMetaObject *mo)
60@@ -626,7 +633,7 @@
61 // Two leading underscores: internal API
62 if (name.startsWith("__"))
63 return;
64- const QString typeName = meth.typeName();
65+ QString typeName = meth.typeName();
66
67 if (implicitSignals.contains(name)
68 && !meth.revision()
69@@ -652,6 +659,8 @@
70 if (revision && object->contains("#version"))
71 method["version"] = object->value("#version").toString();
72
73+ if (typeName.endsWith("*"))
74+ typeName.truncate(typeName.size() - 1);
75 if (typeName != QLatin1String("void"))
76 method["returns"] = typeName;
77
78@@ -850,6 +859,7 @@
79 cppToId.insert("QPoint", "Qt.point");
80 cppToId.insert("QColor", "color");
81 cppToId.insert("QQmlEasingValueType::Type", "Type");
82+ cppToId.insert("QTestRootObject", "QtObject");
83
84 // find a valid QtQuick import
85 QByteArray importCode;
86
87=== modified file 'tests/qml/Extinct.Animals.api'
88--- tests/qml/Extinct.Animals.api 2016-03-03 11:11:58 +0000
89+++ tests/qml/Extinct.Animals.api 2016-09-21 16:04:42 +0000
90@@ -11,21 +11,21 @@
91 Extinct.Animals.Europe 4.2: Europe
92 readonly property ushort era 4.2
93 function ushort era(uchar year)
94-Extinct.Animals.Europe.ModernContinent: Enum
95- America
96- Europe
97 Extinct.Animals.Excavator 1.0 1.1
98 Extinct.Animals.Gigantophis 4.3: QQuickItem
99 property bool extinct
100 function var first()
101 function var fourth()
102+Extinct.Animals.ModernContinent: Enum
103+ America
104+ Europe
105+Extinct.Animals.ModernContinent: Enum
106+ America
107+ Europe
108 Extinct.Animals.Pangaea 1.0: QtObject singleton
109 Extinct.Animals.Pangaea 4.0: Pangaea singleton
110 readonly property ushort era 4.0
111 function ushort era(uchar year)
112-Extinct.Animals.Pangaea.ModernContinent: Enum
113- America
114- Europe
115 Extinct.Animals.Smilodon 1.0 ScimitarCat 0.1 EASmilodon: QtObject
116 function string paw(int i)
117 property string name

Subscribers

People subscribed via source and target branches

to all changes: