[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdev-php] completion: fix override member var completion
From:       Niko Sams <niko.sams () gmail ! com>
Date:       2014-03-08 8:41:35
Message-ID: E1WMCp5-0001dF-Mb () scm ! kde ! org
[Download RAW message or body]

Git commit 1a2da6da8c07010e096c503d6dc562a97d47bed3 by Niko Sams.
Committed on 08/03/2014 at 08:07.
Pushed by nsams into branch 'master'.

fix override member var completion

add test so it doesn't break again in future

M  +5    -2    completion/context.cpp
M  +30   -0    completion/tests/test_completion.cpp
M  +1    -0    completion/tests/test_completion.h

http://commits.kde.org/kdev-php/1a2da6da8c07010e096c503d6dc562a97d47bed3

diff --git a/completion/context.cpp b/completion/context.cpp
index f7bd51a..71cd035 100644
--- a/completion/context.cpp
+++ b/completion/context.cpp
@@ -1239,6 +1239,7 @@ QList<CompletionTreeItemPointer> \
CodeCompletionContext::completionItems(bool& ab  ADD_KEYWORD("const");
                 }
             }
+            ifDebug( kDebug() << "showOverloadable" << showOverloadable; )
             // complete overloadable methods from parents
             if (showOverloadable) {
                 // TODO: use m_duContext instead of ctx
@@ -1254,7 +1255,8 @@ QList<CompletionTreeItemPointer> \
                CodeCompletionContext::completionItems(bool& ab
                     //TODO: always add __construct, __destruct and maby other magic \
                functions
                     // get all visible declarations and add inherited to the \
                completion items
                     foreach(const DeclarationDepthPair& decl, \
                ctx->allDeclarations(ctx->range().end, m_duContext->topContext(), \
                false)) {
-                        ClassFunctionDeclaration *member = \
dynamic_cast<ClassFunctionDeclaration*>(decl.first); +                        \
ClassMemberDeclaration *member = dynamic_cast<ClassMemberDeclaration*>(decl.first); + \
ClassFunctionDeclaration *classFunc = \
dynamic_cast<ClassFunctionDeclaration*>(decl.first);  if (member) {
                             if (decl.second == 0) {
                                 // this function is already implemented
@@ -1284,7 +1286,7 @@ QList<CompletionTreeItemPointer> \
CodeCompletionContext::completionItems(bool& ab  continue;
                             }
                             // skip final members
-                            if (member->isFinal()) {
+                            if (classFunc && classFunc->isFinal()) {
                                 // make sure no non-final base members are added
                                 alreadyImplemented << \
decl.first->indexedIdentifier().getIndex();  continue;
@@ -1307,6 +1309,7 @@ QList<CompletionTreeItemPointer> \
CodeCompletionContext::completionItems(bool& ab  } else {
                                 itype = ImplementationItem::Override;
                             }
+                            ifDebug( kDebug() << "ImplementationItem" << itype; )
 
                             items << CompletionTreeItemPointer(new \
                ImplementationItem(itype, DeclarationPointer(decl.first),
                                                                 \
                KDevelop::CodeCompletionContext::Ptr(this), decl.second));
diff --git a/completion/tests/test_completion.cpp \
b/completion/tests/test_completion.cpp index 6e4a816..3bafd8b 100644
--- a/completion/tests/test_completion.cpp
+++ b/completion/tests/test_completion.cpp
@@ -746,6 +746,36 @@ void TestCompletion::overrideMethods()
     //TODO: verify actual completion text
 }
 
+void TestCompletion::overrideVars()
+{
+    //                 0         1         2         3         4         5         6 \
7 +    //                 \
01234567890123456789012345678901234567890123456789012345678901234567890123456789 +    \
QByteArray method("<? class A { protected $x;  } class B extends A {  }"); +
+    TopDUContext* top = parse(method, DumpNone);
+    DUChainReleaser releaseTop(top);
+    DUChainWriteLocker lock(DUChain::lock());
+
+    // context of class B
+    DUContext* classContext = top->childContexts().last();
+    {
+        PhpCompletionTester tester(classContext, "{");
+        QStringList compItems;
+        compItems << "x";
+        compItems << "const";
+        compItems << "final";
+        compItems << "function";
+        compItems << "public";
+        compItems << "private";
+        compItems << "protected";
+        compItems << "static";
+        compItems << "var";
+        compItems.sort();
+        tester.names.sort();
+        QCOMPARE(tester.names, compItems);
+    }
+}
+
 void TestCompletion::inArray()
 {
     TopDUContext* top = parse("", DumpNone);
diff --git a/completion/tests/test_completion.h b/completion/tests/test_completion.h
index 56fe20a..7bfff7e 100644
--- a/completion/tests/test_completion.h
+++ b/completion/tests/test_completion.h
@@ -67,6 +67,7 @@ private slots:
     void interfaceMethods();
     void interfaceMethods2();
     void overrideMethods();
+    void overrideVars();
     void implementMethods();
     void inArray();
     void newExtends();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic