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

« back to all changes in this revision

Viewing changes to completion/implementationitem.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2010-03-14 10:19:34 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100314101934-d24i8t1niai087ul
Tags: 1.0.0~beta4-1
New upstream release. (Closes: #573811)

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include <ktexteditor/document.h>
36
36
#include <kicon.h>
37
37
#include <klocalizedstring.h>
 
38
#include <KTextEditor/View>
 
39
#include <language/duchain/duchainutils.h>
 
40
#include <language/duchain/classdeclaration.h>
38
41
 
39
42
using namespace KDevelop;
40
43
 
167
170
            }
168
171
        }
169
172
 
170
 
        if (ClassFunctionDeclaration* method = dynamic_cast<ClassFunctionDeclaration*>(m_declaration.data())) {
 
173
        QString functionName;
 
174
        bool isConstructorOrDestructor = false;
 
175
        bool isInterface = false;
 
176
 
 
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";
181
188
            }
 
189
            functionName = method->prettyName().str();
 
190
 
 
191
            isConstructorOrDestructor = method->isConstructor() || method->isDestructor();
 
192
 
 
193
            if (method->context() && method->context()->owner()) {
 
194
                ClassDeclaration* classDec = dynamic_cast<ClassDeclaration*>(method->context()->owner());
 
195
                if (classDec) {
 
196
                    isInterface = (classDec->classType() == ClassDeclarationData::Interface);
 
197
                }
 
198
            }
182
199
        } else {
183
200
            kDebug() << "completion item for implementation was not a classfunction declaration!";
 
201
            functionName = m_declaration->identifier().toString();
184
202
        }
185
203
 
186
204
        if (!modifiers.contains("function")) {
187
205
            replText += "function ";
188
206
        }
189
207
 
190
 
        replText += m_declaration->identifier().toString();
 
208
        replText += functionName;
191
209
 
192
210
        {
193
211
            // get argument list
194
212
            QString arguments;
195
213
            createArgumentList(*this, arguments, 0, true);
196
 
 
197
214
            replText += arguments;
198
215
        }
199
216
 
200
 
        // ) {...}
201
 
        replText += QString("{\n%1  \n%1}\n%1").arg(indendation);
 
217
        QString arguments;
 
218
        QVector<Declaration*> parameters;
 
219
        if (DUChainUtils::getArgumentContext(m_declaration.data()))
 
220
            parameters = DUChainUtils::getArgumentContext(m_declaration.data())->localDeclarations();
 
221
        arguments = '(';
 
222
        bool first = true;
 
223
        foreach(Declaration* dec, parameters) {
 
224
            if (first)
 
225
                first = false;
 
226
            else
 
227
                arguments += ", ";
 
228
 
 
229
            arguments += '$' + dec->identifier().toString();
 
230
        }
 
231
        arguments += ')';
 
232
 
 
233
 
 
234
        replText += QString("\n%1{\n%1    ").arg(indendation);
 
235
        if (isInterface) {
 
236
        } else if (!isConstructorOrDestructor) {
 
237
            replText += QString("$ret = parent::%2%3;\n%1    return $ret;").arg(indendation).arg(functionName).arg(arguments);
 
238
        } else {
 
239
            replText += QString("parent::%1%2;").arg(functionName).arg(arguments);
 
240
        }
 
241
        replText += QString("\n%1}\n%1")
 
242
                .arg(indendation);
202
243
 
203
244
        //TODO: properly place the cursor inside the {} part
204
245
        document->replaceText(replaceRange, replText);
 
246
 
205
247
    } else {
206
248
        kDebug() << "Declaration disappeared";
207
249
    }