[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdev-ruby] /: Update ruby new class generation code to match the new API
From: Alexander Dymo <adymo () kdevelop ! org>
Date: 2012-10-26 12:08:52
Message-ID: 20121026120852.D11FCA6078 () git ! kde ! org
[Download RAW message or body]
Git commit bcbcb54167ecb32e174d59187795a16abaa2e7e2 by Alexander Dymo.
Committed on 26/10/2012 at 14:07.
Pushed by dymo into branch 'master'.
Update ruby new class generation code to match the new API
(changed after merging file templates branch)
M +1 -1 CMakeLists.txt
M +34 -57 codegen/rubynewclass.cpp
M +12 -53 codegen/rubynewclass.h
D +0 -91 codegen/rubyrefactoring.cpp
D +0 -74 codegen/rubyrefactoring.h
M +7 -17 rubylanguagesupport.cpp
M +2 -9 rubylanguagesupport.h
http://commits.kde.org/kdev-ruby/bcbcb54167ecb32e174d59187795a16abaa2e7e2
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9bff8d1..e70234a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,13 +20,13 @@ add_subdirectory(duchain)
add_subdirectory(navigation)
add_subdirectory(completion)
add_subdirectory(app_templates)
+add_subdirectory(file_templates)
set(kdevrubylanguagesupport_PART_SRCS
rubyparsejob.cpp
rubyhighlighting.cpp
rubylanguagesupport.cpp
- codegen/rubyrefactoring.cpp
codegen/rubynewclass.cpp
)
diff --git a/codegen/rubynewclass.cpp b/codegen/rubynewclass.cpp
index 9c5d532..d2eb2d3 100644
--- a/codegen/rubynewclass.cpp
+++ b/codegen/rubynewclass.cpp
@@ -18,14 +18,13 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include <KTemporaryFile>
#include <codegen/rubynewclass.h>
#include <language/codegen/documentchangeset.h>
#include <language/duchain/duchain.h>
#include <language/duchain/duchainlock.h>
-#include <KTemporaryFile>
-#include <KLocale>
-#include <QTreeWidgetItem>
+
#include <rubydefs.h>
@@ -33,84 +32,62 @@ namespace Ruby
{
using namespace KDevelop;
-RubyNewClass::RubyNewClass(KDevelop::ProjectBaseItem *parentItem)
- : m_parentItem(parentItem)
-{
- /* There's nothing to do here */
-}
-
-KDevelop::DocumentChangeSet RubyNewClass::generate()
-{
- /* TODO */
- KDevelop::DocumentChangeSet changes;
- return changes;
-}
-
-KDevelop::StructureType::Ptr RubyNewClass::objectType() const
-{
- /* TODO: fix this */
- return KDevelop::StructureType::Ptr(NULL);
-}
-
-const KDevelop::ProjectBaseItem * RubyNewClass::parentItem() const
-{
- return m_parentItem;
-}
-
-RubyNewClassAssistant::RubyNewClassAssistant(QWidget *parent, RubyNewClass *gen, \
KUrl baseUrl)
- : KDevelop::CreateClassAssistant(parent, gen, baseUrl)
-{
- setup();
-}
-
-KDevelop::ClassIdentifierPage* RubyNewClassAssistant::newIdentifierPage()
+RubyClassHelper::RubyClassHelper()
+ :ICreateClassHelper()
{
- /* TODO: Under construction */
- return new KDevelop::ClassIdentifierPage(this);
}
-KDevelop::OverridesPage* RubyNewClassAssistant::newOverridesPage()
+RubyClassHelper::~RubyClassHelper()
{
- return new RubyOverridesPage(generator(), this);
}
-RubyOverridesPage::RubyOverridesPage(KDevelop::ClassGenerator *gen, QWidget *parent)
- : KDevelop::OverridesPage(gen, parent)
+TemplateClassGenerator* RubyClassHelper::createGenerator(const KUrl& baseUrl)
{
- /* There's nothing to do here */
+ return new RubyNewClass(baseUrl);
}
-void RubyOverridesPage::populateOverrideTree(const \
QList<KDevelop::DeclarationPointer> & baseList) +QList<DeclarationPointer> \
RubyClassHelper::defaultMethods(const QString& name) const {
- /* TODO: read the TODO from the RubyOverridesPage class declaration */
- OverridesPage::populateOverrideTree(baseList);
-
- // Generate ruby code with some default methods
- const QString newClass = generator()->name();
KTemporaryFile file;
file.setSuffix(".rb");
file.setAutoRemove(false);
file.open();
QTextStream stream(&file);
- stream << "class " << newClass << "\n"
- << " def initialize\n end\n" << " def to_s\n end\nend";
+ stream << "class " << name << "\n"
+ // constructor
+ << " def initialize\n end\n"
+ // serializer to string
+ << " def to_s\n end\nend";
file.close();
- ReferencedTopDUContext \
context(DUChain::self()->waitForUpdate(IndexedString(file.fileName()),
- \
KDevelop::TopDUContext::AllDeclarationsAndContexts)); + ReferencedTopDUContext \
context(DUChain::self()->waitForUpdate( + IndexedString(file.fileName()),
+ KDevelop::TopDUContext::AllDeclarationsAndContexts));
DUChainReadLocker lock;
+
+ QList<DeclarationPointer> methods;
+
if (!context || !context->childContexts().size() == 1) {
kWarning() << "invalid context for generated ruby file with default methods" \
<< file.fileName();
- file.remove();
- return;
+ } else {
+ foreach (Declaration* declaration, \
context->childContexts().first()->localDeclarations()) { + methods << \
DeclarationPointer(declaration); + }
}
- QTreeWidgetItem *items = new QTreeWidgetItem(overrideTree(), QStringList() << \
i18n("Default methods"));
- foreach (Declaration *decl, \
context->childContexts().first()->localDeclarations())
- OverridesPage::addPotentialOverride(items, DeclarationPointer(decl));
-
file.remove();
+ return methods;
}
+
+RubyNewClass::RubyNewClass(KUrl url)
+ :TemplateClassGenerator(url)
+{
}
+KDevelop::DocumentChangeSet RubyNewClass::generate()
+{
+ return TemplateClassGenerator::generate();
+}
+
+}
diff --git a/codegen/rubynewclass.h b/codegen/rubynewclass.h
index 6f274fd..ab2dc4a 100644
--- a/codegen/rubynewclass.h
+++ b/codegen/rubynewclass.h
@@ -22,73 +22,32 @@
#ifndef RUBY_NEWCLASS_H
#define RUBY_NEWCLASS_H
+#include <KUrl>
-#include <project/projectmodel.h>
-#include <language/duchain/types/structuretype.h>
-#include <language/codegen/createclass.h>
-#include <language/codegen/overridespage.h>
-
-
-/*
- * TODO: under construction
- */
-
+#include <language/duchain/declaration.h>
+#include <language/interfaces/icreateclasshelper.h>
+#include <language/codegen/templateclassgenerator.h>
namespace Ruby
{
-class RubyNewClass : public KDevelop::ClassGenerator
-{
-public:
- RubyNewClass(KDevelop::ProjectBaseItem* parentItem);
- virtual KDevelop::DocumentChangeSet generate();
-
- virtual KDevelop::StructureType::Ptr objectType() const;
-
- const KDevelop::ProjectBaseItem * parentItem() const;
-
-private:
- KDevelop::ProjectBaseItem *m_parentItem;
-};
-
-class RubyNewClassAssistant : public KDevelop::CreateClassAssistant
-{
+class RubyClassHelper: public KDevelop::ICreateClassHelper {
public:
- RubyNewClassAssistant(QWidget *parent, RubyNewClass *gen, KUrl baseUrl = \
KUrl()); + RubyClassHelper();
+ virtual ~RubyClassHelper();
- virtual KDevelop::ClassIdentifierPage * newIdentifierPage();
- virtual KDevelop::OverridesPage * newOverridesPage();
+ virtual KDevelop::TemplateClassGenerator* createGenerator(const KUrl& baseUrl);
+ virtual QList< KDevelop::DeclarationPointer > defaultMethods(const QString& \
name) const; };
-/*
- * TODO: We need to subclass the IdentifierPage so we can implement the
- * following ideas:
- * -> In ruby multiple inheritance is not allowed.
- * -> The user might want to add include's/extend's
- */
-
-/*
- * TODO: The tree should be populated with the methods from the superclass, the
- * included/extended methods and the methods from the Class class.
- */
-class RubyOverridesPage : public KDevelop::OverridesPage
-{
- Q_OBJECT
-
+class RubyNewClass : public KDevelop::TemplateClassGenerator {
public:
- RubyOverridesPage(KDevelop::ClassGenerator *gen, QWidget *parent);
+ RubyNewClass(KUrl url);
+ virtual KDevelop::DocumentChangeSet generate();
- virtual void populateOverrideTree(const QList<KDevelop::DeclarationPointer> & \
baseList); };
-/*
- * TODO: for the other pages:
- * - In the license page it seems that there's only licenses with C++ comments.
- * - In the output page, it makes no sense to output two files.
- */
-
-
}
diff --git a/codegen/rubyrefactoring.cpp b/codegen/rubyrefactoring.cpp
deleted file mode 100644
index 82b4327..0000000
--- a/codegen/rubyrefactoring.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * This file is part of KDevelop
- * Copyright 2012 Miquel Sabaté <mikisabate@gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Library General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-
-// Qt + KDE
-#include <QApplication>
-#include <QAction>
-#include <KLocalizedString>
-
-// Ruby
-#include <codegen/rubyrefactoring.h>
-#include <codegen/rubynewclass.h>
-
-
-namespace Ruby
-{
-
-RubyRefactoring & RubyRefactoring::self()
-{
- static RubyRefactoring rr;
- return rr;
-}
-
-void RubyRefactoring::doContextMenu(KDevelop::ContextMenuExtension &extension,
- KDevelop::Context *context)
-{
- if (KDevelop::ProjectItemContext* projectContext = \
dynamic_cast<KDevelop::ProjectItemContext*>(context)) {
- if (projectContext->items().count() == 1) {
- KDevelop::ProjectBaseItem* item = projectContext->items().first();
- if (item->folder() || item->target()) {
- QAction *action = new QAction(i18n("Create New Ruby Class"), this);
- action->setData(QVariant::fromValue<KDevelop::ProjectBaseItem*>(item));
- connect(action, SIGNAL(triggered(bool)),
- this, SLOT(executeNewClassAction()));
- extension.addAction(KDevelop::ContextMenuExtension::FileGroup, \
action);
- }
- }
- }
-}
-
-void RubyRefactoring::createNewClass(KDevelop::ProjectBaseItem *item)
-{
- /*
- * TODO: the code below is not complete. It should detect if this is a Rails
- * application. If it's so, then it has to check if the user clicked
- * over a "relevant" directory (models, controllers,...). Otherwise we
- * have to retrieve the url just like the c++ plugin does.
- * TODO: move this code to the RubyNewClass class.
- */
- KUrl u = KUrl();
- if (item) {
- KDevelop::ProjectBaseItem *ff = item->folder();
- if(!ff && item->target())
- ff = static_cast<KDevelop::ProjectBaseItem*>(item->parent())->folder();
- if(ff)
- u = ff->url();
- } else {
- // TODO: get url from current selection
- }
- RubyNewClass newClass(item);
- RubyNewClassAssistant newClassWizard(qApp->activeWindow(), &newClass, u);
- newClassWizard.exec();
-}
-
-void RubyRefactoring::executeNewClassAction()
-{
- QAction* action = qobject_cast<QAction *>(sender());
- if (action) {
- KDevelop::ProjectBaseItem* item = \
action->data().value<KDevelop::ProjectBaseItem *>();
- createNewClass(item);
- }
-}
-
-}
diff --git a/codegen/rubyrefactoring.h b/codegen/rubyrefactoring.h
deleted file mode 100644
index 2a79cf8..0000000
--- a/codegen/rubyrefactoring.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * This file is part of KDevelop
- * Copyright 2012 Miquel Sabaté <mikisabate@gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Library General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-
-#ifndef RUBY_REFACTORING_H
-#define RUBY_REFACTORING_H
-
-
-#include <interfaces/contextmenuextension.h>
-#include <interfaces/context.h>
-
-
-namespace Ruby
-{
-
-/**
- * @class RubyRefactoring
- *
- * The RubyRefactoring class packs all the refactoring functionalities
- * that this plugin provides.
- */
-class RubyRefactoring : public QObject
-{
- Q_OBJECT
-
-public:
- /**
- * @return instance of this class.
- */
- static RubyRefactoring & self();
-
- /**
- * It extends the context menu by adding all the available refactoring
- * actions. In order to do this, it takes the context menu @p extension
- * and the given @param context.
- */
- void doContextMenu(KDevelop::ContextMenuExtension &extension, KDevelop::Context \
*context);
-
- /**
- * It makes the 'Create New Ruby Class' dialog to appear.
- *
- * @param item the KDevelop::ProjectBaseItem that the user may have
- * selected.
- */
- void createNewClass(KDevelop::ProjectBaseItem *item);
-
-private slots:
- /**
- * Executed from the context menu when the user wants to
- * create a new class.
- */
- void executeNewClassAction();
-};
-
-}
-
-#endif /* RUBY_REFACTORING_H */
diff --git a/rubylanguagesupport.cpp b/rubylanguagesupport.cpp
index 3a05221..e71572c 100644
--- a/rubylanguagesupport.cpp
+++ b/rubylanguagesupport.cpp
@@ -53,11 +53,11 @@
#include <rubylanguagesupport.h>
#include <rubyparsejob.h>
#include <rubyhighlighting.h>
+#include <codegen/rubynewclass.h>
#include <navigation/railsswitchers.h>
#include <navigation/railsdataprovider.h>
#include <duchain/helpers.h>
#include <completion/model.h>
-#include <codegen/rubyrefactoring.h>
//END Includes
@@ -134,13 +134,6 @@ KDevelop::ICodeHighlighting * \
LanguageSupport::codeHighlighting() const return m_highlighting;
}
-ContextMenuExtension LanguageSupport::contextMenuExtension(KDevelop::Context *ctx)
-{
- KDevelop::ContextMenuExtension cm;
- RubyRefactoring::self().doContextMenu(cm, ctx);
- return cm;
-}
-
bool LanguageSupport::builtinsLoaded() const
{
return m_builtinsLoaded;
@@ -156,11 +149,6 @@ enum ruby_version LanguageSupport::version() const
return m_version;
}
-void LanguageSupport::createNewClass()
-{
- RubyRefactoring::self().createNewClass(0);
-}
-
void LanguageSupport::updateReady(KDevelop::IndexedString url, \
KDevelop::ReferencedTopDUContext topContext) {
Q_UNUSED(topContext)
@@ -312,10 +300,6 @@ void \
LanguageSupport::createActionsForMainWindow(Sublime::MainWindow* /*window*/ \
action->setText(i18n("Run Current Test Function")); action->setShortcut(Qt::META | \
Qt::SHIFT | Qt::Key_F9);
connect(action, SIGNAL(triggered(bool)), this, SLOT(runCurrentTestFunction()));
-
- action = actions.addAction("ruby_new_class");
- action->setText(i18n("Create New Ruby Class"));
- connect(action, SIGNAL(triggered(bool)), this, SLOT(createNewClass()));
}
void LanguageSupport::setupQuickOpen()
@@ -330,6 +314,12 @@ void LanguageSupport::setupQuickOpen()
}
}
+KDevelop::ICreateClassHelper* LanguageSupport::createClassHelper() const
+{
+ return new RubyClassHelper;
+}
+
+
} // End of namespace Ruby
diff --git a/rubylanguagesupport.h b/rubylanguagesupport.h
index aef5f58..735b072 100644
--- a/rubylanguagesupport.h
+++ b/rubylanguagesupport.h
@@ -105,12 +105,6 @@ public:
virtual KDevelop::ICodeHighlighting * codeHighlighting() const;
/**
- * Override from KDevelop::IPlugin so it can @return an extension
- * of the context menu.
- */
- KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context *ctx);
-
- /**
* @return true if the builtins file is loaded, false otherwise.
*/
bool builtinsLoaded() const;
@@ -130,6 +124,8 @@ public:
*/
virtual void createActionsForMainWindow(Sublime::MainWindow* window, QString& \
xmlFile, KActionCollection& actions);
+
+ virtual KDevelop::ICreateClassHelper* createClassHelper() const;
private:
/**
* @internal Find or create a launch for a the given @p name.
@@ -156,9 +152,6 @@ private:
void setupQuickOpen();
public slots:
- /// The slot for the Create New Class dialog.
- void createNewClass();
-
/// Get notified by background parser when the builtins file is loaded.
void updateReady(KDevelop::IndexedString url, KDevelop::ReferencedTopDUContext \
topContext);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic