Commit 0daf22c7 authored by Christian Kamm's avatar Christian Kamm

Quickfix: Add a typeOf helper to conveniently get the type of an expr.

Reviewed-by: Erik Verbruggen
parent 77b59b02
......@@ -841,7 +841,10 @@ Snapshot QuickFixOperation::snapshot() const
{ return _snapshot; }
void QuickFixOperation::setSnapshot(const CPlusPlus::Snapshot &snapshot)
{ _snapshot = snapshot; }
{
_snapshot = snapshot;
_typeOfExpression.setSnapshot(snapshot);
}
CPPEditor *QuickFixOperation::editor() const
{ return _editor; }
......@@ -1032,7 +1035,7 @@ QString QuickFixOperation::textOf(int firstOffset, int lastOffset) const
return tc.selectedText();
}
QString QuickFixOperation::textOf(AST *ast) const
QString QuickFixOperation::textOf(const AST *ast) const
{
return textOf(startOf(ast), endOf(ast));
}
......@@ -1054,6 +1057,22 @@ void QuickFixOperation::apply()
_textCursor.endEditBlock();
}
/**
* Returns a list of possible fully specified types associated with the
* given expression.
*
* NOTE: The fully specified types only stay valid until the next call to typeOf.
*/
const QList<LookupItem> QuickFixOperation::typeOf(const CPlusPlus::ExpressionAST *ast)
{
unsigned line, column;
document()->translationUnit()->getTokenStartPosition(ast->firstToken(), &line, &column);
Symbol *lastVisibleSymbol = document()->findSymbolAt(line, column);
return _typeOfExpression(textOf(ast), document(), lastVisibleSymbol,
TypeOfExpression::Preprocess);
}
CPPQuickFixCollector::CPPQuickFixCollector()
: _modelManager(CppTools::CppModelManagerInterface::instance()), _editor(0)
{ }
......
......@@ -33,6 +33,7 @@
#include <texteditor/icompletioncollector.h>
#include <cplusplus/CppDocument.h>
#include <cplusplus/TypeOfExpression.h>
#include <ASTfwd.h>
#include <utils/changeset.h>
......@@ -114,7 +115,7 @@ protected:
void copy(const CPlusPlus::AST *ast, int to);
QString textOf(int firstOffset, int lastOffset) const;
QString textOf(CPlusPlus::AST *ast) const;
QString textOf(const CPlusPlus::AST *ast) const;
struct Range {
Range() {}
......@@ -127,6 +128,8 @@ protected:
Range createRange(CPlusPlus::AST *ast) const; // ### rename me
void reindent(const Range &range);
const QList<CPlusPlus::LookupItem> typeOf(const CPlusPlus::ExpressionAST *ast);
private:
CPlusPlus::Document::Ptr _document;
CPlusPlus::Snapshot _snapshot;
......@@ -134,6 +137,7 @@ private:
Utils::ChangeSet _changeSet;
CPPEditor *_editor;
CPlusPlus::AST *_topLevelNode;
CPlusPlus::TypeOfExpression _typeOfExpression;
};
class CPPQuickFixCollector: public TextEditor::IQuickFixCollector
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment