diff options
Diffstat (limited to 'examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend')
8 files changed, 667 insertions, 195 deletions
diff --git a/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackend.pro b/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackend.pro index d4041016..9c4cf0ab 100644 --- a/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackend.pro +++ b/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackend.pro @@ -8,8 +8,15 @@ include(../../duse-mt-plugin.pri) QT += widgets gui -HEADERS += gccxmlarchitecturerecoverybackendplugin.h +DEFINES += GCCXMLARCHITECTURERECOVERYBACKEND_LIBRARY -SOURCES += gccxmlarchitecturerecoverybackendplugin.cpp +HEADERS += gccxmlarchitecturerecoverybackend_export.h \ + gccxmlarchitecturerecoverybackendplugin.h \ + xmlfilemanager.h \ + xmlfilereader.h + +SOURCES += gccxmlarchitecturerecoverybackendplugin.cpp \ + xmlfilemanager.cpp \ + xmlfilereader.cpp OTHER_FILES += gccxmlarchitecturerecoverybackend.json diff --git a/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackend_export.h b/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackend_export.h new file mode 100644 index 00000000..e96b5845 --- /dev/null +++ b/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackend_export.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Sandro S. Andrade <sandroandrade@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtUml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef GCCXMLARCHITECTURERECOVERYBACKEND_EXPORT_H +#define GCCXMLARCHITECTURERECOVERYBACKEND_EXPORT_H + +#include <qglobal.h> + +#if defined(GCCXMLARCHITECTURERECOVERYBACKEND_LIBRARY) +# define GCCXMLARCHITECTURERECOVERYBACKEND_EXPORT Q_DECL_EXPORT +#else +# define GCCXMLARCHITECTURERECOVERYBACKEND_EXPORT Q_DECL_IMPORT +#endif + +#endif // GCCXMLARCHITECTURERECOVERYBACKEND_EXPORT_H diff --git a/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackendplugin.cpp b/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackendplugin.cpp index e161b412..220bf417 100644 --- a/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackendplugin.cpp +++ b/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackendplugin.cpp @@ -42,7 +42,9 @@ #include <QtWidgets/QAction> #include <QtWidgets/QFileDialog> +#include <QtWidgets/QMessageBox> +#include <QtCore/QDebug> #include <QtCore/QProcess> #include <QtCore/QXmlStreamReader> @@ -54,244 +56,247 @@ namespace DuSE GccXmlArchitectureRecoveryBackendPlugin::GccXmlArchitectureRecoveryBackendPlugin(QObject *parent) : IPlugin(parent) { + _name = "C++ (GCC-XML)"; + qRegisterMetaType<DependencyRelations>("DependencyRelations"); } bool GccXmlArchitectureRecoveryBackendPlugin::initialize() { - QAction *newArchitectureRecoveryProcessAction = new QAction(QIcon(), tr("New architecture recovery process"), this); - connect(newArchitectureRecoveryProcessAction, SIGNAL(triggered()), this, SLOT(newArchitectureRecoveryProcess())); - ICore::self()->uiController()->addAction(newArchitectureRecoveryProcessAction, tr("menu_File")); - qRegisterMetaType<ClassFunctions>("ClassFunctions"); return true; } -void GccXmlArchitectureRecoveryBackendPlugin::setRootProjectDir(const QDir &rootProjectDir) -{ - _rootProjectDir = rootProjectDir; -} - -void GccXmlArchitectureRecoveryBackendPlugin::newArchitectureRecoveryProcess() -{ - QString directory = QFileDialog::getExistingDirectory(0, tr("Open code tree"), QDir::currentPath()); - _rootProjectDir = QDir(directory); - components(); -} QObjectList GccXmlArchitectureRecoveryBackendPlugin::components() { QObjectList components; - QStringList headers = _rootProjectDir.entryList(QStringList("*.h"), QDir::Files | QDir::NoSymLinks); - QStringList xmlFiles = generateXmlFiles(headers); - int xmlFilesSize = xmlFiles.size(); - for (int i = 0; i < xmlFilesSize; ++i) { - _xmlFileName = xmlFiles.at(i).toLocal8Bit().constData(); - - QObject *component = extractComponent(); - components.append(component); - } + QObject *componentsDependencyRelations = new QObject; + componentsDependencyRelations->setProperty("components", QVariant::fromValue(_dependencyRelations)); + componentsDependencyRelations->setProperty("systemDirectory", QVariant::fromValue(_rootProjectDirectoryString)); + components.append(componentsDependencyRelations); return components; } QObjectList GccXmlArchitectureRecoveryBackendPlugin::connectors() { - return QObjectList(); + QObjectList connectors; + + return connectors; } -QStringList GccXmlArchitectureRecoveryBackendPlugin::generateXmlFiles(const QStringList &codeFiles) const +void GccXmlArchitectureRecoveryBackendPlugin::run() { - int codeFilesSize = codeFiles.size(); - - 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"); - - QProcess process; - process.start("gccxml " + fileDir + " -fxml=" + xmlFileDir); - process.waitForFinished(); - } - - return _rootProjectDir.entryList(QStringList("*.xml"), QDir::Files | QDir::NoSymLinks); + runGccXml(); + recoverDependencyRelations(); } -bool GccXmlArchitectureRecoveryBackendPlugin::openXmlFile(const QString &filePath) +void GccXmlArchitectureRecoveryBackendPlugin::runGccXml() { - _xmlFile.setFileName(filePath); - _xmlReader = new QXmlStreamReader(&_xmlFile); + _rootProjectDirectoryString = QFileDialog::getExistingDirectory(0, "Escolha o diretório raíz do projeto", QDir::currentPath()); - if (!_xmlFile.open(QIODevice::ReadOnly | QIODevice::Text)) { - return false; + if (_rootProjectDirectoryString.isEmpty()) { + QMessageBox errorMessage; + errorMessage.setInformativeText("Diretório inválido."); + errorMessage.show(); + } else { + _rootProjectDirectory = QDir(_rootProjectDirectoryString); + _xmlFilesList = _xmlFileManager->generateXmlFiles(_rootProjectDirectory); + _xmlCount = _xmlFilesList.count(); } - - return true; } -QStringList GccXmlArchitectureRecoveryBackendPlugin::findConstructorsFromXml() +void GccXmlArchitectureRecoveryBackendPlugin::recoverDependencyRelations() { - QStringList constructors; + QString fileName; - openXmlFile(_rootProjectDir.absolutePath() + "/" + _xmlFileName); - QString className = _xmlFileName; - className.replace(".xml", ""); - while (!_xmlReader->atEnd() && !_xmlReader->hasError()) { - QXmlStreamReader::TokenType token = _xmlReader->readNext(); + for (int i = 0; i < _xmlCount; ++i) { + fileName = _xmlFilesList.at(i).toLocal8Bit().constData(); - if (token == QXmlStreamReader::StartElement) { - if (_xmlReader->name() == "Constructor") { - QXmlStreamAttributes attributes = _xmlReader->attributes(); + _reader = new XmlFileReader(_rootProjectDirectory.absolutePath(), fileName); - QString attribute = attributes.value("demangled").toString(); - if (attribute.contains(className + "::", Qt::CaseInsensitive)) { - constructors.append(attribute); - } - } - } - } - if (_xmlFile.isOpen()) { - _xmlFile.close(); - } - - return constructors; -} + _reader->fillTagContainers(); -QObject *GccXmlArchitectureRecoveryBackendPlugin::extractComponent() -{ - QObject *component = new QObject; - QString className; - QStringList constructors = findConstructorsFromXml(); + _fileClasses.insert(fileName, _reader->fileClasses()); + _fileFields.insert(fileName, _reader->fileFields()); + _filePointers.insert(fileName, _reader->filePointers()); + _fileBases.insert(fileName, _reader->fileBases()); + _fileArguments.insert(fileName, _reader->fileArguments()); - if (!constructors.isEmpty()) { - QString expression = constructors.last(); - QStringList elements = expression.split("::"); - className = elements.at(0) + "::" + elements.at(1); + fieldAdjacencies(); + baseAdjacencies(); + argumentsAdjacencies(); - component->setObjectName(className); - } else { - className = _xmlFileName; - className.replace(".xml", ""); - component->setObjectName(className); + qDebug() << "Tamanho de dependencyRelations: " << _dependencyRelations.count(); } - - findFunctionsFromXml(component); - - return component; } -void GccXmlArchitectureRecoveryBackendPlugin::findFunctionsFromXml(QObject *component) +void GccXmlArchitectureRecoveryBackendPlugin::fieldAdjacencies() { - QHash<QString, QMultiHash<QString, QString> > classFunctions; - - openXmlFile(_rootProjectDir.absolutePath() + "/" + _xmlFileName); - - QStringList expression = component->objectName().split("::"); - QString classNamespace = expression.first(); - - while (!_xmlReader->atEnd() && !_xmlReader->hasError()) { - QXmlStreamReader::TokenType token = _xmlReader->readNext(); - - if (token == QXmlStreamReader::StartElement) { - if ((_xmlReader->name() == "Method") || - (_xmlReader->name() == "Constructor") || - (_xmlReader->name() == "Destructor")) { - QString attribute = _xmlReader->attributes().value("demangled").toString(); + QString fileName; + + for (int i = 0; i < _xmlCount; ++i) { + + fileName = _xmlFilesList.at(i).toLocal8Bit().constData(); + + QMap<QString, QString> classes = _fileClasses.value(fileName); + QList<QPair<QString, QString> > fields = _fileFields.value(fileName); + QMap<QString, QString> pointers = _filePointers.value(fileName); + + QString dependent; + QString dependency; + + QStringList classIds = classes.keys(); + foreach (QString classId, classIds) { + dependent = classes.value(classId); + for (int i = 0; i < fields.size(); ++i) { + QPair<QString, QString> field = fields.at(i); + if (classId == field.first) { + if (classes.value(field.second).isEmpty()) { + QStringList pointersId = pointers.keys(); + foreach (QString pointerId, pointersId) { + if (field.second == pointerId) { + if (!classes.value(pointers.value(pointerId)).isEmpty()) { + dependency = classes.value(pointers.value(pointerId)); + } + } + } + } else { + dependency = classes.value(field.second); + } + } - if (attribute.contains(classNamespace + "::", Qt::CaseInsensitive)) { - classFunctions = classFunctionsContainer(attribute, classFunctions); + if (!_dependencyRelations.keys().contains(dependent)) { + if (!dependent.isEmpty() && !dependency.isEmpty()) { + _dependencyRelations.insert(dependent, dependency); + } + } else { + bool isNewDependencie = false; + QStringList dependencies = _dependencyRelations.values(dependent); + foreach (QString d, dependencies) { + if (dependency == d) { + isNewDependencie = true; + } + } + if (isNewDependencie == false) { + if (!dependent.isEmpty() && !dependency.isEmpty()) { + _dependencyRelations.insert(dependent, dependency); + } + } } + + dependency = ""; } } } - if (_xmlFile.isOpen()) { - _xmlFile.close(); - } - - component->setProperty("Functions", QVariant::fromValue(classFunctions)); } -QHash<QString, QMultiHash<QString, QString> > GccXmlArchitectureRecoveryBackendPlugin::classFunctionsContainer(QString xmlAttribute, QHash<QString, QMultiHash<QString, QString> > &classFunctions) +void GccXmlArchitectureRecoveryBackendPlugin::baseAdjacencies() { - QMultiHash<QString, QString> function; + QString fileName; - QStringList signature = xmlAttribute.split("::"); - QString className = signature.at(0) + "::" + signature.at(1); - QString functionName = signature.at(2).left(signature.at(2).indexOf("(")); + for (int i = 0; i < _xmlCount; ++i) { - findFunctionParameters(functionName, function); - classFunctions.insert(className, function); + fileName = _xmlFilesList.at(i).toLocal8Bit().constData(); - return classFunctions; -} + QMap<QString, QString> classes = _fileClasses.value(fileName); + QList<QPair<QString, QString> > bases = _fileBases.value(fileName); -void GccXmlArchitectureRecoveryBackendPlugin::findFunctionParameters(const QString &functionName, QMultiHash<QString, QString> &function) -{ - while (_xmlReader->readNextStartElement()) { - if (!_xmlReader->attributes().value("name").toString().isEmpty()) { - QString parameterName = _xmlReader->attributes().value("name").toString(); - QString typeID = _xmlReader->attributes().value("type").toString(); - - QString parameterTypeNumber = findTypeNumber(typeID); - QString parameterType = findType(parameterTypeNumber); - if (parameterType == "") { - parameterType = findType(typeID); - } + QString dependent; + QString dependency; - function.insert(functionName, parameterName + " " + parameterType); - } - } -} - -QString GccXmlArchitectureRecoveryBackendPlugin::findTypeNumber(const QString &typeID) -{ - QFile file(_rootProjectDir.absolutePath() + "/" + _xmlFileName); - QXmlStreamReader *typeNumberCollector = new QXmlStreamReader(&file); - file.open(QIODevice::ReadOnly | QIODevice::Text); - - while (!typeNumberCollector->atEnd() && !typeNumberCollector->hasError()) { - QXmlStreamReader::TokenType token = typeNumberCollector->readNext(); + QStringList classIds = classes.keys(); + foreach (QString classId, classIds) { + dependent = classes.value(classId); + for (int i = 0; i < bases.size(); ++i) { + QPair<QString, QString> base = bases.at(i); + if (classId == base.first) { + dependency = classes.value(base.second); + } + } - if (token == QXmlStreamReader::StartElement) { - if (typeNumberCollector->name() == "PointerType") { - if (typeNumberCollector->attributes().value("id").toString() == typeID) { - break; + if (!_dependencyRelations.keys().contains(dependent)) { + if (!dependent.isEmpty() && !dependency.isEmpty()) { + _dependencyRelations.insert(dependent, dependency); + } + } else { + bool isNewDependencie = false; + QStringList dependencies = _dependencyRelations.values(dependent); + foreach (QString d, dependencies) { + if (dependency == d) { + isNewDependencie = true; + } + } + if (isNewDependencie == false) { + if (!dependent.isEmpty() && !dependency.isEmpty()) { + _dependencyRelations.insert(dependent, dependency); + } } } + + dependency = ""; } } - - QString typeNumber = typeNumberCollector->attributes().value("type").toString(); - - file.close(); - delete typeNumberCollector; - - return typeNumber; } -QString GccXmlArchitectureRecoveryBackendPlugin::findType(const QString &typeNumber) +void GccXmlArchitectureRecoveryBackendPlugin::argumentsAdjacencies() { - QFile file(_rootProjectDir.absolutePath() + "/" + _xmlFileName); - QXmlStreamReader *typeCollector = new QXmlStreamReader(&file); - file.open(QIODevice::ReadOnly | QIODevice::Text); - - while (!typeCollector->atEnd() && !typeCollector->hasError()) { - QXmlStreamReader::TokenType token = typeCollector->readNext(); + QString fileName; + + for (int i = 0; i < _xmlCount; ++i) { + + fileName = _xmlFilesList.at(i).toLocal8Bit().constData(); + + QMap<QString, QString> classes = _fileClasses.value(fileName); + QList<QPair<QString, QString> > arguments = _fileArguments.value(fileName); + QMap<QString, QString> pointers = _filePointers.value(fileName); + + QString dependent; + QString dependency; + + QStringList classIds = classes.keys(); + foreach (QString classId, classIds) { + dependent = classes.value(classId); + for (int i = 0; i < arguments.size(); ++i) { + QPair<QString, QString> argument = arguments.at(i); + if (classId == argument.first) { + if (classes.value(argument.second).isEmpty()) { + QStringList pointersId = pointers.keys(); + foreach (QString pointerId, pointersId) { + if (argument.second == pointerId) { + if (!classes.value(pointers.value(pointerId)).isEmpty()) { + dependency = classes.value(pointers.value(pointerId)); + } + } + } + } else { + dependency = classes.value(argument.second); + } + } + } - if (token == QXmlStreamReader::StartElement) { - if (typeCollector->name() == "Class") { - if (typeCollector->attributes().value("id").toString() == typeNumber) { - break; + if (!_dependencyRelations.keys().contains(dependent)) { + if (!dependent.isEmpty() && !dependency.isEmpty()) { + _dependencyRelations.insert(dependent, dependency); + } + } else { + bool isNewDependencie = false; + QStringList dependencies = _dependencyRelations.values(dependent); + foreach (QString d, dependencies) { + if (dependency == d) { + isNewDependencie = true; + } + } + if (isNewDependencie == false) { + if (!dependent.isEmpty() && !dependency.isEmpty()) { + _dependencyRelations.insert(dependent, dependency); + } } } + + dependency = ""; } } - - QString type = typeCollector->attributes().value("name").toString(); - - file.close(); - delete typeCollector; - - return type; } } diff --git a/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackendplugin.h b/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackendplugin.h index 8c14f3c1..e83efce8 100644 --- a/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackendplugin.h +++ b/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/gccxmlarchitecturerecoverybackendplugin.h @@ -47,10 +47,16 @@ #include <QtCore/QDir> #include <QtCore/QHash> #include <QtCore/QObjectList> +#include <QtCore/QObject> #include <QtCore/QStringList> #include <QtCore/QMetaType> #include <QtCore/QVariant> +#include "xmlfilemanager.h" +#include "xmlfilereader.h" + +#include "gccxmlarchitecturerecoverybackend_export.h" + QT_BEGIN_NAMESPACE class QXmlStreamReader; QT_END_NAMESPACE @@ -58,7 +64,7 @@ QT_END_NAMESPACE namespace DuSE { -class GccXmlArchitectureRecoveryBackendPlugin : public IPlugin, public IArchitectureRecoveryBackend +class GCCXMLARCHITECTURERECOVERYBACKEND_EXPORT GccXmlArchitectureRecoveryBackendPlugin : public IPlugin, public IArchitectureRecoveryBackend { Q_OBJECT Q_PLUGIN_METADATA(IID "org.liveblue.DuSE.IPlugin" FILE "gccxmlarchitecturerecoverybackend.json") @@ -68,35 +74,36 @@ public: virtual bool initialize(); - void setRootProjectDir(const QDir &rootProjectDir); - virtual QObjectList components(); virtual QObjectList connectors(); + void run(); + void runGccXml(); + void recoverDependencyRelations(); + void fieldAdjacencies(); + void baseAdjacencies(); + void argumentsAdjacencies(); private Q_SLOTS: - void newArchitectureRecoveryProcess(); private: - QStringList generateXmlFiles(const QStringList &codeFiles) const; - bool openXmlFile(const QString &filePath); - QStringList findConstructorsFromXml(); - QObject *extractComponent(); - void findFunctionsFromXml(QObject *component); - QHash<QString, QMultiHash<QString, QString> > classFunctionsContainer(QString xmlAttribute, QHash<QString, QMultiHash<QString, QString> > &classFunctions); - void findFunctionParameters(const QString &functionName, QMultiHash<QString, QString> &function); - QString findTypeNumber(const QString &typeID); - QString findType(const QString &typeNumber); - - QDir _rootProjectDir; - QFile _xmlFile; - QString _xmlFileName; - QXmlStreamReader *_xmlReader; + int _xmlCount; + QDir _rootProjectDirectory; + QString _rootProjectDirectoryString; + QStringList _xmlFilesList; + XmlFileManager *_xmlFileManager; + XmlFileReader *_reader; + QMap<QString, QMap<QString, QString> > _fileClasses; + QMap<QString, QList<QPair<QString, QString> > > _fileFields; + QMap<QString, QMap<QString, QString> > _filePointers; + QMap<QString, QList<QPair<QString, QString> > > _fileBases; + QMap<QString, QList<QPair<QString, QString> > > _fileArguments; + QMultiMap<QString, QString> _dependencyRelations; }; -typedef QHash<QString, QMultiHash<QString, QString> > ClassFunctions; +typedef QMultiMap<QString, QString> DependencyRelations; #endif // GCCXMLARCHITECTURERECOVERYBACKENDPLUGIN } -Q_DECLARE_METATYPE(DuSE::ClassFunctions); +Q_DECLARE_METATYPE(DuSE::DependencyRelations); diff --git a/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/xmlfilemanager.cpp b/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/xmlfilemanager.cpp new file mode 100644 index 00000000..fee7f8d5 --- /dev/null +++ b/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/xmlfilemanager.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Sandro S. Andrade <sandroandrade@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtUml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "xmlfilemanager.h" + +#include <QtCore/QDir> +#include <QtCore/QProcess> +#include <QtCore/QXmlStreamReader> + +namespace DuSE +{ + +XmlFileManager::XmlFileManager() +{ +} + +QStringList XmlFileManager::generateXmlFiles(const QDir &rootProjectDir) const +{ + QStringList headers = rootProjectDir.entryList(QStringList("*.h"), QDir::Files | QDir::NoSymLinks); + + int codeFilesSize = headers.size(); + + for (int i = 0; i < codeFilesSize; ++i) { + QString file = headers.at(i).toLocal8Bit().constData(); + QString fileDir = rootProjectDir.absolutePath() + "/" + file; + QString xmlFileDir = rootProjectDir.absolutePath() + "/" + file.replace(".h", ".xml"); + + QProcess process; + process.start("gccxml " + fileDir + " -fxml=" + xmlFileDir); + process.waitForFinished(); + } + + return rootProjectDir.entryList(QStringList("*.xml"), QDir::Files | QDir::NoSymLinks); +} + +QXmlStreamReader *XmlFileManager::openXmlFile(const QString &filePath) +{ + _xmlFile.setFileName(filePath); + _xmlReader = new QXmlStreamReader(&_xmlFile); + + if (!_xmlFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + return new QXmlStreamReader; + } + + return _xmlReader; +} + +void XmlFileManager::closeXmlFile() +{ + if (_xmlFile.isOpen()) { + _xmlFile.close(); + } +} + +} diff --git a/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/xmlfilemanager.h b/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/xmlfilemanager.h new file mode 100644 index 00000000..cad93994 --- /dev/null +++ b/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/xmlfilemanager.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Sandro S. Andrade <sandroandrade@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtUml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef XMLFILEMANAGER_H +#define XMLFILEMANAGER_H + +#include <QtCore/QFile> +#include <QtCore/QStringList> + +QT_BEGIN_NAMESPACE +class QDir; +class QXmlStreamReader; +QT_END_NAMESPACE + +namespace DuSE +{ + +class XmlFileManager +{ +public: + XmlFileManager(); + + ~XmlFileManager(); + + QStringList generateXmlFiles(const QDir &rootProjectDir) const; + QXmlStreamReader* openXmlFile(const QString &filePath); + void closeXmlFile(); + +private: + QFile _xmlFile; + QXmlStreamReader *_xmlReader; +}; + +} + +#endif // XMLFILEMANAGER_H diff --git a/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/xmlfilereader.cpp b/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/xmlfilereader.cpp new file mode 100644 index 00000000..79ce4297 --- /dev/null +++ b/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/xmlfilereader.cpp @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Sandro S. Andrade <sandroandrade@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtUml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "xmlfilereader.h" + +#include <QXmlStreamAttributes> + +namespace DuSE +{ + +XmlFileReader::XmlFileReader(QString rootDirectory, QString fileName) + : _rootProjectDir(rootDirectory), _fileName(fileName) +{ + _xmlFileManager = new XmlFileManager; +} + +void XmlFileReader::fillTagContainers() +{ + _xmlReader = _xmlFileManager->openXmlFile(_rootProjectDir + "/" + _fileName); + + while (!_xmlReader->atEnd() & !_xmlReader->hasError()) { + QXmlStreamReader::TokenType token = _xmlReader->readNext(); + QPair<QString, QString> auxPair; + + if (token == QXmlStreamReader::StartElement) { + QXmlStreamAttributes attributes; + + if (_xmlReader->name() == "Class") { + attributes = _xmlReader->attributes(); + QString classId = attributes.value("id").toString(); + QString className = attributes.value("name").toString(); + if (!_fileClasses.values().contains(className)) { + _fileClasses.insert(classId, className); + } + + do { + if (_xmlReader->readNextStartElement()) { + if (_xmlReader->name() == "Base") { + attributes = _xmlReader->attributes(); + QString baseType = attributes.value("type").toString(); + auxPair.first = classId; + auxPair.second = baseType; + _fileBases.append(auxPair); + } + } + } while (_xmlReader->name() == "Base"); + } + + if (_xmlReader->name() == "Field") { + attributes = _xmlReader->attributes(); + QString fieldContext = attributes.value("context").toString(); + QString fieldType = attributes.value("type").toString(); + auxPair.first = fieldContext; + auxPair.second = fieldType; + _fileFields.append(auxPair); + } + + if (_xmlReader->name() == "PointerType") { + attributes = _xmlReader->attributes(); + QString pointerId = attributes.value("id").toString(); + QString pointerType = attributes.value("type").toString(); + auxPair.first = pointerId; + auxPair.second = pointerType; + _filePointers.insert(pointerId, pointerType); + } + + + if (_xmlReader->name() == "Method") { + attributes = _xmlReader->attributes(); + QString methodContext = attributes.value("context").toString(); + + do { + if (_xmlReader->readNextStartElement()) { + if (_xmlReader->name() == "Argument") { + attributes = _xmlReader->attributes(); + QString argumentType = attributes.value("type").toString(); + auxPair.first = methodContext; + auxPair.second = argumentType; + _fileArguments.append(auxPair); + } + } + } while (_xmlReader->name() == "Argument"); + } + } + } _xmlFileManager->closeXmlFile(); +} + +QMap<QString, QString> XmlFileReader::fileClasses() +{ + return _fileClasses; +} + +QList<QPair<QString, QString> > XmlFileReader::fileFields() +{ + return _fileFields; +} + +QMap<QString, QString> XmlFileReader::filePointers() +{ + return _filePointers; +} + +QList<QPair<QString, QString> > XmlFileReader::fileBases() +{ + return _fileBases; +} + +QList<QPair<QString, QString> > XmlFileReader::fileArguments() +{ + return _fileArguments; +} + +} diff --git a/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/xmlfilereader.h b/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/xmlfilereader.h new file mode 100644 index 00000000..6059c8f5 --- /dev/null +++ b/examples/uml/duse-mt/src/plugins/gccxmlarchitecturerecoverybackend/xmlfilereader.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Sandro S. Andrade <sandroandrade@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtUml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef XMLFILEREADER_H +#define XMLFILEREADER_H + +#include <QHash> +#include <QList> +#include <QMultiMap> +#include <QtCore/QStringList> + +QT_BEGIN_NAMESPACE +class QXmlStreamReader; +QT_END_NAMESPACE + +#include "xmlfilemanager.h" + +namespace DuSE +{ + +class XmlFileReader +{ +public: + XmlFileReader(QString rootDirectory, QString fileName); + ~XmlFileReader(); + + void fillTagContainers(); + QMap<QString, QString> fileClasses(); + QList<QPair<QString, QString> > fileFields(); + QMap<QString, QString> filePointers(); + QList<QPair<QString, QString> > fileBases(); + QList<QPair<QString, QString> > fileArguments(); + +private: + QString _rootProjectDir; + QString _fileName; + QXmlStreamReader *_xmlReader; + XmlFileManager *_xmlFileManager; + QMap<QString, QString> _fileClasses; + QList<QPair<QString, QString> > _fileFields; + QMap<QString, QString> _filePointers; + QList<QPair<QString, QString> > _fileBases; + QList<QPair<QString, QString> > _fileArguments; +}; + +} + +#endif // XMLFILEREADER_H |