Skip to content

Commit

Permalink
Refactoring and fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
fpoussin committed Dec 10, 2015
1 parent 3139ffd commit 8aa2716
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 53 deletions.
89 changes: 55 additions & 34 deletions doxygen.cpp
Expand Up @@ -48,6 +48,7 @@
#include <QFileInfo>
#include <QRegExp>
#include <QProgressDialog>
#include <QMessageBox>

using namespace CPlusPlus;
using namespace ProjectExplorer;
Expand Down Expand Up @@ -120,11 +121,11 @@ Symbol* currentSymbol(Core::IEditor *editor)

// TODO: Recode it entirely.
// TODO: Duplicate detection.
void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor)
bool Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor)
{
// before continuing, test if the editor is actually showing a file.
if(!editor)
return;
return false;

// get the widget for later.
TextEditor::TextEditorWidget *editorWidget = qobject_cast<TextEditor::TextEditorWidget*>(
Expand All @@ -144,38 +145,36 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor
editorWidget->gotoNextWord();
// infinite loop prevention
if(lastLine == editor->currentLine() && lastColumn == editor->currentColumn())
return;
return false;
lastLine = editor->currentLine();
lastColumn = editor->currentColumn();
lastSymbol = currentSymbol(editor);
}
//qDebug() << lastLine << " " << lastColumn;
if (!lastSymbol)
{
return;
return false;
}

// We don't want to document multiple times.
//QRegExp duplicate("\\brief\s*([^\n\r])+");
// Todo: fix when doc is not saved
QRegExp duplicate("^(\\s|\t)?\\*/");
QRegExp commentClosing("\\*/");
QString text(editorWidget->document()->toPlainText());
QStringList lines(text.split(QRegExp("\n|\r\n|\r")));

for (int i= 1; i <= 10; i++)
for (int i= 1; i <= 5; i++)
{
int prevLine = lastLine - i;
if (prevLine < 0) break;
QString checkText(lines.at(prevLine));
if (checkText.contains(duplicate))
if (checkText.contains(commentClosing))
{
qDebug() << "Duplicate found in" << editor->document()->filePath().toString() << prevLine;
qDebug() << checkText;
return;
//qDebug() << "Duplicate found in" << editor->document()->filePath().toString() << prevLine;
//qDebug() << checkText;
return false;
}
}


QStringList scopes = scopesForSymbol(lastSymbol);
Overview overview;
overview.showArgumentNames = true;
Expand Down Expand Up @@ -204,7 +203,7 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor
// quickfix when calling the method on "};" (end class) or "}" (end namespace)
if(indent.contains(QRegExp("^\\};?")))
{
return;
return false;
}

if(indent.endsWith('~'))
Expand Down Expand Up @@ -273,7 +272,7 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor
if(DoxySettings.shortVarDoc)
{
printAtEnd = true;
docToWrite = DoxySettings.DoxyComment.doxShortVarDoc + "TODO" + DoxySettings.DoxyComment.doxShortVarDocEnd;
docToWrite = DoxySettings.DoxyComment.doxShortVarDoc + "TODO: describe" + DoxySettings.DoxyComment.doxShortVarDocEnd;
}
else
{
Expand All @@ -288,7 +287,7 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor
// Never noticed it before, a useless comment block because of the Q_OBJECT macro
// so let's just ignore that will we?
if(overview.prettyName(name) == "qt_metacall")
return;
return false;

if(DoxySettings.verbosePrinting)
docToWrite += indent + DoxySettings.DoxyComment.doxNewLine + "fn " + overview.prettyName(name) + "\n";
Expand Down Expand Up @@ -353,22 +352,27 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor
editorWidget->moveCursor(QTextCursor::EndOfLine);
else
editorWidget->moveCursor(QTextCursor::StartOfBlock);

editorWidget->insertPlainText(docToWrite);
return true;
}
return false;
}

void Doxygen::addFileComment(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor)
bool Doxygen::addFileComment(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor)
{
// before continuing, test if the editor is actually showing a file.
if(!editor)
return;
return false;

// get the widget for later.
TextEditor::TextEditorWidget *editorWidget = qobject_cast<TextEditor::TextEditorWidget*>(
editor->widget());
// get our symbol
editorWidget->gotoLine(1, 0);
editorWidget->insertPlainText(DoxySettings.fileComment + "\n");

return true;
}

void Doxygen::addSymbol(const CPlusPlus::Symbol* symbol, QList<const Symbol*> &symmap)
Expand Down Expand Up @@ -400,29 +404,29 @@ void Doxygen::addSymbol(const CPlusPlus::Symbol* symbol, QList<const Symbol*> &s
}
}

void Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor)
uint Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor)
{
// before continuing, test if the editor is actually showing a file.
if(!editor)
{
//qDebug() << "No editor";
return;
return 0;
}

CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
//ExtensionSystem::PluginManager::instance()->getObject<CPlusPlus::CppModelManagerInterface>();
if(!modelManager)
{
//qDebug() << "No modelManager";
return;
return 0;
}

const Snapshot snapshot = modelManager->snapshot();
Document::Ptr doc = snapshot.document(editor->document()->filePath());
if(!doc)
{
//qDebug() << "No document";
return;
return 0;
}

// TODO : check
Expand All @@ -434,10 +438,9 @@ void Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEdi
addFileComment(DoxySettings, editor);
}
//qDebug() << "No global symbols";
return;
return 0;
}


// check that as well...
Scope* scope = doc->scopeAt(0,0);
if(!scope)
Expand All @@ -447,7 +450,7 @@ void Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEdi
addFileComment(DoxySettings, editor);
}
//qDebug() << "No scope";
return;
return 0;
}

unsigned symbolcount = scope->memberCount();
Expand All @@ -467,36 +470,53 @@ void Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEdi

TextEditor::TextEditorWidget *editorWidget = qobject_cast<TextEditor::TextEditorWidget*>(editor->widget());

uint count = 0;
if (editorWidget)
{
QList<const Symbol*>::iterator it = symmap.end();
for(; it != symmap.begin(); --it)
{
const Symbol* sym = *(it-1);
editorWidget->gotoLine(sym->line());
createDocumentation(DoxySettings, editor);
if (createDocumentation(DoxySettings, editor))
count++;
}

if(DoxySettings.fileCommentsEnabled)
{
addFileComment(DoxySettings, editor);
if (addFileComment(DoxySettings, editor))
count++;
}
}
//qDebug() << "Count" << count;

return count;
}

// TODO fix this!!!
void Doxygen::documentActiveProject(const DoxygenSettingsStruct &DoxySettings)
// TODO: fix this! Unused at the moment.
uint Doxygen::documentSpecificProject(const DoxygenSettingsStruct &DoxySettings)
{
documentProject(ProjectExplorer::SessionManager::startupProject(), DoxySettings);
return documentProject(ProjectExplorer::SessionManager::startupProject(), DoxySettings);
}

void Doxygen::documentOpenedProject(const DoxygenSettingsStruct &DoxySettings)
uint Doxygen::documentCurrentProject(const DoxygenSettingsStruct &DoxySettings)
{
documentProject(ProjectExplorer::ProjectTree::currentProject(), DoxySettings);
return documentProject(ProjectExplorer::ProjectTree::currentProject(), DoxySettings);
}

void Doxygen::documentProject(ProjectExplorer::Project *p, const DoxygenSettingsStruct &DoxySettings)
uint Doxygen::documentProject(ProjectExplorer::Project *p, const DoxygenSettingsStruct &DoxySettings)
{
// prevent a crash if user launches this command with no project opened
// You don't need to have an editor open for that.
if (!p) {
QMessageBox::warning((QWidget*)parent(),
tr("Doxygen"),
tr("You don't have any current project."),
QMessageBox::Close, QMessageBox::NoButton);
return 0;
}

uint count = 0;
Core::EditorManager *editorManager = Core::EditorManager::instance();
QStringList files = p->files(ProjectExplorer::Project::ExcludeGeneratedFiles);
QProgressDialog progress("Processing files...", "Cancel", 0, files.size());
Expand Down Expand Up @@ -533,7 +553,7 @@ void Doxygen::documentProject(ProjectExplorer::Project *p, const DoxygenSettings
if(editor)
{
documented = true;
documentFile(DoxySettings, editor);
count += documentFile(DoxySettings, editor);
}
}

Expand All @@ -555,11 +575,12 @@ void Doxygen::documentProject(ProjectExplorer::Project *p, const DoxygenSettings
{
Core::IEditor *editor = editorManager->openEditor(files[i]);
if(editor)
addFileComment(DoxySettings, editor);
count += addFileComment(DoxySettings, editor);
}
}
}
progress.setValue(files.size());
return count;
}

QString Doxygen::getProjectRoot()
Expand Down
17 changes: 10 additions & 7 deletions doxygen.h
Expand Up @@ -30,18 +30,21 @@
namespace DoxyPlugin {
namespace Internal {

class Doxygen
class Doxygen : public QObject
{
public:
static Doxygen* instance();
static QString getProjectRoot();
void addSymbol(const CPlusPlus::Symbol* symbol, QList<const CPlusPlus::Symbol*> &symmap);
void createDocumentation(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor);
void addFileComment(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor);
void documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor);
void documentProject(ProjectExplorer::Project *p, const DoxygenSettingsStruct &DoxySettings);
void documentActiveProject(const DoxygenSettingsStruct &DoxySettings);
void documentOpenedProject(const DoxygenSettingsStruct &DoxySettings);
bool createDocumentation(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor);
bool addFileComment(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor);
uint documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor);
uint documentProject(ProjectExplorer::Project *p, const DoxygenSettingsStruct &DoxySettings);
uint documentSpecificProject(const DoxygenSettingsStruct &DoxySettings);
uint documentCurrentProject(const DoxygenSettingsStruct &DoxySettings);

signals:
void message(QString);

private:
Doxygen();
Expand Down
34 changes: 25 additions & 9 deletions doxygenplugin.cpp
Expand Up @@ -53,6 +53,7 @@
#include <QKeySequence>
#include <QStringList>
#include <QFileInfo>
#include <QString>

#include <QtPlugin>

Expand Down Expand Up @@ -152,7 +153,7 @@ bool DoxygenPlugin::initialize(const QStringList &arguments, QString *errorStrin
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F8")));
connect(m_doxygenDocumentActiveProjectAction, SIGNAL(triggered(bool)),
this, SLOT(documentActiveProject()));
this, SLOT(documentCurrentProject()));
doxygenMenu->addAction(command);

// "compile" documentation action
Expand Down Expand Up @@ -203,18 +204,32 @@ void DoxygenPlugin::createDocumentation()

void DoxygenPlugin::documentFile()
{
Core::IEditor *editor = Core::EditorManager::instance()->currentEditor();
Doxygen::instance()->documentFile(settings(), editor);
if (QMessageBox::question((QWidget*)this->parent(),
"Doxygen", "Document current File?",
QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
{
Core::IEditor *editor = Core::EditorManager::instance()->currentEditor();
uint count = Doxygen::instance()->documentFile(settings(), editor);
QString msg;
this->externalString(msg.sprintf("Doxygen blocs generated: %u", count));
}
}

void DoxygenPlugin::documentOpenedProject()
void DoxygenPlugin::documentSpecificProject()
{
Doxygen::instance()->documentOpenedProject(settings());
Doxygen::instance()->documentSpecificProject(settings());
}

void DoxygenPlugin::documentActiveProject()
void DoxygenPlugin::documentCurrentProject()
{
Doxygen::instance()->documentActiveProject(settings());
if (QMessageBox::question((QWidget*)this->parent(),
"Doxygen", "Document current project?",
QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
{
uint count = Doxygen::instance()->documentCurrentProject(settings());
QString msg;
this->externalString(msg.sprintf("Doxygen blocs generated: %u", count));
}
}

bool DoxygenPlugin::buildDocumentation() // TODO: refactor
Expand Down Expand Up @@ -262,7 +277,7 @@ void DoxygenPlugin::doxyfileWizard() // TODO: refactor
ProjectExplorer::Project *p = ProjectExplorer::ProjectTree::currentProject();
if (!p) {
QMessageBox::warning((QWidget*)parent(),
tr("No Current Project"),
tr("Doxygen"),
tr("You don't have any current project."),
QMessageBox::Close, QMessageBox::NoButton);
return;
Expand Down Expand Up @@ -348,9 +363,10 @@ DoxygenResponse DoxygenPlugin::runDoxygen(const QStringList &arguments, int time
return response;
}

void DoxygenPlugin::externalString(const QString& text, bool)
void DoxygenPlugin::externalString(const QString& text)
{
Core::MessageManager::write(text);
Core::MessageManager::showOutputPane();
}

DoxygenSettingsStruct DoxygenPlugin::settings() const
Expand Down
6 changes: 3 additions & 3 deletions doxygenplugin.h
Expand Up @@ -72,11 +72,11 @@ class DoxygenPlugin : public ExtensionSystem::IPlugin
private slots:
void createDocumentation();
void documentFile();
void documentOpenedProject();
void documentActiveProject();
void documentSpecificProject();
void documentCurrentProject();
bool buildDocumentation();
void doxyfileWizard();
void externalString(const QString&, bool);
void externalString(const QString&);
};

} // namespace Internal
Expand Down

0 comments on commit 8aa2716

Please sign in to comment.