1999
1999
QCOMPARE(top->problems().at(1)->finalLocation().start.line, 3);
2002
void TestDUChain::declareMemberOutOfClass2()
2004
// see also: https://bugs.kde.org/show_bug.cgi?id=283356
2006
// 01234567890123456789012345678901234567890123456789012345678901234567890123456789
2007
QByteArray code("<? $a = new A();\n"
2008
// allowed, should re-use existing declaration
2010
"class A { var $x = 1; }");
2011
TopDUContext* top = parse(code, DumpAST);
2014
top = parse(code, DumpNone, top->url().str(), ReferencedTopDUContext(top));
2015
DUChainReleaser releaseTop(top);
2016
DUChainWriteLocker lock;
2018
QVERIFY(top->problems().isEmpty());
2020
QList<Declaration*> decs = top->findLocalDeclarations(Identifier("a"));
2021
QCOMPARE(decs.size(), 2);
2023
Declaration *dec = decs.first();
2024
QVERIFY(dynamic_cast<VariableDeclaration*>(dec));
2025
QVERIFY(dec->type<StructureType>());
2026
QVERIFY(dec->type<StructureType>()->declaration(top)->identifier().nameEquals(Identifier("a")));
2029
Declaration *dec = decs.last();
2030
QVERIFY(dynamic_cast<ClassDeclaration*>(dec));
2031
QVERIFY(dec->type<StructureType>());
2032
QVERIFY(dec->type<StructureType>()->declaration(top)->identifier().nameEquals(Identifier("a")));
2035
{ // check if x got declared
2036
QList<Declaration*> decs = top->childContexts().first()->findDeclarations(Identifier("x"));
2037
// the type of both assignments to $bar->asdf are the same, hence it should only be declared once
2038
QCOMPARE(decs.size(), 1);
2039
ClassMemberDeclaration* cmdec = dynamic_cast<ClassMemberDeclaration*>(decs.first());
2041
QVERIFY(cmdec->accessPolicy() == Declaration::Public);
2042
QVERIFY(!cmdec->isStatic());
2043
QVERIFY(cmdec->type<IntegralType>());
2044
QCOMPARE(cmdec->type<IntegralType>()->dataType(), (uint) IntegralType::TypeInt);
2002
2048
void TestDUChain::declareMemberInClassMethod()
2004
2050
QByteArray code("<? class foo { private $priv = 0; protected $prot = 0; } class bar extends foo {\n"
2761
2807
QVERIFY(top->problems().isEmpty());
2812
char* toString(const KDevelop::CursorInRevision& c)
2816
.arg(QTest::toString(c.line))
2817
.arg(QTest::toString(c.column))
2818
.toLocal8Bit().constData());
2821
char* toString(const KDevelop::RangeInRevision& r)
2825
.arg(QTest::toString(r.start))
2826
.arg(QTest::toString(r.end))
2827
.toLocal8Bit().constData());
2831
void TestDUChain::bug296709()
2833
// see also: https://bugs.kde.org/show_bug.cgi?id=296709
2835
// 01234567890123456789012345678901234567890123456789012345678901234567890123456789
2836
TopDUContext* top = parse(
2838
"foreach(array() as $a) {\n"
2842
DUChainReleaser releaseTop(top);
2843
DUChainWriteLocker lock;
2844
QVERIFY(top->problems().isEmpty());
2845
QList< Declaration* > decs = top->findLocalDeclarations(Identifier("a"));
2846
QCOMPARE(decs.size(), 1);
2847
QCOMPARE(decs.at(0)->range(), RangeInRevision(1, 19, 1, 21));
2848
QCOMPARE(decs.at(0)->uses().count(), 1);
2849
QCOMPARE(decs.at(0)->uses().begin()->count(), 1);
2850
QCOMPARE(decs.at(0)->uses().begin()->first(), RangeInRevision(2, 2, 2, 4));
2764
2853
#include "duchain.moc"