4
#include <qstringlist.h>
7
#include <qprogressbar.h>
8
#include <qwhatsthis.h>
10
#include <kgenericfactory.h>
11
#include <kapplication.h>
14
#include <kstatusbar.h>
15
#include <kdialogbase.h>
16
#include <kiconloader.h>
21
#include "kdevgenericfactory.h"
23
#include "kdevproject.h"
24
#include "kdevmainwindow.h"
25
#include "kdevpartcontroller.h"
26
#include "codemodel.h"
27
#include "adasupportpart.h"
28
#include "problemreporter.h"
29
#include "backgroundparser.h"
31
#include "AdaLexer.hpp"
32
#include "AdaParser.hpp"
33
#include "AdaStoreWalker.hpp"
36
#include <kdevplugininfo.h>
38
enum { KDEV_DB_VERSION = 6 };
39
enum { KDEV_PCS_VERSION = 6 };
41
typedef KDevGenericFactory<AdaSupportPart> AdaSupportPartFactory;
43
static const KDevPluginInfo data("kdevadasupport");
44
K_EXPORT_COMPONENT_FACTORY (libkdevadasupport, AdaSupportPartFactory (data))
47
struct AdaSupportPartData {
48
ProblemReporter* problemReporter;
50
AdaSupportPartData () : problemReporter (0) {}
53
AdaSupportPart::AdaSupportPart (QObject *parent, const char *name, const QStringList &)
54
: KDevLanguageSupport (&data, parent, name ? name : "AdaSupportPart"), d (new AdaSupportPartData())
56
setInstance (AdaSupportPartFactory::instance ());
58
d->problemReporter = new ProblemReporter (this);
59
// connect (core (), SIGNAL (configWidget (KDialogBase*)),
60
// d->problemReporter, SLOT (configWidget (KDialogBase*)));
61
d->problemReporter->setIcon( SmallIcon("info") );
62
mainWindow( )->embedOutputView( d->problemReporter, i18n("Problems"), i18n("Problem reporter"));
63
QWhatsThis::add(d->problemReporter, i18n("<b>Problem reporter</b><p>This window shows various \"problems\" in your project. "
64
"It displays errors reported by a language parser."));
66
setXMLFile ("adasupportpart.rc");
68
connect (core (), SIGNAL (projectOpened ()), this, SLOT (projectOpened ()));
69
connect (core (), SIGNAL (projectClosed ()), this, SLOT (projectClosed ()));
71
connect (partController (), SIGNAL (savedFile (const KURL&)),
72
this, SLOT (savedFile (const KURL&)));
74
// connect (core (), SIGNAL (configWidget (KDialogBase*)), this, SLOT (configWidget (KDialogBase*)));
75
connect( core(), SIGNAL(configWidget(KDialogBase*)),
76
d->problemReporter, SLOT(configWidget(KDialogBase*)) );
78
// a small hack (robe)
79
//classStore ()->globalScope ()->setName ("(default packages)");
80
//classStore ()->addScope (classStore ()->globalScope ());
81
//classStore ()->globalScope ()->setName (QString::null);
85
AdaSupportPart::~AdaSupportPart ()
87
mainWindow ()->removeView (d->problemReporter);
88
delete (d->problemReporter);
89
d->problemReporter = 0;
96
KDevLanguageSupport::Features AdaSupportPart::features ()
98
return KDevLanguageSupport::Features
100
Functions | Namespaces);
103
void AdaSupportPart::projectOpened ()
105
connect (project (), SIGNAL (addedFilesToProject (const QStringList &)),
106
this, SLOT (addedFilesToProject (const QStringList &)));
107
connect (project (), SIGNAL (removedFilesFromProject (const QStringList &)),
108
this, SLOT (removedFilesFromProject (const QStringList &)));
109
connect( project( ), SIGNAL( changedFilesInProject( const QStringList & ) ),
110
this, SLOT( changedFilesInProject( const QStringList & ) ) );
112
QTimer::singleShot (0, this, SLOT (initialParse ()));
116
void AdaSupportPart::projectClosed ()
118
saveProjectSourceInfo();
122
void AdaSupportPart::initialParse ()
124
kdDebug () << "------------------------------------------> initialParse ()" << endl;
128
mainWindow()->statusBar()->message( i18n("Updating...") );
129
kapp->processEvents( );
130
kapp->setOverrideCursor (waitCursor);
133
QStringList files = project ()->allFiles ();
135
QProgressBar* bar = new QProgressBar( files.count( ), mainWindow( )->statusBar( ) );
136
bar->setMinimumWidth( 120 );
137
bar->setCenterIndicator( true );
138
mainWindow( )->statusBar( )->addWidget( bar );
141
for (QStringList::Iterator it = files.begin (); it != files.end (); ++it) {
142
bar->setProgress( n++ );
144
QString fn = project ()->projectDirectory () + "/" + *it;
146
kapp->processEvents (500);
149
emit updatedSourceInfo();
151
mainWindow( )->statusBar( )->removeWidget( bar );
154
kapp->restoreOverrideCursor ();
155
mainWindow( )->statusBar( )->message( i18n( "Done" ), 2000 );
156
/* mainWindow ()->statusBar ()->message
157
(i18n ("Found 1 problem", "Found %n problems", d->problemReporter->childCount ()));*/
161
QStringList AdaSupportPart::fileExtensions ()
163
return QStringList () << "ads" << "adb";
166
void AdaSupportPart::maybeParse (const QString &fileName)
168
kdDebug () << "AdaSupportPart::maybeParse: " << fileName << endl;
170
if (!fileExtensions ().contains (QFileInfo (fileName).extension ()))
173
// mainWindow ()->statusBar ()->message (i18n ("Parsing file: %1").arg (fileName));
178
void AdaSupportPart::addedFilesToProject (const QStringList &fileList)
180
QStringList::ConstIterator it;
182
for (it = fileList.begin (); it != fileList.end (); ++it)
184
QString path = project ()->projectDirectory () + "/" + (*it);
186
emit addedSourceInfo( path );
191
void AdaSupportPart::removedFilesFromProject (const QStringList &fileList)
193
QStringList::ConstIterator it;
195
for (it = fileList.begin (); it != fileList.end (); ++it)
197
kdDebug () << "AdaSupportPart::removedFileFromProject () -- " << (*it) << endl;
198
QString path = project ()->projectDirectory () + "/" + (*it);
200
if( codeModel()->hasFile(path) )
202
emit aboutToRemoveSourceInfo( path );
203
codeModel()->removeFile( codeModel()->fileByName(path) );
207
// emit updatedSourceInfo();
211
void AdaSupportPart::parse (const QString &fileName)
213
kdDebug () << "AdaSupportPart::parse () -- " << fileName << endl;
215
std::ifstream stream (QFile::encodeName( fileName ).data());
216
QCString _fn = fileName.utf8 ();
217
std::string fn (_fn.data ());
219
AdaLexer lexer (stream);
220
lexer.setFilename (fn);
221
lexer.setProblemReporter (d->problemReporter);
223
AdaParser parser (lexer);
224
parser.setFilename (fn);
225
parser.setProblemReporter (d->problemReporter);
227
// make an ast factory
228
antlr::ASTFactory ast_factory;
229
// initialize and put it in the parser...
230
parser.initializeASTFactory (ast_factory);
231
parser.setASTFactory (&ast_factory);
232
// parser.setASTNodeType ("RefAdaAST");
235
// old: parser.setASTNodeFactory (AdaAST::factory);
236
lexer.resetErrors ();
237
parser.resetErrors ();
239
parser.compilation_unit ();
240
int errors = lexer.numberOfErrors () + parser.numberOfErrors ();
242
RefAdaAST ast = RefAdaAST (parser.getAST ());
244
if (errors == 0 && ast != antlr::nullAST) {
245
kdDebug () << "-------------------> start StoreWalker" << endl;
246
AdaStoreWalker walker;
247
walker.setFileName (fileName);
248
walker.setCodeModel (codeModel ());
249
walker.compilation_unit (ast);
251
} catch (antlr::ANTLRException& ex) {
252
kdDebug () << "*exception*: " << ex.toString ().c_str () << endl;
253
d->problemReporter->reportError (QString::fromLatin1( ex.getMessage ().c_str() ),
260
void AdaSupportPart::parseContents (const QString& contents, const QString& fileName)
262
kdDebug () << "AdaSupportPart::parseContents () -- " << fileName << endl;
264
QCString _fn = QFile::encodeName (fileName);
265
std::string fn (_fn.data ());
267
QCString text = contents.utf8 ();
268
std::istringstream stream ((const char *)text);
270
AdaLexer lexer (stream);
271
lexer.setFilename (fn);
272
lexer.setProblemReporter (d->problemReporter);
274
AdaParser parser (lexer);
275
parser.setFilename (fn);
276
parser.setProblemReporter (d->problemReporter);
279
lexer.resetErrors ();
280
parser.resetErrors ();
282
parser.compilation_unit ();
283
int errors = lexer.numberOfErrors () + parser.numberOfErrors ();
286
} catch (antlr::ANTLRException& ex) {
287
kdDebug () << "*exception*: " << ex.toString ().c_str () << endl;
288
d->problemReporter->reportError (QString::fromLatin1( ex.getMessage().c_str() ),
297
void AdaSupportPart::savedFile (const KURL& fileName)
299
kdDebug () << "AdaSupportPart::savedFile ()" << endl;
301
if (project ()->allFiles ().contains (fileName.path().mid (project ()->projectDirectory ().length () + 1))) {
302
maybeParse (fileName.path());
303
emit updatedSourceInfo();
307
KMimeType::List AdaSupportPart::mimeTypes( )
309
KMimeType::List list;
311
list << KMimeType::mimeType( "text/x-adasrc" );
316
//@todo adymo: implement source info loading and saving
317
//hint: check javasupport for an example
318
// and modify initialParse() method
319
void AdaSupportPart::saveProjectSourceInfo( )
321
/* const FileList fileList = codeModel()->fileList();
323
if( !project() || fileList.isEmpty() )
326
QFile f( project()->projectDirectory() + "/" + project()->projectName() + ".pcs" );
327
if( !f.open( IO_WriteOnly ) )
330
QDataStream stream( &f );
331
QMap<QString, Q_ULONG> offsets;
333
QString pcs( "PCS" );
334
stream << pcs << KDEV_PCS_VERSION;
336
stream << int( fileList.size() );
337
for( FileList::ConstIterator it=fileList.begin(); it!=fileList.end(); ++it ){
338
const FileDom dom = (*it);
339
#if QT_VERSION >= 0x030100
340
stream << dom->name() << m_timestamp[ dom->name() ].toTime_t();
342
stream << dom->name() << toTime_t(m_timestamp[ dom->name() ]);
344
offsets.insert( dom->name(), stream.device()->at() );
345
stream << (Q_ULONG)0; // dummy offset
348
for( FileList::ConstIterator it=fileList.begin(); it!=fileList.end(); ++it ){
349
const FileDom dom = (*it);
350
int offset = stream.device()->at();
352
dom->write( stream );
354
int end = stream.device()->at();
356
stream.device()->at( offsets[dom->name()] );
358
stream.device()->at( end );
362
void AdaSupportPart::changedFilesInProject( const QStringList & fileList )
364
QStringList files = fileList;
366
for ( QStringList::ConstIterator it = files.begin(); it != files.end(); ++it )
368
QString path = project ()->projectDirectory () + "/" + *it ;
371
emit addedSourceInfo( path );
376
#include "adasupportpart.moc"