~ubuntu-branches/ubuntu/raring/kdevplatform/raring

« back to all changes in this revision

Viewing changes to language/backgroundparser/parsejob.cpp

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2012-01-17 03:21:56 UTC
  • mfrom: (0.3.15)
  • Revision ID: package-import@ubuntu.com-20120117032156-toarhfq5ihtpvm2p
Tags: 1.2.81-0ubuntu1
* New upstream release
  - Refreshed kubuntu_01_appmenu_fix.diff
  - Bump SONAME for kdevplatform and libsublime
    + Add appropriate Breaks/Replaces
  - Refresh install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
 
56
56
using namespace KTextEditor;
57
57
 
58
 
Q_DECLARE_METATYPE(KDevelop::IndexedString)
59
 
Q_DECLARE_METATYPE(KDevelop::IndexedTopDUContext)
60
 
Q_DECLARE_METATYPE(KDevelop::ReferencedTopDUContext)
61
 
 
62
58
static QMutex minimumFeaturesMutex;
63
59
static QHash<KDevelop::IndexedString, QList<KDevelop::TopDUContext::Features> > staticMinimumFeatures;
64
60
 
110
106
        d(new ParseJobPrivate(url))
111
107
{}
112
108
 
113
 
void ParseJob::setTracker ( DocumentChangeTracker* tracker )
114
 
{
115
 
    d->tracker = tracker;
116
 
}
117
 
 
118
 
DocumentChangeTracker* ParseJob::tracker() const
119
 
{
120
 
    return d->tracker.data();
121
 
}
122
 
 
123
109
ParseJob::~ParseJob()
124
110
{
125
111
    typedef QWeakPointer<QObject> QObjectPointer;
179
165
    return d->duContext;
180
166
}
181
167
 
182
 
void ParseJob::addJob(Job* job)
183
 
{
184
 
    if (backgroundParser())
185
 
        job->assignQueuePolicy(backgroundParser()->dependencyPolicy());
186
 
 
187
 
    JobSequence::addJob(job);
188
 
}
189
 
 
190
 
BackgroundParser* ParseJob::backgroundParser() const
191
 
{
192
 
    return d->backgroundParser;
193
 
}
194
 
 
195
 
void ParseJob::setBackgroundParser(BackgroundParser* parser)
196
 
{
197
 
    if (parser) {
198
 
        assignQueuePolicy(parser->dependencyPolicy());
199
 
 
200
 
        for (int i = 0; i < jobListLength(); ++i)
201
 
            jobAt(i)->assignQueuePolicy(parser->dependencyPolicy());
202
 
 
203
 
    } else if (d->backgroundParser) {
204
 
 
205
 
        removeQueuePolicy(d->backgroundParser->dependencyPolicy());
206
 
 
207
 
        for (int i = 0; i < jobListLength(); ++i)
208
 
            jobAt(i)->removeQueuePolicy(d->backgroundParser->dependencyPolicy());
209
 
    }
210
 
 
211
 
    d->backgroundParser = parser;
212
 
}
213
 
 
214
 
bool ParseJob::addDependency(ParseJob* dependency, ThreadWeaver::Job* actualDependee)
215
 
{
216
 
    if (!backgroundParser())
217
 
        return false;
218
 
 
219
 
    return backgroundParser()->dependencyPolicy()->addDependency(dependency, this, actualDependee);
220
 
}
221
 
 
222
168
bool ParseJob::abortRequested() const
223
169
{
224
170
    QMutexLocker lock(d->abortMutex);
265
211
    QFileInfo fileInfo( localFile );
266
212
 
267
213
    QDateTime lastModified = fileInfo.lastModified();
268
 
    
269
 
    ForegroundLock lock;
270
 
    
 
214
 
 
215
    d->tracker = ICore::self()->languageController()->backgroundParser()->trackerForUrl(document());
 
216
 
271
217
    //Try using an artificial code-representation, which overrides everything else
272
218
    if(artificialCodeRepresentationExists(document())) {
273
219
        CodeRepresentation::Ptr repr = createCodeRepresentation(document());
275
221
        kDebug() << "took contents for " << document().str() << " from artificial code-representation";
276
222
        return KDevelop::ProblemPointer();
277
223
    }
278
 
    
279
 
    if(DocumentChangeTracker* t = d->tracker.data())
 
224
 
 
225
    bool hadTracker = false;
 
226
    if(d->tracker)
280
227
    {
281
 
        // The file is open in an editor
282
 
        d->previousRevision = t->revisionAtLastReset();
 
228
        ForegroundLock lock;
 
229
        if(DocumentChangeTracker* t = d->tracker.data())
 
230
        {
 
231
            // The file is open in an editor
 
232
            d->previousRevision = t->revisionAtLastReset();
283
233
 
284
 
        t->reset(); // Reset the tracker to the current revision
285
 
        Q_ASSERT(t->revisionAtLastReset());
286
 
        
287
 
        d->contents.contents = t->textAtLastReset().toUtf8();
288
 
        d->contents.modification = KDevelop::ModificationRevision( lastModified, t->revisionAtLastReset()->revision() );
289
 
        
290
 
        d->revision = t->acquireRevision(d->contents.modification.revision);
291
 
    }else{
 
234
            t->reset(); // Reset the tracker to the current revision
 
235
            Q_ASSERT(t->revisionAtLastReset());
 
236
            
 
237
            d->contents.contents = t->textAtLastReset().toUtf8();
 
238
            d->contents.modification = KDevelop::ModificationRevision( lastModified, t->revisionAtLastReset()->revision() );
 
239
            
 
240
            d->revision = t->acquireRevision(d->contents.modification.revision);
 
241
            hadTracker = true;
 
242
        }
 
243
    }
 
244
    if (!hadTracker) {
292
245
        // We have to load the file from disk
293
 
        
294
 
        lock.unlock(); // Unlock the foreground lock before reading from disk, so the UI won't block due to I/O
295
 
        
 
246
 
296
247
        QFile file( localFile );
297
248
        
298
249
        if ( !file.open( QIODevice::ReadOnly ) )
326
277
        file.close();
327
278
    }
328
279
 
 
280
    // To make the parsing more robust, we add some zeroes to the end of the buffer.
329
281
    d->contents.contents.push_back((char)0);
330
282
    d->contents.contents.push_back((char)0);
331
283
    d->contents.contents.push_back((char)0);