1
/***************************************************************************
2
* This file is part of KDevelop *
3
* Copyright 2008 Milian Wolff <mail@milianw.de> *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU Library General Public License as *
7
* published by the Free Software Foundation; either version 2 of the *
8
* License, or (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU Library General Public *
16
* License along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19
***************************************************************************/
21
#include "classmethoddeclaration.h"
23
#include <language/duchain/duchainregister.h>
24
#include <language/duchain/types/functiontype.h>
25
using namespace KDevelop;
29
REGISTER_DUCHAIN_ITEM(ClassMethodDeclaration);
31
ClassMethodDeclaration::ClassMethodDeclaration(const ClassMethodDeclaration& rhs)
32
: KDevelop::ClassFunctionDeclaration(*new ClassMethodDeclarationData(*rhs.d_func()))
34
setSmartRange(rhs.smartRange(), DocumentRangeObject::DontOwn);
37
ClassMethodDeclaration::ClassMethodDeclaration(const KDevelop::SimpleRange& range, KDevelop::DUContext* context)
38
: KDevelop::ClassFunctionDeclaration(*new ClassMethodDeclarationData, range, context)
40
d_func_dynamic()->setClassId(this);
45
ClassMethodDeclaration::ClassMethodDeclaration(ClassMethodDeclarationData& data)
46
: KDevelop::ClassFunctionDeclaration(data)
50
ClassMethodDeclaration::ClassMethodDeclaration(ClassMethodDeclarationData& data, const KDevelop::SimpleRange& range, KDevelop::DUContext* context)
51
: KDevelop::ClassFunctionDeclaration(data, range, context)
55
ClassMethodDeclaration::~ClassMethodDeclaration()
59
bool ClassMethodDeclaration::isConstructor() const
61
Identifier id = identifier();
62
return id.nameEquals(Identifier("__construct"))
63
|| id.nameEquals(context()->indexedLocalScopeIdentifier().identifier().first());
66
bool ClassMethodDeclaration::isDestructor() const
68
//TODO: register_shutdown_function
69
return identifier().nameEquals(Identifier("__destruct"));
72
Declaration* ClassMethodDeclaration::clonePrivate() const
74
return new ClassMethodDeclaration(*this);
77
QString ClassMethodDeclaration::prettyName() const
79
return d_func()->prettyName.str();
82
void ClassMethodDeclaration::setPrettyName( const QString& name )
84
d_func_dynamic()->prettyName = KDevelop::IndexedString(name);
87
QString ClassMethodDeclaration::toString() const
90
return ClassMemberDeclaration::toString();
92
TypePtr<FunctionType> function = type<FunctionType>();
94
return QString("%1 %2 %3").arg(function->partToString( FunctionType::SignatureReturn ))
96
.arg(function->partToString( FunctionType::SignatureArguments ));
98
QString type = abstractType() ? abstractType()->toString() : QString("<notype>");
99
kDebug(9505) << "A function has a bad type attached:" << type;
100
return QString("invalid member-function %1 type %2").arg(prettyName()).arg(type);