Improved the C++ hover handler.

Done with: bjorn
This commit is contained in:
Roberto Raggi
2009-02-16 17:55:05 +01:00
parent 01145fd552
commit fa216de41c
4 changed files with 164 additions and 48 deletions

View File

@@ -42,7 +42,8 @@ Overview::Overview()
: _markArgument(0),
_showArgumentNames(false),
_showReturnTypes(false),
_showFunctionSignatures(true)
_showFunctionSignatures(true),
_showFullyQualifiedNames(false)
{ }
Overview::~Overview()
@@ -88,6 +89,16 @@ void Overview::setShowFunctionSignatures(bool showFunctionSignatures)
_showFunctionSignatures = showFunctionSignatures;
}
bool Overview::showFullyQualifiedNames() const
{
return _showFullyQualifiedNames;
}
void Overview::setShowFullyQualifiedNamed(bool showFullyQualifiedNames)
{
_showFullyQualifiedNames = showFullyQualifiedNames;
}
QString Overview::prettyName(Name *name) const
{
NamePrettyPrinter pp(this);

View File

@@ -57,6 +57,9 @@ public:
bool showFunctionSignatures() const;
void setShowFunctionSignatures(bool showFunctionSignatures);
bool showFullyQualifiedNames() const;
void setShowFullyQualifiedNamed(bool showFullyQualifiedNames);
// 1-based
// ### rename
unsigned markArgument() const;
@@ -77,6 +80,7 @@ private:
bool _showArgumentNames: 1;
bool _showReturnTypes: 1;
bool _showFunctionSignatures: 1;
bool _showFullyQualifiedNames: 1;
};
} // end of namespace CPlusPlus

View File

@@ -37,9 +37,41 @@
#include <CoreTypes.h>
#include <Symbols.h>
#include <Scope.h>
#include <QStringList>
#include <QtDebug>
using namespace CPlusPlus;
static QString fullyQualifiedName(Symbol *symbol, const Overview *overview)
{
QStringList nestedNameSpecifier;
for (Scope *scope = symbol->scope(); scope && scope->enclosingScope();
scope = scope->enclosingScope())
{
Symbol *owner = scope->owner();
if (! owner) {
qWarning() << "invalid scope."; // ### better message.
continue;
}
if (! owner->name())
nestedNameSpecifier.prepend(QLatin1String("<anonymous>"));
else {
const QString name = overview->prettyName(owner->name());
nestedNameSpecifier.prepend(name);
}
}
nestedNameSpecifier.append(overview->prettyName(symbol->name()));
return nestedNameSpecifier.join(QLatin1String("::"));
}
TypePrettyPrinter::TypePrettyPrinter(const Overview *overview)
: _overview(overview),
_name(0)
@@ -150,16 +182,26 @@ void TypePrettyPrinter::visit(Namespace *type)
applyPtrOperators();
}
void TypePrettyPrinter::visit(Class *type)
void TypePrettyPrinter::visit(Class *classTy)
{
_text += overview()->prettyName(type->name());
if (overview()->showFullyQualifiedNames())
_text += fullyQualifiedName(classTy, overview());
else
_text += overview()->prettyName(classTy->name());
applyPtrOperators();
}
void TypePrettyPrinter::visit(Enum *type)
{
_text += overview()->prettyName(type->name());
if (overview()->showFullyQualifiedNames())
_text += fullyQualifiedName(type, overview());
else
_text += overview()->prettyName(type->name());
applyPtrOperators();
}
@@ -259,11 +301,14 @@ void TypePrettyPrinter::visit(Function *type)
if (! _ptrOperators.isEmpty()) {
out(QLatin1Char('('));
applyPtrOperators(false);
if (! _name.isEmpty()) {
_text += _name;
_name.clear();
}
out(QLatin1Char(')'));
} else if (! _name.isEmpty() && _overview->showFunctionSignatures()) {
space();
out(_name);