From fd76b29cfd51f6521837c9cdcd2fdf984909afba Mon Sep 17 00:00:00 2001 From: Luis Paulo Torres de Oliveira Date: Tue, 19 Nov 2013 06:10:25 -0300 Subject: Fix revision issues from gccxml architecture recovery backend plugin. Change-Id: I05a0313df2cc6a366ef4b5347d1fe4d169c2658f Reviewed-by: Sandro S. Andrade --- .../gccxmlarchitecturerecoverybackendplugin.cpp | 63 ++++++++-------------- .../gccxmlarchitecturerecoverybackendplugin.h | 6 +-- 2 files changed, 23 insertions(+), 46 deletions(-) (limited to 'examples/uml') diff --git a/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackendplugin.cpp b/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackendplugin.cpp index 0c733509..f9ee53f3 100644 --- a/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackendplugin.cpp +++ b/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackendplugin.cpp @@ -53,23 +53,21 @@ bool GccXmlArchitectureRecoveryBackendPlugin::initialize(DuSE::ICore *core) void GccXmlArchitectureRecoveryBackendPlugin::setRootProjectDir(const QDir &rootProjectDir) { - this->rootProjectDir = rootProjectDir; + _rootProjectDir = rootProjectDir; } QObjectList GccXmlArchitectureRecoveryBackendPlugin::components() { - QList components; + QObjectList components; - QStringList headers = findFiles("*.h"); + QStringList headers = _rootProjectDir.entryList(QStringList("*.h"), QDir::Files | QDir::NoSymLinks); QStringList xmlFiles = generateXmlFiles(headers); + int xmlFilesSize = xmlFiles.size(); - - for (int i = 0; i < xmlFiles.size(); ++i) { - + for (int i = 0; i < xmlFilesSize; ++i) { QString xmlFile = xmlFiles.at(i).toLocal8Bit().constData(); - if (openXmlFile(rootProjectDir.absolutePath() + "/" + xmlFile)) { - + if (openXmlFile(_rootProjectDir.absolutePath() + "/" + xmlFile)) { QObject *component = extractComponent(xmlFile); components.append(component); } @@ -83,40 +81,29 @@ QObjectList GccXmlArchitectureRecoveryBackendPlugin::connectors() return QObjectList(); } -QStringList GccXmlArchitectureRecoveryBackendPlugin::findFiles(const QString &name) const -{ - - return rootProjectDir.entryList(QStringList(name), QDir::Files | QDir::NoSymLinks); -} - - QStringList GccXmlArchitectureRecoveryBackendPlugin::generateXmlFiles(const QStringList &codeFiles) const { + int codeFilesSize = codeFiles.size(); - for (int i = 0; i < codeFiles.size(); ++i) { - + for (int i = 0; i < codeFilesSize; ++i) { QString file = codeFiles.at(i).toLocal8Bit().constData(); - QString fileDir = rootProjectDir.absolutePath() + "/" + file; - QString xmlFileDir = rootProjectDir.absolutePath() + "/" + file.replace(".h", ".xml"); - - QString command = "gccxml " + fileDir + " -fxml=" + xmlFileDir; + QString fileDir = _rootProjectDir.absolutePath() + "/" + file; + QString xmlFileDir = _rootProjectDir.absolutePath() + "/" + file.replace(".h", ".xml"); QProcess process; - process.start(command); + process.start("gccxml " + fileDir + " -fxml=" + xmlFileDir); process.waitForFinished(); } - return rootProjectDir.entryList(QStringList("*.xml"), QDir::Files | QDir::NoSymLinks); + return _rootProjectDir.entryList(QStringList("*.xml"), QDir::Files | QDir::NoSymLinks); } bool GccXmlArchitectureRecoveryBackendPlugin::openXmlFile(const QString &filePath) { + QFile file(filePath); + _xmlReader = new QXmlStreamReader(&file); - QFile *file = new QFile(filePath); - - xml = new QXmlStreamReader(file); - - if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) { + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { return false; } @@ -127,18 +114,12 @@ QStringList GccXmlArchitectureRecoveryBackendPlugin::findConstructorsFromXml(con { QStringList constructors; - while (!xml->atEnd() && !xml->hasError()) { - - QXmlStreamReader::TokenType token = xml->readNext(); - - if (token == QXmlStreamReader::StartDocument) { - continue; - } + while (!_xmlReader->atEnd() && !_xmlReader->hasError()) { + QXmlStreamReader::TokenType token = _xmlReader->readNext(); if (token == QXmlStreamReader::StartElement) { - - if (xml->name() == "Constructor") { - QXmlStreamAttributes attributes = xml->attributes(); + if (_xmlReader->name() == "Constructor") { + QXmlStreamAttributes attributes = _xmlReader->attributes(); QString attribute = attributes.value("demangled").toString(); if (attribute.contains(className + "::")) { @@ -153,16 +134,14 @@ QStringList GccXmlArchitectureRecoveryBackendPlugin::findConstructorsFromXml(con QObject *GccXmlArchitectureRecoveryBackendPlugin::extractComponent(QString xmlFile) { - QStringList constructors = findConstructorsFromXml(xmlFile.replace(".xml", "")); - QString expression = constructors.at(constructors.size() - 1).toLocal8Bit().constData(); + QString expression = constructors.last(); QStringList elements = expression.split("::"); - QString className = elements.at(1).toLocal8Bit().constData(); + QString className = elements.at(1); QObject *component = new QObject; component->setObjectName(className); return component; } - diff --git a/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackendplugin.h b/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackendplugin.h index c09f679a..eae3a635 100644 --- a/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackendplugin.h +++ b/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackendplugin.h @@ -66,15 +66,13 @@ public: virtual QObjectList connectors(); private: - QStringList findFiles(const QString &name) const; QStringList generateXmlFiles(const QStringList &codeFiles) const; bool openXmlFile(const QString &filePath); QStringList findConstructorsFromXml(const QString &className); QObject *extractComponent(QString xmlFile); - QDir rootProjectDir; - QXmlStreamReader *xml; + QDir _rootProjectDir; + QXmlStreamReader *_xmlReader; }; #endif // GCCXMLARCHITECTURERECOVERYBACKENDPLUGIN - -- cgit v1.2.3