CppEditor: Do not crash on anonymous classes

While performing generate getters and setters we crashed
when using members of anonymous classes.

Change-Id: I27dc8da950345aa4e26ddb1da3914edcffad5af3
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Stenger
2022-04-06 09:07:04 +02:00
parent 0180f24552
commit 2f64cf4779
3 changed files with 66 additions and 0 deletions

View File

@@ -3273,6 +3273,58 @@ void QuickfixTest::testGenerateGetterSetterOnlySetter()
QuickFixOperationTest(testDocuments, &factory, ProjectExplorer::HeaderPaths(), 0);
}
void QuickfixTest::testGenerateGetterSetterAnonymousClass()
{
QList<TestDocumentPtr> testDocuments;
QByteArray original;
QByteArray expected;
QuickFixSettings s;
s->setterInCppFileFrom = 1;
s->setterParameterNameTemplate = "value";
// Header File
original = R"(
class {
int @m_foo;
} bar;
)";
expected = R"(
class {
int m_foo;
public:
int foo() const
{
return m_foo;
}
void setFoo(int value)
{
if (m_foo == value)
return;
m_foo = value;
emit fooChanged();
}
void resetFoo()
{
setFoo({}); // TODO: Adapt to use your actual default defaultValue
}
signals:
void fooChanged();
private:
Q_PROPERTY(int foo READ foo WRITE setFoo RESET resetFoo NOTIFY fooChanged)
} bar;
)";
testDocuments << CppTestDocument::create("file.h", original, expected);
// Source File
testDocuments << CppTestDocument::create("file.cpp", {}, {});
GenerateGetterSetter factory;
QuickFixOperationTest(testDocuments, &factory, ProjectExplorer::HeaderPaths(), 4);
}
void QuickfixTest::testGenerateGetterSetterInlineInHeaderFile()
{
QList<TestDocumentPtr> testDocuments;