Cpp: No need for accessors for simple structs

Change-Id: Ie09c1fc59dd54d2302a78cfc9769d5cda6012be7
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
hjk
2012-10-10 22:09:44 +02:00
parent 52e381b8e8
commit 6dfe3207d2
7 changed files with 57 additions and 166 deletions

View File

@@ -38,99 +38,16 @@
using namespace CPlusPlus; using namespace CPlusPlus;
Overview::Overview() Overview::Overview()
: _markedArgument(0), : markedArgument(0),
_markedArgumentBegin(0), markedArgumentBegin(0),
_markedArgumentEnd(0), markedArgumentEnd(0),
_showArgumentNames(false), showArgumentNames(false),
_showReturnTypes(false), showReturnTypes(false),
_showFunctionSignatures(true), showFunctionSignatures(true),
_showDefaultArguments(true), showDefaultArguments(true),
_showTemplateParameters(false) showTemplateParameters(false)
{ } { }
Overview::~Overview()
{ }
bool Overview::showArgumentNames() const
{
return _showArgumentNames;
}
void Overview::setShowArgumentNames(bool showArgumentNames)
{
_showArgumentNames = showArgumentNames;
}
void Overview::setShowReturnTypes(bool showReturnTypes)
{
_showReturnTypes = showReturnTypes;
}
bool Overview::showReturnTypes() const
{
return _showReturnTypes;
}
unsigned Overview::markedArgument() const
{
return _markedArgument;
}
void Overview::setMarkedArgument(unsigned position)
{
_markedArgument = position;
}
int Overview::markedArgumentBegin() const
{
return _markedArgumentBegin;
}
void Overview::setMarkedArgumentBegin(int begin)
{
_markedArgumentBegin = begin;
}
int Overview::markedArgumentEnd() const
{
return _markedArgumentEnd;
}
void Overview::setMarkedArgumentEnd(int end)
{
_markedArgumentEnd = end;
}
bool Overview::showFunctionSignatures() const
{
return _showFunctionSignatures;
}
void Overview::setShowFunctionSignatures(bool showFunctionSignatures)
{
_showFunctionSignatures = showFunctionSignatures;
}
bool Overview::showDefaultArguments() const
{
return _showDefaultArguments;
}
void Overview::setShowDefaultArguments(bool showDefaultArguments)
{
_showDefaultArguments = showDefaultArguments;
}
bool Overview::showTemplateParameters() const
{
return _showTemplateParameters;
}
void Overview::setShowTemplateParameters(bool showTemplateParameters)
{
_showTemplateParameters = showTemplateParameters;
}
QString Overview::prettyName(const Name *name) const QString Overview::prettyName(const Name *name) const
{ {
NamePrettyPrinter pp(this); NamePrettyPrinter pp(this);

View File

@@ -44,32 +44,6 @@ class CPLUSPLUS_EXPORT Overview
public: public:
Overview(); Overview();
~Overview();
bool showArgumentNames() const;
void setShowArgumentNames(bool showArgumentNames);
bool showReturnTypes() const;
void setShowReturnTypes(bool showReturnTypes);
bool showFunctionSignatures() const;
void setShowFunctionSignatures(bool showFunctionSignatures);
bool showDefaultArguments() const;
void setShowDefaultArguments(bool showDefaultArguments);
bool showTemplateParameters() const;
void setShowTemplateParameters(bool showTemplateParameters);
// argument index that you want to mark
unsigned markedArgument() const;
void setMarkedArgument(unsigned position);
int markedArgumentBegin() const;
void setMarkedArgumentBegin(int begin);
int markedArgumentEnd() const;
void setMarkedArgumentEnd(int end);
QString operator()(const Name *name) const QString operator()(const Name *name) const
{ return prettyName(name); } { return prettyName(name); }
@@ -85,15 +59,15 @@ public:
QString prettyType(const FullySpecifiedType &type, const Name *name = 0) const; QString prettyType(const FullySpecifiedType &type, const Name *name = 0) const;
QString prettyType(const FullySpecifiedType &type, const QString &name) const; QString prettyType(const FullySpecifiedType &type, const QString &name) const;
private: public:
unsigned _markedArgument; unsigned markedArgument;
int _markedArgumentBegin; int markedArgumentBegin;
int _markedArgumentEnd; int markedArgumentEnd;
bool _showArgumentNames: 1; bool showArgumentNames: 1;
bool _showReturnTypes: 1; bool showReturnTypes: 1;
bool _showFunctionSignatures: 1; bool showFunctionSignatures: 1;
bool _showDefaultArguments: 1; bool showDefaultArguments: 1;
bool _showTemplateParameters: 1; bool showTemplateParameters: 1;
}; };
} // namespace CPlusPlus } // namespace CPlusPlus

View File

@@ -143,7 +143,7 @@ void TypePrettyPrinter::visit(Namespace *type)
void TypePrettyPrinter::visit(Template *type) void TypePrettyPrinter::visit(Template *type)
{ {
if (Symbol *d = type->declaration()) { if (Symbol *d = type->declaration()) {
if (overview()->showTemplateParameters() && ! _name.isEmpty()) { if (overview()->showTemplateParameters && ! _name.isEmpty()) {
_name += QLatin1Char('<'); _name += QLatin1Char('<');
for (unsigned index = 0; index < type->templateParameterCount(); ++index) { for (unsigned index = 0; index < type->templateParameterCount(); ++index) {
if (index) if (index)
@@ -309,13 +309,13 @@ void TypePrettyPrinter::visit(Function *type)
} }
_text.append(QLatin1Char(')')); _text.append(QLatin1Char(')'));
_needsParens = false; _needsParens = false;
} else if (! _name.isEmpty() && _overview->showFunctionSignatures()) { } else if (! _name.isEmpty() && _overview->showFunctionSignatures) {
appendSpace(); appendSpace();
_text.append(_name); _text.append(_name);
_name.clear(); _name.clear();
} }
if (_overview->showReturnTypes()) { if (_overview->showReturnTypes) {
const QString returnType = _overview->prettyType(type->returnType()); const QString returnType = _overview->prettyType(type->returnType());
if (!returnType.isEmpty()) { if (!returnType.isEmpty()) {
if (!endsWithPtrOrRef(returnType)) if (!endsWithPtrOrRef(returnType))
@@ -324,11 +324,11 @@ void TypePrettyPrinter::visit(Function *type)
} }
} }
if (_overview->showFunctionSignatures()) { if (_overview->showFunctionSignatures) {
Overview argumentText; Overview argumentText;
argumentText.setShowReturnTypes(true); argumentText.showReturnTypes = true;
argumentText.setShowArgumentNames(false); argumentText.showArgumentNames = false;
argumentText.setShowFunctionSignatures(true); argumentText.showFunctionSignatures = true;
_text += QLatin1Char('('); _text += QLatin1Char('(');
@@ -337,25 +337,25 @@ void TypePrettyPrinter::visit(Function *type)
_text += QLatin1String(", "); _text += QLatin1String(", ");
if (Argument *arg = type->argumentAt(index)->asArgument()) { if (Argument *arg = type->argumentAt(index)->asArgument()) {
if (index + 1 == _overview->markedArgument()) if (index + 1 == _overview->markedArgument)
const_cast<Overview*>(_overview)->setMarkedArgumentBegin(_text.length()); const_cast<Overview*>(_overview)->markedArgumentBegin = _text.length();
const Name *name = 0; const Name *name = 0;
if (_overview->showArgumentNames()) if (_overview->showArgumentNames)
name = arg->name(); name = arg->name();
_text += argumentText(arg->type(), name); _text += argumentText(arg->type(), name);
if (_overview->showDefaultArguments()) { if (_overview->showDefaultArguments) {
if (const StringLiteral *initializer = arg->initializer()) { if (const StringLiteral *initializer = arg->initializer()) {
_text += QLatin1String(" ="); _text += QLatin1String(" =");
_text += QString::fromUtf8(initializer->chars(), initializer->size()); _text += QString::fromUtf8(initializer->chars(), initializer->size());
} }
} }
if (index + 1 == _overview->markedArgument()) if (index + 1 == _overview->markedArgument)
const_cast<Overview*>(_overview)->setMarkedArgumentEnd(_text.length()); const_cast<Overview*>(_overview)->markedArgumentEnd = _text.length();
} }
} }

View File

@@ -334,8 +334,8 @@ CppDeclarableElement::CppDeclarableElement(Symbol *declaration) : CppElement()
m_icon = Icons().iconForSymbol(declaration); m_icon = Icons().iconForSymbol(declaration);
Overview overview; Overview overview;
overview.setShowArgumentNames(true); overview.showArgumentNames = true;
overview.setShowReturnTypes(true); overview.showReturnTypes = true;
m_name = overview.prettyName(declaration->name()); m_name = overview.prettyName(declaration->name());
if (declaration->enclosingScope()->isClass() || if (declaration->enclosingScope()->isClass() ||
declaration->enclosingScope()->isNamespace() || declaration->enclosingScope()->isNamespace() ||
@@ -469,10 +469,10 @@ CppFunction::CppFunction(Symbol *declaration) : CppDeclarableElement(declaration
// Functions marks can be found either by the main overload or signature based // Functions marks can be found either by the main overload or signature based
// (with no argument names and no return). Help ids have no signature at all. // (with no argument names and no return). Help ids have no signature at all.
Overview overview; Overview overview;
overview.setShowDefaultArguments(false); overview.showDefaultArguments = false;
setHelpMark(overview.prettyType(type, name())); setHelpMark(overview.prettyType(type, name()));
overview.setShowFunctionSignatures(false); overview.showFunctionSignatures = false;
addHelpIdCandidate(overview.prettyName(declaration->name())); addHelpIdCandidate(overview.prettyName(declaration->name()));
} }

View File

@@ -596,10 +596,10 @@ Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targ
return changes; return changes;
Overview overview; Overview overview;
overview.setShowReturnTypes(true); overview.showReturnTypes = true;
overview.setShowTemplateParameters(true); overview.showTemplateParameters = true;
overview.setShowArgumentNames(true); overview.showArgumentNames = true;
overview.setShowFunctionSignatures(true); overview.showFunctionSignatures = true;
// abort if the name of the newly parsed function is not the expected one // abort if the name of the newly parsed function is not the expected one
DeclaratorIdAST *newDeclId = getDeclaratorId(newDef->declarator); DeclaratorIdAST *newDeclId = getDeclaratorId(newDef->declarator);

View File

@@ -207,9 +207,9 @@ QList<CppQuickFixOperation::Ptr> DeclFromDef::match(
QString InsertDeclOperation::generateDeclaration(Function *function) QString InsertDeclOperation::generateDeclaration(Function *function)
{ {
Overview oo; Overview oo;
oo.setShowFunctionSignatures(true); oo.showFunctionSignatures = true;
oo.setShowReturnTypes(true); oo.showReturnTypes = true;
oo.setShowArgumentNames(true); oo.showArgumentNames = true;
QString decl; QString decl;
decl += oo(function->type(), function->unqualifiedName()); decl += oo(function->type(), function->unqualifiedName());
@@ -247,9 +247,9 @@ public:
CppRefactoringFilePtr targetFile = refactoring.file(m_loc.fileName()); CppRefactoringFilePtr targetFile = refactoring.file(m_loc.fileName());
Overview oo; Overview oo;
oo.setShowFunctionSignatures(true); oo.showFunctionSignatures = true;
oo.setShowReturnTypes(true); oo.showReturnTypes = true;
oo.setShowArgumentNames(true); oo.showArgumentNames = true;
// make target lookup context // make target lookup context
Document::Ptr targetDoc = targetFile->cppDocument(); Document::Ptr targetDoc = targetFile->cppDocument();

View File

@@ -401,14 +401,14 @@ private:
QString CppFunctionHintModel::text(int index) const QString CppFunctionHintModel::text(int index) const
{ {
Overview overview; Overview overview;
overview.setShowReturnTypes(true); overview.showReturnTypes = true;
overview.setShowArgumentNames(true); overview.showArgumentNames = true;
overview.setMarkedArgument(m_currentArg + 1); overview.markedArgument = m_currentArg + 1;
Function *f = m_functionSymbols.at(index); Function *f = m_functionSymbols.at(index);
const QString prettyMethod = overview(f->type(), f->name()); const QString prettyMethod = overview.prettyType(f->type(), f->name());
const int begin = overview.markedArgumentBegin(); const int begin = overview.markedArgumentBegin;
const int end = overview.markedArgumentEnd(); const int end = overview.markedArgumentEnd;
QString hintText; QString hintText;
hintText += Qt::escape(prettyMethod.left(begin)); hintText += Qt::escape(prettyMethod.left(begin));
@@ -536,8 +536,8 @@ public:
: _item(0) : _item(0)
, _symbol(0) , _symbol(0)
{ {
overview.setShowReturnTypes(true); overview.showReturnTypes = true;
overview.setShowArgumentNames(true); overview.showArgumentNames = true;
} }
BasicProposalItem *operator()(Symbol *symbol) BasicProposalItem *operator()(Symbol *symbol)
@@ -1574,9 +1574,9 @@ bool CppCompletionAssistProcessor::completeQtMethod(const QList<CPlusPlus::Looku
ConvertToCompletionItem toCompletionItem; ConvertToCompletionItem toCompletionItem;
Overview o; Overview o;
o.setShowReturnTypes(false); o.showReturnTypes = false;
o.setShowArgumentNames(false); o.showArgumentNames = false;
o.setShowFunctionSignatures(true); o.showFunctionSignatures = true;
QSet<QString> signatures; QSet<QString> signatures;
foreach (const LookupItem &p, results) { foreach (const LookupItem &p, results) {
@@ -1882,8 +1882,8 @@ bool CppCompletionAssistProcessor::completeConstructorOrFunction(const QList<CPl
// set up signature autocompletion // set up signature autocompletion
foreach (Function *f, functions) { foreach (Function *f, functions) {
Overview overview; Overview overview;
overview.setShowArgumentNames(true); overview.showArgumentNames = true;
overview.setShowDefaultArguments(false); overview.showDefaultArguments = false;
const FullySpecifiedType localTy = rewriteType(f->type(), &env, control); const FullySpecifiedType localTy = rewriteType(f->type(), &env, control);