aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzzhongwei2012-11-26 01:23:28 (EST)
committerzzhongwei2012-11-26 01:23:28 (EST)
commit6d09f8eb9e48eb06f807533685f3adde358bc8db (patch)
tree87c0df673189e891c8d11352c65fe15c4df3d8d1
parent0ba0f9d1432e1722ef7f2a86a3167cc971aac79e (diff)
downloadorg.eclipse.pdt-6d09f8eb9e48eb06f807533685f3adde358bc8db.zip
org.eclipse.pdt-6d09f8eb9e48eb06f807533685f3adde358bc8db.tar.gz
org.eclipse.pdt-6d09f8eb9e48eb06f807533685f3adde358bc8db.tar.bz2
395040: wrong Content Assist suggestion in method body
https://bugs.eclipse.org/bugs/show_bug.cgi?id=395040
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/LocalMethodElementsCompositeStrategy.java9
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/MethodKeywordStrategy.java28
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassMembers20-nonstrict.pdtt1
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassMembers20-strict.pdtt1
4 files changed, 37 insertions, 2 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/LocalMethodElementsCompositeStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/LocalMethodElementsCompositeStrategy.java
index 6af6177..cb71cac 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/LocalMethodElementsCompositeStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/LocalMethodElementsCompositeStrategy.java
@@ -16,6 +16,7 @@ import java.util.Collection;
import org.eclipse.php.core.codeassist.ICompletionContext;
import org.eclipse.php.core.codeassist.ICompletionStrategy;
+import org.eclipse.php.internal.core.codeassist.CompletionCompanion;
import org.eclipse.php.internal.core.codeassist.ICompletionReporter;
/**
@@ -38,6 +39,14 @@ public class LocalMethodElementsCompositeStrategy extends
strategies.add(new MethodKeywordStrategy(context));
}
+ @Override
+ public void init(CompletionCompanion companion) {
+ super.init(companion);
+ for (ICompletionStrategy strategy : strategies) {
+ strategy.init(companion);
+ }
+ }
+
public void apply(ICompletionReporter reporter) throws Exception {
for (ICompletionStrategy strategy : strategies) {
strategy.apply(reporter);
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/MethodKeywordStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/MethodKeywordStrategy.java
index c5b8916..2fb7eda 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/MethodKeywordStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/MethodKeywordStrategy.java
@@ -11,8 +11,13 @@
*******************************************************************************/
package org.eclipse.php.internal.core.codeassist.strategies;
+import org.eclipse.dltk.core.IType;
+import org.eclipse.dltk.core.ITypeHierarchy;
+import org.eclipse.dltk.core.ModelException;
import org.eclipse.php.core.codeassist.ICompletionContext;
import org.eclipse.php.core.codeassist.IElementFilter;
+import org.eclipse.php.core.compiler.PHPFlags;
+import org.eclipse.php.internal.core.codeassist.contexts.GlobalMethodStatementContext;
import org.eclipse.php.internal.core.language.keywords.PHPKeywords;
import org.eclipse.php.internal.core.language.keywords.PHPKeywords.KeywordData;
@@ -50,6 +55,29 @@ public class MethodKeywordStrategy extends KeywordsStrategy {
*/
@Override
protected boolean filterKeyword(KeywordData keyword) {
+ // if the class does not have parent
+ if ((keyword.context & PHPKeywords.METHOD_BODY) != 0
+ && keyword.name.equals("parent")) {
+ ICompletionContext context = getContext();
+ if (context instanceof GlobalMethodStatementContext) {
+ GlobalMethodStatementContext globalContext = (GlobalMethodStatementContext) context;
+ IType type = globalContext.getEnclosingType();
+ try {
+ if (PHPFlags.isClass(type.getFlags())) {
+ ITypeHierarchy hierarchy = getCompanion()
+ .getSuperTypeHierarchy(type, null);
+ IType[] superTypes = hierarchy.getAllSupertypes(type);
+ for (IType superType : superTypes) {
+ if (PHPFlags.isClass(superType.getFlags())) {
+ return false;
+ }
+ }
+ }
+ } catch (ModelException e) {
+ }
+ return true;
+ }
+ }
return (keyword.context & PHPKeywords.METHOD_BODY) == 0;
}
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassMembers20-nonstrict.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassMembers20-nonstrict.pdtt
index ed136ee..e9dd0c0 100644
--- a/tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassMembers20-nonstrict.pdtt
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassMembers20-nonstrict.pdtt
@@ -5,7 +5,6 @@ org.eclipse.php.core/contentAssistShowStrictOptions=false
--FILE--
<? class MyClass { function getInstance() { pare|} } ?>
--EXPECT--
-keyword(parent)
type(ParentIterator)
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassMembers20-strict.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassMembers20-strict.pdtt
index 3d98ff0..9451349 100644
--- a/tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassMembers20-strict.pdtt
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassMembers20-strict.pdtt
@@ -5,7 +5,6 @@ org.eclipse.php.core/contentAssistShowStrictOptions=true
--FILE--
<? class MyClass { function getInstance() { pare|} } ?>
--EXPECT--
-keyword(parent)
type(ParentIterator)