~ubuntu-branches/ubuntu/utopic/kdevelop-php/utopic

« back to all changes in this revision

Viewing changes to duchain/tests/uses.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-12-20 14:59:02 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20101220145902-a6cmovse1qmue52p
Tags: 1.1.80-0ubuntu1
* New upstream release
* Build-dep on kdevplatform >= 1.1.80
* Get rid of l10n packages, not relevant in Ubuntu, put locale files into main package

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "../declarations/classdeclaration.h"
28
28
#include "../declarations/variabledeclaration.h"
29
29
 
30
 
using namespace KTextEditor;
31
30
using namespace KDevelop;
32
31
 
33
32
QTEST_MAIN(Php::TestUses)
35
34
namespace Php
36
35
{
37
36
 
38
 
void compareUses(Declaration* dec, QList<SimpleRange> ranges)
 
37
void compareUses(Declaration* dec, QList<RangeInRevision> ranges)
39
38
{
40
39
    kDebug() << "comparing uses for" << dec->toString();
41
40
    QCOMPARE(dec->uses().keys().count(), 1);
42
41
    QCOMPARE(dec->uses().values().count(), 1);
43
42
    QCOMPARE(dec->uses().values().first().count(), ranges.count());
44
43
    for (int i = 0; i < ranges.count(); ++i) {
45
 
        kDebug() << dec->uses().values().first().at(i).textRange() << ranges.at(i).textRange();
 
44
        kDebug() << dec->uses().values().first().at(i).castToSimpleRange() << ranges.at(i).castToSimpleRange();
46
45
        QCOMPARE(dec->uses().values().first().at(i), ranges.at(i));
47
46
    }
48
47
}
49
48
 
50
 
void compareUses(Declaration* dec, SimpleRange range)
 
49
void compareUses(Declaration* dec, RangeInRevision range)
51
50
{
52
 
    QList<SimpleRange> r;
 
51
    QList<RangeInRevision> r;
53
52
    r << range;
54
53
    compareUses(dec, r);
55
54
}
67
66
    TopDUContext* top = parse(method, DumpNone, "/usestest/newObject.php");
68
67
    DUChainReleaser releaseTop(top);
69
68
    DUChainWriteLocker lock(DUChain::lock());
70
 
    compareUses(top->localDeclarations().first(), SimpleRange(0, 25, 0, 28));
 
69
    compareUses(top->localDeclarations().first(), RangeInRevision(0, 25, 0, 28));
71
70
    QCOMPARE(top->localDeclarations().first()->uses().keys().first(), IndexedString("/usestest/newObject.php"));
72
71
}
73
72
 
81
80
    DUChainReleaser releaseTop(top);
82
81
    DUChainWriteLocker lock(DUChain::lock());
83
82
    Declaration* fun = top->localDeclarations().first();
84
 
    compareUses(fun, SimpleRange(0, 21, 0, 24));
 
83
    compareUses(fun, RangeInRevision(0, 21, 0, 24));
85
84
    QCOMPARE(fun->uses().keys().first(), IndexedString("/usestest/functionCall.php"));
86
85
}
87
86
 
95
94
    DUChainReleaser releaseTop(top);
96
95
    DUChainWriteLocker lock(DUChain::lock());
97
96
    Declaration* fun = top->childContexts().first()->localDeclarations().first();
98
 
    compareUses(fun, SimpleRange(0, 51, 0, 54));
 
97
    compareUses(fun, RangeInRevision(0, 51, 0, 54));
99
98
    QCOMPARE(fun->uses().keys().first(), IndexedString("/usestest/memberFunctionCall.php"));
100
99
}
101
100
 
109
108
    DUChainReleaser releaseTop(top);
110
109
    DUChainWriteLocker lock(DUChain::lock());
111
110
    Declaration* var = top->childContexts().first()->localDeclarations().first();
112
 
    compareUses(var, SimpleRange(0, 46, 0, 49));
 
111
    compareUses(var, RangeInRevision(0, 46, 0, 49));
113
112
    QCOMPARE(var->uses().keys().first(), IndexedString("/usestest/memberVariable.php"));
114
113
}
115
114
 
121
120
    TopDUContext* top = parse(method, DumpAll);
122
121
    DUChainReleaser releaseTop(top);
123
122
    DUChainWriteLocker lock(DUChain::lock());
124
 
    QList<SimpleRange> ranges;
125
 
    ranges << SimpleRange(1, 42 - 3, 1, 44 - 3) << SimpleRange(1, 46 - 3, 1, 48 - 3) << SimpleRange(1, 59 - 3, 1, 61 - 3);
 
123
    QList<RangeInRevision> ranges;
 
124
    ranges << RangeInRevision(1, 42 - 3, 1, 44 - 3) << RangeInRevision(1, 46 - 3, 1, 48 - 3) << RangeInRevision(1, 59 - 3, 1, 61 - 3);
126
125
    compareUses(top->localDeclarations().at(1), ranges);
127
126
}
128
127
 
135
134
    TopDUContext* top = parse(method, DumpAll);
136
135
    DUChainReleaser releaseTop(top);
137
136
    DUChainWriteLocker lock(DUChain::lock());
138
 
    QList<SimpleRange> ranges;
139
 
    ranges << SimpleRange(0, 13, 0, 15) << SimpleRange(0, 17, 0, 19);
 
137
    QList<RangeInRevision> ranges;
 
138
    ranges << RangeInRevision(0, 13, 0, 15) << RangeInRevision(0, 17, 0, 19);
140
139
    compareUses(top->localDeclarations().at(0), ranges);
141
140
}
142
141
 
150
149
    DUChainReleaser releaseTop(top);
151
150
    DUChainWriteLocker lock(DUChain::lock());
152
151
 
153
 
    QList<SimpleRange> ranges;
154
 
    ranges << SimpleRange(0, 43, 0, 45) << SimpleRange(0, 51, 0, 53) << SimpleRange(0, 58, 0, 60);
 
152
    QList<RangeInRevision> ranges;
 
153
    ranges << RangeInRevision(0, 43, 0, 45) << RangeInRevision(0, 51, 0, 53) << RangeInRevision(0, 58, 0, 60);
155
154
    compareUses(top->localDeclarations().at(1), ranges);
156
155
 
157
156
    ranges.clear();
158
 
    ranges << SimpleRange(0, 47, 0, 48) << SimpleRange(0, 55, 0, 56) << SimpleRange(0, 62, 0, 63);
 
157
    ranges << RangeInRevision(0, 47, 0, 48) << RangeInRevision(0, 55, 0, 56) << RangeInRevision(0, 62, 0, 63);
159
158
    compareUses(top->childContexts().first()->localDeclarations().first(), ranges);
160
159
}
161
160
 
170
169
    DUChainWriteLocker lock(DUChain::lock());
171
170
 
172
171
    //$a
173
 
    compareUses(top->localDeclarations().at(1), SimpleRange(0, 50, 0, 52));
 
172
    compareUses(top->localDeclarations().at(1), RangeInRevision(0, 50, 0, 52));
174
173
 
175
174
    //foo
176
 
    compareUses(top->childContexts().first()->localDeclarations().first(), SimpleRange(0, 54, 0, 57));
 
175
    compareUses(top->childContexts().first()->localDeclarations().first(), RangeInRevision(0, 54, 0, 57));
177
176
}
178
177
 
179
178
void TestUses::variableTypeChange()
186
185
    DUChainReleaser releaseTop(top);
187
186
    DUChainWriteLocker lock(DUChain::lock());
188
187
 
189
 
    QList<SimpleRange> ranges;
190
 
    ranges << SimpleRange(0, 25, 0, 27);
191
 
    ranges << SimpleRange(0, 29, 0, 31);
192
 
    ranges << SimpleRange(0, 37, 0, 39);
193
 
    ranges << SimpleRange(0, 41, 0, 43);
194
 
    ranges << SimpleRange(0, 51, 0, 53);
 
188
    QList<RangeInRevision> ranges;
 
189
    ranges << RangeInRevision(0, 25, 0, 27);
 
190
    ranges << RangeInRevision(0, 29, 0, 31);
 
191
    ranges << RangeInRevision(0, 37, 0, 39);
 
192
    ranges << RangeInRevision(0, 41, 0, 43);
 
193
    ranges << RangeInRevision(0, 51, 0, 53);
195
194
    compareUses(top->localDeclarations().at(1), ranges);
196
195
}
197
196
 
206
205
    DUChainReleaser releaseTop(top);
207
206
    DUChainWriteLocker lock(DUChain::lock());
208
207
 
209
 
    QList<SimpleRange> ranges;
210
 
    ranges << SimpleRange(0, 28, 0, 30);
211
 
    ranges << SimpleRange(0, 32, 0, 34);
212
 
    ranges << SimpleRange(0, 38, 0, 40);
213
 
    ranges << SimpleRange(0, 42, 0, 44);
 
208
    QList<RangeInRevision> ranges;
 
209
    ranges << RangeInRevision(0, 28, 0, 30);
 
210
    ranges << RangeInRevision(0, 32, 0, 34);
 
211
    ranges << RangeInRevision(0, 38, 0, 40);
 
212
    ranges << RangeInRevision(0, 42, 0, 44);
214
213
    compareUses(top->childContexts().at(1)->localDeclarations().at(0), ranges);
215
214
}
216
215
 
222
221
    TopDUContext* top = parse(method, DumpAll);
223
222
    DUChainWriteLocker lock(DUChain::lock());
224
223
 
225
 
    compareUses(top->localDeclarations().at(0), SimpleRange(0, 31, 0, 32));
 
224
    compareUses(top->localDeclarations().at(0), RangeInRevision(0, 31, 0, 32));
226
225
}
227
226
 
228
227
void TestUses::classImplements()
234
233
    DUChainReleaser releaseTop(top);
235
234
    DUChainWriteLocker lock(DUChain::lock());
236
235
 
237
 
    compareUses(top->localDeclarations().at(0), SimpleRange(0, 38, 0, 39));
 
236
    compareUses(top->localDeclarations().at(0), RangeInRevision(0, 38, 0, 39));
238
237
}
239
238
 
240
239
void TestUses::classImplementsMultiple()
246
245
    DUChainReleaser releaseTop(top);
247
246
    DUChainWriteLocker lock(DUChain::lock());
248
247
 
249
 
    compareUses(top->localDeclarations().at(0), SimpleRange(0, 54, 0, 55));
250
 
    compareUses(top->localDeclarations().at(1), SimpleRange(0, 57, 0, 58));
 
248
    compareUses(top->localDeclarations().at(0), RangeInRevision(0, 54, 0, 55));
 
249
    compareUses(top->localDeclarations().at(1), RangeInRevision(0, 57, 0, 58));
251
250
}
252
251
 
253
252
void TestUses::interfaceExtends()
259
258
    DUChainReleaser releaseTop(top);
260
259
    DUChainWriteLocker lock(DUChain::lock());
261
260
 
262
 
    compareUses(top->localDeclarations().at(0), SimpleRange(0, 39, 0, 40));
 
261
    compareUses(top->localDeclarations().at(0), RangeInRevision(0, 39, 0, 40));
263
262
}
264
263
 
265
264
void TestUses::interfaceExtendsMultiple()
271
270
    DUChainReleaser releaseTop(top);
272
271
    DUChainWriteLocker lock(DUChain::lock());
273
272
 
274
 
    compareUses(top->localDeclarations().at(0), SimpleRange(0, 55, 0, 56));
275
 
    compareUses(top->localDeclarations().at(1), SimpleRange(0, 58, 0, 59));
 
273
    compareUses(top->localDeclarations().at(0), RangeInRevision(0, 55, 0, 56));
 
274
    compareUses(top->localDeclarations().at(1), RangeInRevision(0, 58, 0, 59));
276
275
}
277
276
 
278
277
void TestUses::staticMemberFunctionCall()
284
283
    DUChainReleaser releaseTop(top);
285
284
    DUChainWriteLocker lock(DUChain::lock());
286
285
 
287
 
    compareUses(top->localDeclarations().first(), SimpleRange(0, 47, 0, 48));
288
 
    compareUses(top->childContexts().first()->localDeclarations().first(), SimpleRange(0, 50, 0, 53));
 
286
    compareUses(top->localDeclarations().first(), RangeInRevision(0, 47, 0, 48));
 
287
    compareUses(top->childContexts().first()->localDeclarations().first(), RangeInRevision(0, 50, 0, 53));
289
288
}
290
289
 
291
290
void TestUses::staticMemberVariable()
297
296
    DUChainReleaser releaseTop(top);
298
297
    DUChainWriteLocker lock(DUChain::lock());
299
298
 
300
 
    compareUses(top->localDeclarations().first(), SimpleRange(0, 43, 0, 44));
301
 
    compareUses(top->childContexts().first()->localDeclarations().first(), SimpleRange(0, 46, 0, 50));
302
 
    compareUses(top->localDeclarations().at(1), SimpleRange(0, 52, 0, 56));
 
299
    compareUses(top->localDeclarations().first(), RangeInRevision(0, 43, 0, 44));
 
300
    compareUses(top->childContexts().first()->localDeclarations().first(), RangeInRevision(0, 46, 0, 50));
 
301
    compareUses(top->localDeclarations().at(1), RangeInRevision(0, 52, 0, 56));
303
302
}
304
303
 
305
304
void TestUses::constant()
311
310
    DUChainReleaser releaseTop(top);
312
311
    DUChainWriteLocker lock(DUChain::lock());
313
312
 
314
 
    compareUses(top->localDeclarations().first(), SimpleRange(0, 28, 0, 29));
 
313
    compareUses(top->localDeclarations().first(), RangeInRevision(0, 28, 0, 29));
315
314
}
316
315
 
317
316
void TestUses::classConstant()
324
323
    DUChainReleaser releaseTop(top);
325
324
    DUChainWriteLocker lock(DUChain::lock());
326
325
 
327
 
    compareUses(top->localDeclarations().first(), SimpleRange(0, 39, 0, 40));
328
 
    compareUses(top->childContexts().first()->localDeclarations().first(), SimpleRange(0, 42, 0, 45));
 
326
    compareUses(top->localDeclarations().first(), RangeInRevision(0, 39, 0, 40));
 
327
    compareUses(top->childContexts().first()->localDeclarations().first(), RangeInRevision(0, 42, 0, 45));
329
328
    }
330
329
    {
331
330
    // bug: https://bugs.kde.org/show_bug.cgi?id=241597
343
342
    Declaration* dec = top->childContexts().first()->localDeclarations().first();
344
343
    QVERIFY(dec->abstractType()->modifiers() & AbstractType::ConstModifier);
345
344
    QCOMPARE(dec->qualifiedIdentifier().toString(), QString("a::FOO"));
346
 
    compareUses(dec, QList<SimpleRange>() << SimpleRange(1, 43, 1, 46)
347
 
                                          << SimpleRange(2, 3, 2, 6)
348
 
                                          << SimpleRange(3, 3, 3, 6));
 
345
    compareUses(dec, QList<RangeInRevision>() << RangeInRevision(1, 43, 1, 46)
 
346
                                          << RangeInRevision(2, 3, 2, 6)
 
347
                                          << RangeInRevision(3, 3, 3, 6));
349
348
    }
350
349
}
351
350
 
358
357
    DUChainReleaser releaseTop(top);
359
358
    DUChainWriteLocker lock(DUChain::lock());
360
359
 
361
 
    QList<SimpleRange> range;
362
 
    range << SimpleRange(0, 47, 0, 48);
363
 
    range << SimpleRange(0, 66, 0, 72);
 
360
    QList<RangeInRevision> range;
 
361
    range << RangeInRevision(0, 47, 0, 48);
 
362
    range << RangeInRevision(0, 66, 0, 72);
364
363
    compareUses(top->localDeclarations().first(), range);
365
364
 
366
 
    compareUses(top->childContexts().first()->localDeclarations().first(), SimpleRange(0, 74, 0, 75));
 
365
    compareUses(top->childContexts().first()->localDeclarations().first(), RangeInRevision(0, 74, 0, 75));
367
366
}
368
367
 
369
368
void TestUses::classSelf()
375
374
    DUChainReleaser releaseTop(top);
376
375
    DUChainWriteLocker lock(DUChain::lock());
377
376
 
378
 
    compareUses(top->localDeclarations().first(), SimpleRange(0, 28, 0, 32));
379
 
    compareUses(top->childContexts().first()->localDeclarations().first(), SimpleRange(0, 34, 0, 35));
 
377
    compareUses(top->localDeclarations().first(), RangeInRevision(0, 28, 0, 32));
 
378
    compareUses(top->childContexts().first()->localDeclarations().first(), RangeInRevision(0, 34, 0, 35));
380
379
}
381
380
void TestUses::classThis()
382
381
{
387
386
    DUChainReleaser releaseTop(top);
388
387
    DUChainWriteLocker lock(DUChain::lock());
389
388
 
390
 
    compareUses(top->localDeclarations().first(), SimpleRange(0, 28, 0, 33));
391
 
    compareUses(top->childContexts().first()->localDeclarations().first(), SimpleRange(0, 35, 0, 36));
 
389
    compareUses(top->localDeclarations().first(), RangeInRevision(0, 28, 0, 33));
 
390
    compareUses(top->childContexts().first()->localDeclarations().first(), RangeInRevision(0, 35, 0, 36));
392
391
}
393
392
 
394
393
void TestUses::objectWithClassName()
400
399
    DUChainReleaser releaseTop(top);
401
400
    DUChainWriteLocker lock(DUChain::lock());
402
401
 
403
 
    QList<SimpleRange> ranges;
404
 
    ranges << SimpleRange(0, 66, 0, 66 + 2);
405
 
    ranges << SimpleRange(0, 78, 0, 78 + 2);
406
 
    ranges << SimpleRange(0, 85, 0, 85 + 2);
 
402
    QList<RangeInRevision> ranges;
 
403
    ranges << RangeInRevision(0, 66, 0, 66 + 2);
 
404
    ranges << RangeInRevision(0, 78, 0, 78 + 2);
 
405
    ranges << RangeInRevision(0, 85, 0, 85 + 2);
407
406
    compareUses(top->localDeclarations().first(), ranges);
408
407
 
409
 
    compareUses(top->localDeclarations().at(1), SimpleRange(0, 70, 0, 70 + 3));
 
408
    compareUses(top->localDeclarations().at(1), RangeInRevision(0, 70, 0, 70 + 3));
410
409
}
411
410
 
412
411
void TestUses::classAndConstWithSameName()
418
417
    DUChainReleaser releaseTop(top);
419
418
    DUChainWriteLocker lock(DUChain::lock());
420
419
 
421
 
    compareUses(top->localDeclarations().first(), SimpleRange(0, 38, 0, 39));
422
 
    compareUses(top->localDeclarations().at(1), SimpleRange(0, 31, 0, 32));
423
 
    compareUses(top->localDeclarations().at(2), SimpleRange(0, 76, 0, 77));
424
 
    compareUses(top->localDeclarations().at(3), SimpleRange(0, 73, 0, 74));
 
420
    compareUses(top->localDeclarations().first(), RangeInRevision(0, 38, 0, 39));
 
421
    compareUses(top->localDeclarations().at(1), RangeInRevision(0, 31, 0, 32));
 
422
    compareUses(top->localDeclarations().at(2), RangeInRevision(0, 76, 0, 77));
 
423
    compareUses(top->localDeclarations().at(3), RangeInRevision(0, 73, 0, 74));
425
424
}
426
425
 
427
426
 
434
433
    DUChainReleaser releaseTop(top);
435
434
    DUChainWriteLocker lock(DUChain::lock());
436
435
 
437
 
    compareUses(top->localDeclarations().first(), SimpleRange(0, 35, 0, 36));
438
 
    compareUses(top->localDeclarations().at(1), SimpleRange(0, 38, 0, 39));
 
436
    compareUses(top->localDeclarations().first(), RangeInRevision(0, 35, 0, 36));
 
437
    compareUses(top->localDeclarations().at(1), RangeInRevision(0, 38, 0, 39));
439
438
}
440
439
 
441
440
void TestUses::constAndVariableWithSameName()
447
446
    DUChainReleaser releaseTop(top);
448
447
    DUChainWriteLocker lock(DUChain::lock());
449
448
 
450
 
    compareUses(top->localDeclarations().first(), SimpleRange(0, 30, 0, 32));
451
 
    compareUses(top->localDeclarations().at(1), SimpleRange(0, 27, 0, 28));
 
449
    compareUses(top->localDeclarations().first(), RangeInRevision(0, 30, 0, 32));
 
450
    compareUses(top->localDeclarations().at(1), RangeInRevision(0, 27, 0, 28));
452
451
}
453
452
 
454
453
void TestUses::functionAndClassWithSameName()
463
462
    Declaration* fnAsdf = top->childContexts().first()->localDeclarations().first();
464
463
    QCOMPARE(fnAsdf->uses().keys().count(), 0);
465
464
 
466
 
    compareUses(top->localDeclarations().at(1), SimpleRange(0, 70, 0, 74));
 
465
    compareUses(top->localDeclarations().at(1), RangeInRevision(0, 70, 0, 74));
467
466
}
468
467
 
469
468
void TestUses::constantInClassMember()
478
477
 
479
478
    Declaration* constant = top->findDeclarations(Identifier("TEST")).first();
480
479
 
481
 
    QList<SimpleRange> uses;
482
 
    uses << SimpleRange(0, 41, 0, 45);
483
 
    uses << SimpleRange(0, 63, 0, 67);
484
 
    uses << SimpleRange(0, 73, 0, 77);
 
480
    QList<RangeInRevision> uses;
 
481
    uses << RangeInRevision(0, 41, 0, 45);
 
482
    uses << RangeInRevision(0, 63, 0, 67);
 
483
    uses << RangeInRevision(0, 73, 0, 77);
485
484
    compareUses(constant, uses);
486
485
}
487
486
 
496
495
    DUChainWriteLocker lock(DUChain::lock());
497
496
 
498
497
    Declaration *d = top->localDeclarations().first();
499
 
    compareUses(d, SimpleRange(0, 16, 0, 18));
 
498
    compareUses(d, RangeInRevision(0, 16, 0, 18));
500
499
}
501
500
 
502
501
void TestUses::foreachArray()
514
513
 
515
514
    // $a
516
515
    Declaration *d = top->localDeclarations().at(0);
517
 
    compareUses(d, SimpleRange(0, 26, 0, 28));
 
516
    compareUses(d, RangeInRevision(0, 26, 0, 28));
518
517
 
519
518
    // $k
520
519
    d = top->localDeclarations().at(1);
521
 
    compareUses(d, SimpleRange(0, 51, 0, 53));
 
520
    compareUses(d, RangeInRevision(0, 51, 0, 53));
522
521
 
523
522
    // $i
524
523
    d = top->localDeclarations().at(2);
525
 
    compareUses(d, SimpleRange(0, 55, 0, 57));
 
524
    compareUses(d, RangeInRevision(0, 55, 0, 57));
526
525
}
527
526
 
528
527
void TestUses::assignmentToMemberArray()
540
539
    QVERIFY(x);
541
540
 
542
541
    // $this
543
 
    compareUses(x, SimpleRange(0, 50, 0, 55));
 
542
    compareUses(x, RangeInRevision(0, 50, 0, 55));
544
543
 
545
544
    // var $y
546
545
    Declaration *y = x->logicalInternalContext(top)->findDeclarations(Identifier("y")).first();
547
546
    QVERIFY(y);
548
547
 
549
548
    // $this->y
550
 
    compareUses(y, SimpleRange(0, 57, 0, 58));
 
549
    compareUses(y, RangeInRevision(0, 57, 0, 58));
551
550
 
552
551
    // function z
553
552
    Declaration *z = x->logicalInternalContext(top)->findDeclarations(Identifier("z")).first();
556
555
    // $a
557
556
    Declaration *a = z->logicalInternalContext(top)->findDeclarations(Identifier("a")).first();
558
557
    QVERIFY(a);
559
 
    compareUses(a, QList<SimpleRange>()
 
558
    compareUses(a, QList<RangeInRevision>()
560
559
                // $b = $a
561
 
                << SimpleRange(0, 46, 0, 48)
 
560
                << RangeInRevision(0, 46, 0, 48)
562
561
                // $this->y[$a]
563
 
                << SimpleRange(0, 59, 0, 61)
 
562
                << RangeInRevision(0, 59, 0, 61)
564
563
               );
565
564
}
566
565
 
578
577
 
579
578
    Declaration* a = top->childContexts().first()->localDeclarations().first();
580
579
    QCOMPARE(a->identifier().toString(), QString("a"));
581
 
    compareUses(a, SimpleRange(0, 68, 0, 70));
 
580
    compareUses(a, RangeInRevision(0, 68, 0, 70));
582
581
 
583
582
    Declaration* i = top->childContexts().first()->childContexts().first()->localDeclarations().first();
584
583
    QCOMPARE(i->identifier().toString(), QString("i"));
585
 
    compareUses(i, SimpleRange(0, 71, 0, 73));
 
584
    compareUses(i, RangeInRevision(0, 71, 0, 73));
586
585
}
587
586
 
588
587
void TestUses::functionParamNewDeclaration()
596
595
    DUChainWriteLocker lock(DUChain::lock());
597
596
 
598
597
    Declaration *d = top->childContexts().first()->localDeclarations().first();
599
 
    QList<SimpleRange> ranges;
600
 
    ranges << SimpleRange(0, 22, 0, 24);
601
 
    ranges << SimpleRange(0, 26, 0, 28);
 
598
    QList<RangeInRevision> ranges;
 
599
    ranges << RangeInRevision(0, 22, 0, 24);
 
600
    ranges << RangeInRevision(0, 26, 0, 28);
602
601
    compareUses(d, ranges);
603
602
}
604
603
 
613
612
    DUChainWriteLocker lock(DUChain::lock());
614
613
 
615
614
    Declaration *d = top->findDeclarations(QualifiedIdentifier("exception")).first();
616
 
    compareUses(d, SimpleRange(0, 18, 0, 27));
 
615
    compareUses(d, RangeInRevision(0, 18, 0, 27));
617
616
}
618
617
 
619
618
void TestUses::variableRedeclaration()
629
628
    QList< Declaration* > decs = top->findDeclarations(QualifiedIdentifier("s"));
630
629
    QCOMPARE(decs.size(), 1);
631
630
    Declaration *d = decs.first();
632
 
    compareUses(d, QList<SimpleRange>()
633
 
                     << SimpleRange(0, 13, 0, 15)
634
 
                     << SimpleRange(0, 18, 0, 20)
635
 
                     << SimpleRange(0, 23, 0, 25)
 
631
    compareUses(d, QList<RangeInRevision>()
 
632
                     << RangeInRevision(0, 13, 0, 15)
 
633
                     << RangeInRevision(0, 18, 0, 20)
 
634
                     << RangeInRevision(0, 23, 0, 25)
636
635
                );
637
636
}
638
637
 
650
649
    QList<Declaration*> decs = top->findLocalDeclarations(Identifier("foobar"));
651
650
    QCOMPARE(decs.size(), 1);
652
651
    Declaration *d = decs.first();
653
 
    compareUses(d, QList<SimpleRange>()
654
 
                    << SimpleRange(1, 0, 1, 6)
655
 
                    << SimpleRange(2, 0, 2, 6)
656
 
                    << SimpleRange(3, 0, 3, 6)
 
652
    compareUses(d, QList<RangeInRevision>()
 
653
                    << RangeInRevision(1, 0, 1, 6)
 
654
                    << RangeInRevision(2, 0, 2, 6)
 
655
                    << RangeInRevision(3, 0, 3, 6)
657
656
                );
658
657
}
659
658
 
673
672
        QList<Declaration*> decs = top->childContexts().first()->findDeclarations(QualifiedIdentifier("foobar"));
674
673
        QCOMPARE(decs.size(), 1);
675
674
        Declaration *d = decs.first();
676
 
        compareUses(d, QList<SimpleRange>()
677
 
                        << SimpleRange(1, 4, 1, 10)
678
 
                        << SimpleRange(2, 4, 2, 10)
679
 
                        << SimpleRange(3, 4, 3, 10)
 
675
        compareUses(d, QList<RangeInRevision>()
 
676
                        << RangeInRevision(1, 4, 1, 10)
 
677
                        << RangeInRevision(2, 4, 2, 10)
 
678
                        << RangeInRevision(3, 4, 3, 10)
680
679
                    );
681
680
    }
682
681
 
684
683
        QList<Declaration*> decs = top->childContexts().first()->findDeclarations(QualifiedIdentifier("barfoo"));
685
684
        QCOMPARE(decs.size(), 1);
686
685
        Declaration *d = decs.first();
687
 
        compareUses(d, QList<SimpleRange>()
688
 
                        << SimpleRange(4, 6, 4, 12)
689
 
                        << SimpleRange(5, 6, 5, 12)
690
 
                        << SimpleRange(6, 6, 6, 12)
 
686
        compareUses(d, QList<RangeInRevision>()
 
687
                        << RangeInRevision(4, 6, 4, 12)
 
688
                        << RangeInRevision(5, 6, 5, 12)
 
689
                        << RangeInRevision(6, 6, 6, 12)
691
690
                    );
692
691
    }
693
692
}
706
705
    QList<Declaration*> decs = top->findLocalDeclarations(Identifier("asdf"));
707
706
    QCOMPARE(decs.size(), 1);
708
707
    Declaration *d = decs.first();
709
 
    compareUses(d, QList<SimpleRange>()
710
 
                    << SimpleRange(1, 4, 1, 8)
711
 
                    << SimpleRange(2, 4, 2, 8)
712
 
                    << SimpleRange(3, 4, 3, 8)
 
708
    compareUses(d, QList<RangeInRevision>()
 
709
                    << RangeInRevision(1, 4, 1, 8)
 
710
                    << RangeInRevision(2, 4, 2, 8)
 
711
                    << RangeInRevision(3, 4, 3, 8)
713
712
                );
714
713
}
715
714
 
725
724
 
726
725
    QVector<Declaration*> decs = top->localDeclarations();
727
726
    QCOMPARE(decs.size(), 1);
728
 
    QCOMPARE(decs.first()->range(), SimpleRange(0, 20, 0, 24));
729
 
    compareUses(decs.first(), SimpleRange(0, 3, 0, 7));
 
727
    QCOMPARE(decs.first()->range(), RangeInRevision(0, 20, 0, 24));
 
728
    compareUses(decs.first(), RangeInRevision(0, 3, 0, 7));
730
729
}
731
730
 
732
731
void TestUses::propertyAndMethodWithSameName()
749
748
    // method name1
750
749
    QVERIFY(decs[0]->identifier().nameEquals(Identifier("name1")));
751
750
    QVERIFY(decs[0]->isFunctionDeclaration());
752
 
    compareUses(decs[0], SimpleRange(2, 4, 2, 9));
 
751
    compareUses(decs[0], RangeInRevision(2, 4, 2, 9));
753
752
    // property name1
754
753
    QVERIFY(decs[1]->identifier().nameEquals(Identifier("name1")));
755
754
    QVERIFY(!decs[1]->isFunctionDeclaration());
756
 
    compareUses(decs[1], SimpleRange(2, 17, 2, 22));
 
755
    compareUses(decs[1], RangeInRevision(2, 17, 2, 22));
757
756
 
758
757
    // property name2
759
758
    QVERIFY(decs[2]->identifier().nameEquals(Identifier("name2")));
760
759
    QVERIFY(!decs[2]->isFunctionDeclaration());
761
 
    compareUses(decs[2], SimpleRange(3, 4, 3, 9));
 
760
    compareUses(decs[2], RangeInRevision(3, 4, 3, 9));
762
761
    // method name2
763
762
    QVERIFY(decs[3]->identifier().nameEquals(Identifier("name2")));
764
763
    QVERIFY(decs[3]->isFunctionDeclaration());
765
 
    compareUses(decs[3], SimpleRange(3, 15, 3, 20));
 
764
    compareUses(decs[3], RangeInRevision(3, 15, 3, 20));
766
765
}
767
766
 
768
767
void TestUses::nestedMethodCalls()
786
785
    // class a
787
786
    QVERIFY(topDecs[0]->identifier().nameEquals(Identifier("a")));
788
787
    QVERIFY(dynamic_cast<ClassDeclaration*>(topDecs[0]));
789
 
    compareUses(topDecs[0], SimpleRange(3, 9, 3, 10));
 
788
    compareUses(topDecs[0], RangeInRevision(3, 9, 3, 10));
790
789
    // class b
791
790
    QVERIFY(topDecs[1]->identifier().nameEquals(Identifier("b")));
792
791
    QVERIFY(dynamic_cast<ClassDeclaration*>(topDecs[1]));
793
 
    compareUses(topDecs[1], SimpleRange(4, 9, 4, 10));
 
792
    compareUses(topDecs[1], RangeInRevision(4, 9, 4, 10));
794
793
 
795
794
    // $a
796
795
    QVERIFY(topDecs[2]->identifier().nameEquals(Identifier("a")));
797
796
    QVERIFY(dynamic_cast<VariableDeclaration*>(topDecs[2]));
798
 
    compareUses(topDecs[2], SimpleRange(5, 0, 5, 2));
 
797
    compareUses(topDecs[2], RangeInRevision(5, 0, 5, 2));
799
798
    // $b
800
799
    QVERIFY(topDecs[3]->identifier().nameEquals(Identifier("b")));
801
800
    QVERIFY(dynamic_cast<VariableDeclaration*>(topDecs[3]));
802
 
    compareUses(topDecs[3], SimpleRange(5, 6, 5, 8));
 
801
    compareUses(topDecs[3], RangeInRevision(5, 6, 5, 8));
803
802
 
804
803
    // function a
805
804
    Declaration* methodADec = topDecs[0]->internalContext()->localDeclarations().first();
806
805
    QVERIFY(methodADec->isFunctionDeclaration());
807
 
    compareUses(methodADec, SimpleRange(5, 4, 5, 5));
 
806
    compareUses(methodADec, RangeInRevision(5, 4, 5, 5));
808
807
 
809
808
    // function b
810
809
    Declaration* methodBDec = topDecs[1]->internalContext()->localDeclarations().first();
811
810
    QVERIFY(methodBDec->isFunctionDeclaration());
812
 
    compareUses(methodBDec, SimpleRange(5, 10, 5, 11));
 
811
    compareUses(methodBDec, RangeInRevision(5, 10, 5, 11));
813
812
}
814
813
 
815
814
void TestUses::unset()
824
823
 
825
824
    QVector<Declaration*> decs = top->localDeclarations();
826
825
    QCOMPARE(decs.size(), 1);
827
 
    QCOMPARE(decs.first()->range(), SimpleRange(0, 3, 0, 5));
828
 
    compareUses(decs.first(), SimpleRange(0, 17, 0, 19));
 
826
    QCOMPARE(decs.first()->range(), RangeInRevision(0, 3, 0, 5));
 
827
    compareUses(decs.first(), RangeInRevision(0, 17, 0, 19));
829
828
}
830
829
 
831
830
void TestUses::functionArguments()
843
842
 
844
843
    // $a
845
844
    Declaration *d = top->childContexts().at(0)->localDeclarations().at(0);
846
 
    compareUses(d, SimpleRange(0, 27, 0, 29));
 
845
    compareUses(d, RangeInRevision(0, 27, 0, 29));
847
846
 
848
847
    // $b
849
848
    d = top->childContexts().at(0)->localDeclarations().at(1);
850
 
    compareUses(d, SimpleRange(0, 35, 0, 37));
 
849
    compareUses(d, RangeInRevision(0, 35, 0, 37));
851
850
}
852
851
 
853
852
void TestUses::namespaces()
868
867
                              "new \\Foo\\Bar\\MyClass;\n"
869
868
                              "function Func(\\Foo\\Bar\\MyClass $a){}\n"
870
869
                              "class a extends \\Foo\\Bar\\MyClass implements \\Foo\\Bar\\MyInterface {}\n"
 
870
                              "}\n"
 
871
                              "namespace Foo {\n"
871
872
                              "}\n", DumpAll);
872
873
    QVERIFY(top);
873
874
    DUChainReleaser releaseTop(top);
875
876
 
876
877
    Declaration* dec;
877
878
 
878
 
    dec = top->findDeclarations(QualifiedIdentifier("foo")).first();
 
879
    dec = top->findDeclarations(QualifiedIdentifier("foo")).last();
879
880
    QCOMPARE(dec->kind(), Declaration::Namespace);
880
 
    compareUses(dec, QList<SimpleRange>() << SimpleRange(8, 1, 8, 4)
881
 
                                          << SimpleRange(9, 1, 9, 4)
882
 
                                          << SimpleRange(10, 1, 10, 4)
883
 
                                          << SimpleRange(11, 5, 11, 8)
884
 
                                          << SimpleRange(12, 15, 12, 18)
885
 
                                          << SimpleRange(13, 17, 13, 20)
886
 
                                          << SimpleRange(13, 45, 13, 48));
 
881
    compareUses(dec, QList<RangeInRevision>()
 
882
                                          << RangeInRevision(1, 10, 1, 13)
 
883
                                          << RangeInRevision(8, 1, 8, 4)
 
884
                                          << RangeInRevision(9, 1, 9, 4)
 
885
                                          << RangeInRevision(10, 1, 10, 4)
 
886
                                          << RangeInRevision(11, 5, 11, 8)
 
887
                                          << RangeInRevision(12, 15, 12, 18)
 
888
                                          << RangeInRevision(13, 17, 13, 20)
 
889
                                          << RangeInRevision(13, 45, 13, 48));
887
890
 
888
891
    dec = top->findDeclarations(QualifiedIdentifier("foo::bar")).first();
889
892
    QCOMPARE(dec->kind(), Declaration::Namespace);
890
893
    QVERIFY(dec->internalContext());
891
 
    compareUses(dec, QList<SimpleRange>() << SimpleRange(8, 5, 8, 8)
892
 
                                          << SimpleRange(9, 5, 9, 8)
893
 
                                          << SimpleRange(10, 5, 10, 8)
894
 
                                          << SimpleRange(11, 9, 11, 12)
895
 
                                          << SimpleRange(12, 19, 12, 22)
896
 
                                          << SimpleRange(13, 21, 13, 24)
897
 
                                          << SimpleRange(13, 49, 13, 52));
 
894
    compareUses(dec, QList<RangeInRevision>() << RangeInRevision(8, 5, 8, 8)
 
895
                                          << RangeInRevision(9, 5, 9, 8)
 
896
                                          << RangeInRevision(10, 5, 10, 8)
 
897
                                          << RangeInRevision(11, 9, 11, 12)
 
898
                                          << RangeInRevision(12, 19, 12, 22)
 
899
                                          << RangeInRevision(13, 21, 13, 24)
 
900
                                          << RangeInRevision(13, 49, 13, 52));
898
901
    QCOMPARE(dec->internalContext()->localDeclarations().size(), 4);
899
902
    foreach(Declaration* d, dec->internalContext()->localDeclarations()) {
900
903
        kDebug() << d->toString() << d->qualifiedIdentifier();
901
904
    }
902
905
 
903
906
    dec = top->findDeclarations(QualifiedIdentifier("foo::bar::MyConst")).first();
904
 
    compareUses(dec, SimpleRange(8, 9, 8, 16));
 
907
    compareUses(dec, RangeInRevision(8, 9, 8, 16));
905
908
 
906
909
    dec = top->findDeclarations(QualifiedIdentifier("foo::bar::myclass")).first();
907
910
    QVERIFY(dynamic_cast<ClassDeclaration*>(dec));
908
 
    compareUses(dec, QList<SimpleRange>() << SimpleRange(9, 9, 9, 16)
909
 
                                          << SimpleRange(11, 13, 11, 20)
910
 
                                          << SimpleRange(12, 23, 12, 30)
911
 
                                          << SimpleRange(13, 25, 13, 32)
 
911
    compareUses(dec, QList<RangeInRevision>() << RangeInRevision(9, 9, 9, 16)
 
912
                                          << RangeInRevision(11, 13, 11, 20)
 
913
                                          << RangeInRevision(12, 23, 12, 30)
 
914
                                          << RangeInRevision(13, 25, 13, 32)
912
915
               );
913
916
    dec = top->findDeclarations(QualifiedIdentifier("foo::bar::myinterface")).first();
914
917
    QVERIFY(dynamic_cast<ClassDeclaration*>(dec));
915
 
    compareUses(dec, SimpleRange(13, 53, 13, 64) );
 
918
    compareUses(dec, RangeInRevision(13, 53, 13, 64) );
916
919
 
917
920
    dec = top->findDeclarations(QualifiedIdentifier("foo::bar::myclass::ClassConst")).first();
918
 
    compareUses(dec, SimpleRange(9, 18, 9, 28));
 
921
    compareUses(dec, RangeInRevision(9, 18, 9, 28));
919
922
 
920
923
    dec = top->findDeclarations(QualifiedIdentifier("foo::bar::myfunc")).first();
921
 
    compareUses(dec, SimpleRange(10, 9, 10, 15));
 
924
    compareUses(dec, RangeInRevision(10, 9, 10, 15));
922
925
}
923
926
 
924
927
void TestUses::useNamespace()
940
943
    Declaration* dec;
941
944
    dec = top->findDeclarations(QualifiedIdentifier("foo")).first();
942
945
    QCOMPARE(dec->kind(), Declaration::Namespace);
943
 
    compareUses(dec, SimpleRange(4, 4, 4, 7));
 
946
    compareUses(dec, RangeInRevision(4, 4, 4, 7));
944
947
 
945
948
    dec = top->findDeclarations(QualifiedIdentifier("foo::bar")).first();
946
949
    QCOMPARE(dec->kind(), Declaration::Namespace);
947
 
    compareUses(dec, SimpleRange(4, 8, 4, 11));
 
950
    compareUses(dec, RangeInRevision(4, 8, 4, 11));
948
951
 
949
952
    dec = top->findDeclarations(QualifiedIdentifier("verylong")).first();
950
953
    QCOMPARE(dec->kind(), Declaration::Namespace);
951
 
    compareUses(dec, SimpleRange(4, 13, 4, 21));
 
954
    compareUses(dec, RangeInRevision(4, 13, 4, 21));
952
955
 
953
956
    dec = top->findDeclarations(QualifiedIdentifier("bar")).first();
954
957
    QCOMPARE(dec->kind(), Declaration::NamespaceAlias);
955
 
    compareUses(dec, QList<SimpleRange>() << SimpleRange(5, 4, 5, 7)
956
 
                                          << SimpleRange(5, 11, 5, 14)
957
 
                                          << SimpleRange(5, 20, 5, 23) );
 
958
    compareUses(dec, QList<RangeInRevision>() << RangeInRevision(5, 4, 5, 7)
 
959
                                          << RangeInRevision(5, 11, 5, 14)
 
960
                                          << RangeInRevision(5, 20, 5, 23) );
958
961
 
959
962
    dec = top->findDeclarations(QualifiedIdentifier("short")).first();
960
963
    QCOMPARE(dec->kind(), Declaration::NamespaceAlias);
961
 
    compareUses(dec, QList<SimpleRange>() << SimpleRange(6, 4, 6, 9)
962
 
                                          << SimpleRange(6, 13, 6, 18)
963
 
                                          << SimpleRange(6, 24, 6, 29) );
 
964
    compareUses(dec, QList<RangeInRevision>() << RangeInRevision(6, 4, 6, 9)
 
965
                                          << RangeInRevision(6, 13, 6, 18)
 
966
                                          << RangeInRevision(6, 24, 6, 29) );
964
967
 
965
968
    dec = top->findDeclarations(QualifiedIdentifier("foo::bar::a")).first();
966
 
    compareUses(dec, SimpleRange(5, 8, 5, 9));
 
969
    compareUses(dec, RangeInRevision(5, 8, 5, 9));
967
970
 
968
971
    dec = top->findDeclarations(QualifiedIdentifier("foo::bar::b")).first();
969
 
    compareUses(dec, SimpleRange(5, 15, 5, 16));
 
972
    compareUses(dec, RangeInRevision(5, 15, 5, 16));
970
973
 
971
974
    dec = top->findDeclarations(QualifiedIdentifier("foo::bar::C")).first();
972
 
    compareUses(dec, SimpleRange(5, 24, 5, 25));
 
975
    compareUses(dec, RangeInRevision(5, 24, 5, 25));
973
976
 
974
977
    dec = top->findDeclarations(QualifiedIdentifier("verylong::a")).first();
975
 
    compareUses(dec, SimpleRange(6, 10, 6, 11));
 
978
    compareUses(dec, RangeInRevision(6, 10, 6, 11));
976
979
 
977
980
    dec = top->findDeclarations(QualifiedIdentifier("verylong::b")).first();
978
 
    compareUses(dec, SimpleRange(6, 19, 6, 20));
 
981
    compareUses(dec, RangeInRevision(6, 19, 6, 20));
979
982
 
980
983
    dec = top->findDeclarations(QualifiedIdentifier("verylong::C")).first();
981
 
    compareUses(dec, SimpleRange(6, 30, 6, 31));
 
984
    compareUses(dec, RangeInRevision(6, 30, 6, 31));
982
985
}
983
986
 
984
987
void TestUses::lateStatic()
990
993
    DUChainReleaser releaseTop(top);
991
994
    DUChainWriteLocker lock;
992
995
 
993
 
    compareUses(top->childContexts().first()->localDeclarations().first(), SimpleRange(0, 39, 0, 40));
 
996
    compareUses(top->childContexts().first()->localDeclarations().first(), RangeInRevision(0, 39, 0, 40));
994
997
}
995
998
 
996
999
void TestUses::closures()
1007
1010
 
1008
1011
    Declaration* a = top->localDeclarations().at(0);
1009
1012
    QCOMPARE(a->identifier().toString(), QString("a"));
1010
 
    compareUses(a, QList<SimpleRange>() << SimpleRange(1, 23, 1, 25) << SimpleRange(1, 36, 1, 38));
 
1013
    compareUses(a, QList<RangeInRevision>() << RangeInRevision(1, 23, 1, 25) << RangeInRevision(1, 36, 1, 38));
1011
1014
 
1012
1015
    Declaration* b = top->localDeclarations().at(1);
1013
1016
    QCOMPARE(b->identifier().toString(), QString("b"));