Add AbstractDeclarationNavigationContext, and move the html-method from
[kdevelopdvcssupport.git] / language / duchain / classfunctiondeclaration.cpp
blob1994e6dc79f1b60a17f6f42fb75b19560f903840
1 /* This is part of KDevelop
2 Copyright 2002-2005 Roberto Raggi <roberto@kdevelop.org>
3 Copyright 2006 Adam Treat <treat@kde.org>
4 Copyright 2006 Hamish Rodda <rodda@kde.org>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License version 2 as published by the Free Software Foundation.
10 This library 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 GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 #include "classfunctiondeclaration.h"
23 #include "ducontext.h"
24 #include "types/functiontype.h"
25 #include "duchainregister.h"
27 namespace KDevelop
29 Identifier conversionIdentifier("operator{...cast...}");
31 REGISTER_DUCHAIN_ITEM(ClassFunctionDeclaration);
33 ClassFunctionDeclaration::ClassFunctionDeclaration(const ClassFunctionDeclaration& rhs)
34 : ClassFunctionDeclarationBase(*new ClassFunctionDeclarationData( *rhs.d_func() )) {
35 setSmartRange(rhs.smartRange(), DocumentRangeObject::DontOwn);
38 void ClassFunctionDeclaration::setAbstractType(AbstractType::Ptr type) {
39 if(!( !type || dynamic_cast<FunctionType*>(type.unsafeData()) ))
40 kWarning(9505) << "WARNING: Non-function type assigned to function declaration";
41 ClassMemberDeclaration::setAbstractType(type);
44 DEFINE_LIST_MEMBER_HASH(ClassFunctionDeclarationData, m_defaultParameters, IndexedString)
46 ClassFunctionDeclaration::ClassFunctionDeclaration(ClassFunctionDeclarationData& data) : ClassFunctionDeclarationBase(data)
50 ClassFunctionDeclaration::ClassFunctionDeclaration(const SimpleRange& range, DUContext* context)
51 : ClassFunctionDeclarationBase(*new ClassFunctionDeclarationData, range)
53 d_func_dynamic()->setClassId(this);
54 if( context )
55 setContext( context );
58 Declaration* ClassFunctionDeclaration::clonePrivate() const {
59 return new ClassFunctionDeclaration(*this);
62 ClassFunctionDeclaration::~ClassFunctionDeclaration()
66 bool ClassFunctionDeclaration::isFunctionDeclaration() const
68 return true;
71 QString ClassFunctionDeclaration::toString() const {
72 if( !abstractType() )
73 return ClassMemberDeclaration::toString();
75 TypePtr<FunctionType> function = type<FunctionType>();
76 if(function) {
77 return QString("%1 %2 %3").arg(function->partToString( FunctionType::SignatureReturn )).arg(identifier().toString()).arg(function->partToString( FunctionType::SignatureArguments ));
78 } else {
79 QString type = abstractType() ? abstractType()->toString() : QString("<notype>");
80 kDebug(9505) << "A function has a bad type attached:" << type;
81 return QString("invalid member-function %1 type %2").arg(identifier().toString()).arg(type);
86 /*bool ClassFunctionDeclaration::isSimilar(KDevelop::CodeItem *other, bool strict ) const
88 if (!CppClassMemberType::isSimilar(other,strict))
89 return false;
91 FunctionModelItem func = dynamic_cast<ClassFunctionDeclaration*>(other);
93 if (isConstant() != func->isConstant())
94 return false;
96 if (arguments().count() != func->arguments().count())
97 return false;
99 for (int i=0; i<arguments().count(); ++i)
101 ArgumentModelItem arg1 = arguments().at(i);
102 ArgumentModelItem arg2 = arguments().at(i);
104 if (arg1->type() != arg2->type())
105 return false;
108 return true;
111 ClassFunctionDeclaration::QtFunctionType ClassFunctionDeclaration::functionType() const
113 return d_func()->m_functionType;
116 void ClassFunctionDeclaration::setFunctionType(QtFunctionType functionType)
118 d_func_dynamic()->m_functionType = functionType;
121 bool ClassFunctionDeclaration::isConversionFunction() const {
122 return identifier() == conversionIdentifier;
125 bool ClassFunctionDeclaration::isConstructor() const
127 DUContext* ctx = context();
128 if (ctx && ctx->type() == DUContext::Class && ctx->localScopeIdentifier().top().nameEquals(identifier()))
129 return true;
130 return false;
133 bool ClassFunctionDeclaration::isDestructor() const
135 DUContext* ctx = context();
136 QString id = identifier().toString();
137 return ctx && ctx->type() == DUContext::Class && id.startsWith('~') && id.mid(1) == ctx->localScopeIdentifier().top().toString();
140 uint ClassFunctionDeclaration::additionalIdentity() const
142 if(abstractType())
143 return abstractType()->hash();
144 else
145 return 0;
148 const IndexedString* ClassFunctionDeclaration::defaultParameters() const
150 return d_func()->m_defaultParameters();
153 int ClassFunctionDeclaration::defaultParametersSize() const
155 return d_func()->m_defaultParametersSize();
158 void ClassFunctionDeclaration::addDefaultParameter(const IndexedString& str)
160 d_func_dynamic()->m_defaultParametersList().append(str);
163 void ClassFunctionDeclaration::clearDefaultParameters()
165 d_func_dynamic()->m_defaultParametersList().clear();
169 // kate: space-indent on; indent-width 2; tab-width 4; replace-tabs on; auto-insert-doxygen on