diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-03-08 04:18:42 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-03-08 04:18:42 (GMT) |
commit | a7b6bb3537f359a406e3e8d0d0340137a73fc677 (patch) | |
tree | a8954ad817f8940fcfad67493c5e0cb85040581e | |
parent | b35bc4ba38992dde4c35c138caa52c018d80b350 (diff) | |
download | Qt-a7b6bb3537f359a406e3e8d0d0340137a73fc677.zip Qt-a7b6bb3537f359a406e3e8d0d0340137a73fc677.tar.gz Qt-a7b6bb3537f359a406e3e8d0d0340137a73fc677.tar.bz2 |
Disallow upper case property, signal and method names in QML
QT-2976
10 files changed, 37 insertions, 0 deletions
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 3c6c949..ef1032b 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -2204,6 +2204,8 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj) if (propNames.contains(prop.name)) COMPILE_EXCEPTION(&prop, QCoreApplication::translate("QDeclarativeCompiler","Duplicate property name")); + if (QString::fromUtf8(prop.name).at(0).isUpper()) + COMPILE_EXCEPTION(&prop, QCoreApplication::translate("QDeclarativeCompiler","Property names cannot begin with an upper case letter")); propNames.insert(prop.name); } @@ -2211,12 +2213,16 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj) QByteArray name = obj->dynamicSignals.at(ii).name; if (methodNames.contains(name)) COMPILE_EXCEPTION(obj, QCoreApplication::translate("QDeclarativeCompiler","Duplicate signal name")); + if (QString::fromUtf8(name).at(0).isUpper()) + COMPILE_EXCEPTION(obj, QCoreApplication::translate("QDeclarativeCompiler","Signal names cannot begin with an upper case letter")); methodNames.insert(name); } for (int ii = 0; ii < obj->dynamicSlots.count(); ++ii) { QByteArray name = obj->dynamicSlots.at(ii).name; if (methodNames.contains(name)) COMPILE_EXCEPTION(obj, QCoreApplication::translate("QDeclarativeCompiler","Duplicate method name")); + if (QString::fromUtf8(name).at(0).isUpper()) + COMPILE_EXCEPTION(obj, QCoreApplication::translate("QDeclarativeCompiler","Method names cannot begin with an upper case letter")); methodNames.insert(name); } diff --git a/tests/auto/declarative/qdeclarativelanguage/data/method.1.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/method.1.errors.txt new file mode 100644 index 0000000..b10984f --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/method.1.errors.txt @@ -0,0 +1 @@ +3:1:Method names cannot begin with an upper case letter diff --git a/tests/auto/declarative/qdeclarativelanguage/data/method.1.qml b/tests/auto/declarative/qdeclarativelanguage/data/method.1.qml new file mode 100644 index 0000000..d9794b4 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/method.1.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +QtObject { + function MyMethod() {} +} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/property.6.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/property.6.errors.txt new file mode 100644 index 0000000..9e8d454 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/property.6.errors.txt @@ -0,0 +1 @@ +4:5:Property names cannot begin with an upper case letter diff --git a/tests/auto/declarative/qdeclarativelanguage/data/property.6.qml b/tests/auto/declarative/qdeclarativelanguage/data/property.6.qml new file mode 100644 index 0000000..f39bed3 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/property.6.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +QtObject { + property int Hello +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/data/property.7.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/property.7.errors.txt new file mode 100644 index 0000000..9e8d454 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/property.7.errors.txt @@ -0,0 +1 @@ +4:5:Property names cannot begin with an upper case letter diff --git a/tests/auto/declarative/qdeclarativelanguage/data/property.7.qml b/tests/auto/declarative/qdeclarativelanguage/data/property.7.qml new file mode 100644 index 0000000..502eb22 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/property.7.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +QtObject { + property int Hello: 10 +} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/signal.4.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/signal.4.errors.txt new file mode 100644 index 0000000..d96f9e3 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/signal.4.errors.txt @@ -0,0 +1 @@ +3:1:Signal names cannot begin with an upper case letter diff --git a/tests/auto/declarative/qdeclarativelanguage/data/signal.4.qml b/tests/auto/declarative/qdeclarativelanguage/data/signal.4.qml new file mode 100644 index 0000000..7279a46 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/signal.4.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +QtObject { + signal MySignal +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index da0bf1a..083c551 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -269,12 +269,17 @@ void tst_qdeclarativelanguage::errors_data() QTest::newRow("signal.1") << "signal.1.qml" << "signal.1.errors.txt" << false; QTest::newRow("signal.2") << "signal.2.qml" << "signal.2.errors.txt" << false; QTest::newRow("signal.3") << "signal.3.qml" << "signal.3.errors.txt" << false; + QTest::newRow("signal.4") << "signal.4.qml" << "signal.4.errors.txt" << false; + + QTest::newRow("method.1") << "method.1.qml" << "method.1.errors.txt" << false; QTest::newRow("property.1") << "property.1.qml" << "property.1.errors.txt" << false; QTest::newRow("property.2") << "property.2.qml" << "property.2.errors.txt" << false; QTest::newRow("property.3") << "property.3.qml" << "property.3.errors.txt" << false; QTest::newRow("property.4") << "property.4.qml" << "property.4.errors.txt" << false; QTest::newRow("property.5") << "property.5.qml" << "property.5.errors.txt" << false; + QTest::newRow("property.6") << "property.6.qml" << "property.6.errors.txt" << false; + QTest::newRow("property.7") << "property.7.qml" << "property.7.errors.txt" << false; QTest::newRow("Script.1") << "script.1.qml" << "script.1.errors.txt" << false; QTest::newRow("Script.2") << "script.2.qml" << "script.2.errors.txt" << false; |