diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index a7b29555c7464a464c48b3b2ae11958e5e12bacc..5295a0135076fb6a156bebe9bcf5a5fc44cda844 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -501,111 +501,6 @@ protected: } }; -class SimplifyDeclarations: protected ASTVisitor -{ - CPPEditor *_editor; - Document::Ptr _doc; - QByteArray _source; - QTextCursor _textCursor; - unsigned _line; - unsigned _column; - -public: - SimplifyDeclarations(CPPEditor *ed, Document::Ptr doc) - : ASTVisitor(doc->control()), _editor(ed), - _doc(doc), _source(doc->source()) - { } - - void operator()(QTextCursor tc) - { - _textCursor = tc; - - _line = _textCursor.blockNumber() + 1; - _column = _textCursor.columnNumber() + 1; - - accept(_doc->translationUnit()->ast()); - } - -protected: - QByteArray text(unsigned firstToken, unsigned lastToken) const - { - const unsigned begin = tokenAt(firstToken).begin(); - const unsigned end = tokenAt(lastToken - 1).end(); - return _source.mid(begin, end - begin); - } - - virtual bool visit(SimpleDeclarationAST *ast) - { - if (! ast->decl_specifier_seq) { - // e.g a ctor/dtor or a cast-function-id. - return true; - } if (! ast->declarators) { - // e.g. - // struct foo { int a; }; - return true; - } else if (! ast->declarators->next) { - // e.g. - // int a; - return true; - } - - unsigned startLine, startColumn; - unsigned endLine, endColumn; - - getTokenStartPosition(ast->firstToken(), &startLine, &startColumn); - getTokenEndPosition(ast->lastToken() - 1, &endLine, &endColumn); - - if (_line < startLine || (_line == startLine && _column < startColumn)) - return true; - else if (_line > endLine || (_line == endLine && _column >= endColumn)) - return true; - - unsigned beginOfDeclSpecifiers = ast->decl_specifier_seq->firstToken(); - unsigned endOfDeclSpecifiers = 0; - - for (SpecifierAST *spec = ast->decl_specifier_seq; spec; spec = spec->next) { - if (spec->asClassSpecifier() != 0) { - // e.g. - // struct foo { int a; } x, y, z; - return true; - } else if (! spec->next) - endOfDeclSpecifiers = spec->lastToken(); - } - - const QByteArray declSpecifiers = - text(beginOfDeclSpecifiers, endOfDeclSpecifiers); - - QByteArray code; - for (DeclaratorListAST *it = ast->declarators; it; it = it->next) { - DeclaratorAST *decl = it->declarator; - - const QByteArray declaratorText = text(decl->firstToken(), decl->lastToken()); - code += declSpecifiers; - code += ' '; - code += declaratorText; - code += ';'; - code += '\n'; - } - - const QString refactoredCode = QString::fromUtf8(code); - - QTextCursor tc = _textCursor; - tc.beginEditBlock(); - tc.setPosition(tc.document()->findBlockByNumber(startLine - 1).position() + startColumn - 1); - int startPos = tc.position(); - tc.setPosition(tc.document()->findBlockByNumber(endLine - 1).position() + endColumn - 1, - QTextCursor::KeepAnchor); - tc.removeSelectedText(); - tc.insertText(refactoredCode); - tc.setPosition(startPos); - tc.setPosition(tc.position() + refactoredCode.length(), QTextCursor::KeepAnchor); - _editor->indentInsertedText(tc); - tc.endEditBlock(); - - return true; - } -}; - } // end of anonymous namespace static QualifiedNameId *qualifiedNameIdForSymbol(Symbol *s, const LookupContext &context) @@ -899,19 +794,6 @@ void CPPEditor::reformatDocument() c.insertText(QString::fromUtf8(str.c_str(), str.length())); } -void CPPEditor::simplifyDeclarations() -{ - Snapshot snapshot = m_modelManager->snapshot(); - const QByteArray plainText = toPlainText().toUtf8(); - const QString fileName = file()->fileName(); - const QByteArray preprocessedCode = snapshot.preprocessedCode(plainText, fileName); - Document::Ptr doc = snapshot.documentFromSource(preprocessedCode, fileName); - doc->check(); - - SimplifyDeclarations simplify(this, doc); - simplify(textCursor()); -} - void CPPEditor::renameInPlace() { updateUsesNow(); diff --git a/src/plugins/cppeditor/cppeditor.h b/src/plugins/cppeditor/cppeditor.h index 7bafa1db61a5e662962d67d6d2963a7dbe458de1..35d7b1a5ead13fef4bf37ede73a2a33734a0e25b 100644 --- a/src/plugins/cppeditor/cppeditor.h +++ b/src/plugins/cppeditor/cppeditor.h @@ -126,7 +126,6 @@ private slots: void updateUsesNow(); void onDocumentUpdated(CPlusPlus::Document::Ptr doc); void reformatDocument(); - void simplifyDeclarations(); void renameInPlace(); void onContentsChanged(int position, int charsRemoved, int charsAdded);