~ubuntu-branches/ubuntu/utopic/kdevelop-php/utopic

« back to all changes in this revision

Viewing changes to duchain/classmethoddeclaration.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2010-01-17 17:10:22 UTC
  • Revision ID: james.westby@ubuntu.com-20100117171022-q2xlgd9ekewo2ijx
Tags: upstream-1.0.0~beta2
ImportĀ upstreamĀ versionĀ 1.0.0~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   This file is part of KDevelop                                         *
 
3
 *   Copyright 2008 Milian Wolff <mail@milianw.de>                         *
 
4
 *                                                                         *
 
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.                       *
 
9
 *                                                                         *
 
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.                          *
 
14
 *                                                                         *
 
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
 ***************************************************************************/
 
20
 
 
21
#include "classmethoddeclaration.h"
 
22
 
 
23
#include <language/duchain/duchainregister.h>
 
24
#include <language/duchain/types/functiontype.h>
 
25
using namespace KDevelop;
 
26
 
 
27
namespace Php
 
28
{
 
29
REGISTER_DUCHAIN_ITEM(ClassMethodDeclaration);
 
30
 
 
31
ClassMethodDeclaration::ClassMethodDeclaration(const ClassMethodDeclaration& rhs)
 
32
        : KDevelop::ClassFunctionDeclaration(*new ClassMethodDeclarationData(*rhs.d_func()))
 
33
{
 
34
    setSmartRange(rhs.smartRange(), DocumentRangeObject::DontOwn);
 
35
}
 
36
 
 
37
ClassMethodDeclaration::ClassMethodDeclaration(const KDevelop::SimpleRange& range, KDevelop::DUContext* context)
 
38
        : KDevelop::ClassFunctionDeclaration(*new ClassMethodDeclarationData, range, context)
 
39
{
 
40
    d_func_dynamic()->setClassId(this);
 
41
    if (context)
 
42
        setContext(context);
 
43
}
 
44
 
 
45
ClassMethodDeclaration::ClassMethodDeclaration(ClassMethodDeclarationData& data)
 
46
        : KDevelop::ClassFunctionDeclaration(data)
 
47
{
 
48
}
 
49
 
 
50
ClassMethodDeclaration::ClassMethodDeclaration(ClassMethodDeclarationData& data, const KDevelop::SimpleRange& range, KDevelop::DUContext* context)
 
51
        : KDevelop::ClassFunctionDeclaration(data, range, context)
 
52
{
 
53
}
 
54
 
 
55
ClassMethodDeclaration::~ClassMethodDeclaration()
 
56
{
 
57
}
 
58
 
 
59
bool ClassMethodDeclaration::isConstructor() const
 
60
{
 
61
    Identifier id = identifier();
 
62
    return id.nameEquals(Identifier("__construct"))
 
63
           || id.nameEquals(context()->indexedLocalScopeIdentifier().identifier().first());
 
64
}
 
65
 
 
66
bool ClassMethodDeclaration::isDestructor() const
 
67
{
 
68
    //TODO: register_shutdown_function
 
69
    return identifier().nameEquals(Identifier("__destruct"));
 
70
}
 
71
 
 
72
Declaration* ClassMethodDeclaration::clonePrivate() const
 
73
{
 
74
    return new ClassMethodDeclaration(*this);
 
75
}
 
76
 
 
77
QString ClassMethodDeclaration::prettyName() const
 
78
{
 
79
    return d_func()->prettyName.str();
 
80
}
 
81
 
 
82
void ClassMethodDeclaration::setPrettyName( const QString& name )
 
83
{
 
84
    d_func_dynamic()->prettyName = KDevelop::IndexedString(name);
 
85
}
 
86
 
 
87
QString ClassMethodDeclaration::toString() const
 
88
{
 
89
    if( !abstractType() )
 
90
        return ClassMemberDeclaration::toString();
 
91
 
 
92
    TypePtr<FunctionType> function = type<FunctionType>();
 
93
    if(function) {
 
94
        return QString("%1 %2 %3").arg(function->partToString( FunctionType::SignatureReturn ))
 
95
                                  .arg(prettyName())
 
96
                                  .arg(function->partToString( FunctionType::SignatureArguments ));
 
97
    } else {
 
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);
 
101
    }
 
102
}
 
103
 
 
104
 
 
105
}