[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdevplatform] language/codegen: reformat code... I can't take this mess anymore
From:       Milian Wolff <mail () milianw ! de>
Date:       2012-10-26 22:19:59
Message-ID: 20121026221959.764A3A60A6 () git ! kde ! org
[Download RAW message or body]

Git commit b5a1bacd18744685429f89e52d0df5cf03750a45 by Milian Wolff.
Committed on 27/10/2012 at 00:12.
Pushed by mwolff into branch 'master'.

reformat code... I can't take this mess anymore

M  +208  -158  language/codegen/documentchangeset.cpp
M  +42   -34   language/codegen/documentchangeset.h

http://commits.kde.org/kdevplatform/b5a1bacd18744685429f89e52d0df5cf03750a45

diff --git a/language/codegen/documentchangeset.cpp \
b/language/codegen/documentchangeset.cpp index 48baf0f..ab33d2b 100644
--- a/language/codegen/documentchangeset.cpp
+++ b/language/codegen/documentchangeset.cpp
@@ -17,63 +17,80 @@
 */
 
 #include "documentchangeset.h"
+
 #include "coderepresentation.h"
-#include <qstringlist.h>
-#include <editor/modificationrevisionset.h>
+
+#include <algorithm>
+
+#include <QStringList>
+
+#include <KLocalizedString>
+
 #include <interfaces/icore.h>
 #include <interfaces/ilanguagecontroller.h>
-#include <language/backgroundparser/backgroundparser.h>
 #include <interfaces/idocumentcontroller.h>
+
 #include <language/duchain/duchain.h>
 #include <language/duchain/duchainlock.h>
 #include <language/duchain/duchainutils.h>
 #include <language/duchain/parsingenvironment.h>
+#include <language/backgroundparser/backgroundparser.h>
+#include <language/editor/modificationrevisionset.h>
+
 #include <interfaces/isourceformattercontroller.h>
 #include <interfaces/isourceformatter.h>
 #include <interfaces/iproject.h>
 #include <interfaces/iprojectcontroller.h>
+
 #include <project/projectmodel.h>
-#include <KLocalizedString>
-#include <algorithm>
 
 namespace KDevelop {
 
+typedef QList<DocumentChangePointer> ChangesList;
+typedef QHash<IndexedString, ChangesList> ChangesHash;
+
 struct DocumentChangeSetPrivate
 {
     DocumentChangeSet::ReplacementPolicy replacePolicy;
     DocumentChangeSet::FormatPolicy formatPolicy;
     DocumentChangeSet::DUChainUpdateHandling updatePolicy;
     DocumentChangeSet::ActivationPolicy activationPolicy;
-    
-    QMap< IndexedString, QList<DocumentChangePointer> > changes;
-    QHash< IndexedString, IndexedString> documentsRename;
-    
-    DocumentChangeSet::ChangeResult addChange(DocumentChangePointer change);
-    DocumentChangeSet::ChangeResult replaceOldText(CodeRepresentation * repr, const \
                QString & newText, const QList<DocumentChangePointer> & \
                sortedChangesList);
-    DocumentChangeSet::ChangeResult generateNewText(const KDevelop::IndexedString & \
file, QList< KDevelop::DocumentChangePointer > & sortedChanges, const \
                KDevelop::CodeRepresentation* repr, QString& output);
-    DocumentChangeSet::ChangeResult removeDuplicates(const IndexedString & file, \
QList<DocumentChangePointer> & filteredChanges); +
+    ChangesHash changes;
+    QHash<IndexedString, IndexedString> documentsRename;
+
+    DocumentChangeSet::ChangeResult addChange(const DocumentChangePointer& change);
+    DocumentChangeSet::ChangeResult replaceOldText(CodeRepresentation* repr, const \
QString& newText, +                                                   const \
ChangesList& sortedChangesList); +    DocumentChangeSet::ChangeResult \
generateNewText(const IndexedString& file, +                                          \
ChangesList& sortedChanges, +                                                    \
const CodeRepresentation* repr, +                                                    \
QString& output); +    DocumentChangeSet::ChangeResult removeDuplicates(const \
IndexedString& file, +                                                     \
ChangesList& filteredChanges);  void formatChanges();
     void updateFiles();
 };
 
-//Simple helper to clear up code clutter
+// Simple helpers to clear up code clutter
 namespace
 {
-inline bool changeIsValid(const DocumentChange & change, const QStringList & \
textLines) +inline bool changeIsValid(const DocumentChange& change, const \
QStringList& textLines)  {
     return change.m_range.start <= change.m_range.end &&
            change.m_range.end.line < textLines.size() &&
            change.m_range.start.line >= 0 &&
            change.m_range.start.column >= 0 &&
            change.m_range.start.column <= \
                textLines[change.m_range.start.line].length() &&
-           change.m_range.end.column >= 0 && 
-           change.m_range.end.column <= textLines[change.m_range.end.line].length() \
&&  +           change.m_range.end.column >= 0 &&
+           change.m_range.end.column <= textLines[change.m_range.end.line].length() \
&&  change.m_range.start.line == change.m_range.end.line;
 }
 
-inline bool duplicateChanges(DocumentChangePointer previous, DocumentChangePointer \
current) +inline bool duplicateChanges(const DocumentChangePointer& previous, const \
DocumentChangePointer& current)  {
-    //Given the option of considering a duplicate two changes in the same range but \
with different old texts to be ignored +    // Given the option of considering a \
duplicate two changes in the same range +    // but with different old texts to be \
ignored  return previous->m_range == current->m_range &&
            previous->m_newText == current->m_newText &&
            (previous->m_oldText == current->m_oldText ||
@@ -81,7 +98,8 @@ inline bool duplicateChanges(DocumentChangePointer previous, \
DocumentChangePoint  }
 }
 
-DocumentChangeSet::DocumentChangeSet() : d(new DocumentChangeSetPrivate)
+DocumentChangeSet::DocumentChangeSet()
+: d(new DocumentChangeSetPrivate)
 {
     d->replacePolicy = StopOnFailedChange;
     d->formatPolicy = AutoFormatChanges;
@@ -89,12 +107,13 @@ DocumentChangeSet::DocumentChangeSet() : d(new \
DocumentChangeSetPrivate)  d->activationPolicy = DoNotActivate;
 }
 
-DocumentChangeSet::DocumentChangeSet(const DocumentChangeSet & rhs) : d(new \
DocumentChangeSetPrivate(*rhs.d)) +DocumentChangeSet::DocumentChangeSet(const \
DocumentChangeSet& rhs) +: d(new DocumentChangeSetPrivate(*rhs.d))
 {
 }
 
 
-DocumentChangeSet& DocumentChangeSet::operator=(const KDevelop::DocumentChangeSet& \
rhs) +DocumentChangeSet& DocumentChangeSet::operator=(const DocumentChangeSet& rhs)
 {
     *d = *rhs.d;
     return *this;
@@ -105,46 +124,48 @@ DocumentChangeSet::~DocumentChangeSet()
     delete d;
 }
 
-KDevelop::DocumentChangeSet::ChangeResult DocumentChangeSet::addChange(const \
KDevelop::DocumentChange& change) { +DocumentChangeSet::ChangeResult \
DocumentChangeSet::addChange(const DocumentChange& change) +{
     return d->addChange(DocumentChangePointer(new DocumentChange(change)));
 }
 
-DocumentChangeSet::ChangeResult DocumentChangeSet::addChange(DocumentChangePointer \
change) +DocumentChangeSet::ChangeResult DocumentChangeSet::addChange(const \
DocumentChangePointer& change)  {
     return d->addChange(change);
 }
 
-DocumentChangeSet::ChangeResult DocumentChangeSet::addDocumentRenameChange(const \
IndexedString& oldFile, const IndexedString& newname) \
+DocumentChangeSet::ChangeResult DocumentChangeSet::addDocumentRenameChange(const \
IndexedString& oldFile, +                                                             \
const IndexedString& newname)  {
-    if(d->documentsRename.value(oldFile)!=newname) {
-        return DocumentChangeSet::ChangeResult(i18n("Couldn't rename '%1' to '%2'", \
oldFile.toUrl().prettyUrl(), newname.str())); +    if \
(d->documentsRename.value(oldFile) != newname) { +        return \
ChangeResult(i18n("Couldn't rename '%1' to '%2'", oldFile.toUrl().pathOrUrl(), \
newname.str()));  }
     d->documentsRename.insert(oldFile, newname);
     return true;
 }
 
-DocumentChangeSet::ChangeResult \
                DocumentChangeSetPrivate::addChange(DocumentChangePointer change) {
-    if(change->m_range.start.line != change->m_range.end.line)
-    {
+DocumentChangeSet::ChangeResult DocumentChangeSetPrivate::addChange(const \
DocumentChangePointer& change) +{
+    if(change->m_range.start.line != change->m_range.end.line) {
         kWarning() << "Multi-line changes are not supported in DocumentChangeSet";
         return DocumentChangeSet::ChangeResult("Multi-line ranges are not \
supported");  }
-    
+
     changes[change->m_document].append(change);
     return true;
 }
 
-void DocumentChangeSet::setReplacementPolicy ( DocumentChangeSet::ReplacementPolicy \
policy ) +void DocumentChangeSet::setReplacementPolicy(DocumentChangeSet::ReplacementPolicy \
policy)  {
     d->replacePolicy = policy;
 }
 
-void DocumentChangeSet::setFormatPolicy ( DocumentChangeSet::FormatPolicy policy )
+void DocumentChangeSet::setFormatPolicy(DocumentChangeSet::FormatPolicy policy)
 {
     d->formatPolicy = policy;
 }
 
-void DocumentChangeSet::setUpdateHandling ( DocumentChangeSet::DUChainUpdateHandling \
policy ) +void DocumentChangeSet::setUpdateHandling(DocumentChangeSet::DUChainUpdateHandling \
policy)  {
     d->updatePolicy = policy;
 }
@@ -154,40 +175,44 @@ void \
DocumentChangeSet::setActivationPolicy(DocumentChangeSet::ActivationPolicy  \
d->activationPolicy = policy;  }
 
-QMap< IndexedString, InsertArtificialCodeRepresentationPointer > \
DocumentChangeSet::temporaryCodeRepresentations() const +QHash<IndexedString, \
InsertArtificialCodeRepresentationPointer> \
DocumentChangeSet::temporaryCodeRepresentations() const  {
-    QMap< IndexedString, InsertArtificialCodeRepresentationPointer > ret;
-    
+    QHash<IndexedString, InsertArtificialCodeRepresentationPointer> ret;
+
     ChangeResult result(true);
-    
-    foreach(const IndexedString &file, d->changes.keys())
-    {
+
+    foreach(const IndexedString &file, d->changes.keys()) {
         CodeRepresentation::Ptr repr = createCodeRepresentation(file);
 
-        if(!repr)
+        if(!repr) {
             continue;
-        
-        QList<DocumentChangePointer> sortedChangesList;
+        }
+
+        ChangesList sortedChangesList;
         result = d->removeDuplicates(file, sortedChangesList);
-        if(!result)
+        if (!result) {
             continue;
+        }
 
         QString newText;
-        
+
         result = d->generateNewText(file, sortedChangesList, repr.data(), newText);
-        if(!result)
+        if (!result) {
             continue;
-        
-        InsertArtificialCodeRepresentationPointer code( new \
InsertArtificialCodeRepresentation(IndexedString(file.toUrl().fileName()), newText) \
); +        }
+
+        InsertArtificialCodeRepresentationPointer code(
+            new InsertArtificialCodeRepresentation(IndexedString(file.toUrl().fileName()), \
newText) );  ret.insert(file, code);
     }
-    
+
     return ret;
 }
 
 DocumentChangeSet::ChangeResult DocumentChangeSet::applyAllChanges()
 {
-    for(QHash<IndexedString, IndexedString>::const_iterator it = \
d->documentsRename.constBegin(); it != d->documentsRename.constEnd(); ++it) { +    \
QHash<IndexedString, IndexedString>::const_iterator it = \
d->documentsRename.constBegin(); +    for(; it != d->documentsRename.constEnd(); \
++it) {  KUrl url = it.key().toUrl();
         IProject* p = ICore::self()->projectController()->findProjectForUrl(url);
         if(p) {
@@ -197,10 +222,13 @@ DocumentChangeSet::ChangeResult \
DocumentChangeSet::applyAllChanges()  if(renamed == ProjectBaseItem::RenameOk) {
                     IndexedString idxNewDoc(KUrl(url.upUrl(), it.value().str()));
 
-                    QMap<IndexedString, QList<DocumentChangePointer> \
                >::const_iterator iter = d->changes.constFind(it.key());
-                    if(iter!=d->changes.constEnd()) {
-                        QList<DocumentChangePointer> value = iter.value();
-                        for(QList<DocumentChangePointer>::iterator \
itChange=value.begin(), itEnd=value.end(); itChange!=itEnd; ++itChange) { +           \
ChangesHash::const_iterator iter = d->changes.constFind(it.key()); +                  \
if (iter != d->changes.constEnd()) { +                        // note: cannot use \
const version, want to have a mutable pointer +                        ChangesList \
value = iter.value(); +                        ChangesList::iterator itChange = \
value.begin(); +                        ChangesList::iterator itEnd = value.end();
+                        for(; itChange != itEnd; ++itChange) {
                             (*itChange)->m_document = idxNewDoc;
                         }
                         d->changes[idxNewDoc] = value;
@@ -214,19 +242,19 @@ DocumentChangeSet::ChangeResult \
DocumentChangeSet::applyAllChanges()  
     QMap<IndexedString, CodeRepresentation::Ptr> codeRepresentations;
     QMap<IndexedString, QString> newTexts;
-    QMap<IndexedString, QList<DocumentChangePointer> > filteredSortedChanges;
+    ChangesHash filteredSortedChanges;
     ChangeResult result(true);
-    
-    QList<KDevelop::IndexedString > files(d->changes.keys());
 
-    foreach(const IndexedString &file, files)
-    {
+    QList<IndexedString> files(d->changes.keys());
+
+    foreach(const IndexedString &file, files) {
         CodeRepresentation::Ptr repr = createCodeRepresentation(file);
-        if(!repr)
+        if(!repr) {
             return ChangeResult(QString("Could not create a Representation for \
                %1").arg(file.str()));
-        
+        }
+
         codeRepresentations[file] = repr;
-        
+
         QList<DocumentChangePointer>& \
sortedChangesList(filteredSortedChanges[file]);  {
             result = d->removeDuplicates(file, sortedChangesList);
@@ -240,102 +268,104 @@ DocumentChangeSet::ChangeResult \
DocumentChangeSet::applyAllChanges()  return result;
         }
     }
-    
+
     QMap<IndexedString, QString> oldTexts;
-    
+
     //Apply the changes to the files
-    foreach(const IndexedString &file, files)
-    {
+    foreach(const IndexedString &file, files) {
         oldTexts[file] = codeRepresentations[file]->text();
-        
+
         result = d->replaceOldText(codeRepresentations[file].data(), newTexts[file], \
                filteredSortedChanges[file]);
-        if(!result && d->replacePolicy == StopOnFailedChange)
-        {
-            //Revert all files 
-            foreach(const IndexedString &revertFile, oldTexts.keys())
+        if(!result && d->replacePolicy == StopOnFailedChange) {
+            //Revert all files
+            foreach(const IndexedString &revertFile, oldTexts.keys()) {
                 codeRepresentations[revertFile]->setText(oldTexts[revertFile]);
-            
+            }
+
             return result;
         }
     }
-        
+
     d->updateFiles();
-    
-    if(d->activationPolicy == Activate)
-        foreach(const IndexedString& file, files)
+
+    if(d->activationPolicy == Activate) {
+        foreach(const IndexedString& file, files) {
             ICore::self()->documentController()->openDocument(file.toUrl());
-    
+        }
+    }
+
     return result;
 }
 
-DocumentChangeSet::ChangeResult \
                DocumentChangeSetPrivate::replaceOldText(CodeRepresentation * repr,
-                                                                         const \
                QString & newText,
-                                                                         const \
QList<DocumentChangePointer> & sortedChangesList) +DocumentChangeSet::ChangeResult \
DocumentChangeSetPrivate::replaceOldText(CodeRepresentation* repr, +                  \
const QString& newText, +                                                             \
const ChangesList& sortedChangesList)  {
     DynamicCodeRepresentation* dynamic = \
dynamic_cast<DynamicCodeRepresentation*>(repr);  if(dynamic) {
         dynamic->startEdit();
         //Replay the changes one by one
-        
-        for(int pos = sortedChangesList.size()-1; pos >= 0; --pos)
-        {
+
+        for(int pos = sortedChangesList.size()-1; pos >= 0; --pos) {
             const DocumentChange& change(*sortedChangesList[pos]);
             if(!dynamic->replace(change.m_range.textRange(), change.m_oldText, \
change.m_newText, change.m_ignoreOldText))  {
                 QString warningString = QString("Inconsistent change in %1 at %2:%3 \
                -> %4:%5 = %6(encountered \"%7\") -> \"%8\"")
-                                                \
.arg(change.m_document.str()).arg(change.m_range.start.line).arg(change.m_range.start.column)
                
-                                                \
                .arg(change.m_range.end.line).arg(change.m_range.end.column).arg(change.m_oldText)
                
-                                                \
                .arg(dynamic->rangeText(change.m_range.textRange())).arg(change.m_newText);
                
-
-                if(replacePolicy == DocumentChangeSet::WarnOnFailedChange)
-                {
+                    .arg(change.m_document.str())
+                    .arg(change.m_range.start.line)
+                    .arg(change.m_range.start.column)
+                    .arg(change.m_range.end.line)
+                    .arg(change.m_range.end.column)
+                    .arg(change.m_oldText)
+                    .arg(dynamic->rangeText(change.m_range.textRange()))
+                    .arg(change.m_newText);
+
+                if(replacePolicy == DocumentChangeSet::WarnOnFailedChange) {
                     kWarning() << warningString;
-                }
-                else if(replacePolicy == DocumentChangeSet::StopOnFailedChange)
-                {
+                } else if(replacePolicy == DocumentChangeSet::StopOnFailedChange) {
                     dynamic->endEdit();
                     return DocumentChangeSet::ChangeResult(warningString);
                 }
                 //If set to ignore failed changes just continue with the others
             }
         }
-        
+
         dynamic->endEdit();
         return true;
     }
-    
+
     //For files on disk
-    if (!repr->setText(newText))
-    {
-        QString warningString = QString("Could not replace text in the document: \
                %1").arg(sortedChangesList.begin()->data()->m_document.str());
-        if(replacePolicy == DocumentChangeSet::WarnOnFailedChange)
-        {
+    if (!repr->setText(newText)) {
+        QString warningString = QString("Could not replace text in the document: \
%1") +            .arg(sortedChangesList.begin()->data()->m_document.str());
+        if(replacePolicy == DocumentChangeSet::WarnOnFailedChange) {
             kWarning() << warningString;
         }
-        
+
         return DocumentChangeSet::ChangeResult(warningString);
     }
-    
+
     return true;
 }
 
 DocumentChangeSet::ChangeResult DocumentChangeSetPrivate::generateNewText(const \
                IndexedString & file,
-                                                                          \
QList<DocumentChangePointer> & sortedChanges, +                                       \
                ChangesList& sortedChanges,
                                                                           const \
                CodeRepresentation * repr,
                                                                           QString & \
output)  {
 
     ISourceFormatter* formatter = 0;
-    if(ICore::self())
+    if(ICore::self()) {
         formatter = \
ICore::self()->sourceFormatterController()->formatterForUrl(file.toUrl()); +    }
 
     //Create the actual new modified file
     QStringList textLines = repr->text().split('\n');
 
     KUrl url = file.toUrl();
-    
+
     KMimeType::Ptr mime = KMimeType::findByUrl(url);
-    
+
     for(int pos = sortedChanges.size()-1; pos >= 0; --pos) {
         DocumentChange& change(*sortedChanges[pos]);
         QString encountered;
@@ -348,60 +378,70 @@ DocumentChangeSet::ChangeResult \
DocumentChangeSetPrivate::generateNewText(const  
             QString rightContext = \
QStringList(textLines.mid(change.m_range.end.line)).join("\n").mid(change.m_range.end.column);
  
-            if(formatter && (formatPolicy == DocumentChangeSet::AutoFormatChanges || \
formatPolicy == DocumentChangeSet::AutoFormatChangesKeepIndentation)) +            \
if(formatter && (formatPolicy == DocumentChangeSet::AutoFormatChanges +               \
|| formatPolicy == DocumentChangeSet::AutoFormatChangesKeepIndentation))  {
                 QString oldNewText = change.m_newText;
                 change.m_newText = formatter->formatSource(change.m_newText, url, \
                mime, leftContext, rightContext);
-                
-                if(formatPolicy == \
                DocumentChangeSet::AutoFormatChangesKeepIndentation)
-                {
+
+                if(formatPolicy == \
DocumentChangeSet::AutoFormatChangesKeepIndentation) {  // Reproduce the previous \
indentation  QStringList oldLines = oldNewText.split('\n');
                     QStringList newLines = change.m_newText.split('\n');
-                    
-                    if(oldLines.size() == newLines.size())
-                    {
-                        for(int line = 0; line < newLines.size(); ++line)
-                        {
+
+                    if(oldLines.size() == newLines.size()) {
+                        for(int line = 0; line < newLines.size(); ++line) {
                             // Keep the previous indentation
                             QString oldIndentation;
-                            for(int a = 0; a < oldLines[line].size(); ++a)
-                                if(oldLines[line][a].isSpace())
+                            for (int a = 0; a < oldLines[line].size(); ++a) {
+                                if (oldLines[line][a].isSpace()) {
                                     oldIndentation.append(oldLines[line][a]);
-                                else
+                                } else {
                                     break;
+                                }
+                            }
 
                             int newIndentationLength = 0;
 
-                            for(int a = 0; a < newLines[line].size(); ++a)
-                                if(newLines[line][a].isSpace())
+                            for(int a = 0; a < newLines[line].size(); ++a) {
+                                if(newLines[line][a].isSpace()) {
                                     newIndentationLength = a;
-                                else
+                                } else {
                                     break;
-                            
+                                }
+                            }
+
                             newLines[line].replace(0, newIndentationLength, \
oldIndentation);  }
                         change.m_newText = newLines.join("\n");
-                    }else{
+                    } else {
                         kDebug() << "Cannot keep the indentation because the line \
count has changed" << oldNewText;  }
                 }
             }
-            
-            textLines[change.m_range.start.line].replace(change.m_range.start.column, \
change.m_range.end.column-change.m_range.start.column, change.m_newText); +
+            textLines[change.m_range.start.line].replace(change.m_range.start.column,
 +                                                         \
change.m_range.end.column-change.m_range.start.column, +                              \
change.m_newText);  }else{
-            QString warningString = QString("Inconsistent change in %1 at %2:%3 -> \
                %4:%5 = \"%6\"(encountered \"%7\") -> \"%8\"")
-                                            \
                .arg(file.str()).arg(change.m_range.start.line).arg(change.m_range.start.column)
                
-                                            \
                .arg(change.m_range.end.line).arg(change.m_range.end.column).arg(change.m_oldText)
                
-                                            .arg(encountered).arg(change.m_newText);
-            
+            QString warningString = QString("Inconsistent change in %1 at %2:%3 -> \
%4:%5" +                                            " = \"%6\"(encountered \"%7\") -> \
\"%8\"") +                                            .arg(file.str())
+                                            .arg(change.m_range.start.line)
+                                            .arg(change.m_range.start.column)
+                                            .arg(change.m_range.end.line)
+                                            .arg(change.m_range.end.column)
+                                            .arg(change.m_oldText)
+                                            .arg(encountered)
+                                            .arg(change.m_newText);
+
             if(replacePolicy == DocumentChangeSet::IgnoreFailedChange) {
                 //Just don't do the replacement
-            }else if(replacePolicy == DocumentChangeSet::WarnOnFailedChange)
+            } else if(replacePolicy == DocumentChangeSet::WarnOnFailedChange) {
                 kWarning() << warningString;
-            else
+            } else {
                 return DocumentChangeSet::ChangeResult(warningString, \
                sortedChanges[pos]);
-                
+            }
         }
     }
 
@@ -410,17 +450,19 @@ DocumentChangeSet::ChangeResult \
DocumentChangeSetPrivate::generateNewText(const  }
 
 //Removes all duplicate changes for a single file, and then returns (via \
                filteredChanges) the filtered duplicates
-DocumentChangeSet::ChangeResult DocumentChangeSetPrivate::removeDuplicates(const \
                IndexedString & file,
-                                                                           \
QList<DocumentChangePointer> & filteredChanges) +DocumentChangeSet::ChangeResult \
DocumentChangeSetPrivate::removeDuplicates(const IndexedString& file, +               \
ChangesList& filteredChanges)  {
-    QMultiMap<SimpleCursor, DocumentChangePointer> sortedChanges;
-    
-    foreach(const DocumentChangePointer &change, changes[file])
+    typedef QMultiMap<SimpleCursor, DocumentChangePointer> ChangesMap;
+    ChangesMap sortedChanges;
+
+    foreach(const DocumentChangePointer &change, changes[file]) {
         sortedChanges.insert(change->m_range.end, change);
-    
+    }
+
     //Remove duplicates
-    QMultiMap<SimpleCursor, DocumentChangePointer>::iterator previous = \
                sortedChanges.begin();
-    for(QMultiMap<SimpleCursor, DocumentChangePointer>::iterator it = \
++sortedChanges.begin(); it != sortedChanges.end(); ) { +    ChangesMap::iterator \
previous = sortedChanges.begin(); +    for(ChangesMap::iterator it = \
                ++sortedChanges.begin(); it != sortedChanges.end(); ) {
         if(( *previous ) && ( *previous )->m_range.end > (*it)->m_range.start) {
             //intersection
             if(duplicateChanges(( *previous ), *it)) {
@@ -428,35 +470,43 @@ DocumentChangeSet::ChangeResult \
DocumentChangeSetPrivate::removeDuplicates(const  it = sortedChanges.erase(it);
                 continue;
             }
-            
+
             //When two changes contain each other, and the container change is set \
                to ignore old text, then it should be safe to
             //just ignore the contained change, and apply the bigger change
-            else if((*it)->m_range.contains(( *previous )->m_range) && \
                (*it)->m_ignoreOldText  )
-            {
+            else if((*it)->m_range.contains(( *previous )->m_range) && \
                (*it)->m_ignoreOldText  ) {
                 kDebug() << "Removing change: " << ( *previous )->m_oldText << "->" \
                << ( *previous )->m_newText
                          << ", because it is contained by change: " << \
(*it)->m_oldText << "->" << (*it)->m_newText;  sortedChanges.erase(previous);
             }
             //This case is for when both have the same end, either of them could be \
                the containing range
-            else if((*previous)->m_range.contains((*it)->m_range) && \
                (*previous)->m_ignoreOldText  )
-            {
+            else if((*previous)->m_range.contains((*it)->m_range) && \
                (*previous)->m_ignoreOldText  ) {
                 kDebug() << "Removing change: " << (*it)->m_oldText << "->" << \
                (*it)->m_newText
-                         << ", because it is contained by change: " << ( *previous \
)->m_oldText << "->" << ( *previous )->m_newText; +                         << ", \
because it is contained by change: " << ( *previous )->m_oldText +                    \
<< "->" << ( *previous )->m_newText;  it = sortedChanges.erase(it);
                 continue;
-            }
-            else
+            } else {
                 return DocumentChangeSet::ChangeResult(
-                       QString("Inconsistent change-request at %1; intersecting \
                changes: \"%2\"->\"%3\"@%4:%5->%6:%7 & \
                \"%8\"->\"%9\"@%10:%11->%12:%13 ")
-                       .arg(file.str(), ( *previous )->m_oldText, ( *previous \
)->m_newText).arg(( *previous )->m_range.start.line).arg(( *previous \
                )->m_range.start.column)
-                       .arg(( *previous )->m_range.end.line).arg(( *previous \
)->m_range.end.column).arg((*it)->m_oldText, \
                (*it)->m_newText).arg((*it)->m_range.start.line)
-                       \
.arg((*it)->m_range.start.column).arg((*it)->m_range.end.line).arg((*it)->m_range.end.column));
                
-            
+                       QString("Inconsistent change-request at %1; "
+                               "intersecting changes: "
+                               "\"%2\"->\"%3\"@%4:%5->%6:%7 & \
\"%8\"->\"%9\"@%10:%11->%12:%13 ") +                        .arg(file.str(), ( \
*previous )->m_oldText, ( *previous )->m_newText) +                        .arg(( \
*previous )->m_range.start.line) +                        .arg(( *previous \
)->m_range.start.column) +                        .arg(( *previous \
)->m_range.end.line) +                        .arg(( *previous )->m_range.end.column)
+                        .arg((*it)->m_oldText, (*it)->m_newText)
+                        .arg((*it)->m_range.start.line)
+                        .arg((*it)->m_range.start.column)
+                        .arg((*it)->m_range.end.line)
+                        .arg((*it)->m_range.end.column));
+            }
+
         }
         previous = it;
         ++it;
     }
-    
+
     filteredChanges = sortedChanges.values();
     return true;
 }
@@ -464,9 +514,10 @@ DocumentChangeSet::ChangeResult \
DocumentChangeSetPrivate::removeDuplicates(const  void \
DocumentChangeSetPrivate::updateFiles()  {
     ModificationRevisionSet::clearCache();
-    foreach(const IndexedString& file, changes.keys())
+    foreach(const IndexedString& file, changes.keys()) {
         ModificationRevision::clearModificationCache(file);
-    
+    }
+
     if(updatePolicy != DocumentChangeSet::NoUpdate && ICore::self())
     {
         // The active document should be updated first, so that the user sees the \
results instantly @@ -485,8 +536,7 @@ void DocumentChangeSetPrivate::updateFiles()
         }
 
         // Eventually update _all_ affected files
-        foreach(const IndexedString &file, changes.keys())
-        {
+        foreach(const IndexedString &file, changes.keys()) {
             if(!file.toUrl().isValid()) {
                 kWarning() << "Trying to apply changes to an invalid document";
                 continue;
diff --git a/language/codegen/documentchangeset.h \
b/language/codegen/documentchangeset.h index 41b12d0..bdc8121 100644
--- a/language/codegen/documentchangeset.h
+++ b/language/codegen/documentchangeset.h
@@ -21,12 +21,14 @@
 
 #include <language/editor/simplerange.h>
 #include <language/duchain/indexedstring.h>
-#include <ksharedptr.h>
-#include <KDE/KUrl>
+
+#include <KSharedPtr>
+#include <KUrl>
+
 #include "coderepresentation.h"
 
 namespace KDevelop {
-    
+
 struct DocumentChangeSetPrivate;
 
 class KDEVPLATFORMLANGUAGE_EXPORT DocumentChange : public QSharedData
@@ -40,7 +42,7 @@ public:
         url.cleanPath();
         m_document = IndexedString(url);
     }
-    
+
     IndexedString m_document;
     SimpleRange m_range;
     QString m_oldText;
@@ -53,40 +55,46 @@ typedef KSharedPtr<DocumentChange> DocumentChangePointer;
 /**
  * Object representing an arbitrary set of changes to an arbitrary set of files that \
                can be applied atomically.
  */
-class KDEVPLATFORMLANGUAGE_EXPORT DocumentChangeSet {
-  public:
-    
+class KDEVPLATFORMLANGUAGE_EXPORT DocumentChangeSet
+{
+public:
     DocumentChangeSet();
     ~DocumentChangeSet();
-    DocumentChangeSet(const DocumentChangeSet & rhs);
+    DocumentChangeSet(const DocumentChangeSet& rhs);
     DocumentChangeSet& operator=(const DocumentChangeSet& rhs);
-    
+
     //Returns true on success
-    struct ChangeResult {
-        ChangeResult(bool success) : m_success(success) {
-        }
-        ChangeResult(QString failureReason, DocumentChangePointer reasonChange = \
DocumentChangePointer()) : m_failureReason(failureReason), \
                m_reasonChange(reasonChange), m_success(false) {
-        }
-        
-        operator bool() const {
+    struct ChangeResult
+    {
+        ChangeResult(bool success)
+        : m_success(success)
+        { }
+        ChangeResult(const QString& failureReason, const DocumentChangePointer& \
reasonChange = DocumentChangePointer()) +        : m_failureReason(failureReason)
+        , m_reasonChange(reasonChange)
+        , m_success(false)
+        { }
+
+        operator bool() const
+        {
             return m_success;
         }
-        
+
         /// Reason why the change failed
         QString m_failureReason;
         /// Specific change that caused the problem (might be 0)
         DocumentChangePointer m_reasonChange;
-        
+
         bool m_success;
     };
-    
+
     /// Add an individual local change to this change-set.
     ///@note Multi-line changes are not (yet) supported.
     ChangeResult addChange(const DocumentChange& change);
-    ChangeResult addChange(DocumentChangePointer change);
-    
+    ChangeResult addChange(const DocumentChangePointer& change);
+
     ///given a file @old, rename it to the @newname
-    ChangeResult addDocumentRenameChange(const KDevelop::IndexedString& oldFile, \
const KDevelop::IndexedString& newname); +    ChangeResult \
addDocumentRenameChange(const IndexedString& oldFile, const IndexedString& newname);  \
  enum ReplacementPolicy {
         IgnoreFailedChange,///If this is given, all changes that could not be \
applied are simply ignored @@ -94,44 +102,44 @@ class KDEVPLATFORMLANGUAGE_EXPORT \
                DocumentChangeSet {
                             ///but following changes are applied, and success is \
                returned.
         StopOnFailedChange ///If this is given to applyAllChanges, then all \
replacements are reverted and an error returned on problems (default)  };
-    
+
     ///@param policy What should be done when a change could not be applied?
     void setReplacementPolicy(ReplacementPolicy policy);
-    
+
     enum FormatPolicy {
         NoAutoFormat, ///If this option is given, no automatic formatting is applied
         AutoFormatChanges,      ///If this option is given, all changes are \
                automatically reformatted using the formatter plugin for the mime \
                type (default)
         AutoFormatChangesKeepIndentation      ///Same as AutoFormatChanges, except \
that the indentation of inserted lines is kept equal  };
-    
+
     ///@param policy How the changed text should be formatted. The default is \
AutoFormatChanges.  void setFormatPolicy(FormatPolicy policy);
-    
+
     enum DUChainUpdateHandling {
         NoUpdate,       ///No updates will be scheduled
         SimpleUpdate ///The changed documents will be added to the background \
parser, plus all documents that are currently open and recursively import those \
                documents (default)
         //FullUpdate       ///All documents in all open projects that recursively \
import any of the changed documents will be updated  };
-    
+
     ///@param policy Whether a duchain update should be triggered for all affected \
documents  void setUpdateHandling(DUChainUpdateHandling policy);
-    
+
     enum ActivationPolicy {
         Activate,           ///The affected files will be activated
         DoNotActivate  ///The affected files will not be activated (default)
     };
-    
+
     ///@param policy Whether the affected documents should be activated when the \
change is applied  void setActivationPolicy(ActivationPolicy policy);
-    
+
     ///Applies all changes to temporary code representations, and returns a map from \
each file-name to  ///the respective inserted artificial code-representation.
-    QMap<IndexedString, InsertArtificialCodeRepresentationPointer> \
                temporaryCodeRepresentations() const;
-    
+    QHash<IndexedString, InsertArtificialCodeRepresentationPointer> \
temporaryCodeRepresentations() const; +
     /// Apply all the changes registered in this changeset to the actual files
     ChangeResult applyAllChanges();
-    
-  private:
+
+private:
     DocumentChangeSetPrivate * d;
 };
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic