File indexing completed on 2024-05-05 16:41:08

0001 /*
0002     SPDX-FileCopyrightText: 2008 Milian Wolff <mail@milianw.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "functiondeclaration.h"
0008 
0009 #include <language/duchain/duchainregister.h>
0010 #include <language/duchain/types/functiontype.h>
0011 
0012 namespace Php {
0013 REGISTER_DUCHAIN_ITEM(FunctionDeclaration);
0014 
0015 FunctionDeclaration::FunctionDeclaration(const FunctionDeclaration& rhs)
0016         : KDevelop::FunctionDeclaration(*new FunctionDeclarationData(*rhs.d_func()))
0017 {
0018 }
0019 
0020 FunctionDeclaration::FunctionDeclaration(const KDevelop::RangeInRevision& range, KDevelop::DUContext* context)
0021         : KDevelop::FunctionDeclaration(*new FunctionDeclarationData, range)
0022 {
0023     d_func_dynamic()->setClassId(this);
0024     if (context) {
0025         setContext(context);
0026     }
0027 }
0028 
0029 FunctionDeclaration::FunctionDeclaration(FunctionDeclarationData& data)
0030         : KDevelop::FunctionDeclaration(data)
0031 {
0032 }
0033 
0034 FunctionDeclaration::FunctionDeclaration(FunctionDeclarationData& data, const KDevelop::RangeInRevision& range, KDevelop::DUContext* context)
0035         : KDevelop::FunctionDeclaration(data, range)
0036 {
0037     if (context) {
0038         setContext(context);
0039     }
0040 }
0041 
0042 FunctionDeclaration::~FunctionDeclaration()
0043 {
0044 }
0045 
0046 KDevelop::Declaration* FunctionDeclaration::clonePrivate() const
0047 {
0048     return new FunctionDeclaration(*this);
0049 }
0050 
0051 KDevelop::IndexedString FunctionDeclaration::prettyName() const
0052 {
0053     return d_func()->prettyName;
0054 }
0055 
0056 void FunctionDeclaration::setPrettyName( const KDevelop::IndexedString& name )
0057 {
0058     d_func_dynamic()->prettyName = name;
0059 }
0060 
0061 QString FunctionDeclaration::toString() const
0062 {
0063   if( !abstractType() )
0064     return Declaration::toString();
0065 
0066   KDevelop::TypePtr<KDevelop::FunctionType> function = type<KDevelop::FunctionType>();
0067   Q_ASSERT(function);
0068 
0069   return QStringLiteral("%1 %2 %3").arg(function->partToString( KDevelop::FunctionType::SignatureReturn ),
0070                                  prettyName().str(),
0071                                  function->partToString( KDevelop::FunctionType::SignatureArguments ));
0072 }
0073 
0074 }