From 5d8ee0d742ef591c23b99bdce29ddd4a4553e98d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= <thorbjorn.lindeijer@nokia.com>
Date: Thu, 26 Mar 2009 16:43:38 +0100
Subject: [PATCH] Moved some complicated checks into convenience functions

---
 src/plugins/cpptools/cppcodecompletion.cpp |  9 ++-------
 src/shared/cplusplus/Symbols.cpp           | 12 ++++++++++++
 src/shared/cplusplus/Symbols.h             |  6 ++++++
 3 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp
index 1be7e410012..2bdaa6445f6 100644
--- a/src/plugins/cpptools/cppcodecompletion.cpp
+++ b/src/plugins/cpptools/cppcodecompletion.cpp
@@ -1209,10 +1209,7 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item)
             if (Function *function = symbol->type()->asFunctionType()) {
                 // If the member is a function, automatically place the opening parenthesis,
                 // except when it might take template parameters.
-                const bool hasReturnType = function->returnType().isValid()  ||
-                                           function->returnType().isSigned() ||
-                                           function->returnType().isUnsigned();
-                if (! hasReturnType && (function->identity() && !function->identity()->isDestructorNameId())) {
+                if (! function->hasReturnType() && (function->identity() && !function->identity()->isDestructorNameId())) {
                     // Don't insert any magic, since the user might have just wanted to select the class
 
                 } else if (function->templateParameterCount() != 0) {
@@ -1224,9 +1221,7 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item)
                     extraChars += QLatin1Char('(');
 
                     // If the function takes no arguments, automatically place the closing parenthesis
-                    if (item.m_duplicateCount == 0 && (function->argumentCount() == 0 ||
-                                                       (function->argumentCount() == 1 &&
-                                                        function->argumentAt(0)->type()->isVoidType()))) {
+                    if (item.m_duplicateCount == 0 && ! function->hasArguments()) {
                         extraChars += QLatin1Char(')');
 
                         // If the function doesn't return anything, automatically place the semicolon,
diff --git a/src/shared/cplusplus/Symbols.cpp b/src/shared/cplusplus/Symbols.cpp
index 5185aa82659..10b82664c34 100644
--- a/src/shared/cplusplus/Symbols.cpp
+++ b/src/shared/cplusplus/Symbols.cpp
@@ -217,6 +217,12 @@ FullySpecifiedType Function::returnType() const
 void Function::setReturnType(FullySpecifiedType returnType)
 { _returnType = returnType; }
 
+bool Function::hasReturnType() const
+{
+    const FullySpecifiedType ty = returnType();
+    return ty.isValid() || ty.isSigned() || ty.isUnsigned();
+}
+
 unsigned Function::argumentCount() const
 {
     if (! _arguments)
@@ -231,6 +237,12 @@ Symbol *Function::argumentAt(unsigned index) const
 Scope *Function::arguments() const
 { return _arguments; }
 
+bool Function::hasArguments() const
+{
+    return ! (argumentCount() == 0 ||
+              (argumentCount() == 1 && argumentAt(0)->type()->isVoidType()));
+}
+
 bool Function::isVariadic() const
 { return _isVariadic; }
 
diff --git a/src/shared/cplusplus/Symbols.h b/src/shared/cplusplus/Symbols.h
index 8efc0fbdbed..4052b746da2 100644
--- a/src/shared/cplusplus/Symbols.h
+++ b/src/shared/cplusplus/Symbols.h
@@ -288,10 +288,16 @@ public:
     FullySpecifiedType returnType() const;
     void setReturnType(FullySpecifiedType returnType);
 
+    /** Convenience function that returns whether the function returns something (including void). */
+    bool hasReturnType() const;
+
     unsigned argumentCount() const;
     Symbol *argumentAt(unsigned index) const;
     Scope *arguments() const;
 
+    /** Convenience function that returns whether the function receives any arguments. */
+    bool hasArguments() const;
+
     bool isVariadic() const;
     void setVariadic(bool isVariadic);
 
-- 
GitLab