35
35
#include <ktexteditor/document.h>
37
37
#include <klocalizedstring.h>
38
#include <KTextEditor/View>
39
#include <language/duchain/duchainutils.h>
40
#include <language/duchain/classdeclaration.h>
39
42
using namespace KDevelop;
170
if (ClassFunctionDeclaration* method = dynamic_cast<ClassFunctionDeclaration*>(m_declaration.data())) {
173
QString functionName;
174
bool isConstructorOrDestructor = false;
175
bool isInterface = false;
177
if (ClassMethodDeclaration* method = dynamic_cast<ClassMethodDeclaration*>(m_declaration.data())) {
171
178
// NOTE: it should _never_ be private - but that's the completionmodel / context / worker's job
172
179
if (!modifiers.contains("public") && !modifiers.contains("protected")) {
173
180
if (method->accessPolicy() == Declaration::Protected) {
179
186
if (!modifiers.contains("static") && method->isStatic()) {
180
187
modifiers << "static";
189
functionName = method->prettyName().str();
191
isConstructorOrDestructor = method->isConstructor() || method->isDestructor();
193
if (method->context() && method->context()->owner()) {
194
ClassDeclaration* classDec = dynamic_cast<ClassDeclaration*>(method->context()->owner());
196
isInterface = (classDec->classType() == ClassDeclarationData::Interface);
183
200
kDebug() << "completion item for implementation was not a classfunction declaration!";
201
functionName = m_declaration->identifier().toString();
186
204
if (!modifiers.contains("function")) {
187
205
replText += "function ";
190
replText += m_declaration->identifier().toString();
208
replText += functionName;
193
211
// get argument list
194
212
QString arguments;
195
213
createArgumentList(*this, arguments, 0, true);
197
214
replText += arguments;
201
replText += QString("{\n%1 \n%1}\n%1").arg(indendation);
218
QVector<Declaration*> parameters;
219
if (DUChainUtils::getArgumentContext(m_declaration.data()))
220
parameters = DUChainUtils::getArgumentContext(m_declaration.data())->localDeclarations();
223
foreach(Declaration* dec, parameters) {
229
arguments += '$' + dec->identifier().toString();
234
replText += QString("\n%1{\n%1 ").arg(indendation);
236
} else if (!isConstructorOrDestructor) {
237
replText += QString("$ret = parent::%2%3;\n%1 return $ret;").arg(indendation).arg(functionName).arg(arguments);
239
replText += QString("parent::%1%2;").arg(functionName).arg(arguments);
241
replText += QString("\n%1}\n%1")
203
244
//TODO: properly place the cursor inside the {} part
204
245
document->replaceText(replaceRange, replText);
206
248
kDebug() << "Declaration disappeared";