[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE
From: Ramon Zarazua <killerfox512 () gmail ! com>
Date: 2009-07-30 5:14:48
Message-ID: 1248930888.710324.8077.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1004402 by rzarazua:
Add functionality to get ranged text from all code representations
Add tests
M +20 -3 kdevelop/languages/cpp/tests/test_cppcodegen.cpp
M +1 -0 kdevelop/languages/cpp/tests/test_cppcodegen.h
M +19 -2 kdevplatform/language/codegen/coderepresentation.cpp
M +1 -1 kdevplatform/language/codegen/coderepresentation.h
--- trunk/KDE/kdevelop/languages/cpp/tests/test_cppcodegen.cpp #1004401:1004402
@@ -143,7 +143,24 @@
QVERIFY(it->data()->localDeclarations()[0]->context()->importedParentContexts()[0].context(it->data()) \
!= it->data()); }
-#include <codegen/simplerefactoring.h>
+void TestCppCodegen::testCodeRepresentations()
+{
+ //text from range
+ CodeRepresentation::Ptr code = \
createCodeRepresentation(IndexedString(CodeRepresentation::artificialUrl("ClassA.h")));
+ QVERIFY(code);
+
+
+ QCOMPARE(code->rangeText(KTextEditor::Range(0, 0, 0, 12)), QString("class \
ClassA")); + QCOMPARE(code->rangeText(KTextEditor::Range(0, 0, 0, \
code->line(0).size())), code->line(0)); +
+ code = createCodeRepresentation(IndexedString(CodeRepresentation::artificialUrl("ClassA.cpp")));
+ QVERIFY(code);
+
+ QCOMPARE(code->rangeText(KTextEditor::Range(0, 0, 1, 0)), \
QString("#include</ClassA.h> \n")); + QCOMPARE(code->rangeText(KTextEditor::Range(0, \
0, code->lines() - 1, code->line(code->lines() - 1).size())), + \
code->text()); +}
+
void TestCppCodegen::testClassGeneration()
{
TopDUContext * top = 0;
@@ -160,8 +177,8 @@
DocumentChangeSet changes = newClass.generate();
changes.applyAllToTemp();
QCOMPARE(changes.tempNamesForAll().size(), 2);
-/* parseFile(changes.tempNamesForAll()[0].second);
- parseFile(changes.tempNamesForAll()[1].second);*/
+ parseFile(changes.tempNamesForAll()[0].second);
+ parseFile(changes.tempNamesForAll()[1].second);
}
void TestCppCodegen::testPrivateImplementation()
--- trunk/KDE/kdevelop/languages/cpp/tests/test_cppcodegen.h #1004401:1004402
@@ -46,6 +46,7 @@
void testAstDuChainMapping();
+ void testCodeRepresentations();
void testClassGeneration();
void testPrivateImplementation();
--- trunk/KDE/kdevplatform/language/codegen/coderepresentation.cpp #1004401:1004402
@@ -27,6 +27,23 @@
static bool onDiskChangesForbidden = false;
+QString CodeRepresentation::rangeText(KTextEditor::Range range) const
+{
+ Q_ASSERT(range.end().line() < lines());
+
+ //Easier for single line ranges which should happen most of the time
+ if(range.onSingleLine())
+ return QString( line( range.start().line() ).mid( range.start().column(), \
range.columnWidth() ) ); +
+ //Add up al the requested lines
+ QString rangedText = line(range.start().line()).mid(range.start().column());
+
+ for(int i = range.start().line() + 1; i <= range.end().line(); ++i)
+ rangedText += '\n' + ((i == range.end().line()) ? \
line(i).left(range.end().column()) : line(i)); +
+ return rangedText;
+}
+
class EditorCodeRepresentation : public DynamicCodeRepresentation {
public:
EditorCodeRepresentation(KTextEditor::Document* document) : m_document(document) {
@@ -215,8 +232,8 @@
KUrl CodeRepresentation::artificialUrl(const QString & name)
{
- KUrl url("artificial:///");
- url.addPath(name);
+ KUrl url(name[0] == '/' ? name : '/' + name);
+ url.setScheme("artificial");
return url;
}
--- trunk/KDE/kdevplatform/language/codegen/coderepresentation.h #1004401:1004402
@@ -42,6 +42,7 @@
virtual QString line(int line) const = 0;
virtual int lines() const = 0;
virtual QString text() const = 0;
+ virtual QString rangeText(KTextEditor::Range range) const;
///Overwrites the text in the file with the new given one
///@return true on success
virtual bool setText(QString) = 0;
@@ -64,7 +65,6 @@
///Used to group edit-history together. Call this before a bunch of replace(), \
and endEdit in the end. virtual void startEdit() = 0;
virtual bool replace(const KTextEditor::Range& range, QString oldText, QString \
newText, bool ignoreOldText = false) = 0;
- virtual QString rangeText(KTextEditor::Range range) const = 0;
///Must be called exactly once per startEdit()
virtual void endEdit() = 0;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic