languages/java/backgroundparser.h
Go to the documentation of this file.00001 /*************************************************************************** 00002 * Copyright (C) 2002 by Roberto Raggi * 00003 * roberto@kdevelop.org * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 ***************************************************************************/ 00011 00012 #ifndef BACKGROUNDPARSER_H 00013 #define BACKGROUNDPARSER_H 00014 00015 #include "driver.h" 00016 #include "JavaAST.hpp" 00017 00018 #include <qthread.h> 00019 #include <qwaitcondition.h> 00020 #include <qmutex.h> 00021 #include <qmap.h> 00022 #include <kdebug.h> 00023 00024 class JavaSupportPart; 00025 class TranslationUnitAST; 00026 class SynchronizedFileList; 00027 00028 class Unit 00029 { 00030 public: 00031 Unit() {} 00032 ~Unit() {} 00033 00034 QString fileName; 00035 QValueList<Problem> problems; 00036 RefJavaAST translationUnit; 00037 00038 protected: 00039 Unit( const Unit& source ); 00040 void operator = ( const Unit& source ); 00041 }; 00042 00043 class BackgroundParser: public QThread 00044 { 00045 public: 00046 BackgroundParser( JavaSupportPart*, QWaitCondition* consumed ); 00047 virtual ~BackgroundParser(); 00048 00049 QMutex& mutex() { return m_mutex; } 00050 void lock() { m_mutex.lock(); } 00051 void unlock() { m_mutex.unlock(); } 00052 00053 QWaitCondition& canParse() { return m_canParse; } 00054 QWaitCondition& isEmpty() { return m_isEmpty; } 00055 00056 bool filesInQueue(); 00057 00058 void addFile( const QString& fileName, bool readFromDisk=false ); 00059 void removeFile( const QString& fileName ); 00060 void removeAllFiles(); 00061 00062 RefJavaAST translationUnit( const QString& fileName ); 00063 QValueList<Problem> problems( const QString& fileName ); 00064 00065 void close(); 00066 00067 virtual void run(); 00068 00069 protected: 00070 Unit* findUnit( const QString& fileName ); 00071 Unit* parseFile( const QString& fileName, bool readFromDisk ); 00072 00073 private: 00074 class KDevDriver* m_driver; 00075 QString m_currentFile; 00076 QWaitCondition m_canParse; 00077 QWaitCondition m_isEmpty; 00078 QWaitCondition* m_consumed; 00079 QMutex m_mutex; 00080 SynchronizedFileList* m_fileList; 00081 JavaSupportPart* m_javaSupport; 00082 bool m_close; 00083 QMap<QString, Unit*> m_unitDict; 00084 }; 00085 00086 #endif