Commit 6dfe3207 authored by hjk's avatar hjk

Cpp: No need for accessors for simple structs

Change-Id: Ie09c1fc59dd54d2302a78cfc9769d5cda6012be7
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 52e381b8
......@@ -38,99 +38,16 @@
using namespace CPlusPlus;
Overview::Overview()
: _markedArgument(0),
_markedArgumentBegin(0),
_markedArgumentEnd(0),
_showArgumentNames(false),
_showReturnTypes(false),
_showFunctionSignatures(true),
_showDefaultArguments(true),
_showTemplateParameters(false)
: markedArgument(0),
markedArgumentBegin(0),
markedArgumentEnd(0),
showArgumentNames(false),
showReturnTypes(false),
showFunctionSignatures(true),
showDefaultArguments(true),
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
{
NamePrettyPrinter pp(this);
......
......@@ -44,32 +44,6 @@ class CPLUSPLUS_EXPORT Overview
public:
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
{ return prettyName(name); }
......@@ -85,15 +59,15 @@ public:
QString prettyType(const FullySpecifiedType &type, const Name *name = 0) const;
QString prettyType(const FullySpecifiedType &type, const QString &name) const;
private:
unsigned _markedArgument;
int _markedArgumentBegin;
int _markedArgumentEnd;
bool _showArgumentNames: 1;
bool _showReturnTypes: 1;
bool _showFunctionSignatures: 1;
bool _showDefaultArguments: 1;
bool _showTemplateParameters: 1;
public:
unsigned markedArgument;
int markedArgumentBegin;
int markedArgumentEnd;
bool showArgumentNames: 1;
bool showReturnTypes: 1;
bool showFunctionSignatures: 1;
bool showDefaultArguments: 1;
bool showTemplateParameters: 1;
};
} // namespace CPlusPlus
......
......@@ -143,7 +143,7 @@ void TypePrettyPrinter::visit(Namespace *type)
void TypePrettyPrinter::visit(Template *type)
{
if (Symbol *d = type->declaration()) {
if (overview()->showTemplateParameters() && ! _name.isEmpty()) {
if (overview()->showTemplateParameters && ! _name.isEmpty()) {
_name += QLatin1Char('<');
for (unsigned index = 0; index < type->templateParameterCount(); ++index) {
if (index)
......@@ -309,13 +309,13 @@ void TypePrettyPrinter::visit(Function *type)
}
_text.append(QLatin1Char(')'));
_needsParens = false;
} else if (! _name.isEmpty() && _overview->showFunctionSignatures()) {
} else if (! _name.isEmpty() && _overview->showFunctionSignatures) {
appendSpace();
_text.append(_name);
_name.clear();
}
if (_overview->showReturnTypes()) {
if (_overview->showReturnTypes) {
const QString returnType = _overview->prettyType(type->returnType());
if (!returnType.isEmpty()) {
if (!endsWithPtrOrRef(returnType))
......@@ -324,11 +324,11 @@ void TypePrettyPrinter::visit(Function *type)
}
}
if (_overview->showFunctionSignatures()) {
if (_overview->showFunctionSignatures) {
Overview argumentText;
argumentText.setShowReturnTypes(true);
argumentText.setShowArgumentNames(false);
argumentText.setShowFunctionSignatures(true);
argumentText.showReturnTypes = true;
argumentText.showArgumentNames = false;
argumentText.showFunctionSignatures = true;
_text += QLatin1Char('(');
......@@ -337,25 +337,25 @@ void TypePrettyPrinter::visit(Function *type)
_text += QLatin1String(", ");
if (Argument *arg = type->argumentAt(index)->asArgument()) {
if (index + 1 == _overview->markedArgument())
const_cast<Overview*>(_overview)->setMarkedArgumentBegin(_text.length());
if (index + 1 == _overview->markedArgument)
const_cast<Overview*>(_overview)->markedArgumentBegin = _text.length();
const Name *name = 0;
if (_overview->showArgumentNames())
if (_overview->showArgumentNames)
name = arg->name();
_text += argumentText(arg->type(), name);
if (_overview->showDefaultArguments()) {
if (_overview->showDefaultArguments) {
if (const StringLiteral *initializer = arg->initializer()) {
_text += QLatin1String(" =");
_text += QString::fromUtf8(initializer->chars(), initializer->size());
}
}
if (index + 1 == _overview->markedArgument())
const_cast<Overview*>(_overview)->setMarkedArgumentEnd(_text.length());
if (index + 1 == _overview->markedArgument)
const_cast<Overview*>(_overview)->markedArgumentEnd = _text.length();
}
}
......
......@@ -334,8 +334,8 @@ CppDeclarableElement::CppDeclarableElement(Symbol *declaration) : CppElement()
m_icon = Icons().iconForSymbol(declaration);
Overview overview;
overview.setShowArgumentNames(true);
overview.setShowReturnTypes(true);
overview.showArgumentNames = true;
overview.showReturnTypes = true;
m_name = overview.prettyName(declaration->name());
if (declaration->enclosingScope()->isClass() ||
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
// (with no argument names and no return). Help ids have no signature at all.
Overview overview;
overview.setShowDefaultArguments(false);
overview.showDefaultArguments = false;
setHelpMark(overview.prettyType(type, name()));
overview.setShowFunctionSignatures(false);
overview.showFunctionSignatures = false;
addHelpIdCandidate(overview.prettyName(declaration->name()));
}
......
......@@ -596,10 +596,10 @@ Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targ
return changes;
Overview overview;
overview.setShowReturnTypes(true);
overview.setShowTemplateParameters(true);
overview.setShowArgumentNames(true);
overview.setShowFunctionSignatures(true);
overview.showReturnTypes = true;
overview.showTemplateParameters = true;
overview.showArgumentNames = true;
overview.showFunctionSignatures = true;
// abort if the name of the newly parsed function is not the expected one
DeclaratorIdAST *newDeclId = getDeclaratorId(newDef->declarator);
......
......@@ -207,9 +207,9 @@ QList<CppQuickFixOperation::Ptr> DeclFromDef::match(
QString InsertDeclOperation::generateDeclaration(Function *function)
{
Overview oo;
oo.setShowFunctionSignatures(true);
oo.setShowReturnTypes(true);
oo.setShowArgumentNames(true);
oo.showFunctionSignatures = true;
oo.showReturnTypes = true;
oo.showArgumentNames = true;
QString decl;
decl += oo(function->type(), function->unqualifiedName());
......@@ -247,9 +247,9 @@ public:
CppRefactoringFilePtr targetFile = refactoring.file(m_loc.fileName());
Overview oo;
oo.setShowFunctionSignatures(true);
oo.setShowReturnTypes(true);
oo.setShowArgumentNames(true);
oo.showFunctionSignatures = true;
oo.showReturnTypes = true;
oo.showArgumentNames = true;
// make target lookup context
Document::Ptr targetDoc = targetFile->cppDocument();
......
......@@ -401,14 +401,14 @@ private:
QString CppFunctionHintModel::text(int index) const
{
Overview overview;
overview.setShowReturnTypes(true);
overview.setShowArgumentNames(true);
overview.setMarkedArgument(m_currentArg + 1);
overview.showReturnTypes = true;
overview.showArgumentNames = true;
overview.markedArgument = m_currentArg + 1;
Function *f = m_functionSymbols.at(index);
const QString prettyMethod = overview(f->type(), f->name());
const int begin = overview.markedArgumentBegin();
const int end = overview.markedArgumentEnd();
const QString prettyMethod = overview.prettyType(f->type(), f->name());
const int begin = overview.markedArgumentBegin;
const int end = overview.markedArgumentEnd;
QString hintText;
hintText += Qt::escape(prettyMethod.left(begin));
......@@ -536,8 +536,8 @@ public:
: _item(0)
, _symbol(0)
{
overview.setShowReturnTypes(true);
overview.setShowArgumentNames(true);
overview.showReturnTypes = true;
overview.showArgumentNames = true;
}
BasicProposalItem *operator()(Symbol *symbol)
......@@ -1574,9 +1574,9 @@ bool CppCompletionAssistProcessor::completeQtMethod(const QList<CPlusPlus::Looku
ConvertToCompletionItem toCompletionItem;
Overview o;
o.setShowReturnTypes(false);
o.setShowArgumentNames(false);
o.setShowFunctionSignatures(true);
o.showReturnTypes = false;
o.showArgumentNames = false;
o.showFunctionSignatures = true;
QSet<QString> signatures;
foreach (const LookupItem &p, results) {
......@@ -1882,8 +1882,8 @@ bool CppCompletionAssistProcessor::completeConstructorOrFunction(const QList<CPl
// set up signature autocompletion
foreach (Function *f, functions) {
Overview overview;
overview.setShowArgumentNames(true);
overview.setShowDefaultArguments(false);
overview.showArgumentNames = true;
overview.showDefaultArguments = false;
const FullySpecifiedType localTy = rewriteType(f->type(), &env, control);
......
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