aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzzhongwei2012-12-02 05:28:33 (EST)
committerzzhongwei2012-12-02 05:32:17 (EST)
commit7be29a3c40c1d92c1f9614240965f61ad1b7d709 (patch)
tree5559e677b67c7a8b03ca9de3c2557f7f6062d55f
parenta5d27e1c64543c99a626a3c9b6159164144f5466 (diff)
downloadorg.eclipse.pdt-7be29a3c40c1d92c1f9614240965f61ad1b7d709.zip
org.eclipse.pdt-7be29a3c40c1d92c1f9614240965f61ad1b7d709.tar.gz
org.eclipse.pdt-7be29a3c40c1d92c1f9614240965f61ad1b7d709.tar.bz2
386637: Code assist not working with global space classes and with out
using `use` operator https://bugs.eclipse.org/bugs/show_bug.cgi?id=386637
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/CodeAssistUtils.java54
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/TraitUtils.java11
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/ClassVariableDeclarationEvaluator.java9
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitMembers10.pdtt24
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitMembers9.pdtt41
5 files changed, 118 insertions, 21 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/CodeAssistUtils.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/CodeAssistUtils.java
index 8cbeeaf..7146b62 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/CodeAssistUtils.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/CodeAssistUtils.java
@@ -19,6 +19,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
import org.eclipse.dltk.ast.references.VariableReference;
import org.eclipse.dltk.core.*;
+import org.eclipse.dltk.evaluation.types.AmbiguousType;
import org.eclipse.dltk.evaluation.types.MultiTypeType;
import org.eclipse.dltk.ti.IContext;
import org.eclipse.dltk.ti.ISourceModuleContext;
@@ -136,21 +137,9 @@ public class CodeAssistUtils {
varReference);
PHPTypeInferencer typeInferencer = new PHPTypeInferencer();
IEvaluatedType evaluatedType = typeInferencer.evaluateType(goal);
-
- if (evaluatedType instanceof MultiTypeType) {
- List<IType> tmpList = new LinkedList<IType>();
- List<IEvaluatedType> possibleTypes = ((MultiTypeType) evaluatedType)
- .getTypes();
- for (IEvaluatedType possibleType : possibleTypes) {
- IType[] tmpArray = PHPTypeInferenceUtils.getModelElements(
- possibleType, (ISourceModuleContext) context,
- position, (IModelAccessCache) null);
- if (tmpArray != null) {
- tmpList.addAll(Arrays.asList(tmpArray));
- }
- }
- // the elements are filtered already
- return tmpList.toArray(new IType[tmpList.size()]);
+ if (evaluatedType instanceof MultiTypeType
+ || evaluatedType instanceof AmbiguousType) {
+ return getTypes(position, context, evaluatedType);
}
IType[] modelElements = PHPTypeInferenceUtils.getModelElements(
@@ -162,6 +151,36 @@ public class CodeAssistUtils {
return EMPTY_TYPES;
}
+ private static IType[] getTypes(int position, IContext context,
+ IEvaluatedType evaluatedType) {
+ List<IType> tmpList = new LinkedList<IType>();
+ List<IEvaluatedType> possibleTypes = new LinkedList<IEvaluatedType>();
+ if (evaluatedType instanceof MultiTypeType) {
+ possibleTypes = ((MultiTypeType) evaluatedType).getTypes();
+ } else if (evaluatedType instanceof AmbiguousType) {
+ possibleTypes.addAll(Arrays.asList(((AmbiguousType) evaluatedType)
+ .getPossibleTypes()));
+ } else {
+ possibleTypes.add(evaluatedType);
+ }
+ for (IEvaluatedType possibleType : possibleTypes) {
+ IType[] tmpArray;
+ if (possibleType instanceof MultiTypeType
+ || possibleType instanceof AmbiguousType) {
+ tmpArray = getTypes(position, context, possibleType);
+ } else {
+ tmpArray = PHPTypeInferenceUtils.getModelElements(possibleType,
+ (ISourceModuleContext) context, position,
+ (IModelAccessCache) null);
+ }
+ if (tmpArray != null) {
+ tmpList.addAll(Arrays.asList(tmpArray));
+ }
+ }
+ // the elements are filtered already
+ return tmpList.toArray(new IType[tmpList.size()]);
+ }
+
/**
* Returns type of a variable defined by name.
*
@@ -184,8 +203,9 @@ public class CodeAssistUtils {
PHPTypeInferencer typeInferencer = new PHPTypeInferencer();
IEvaluatedType evaluatedType = typeInferencer.evaluateType(goal);
- IType[] modelElements = PHPTypeInferenceUtils.getModelElements(
- evaluatedType, (ISourceModuleContext) context, position);
+ IType[] modelElements = getTypes(position, context, evaluatedType);
+ // IType[] modelElements = PHPTypeInferenceUtils.getModelElements(
+ // evaluatedType, (ISourceModuleContext) context, position);
if (modelElements != null) {
return modelElements;
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/TraitUtils.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/TraitUtils.java
index b79ed53..c6b8da3 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/TraitUtils.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/TraitUtils.java
@@ -60,9 +60,16 @@ public class TraitUtils {
useTrait = new UseTrait();
}
for (TypeReference typeReference : statement.getTraitList()) {
+ String name = typeReference.getName();
+ if (typeReference instanceof FullyQualifiedReference) {
+ FullyQualifiedReference reference = (FullyQualifiedReference) typeReference;
+ if (reference.getNamespace() != null) {
+ name = reference.getNamespace().getName()
+ + NamespaceReference.NAMESPACE_SEPARATOR + name;
+ }
+ }
useTrait.getTraits().add(
- PHPModelUtils.getFullName(typeReference.getName(),
- sourceModule, offset));
+ PHPModelUtils.getFullName(name, sourceModule, offset));
}
for (TraitStatement traitStatement : statement.getTsList()) {
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/ClassVariableDeclarationEvaluator.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/ClassVariableDeclarationEvaluator.java
index 75c41b7..52e9ca7 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/ClassVariableDeclarationEvaluator.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/ClassVariableDeclarationEvaluator.java
@@ -33,6 +33,7 @@ import org.eclipse.php.internal.core.compiler.ast.nodes.*;
import org.eclipse.php.internal.core.typeinference.*;
import org.eclipse.php.internal.core.typeinference.context.ContextFinder;
import org.eclipse.php.internal.core.typeinference.context.IModelCacheContext;
+import org.eclipse.php.internal.core.typeinference.context.MethodContext;
import org.eclipse.php.internal.core.typeinference.context.TypeContext;
import org.eclipse.php.internal.core.typeinference.goals.ClassVariableDeclarationGoal;
@@ -171,8 +172,12 @@ public class ClassVariableDeclarationEvaluator extends AbstractPHPGoalEvaluator
Map<ASTNode, IContext> staticDeclarations = searcher
.getStaticDeclarations();
for (ASTNode node : staticDeclarations.keySet()) {
- subGoals.add(new ExpressionTypeGoal(staticDeclarations
- .get(node), node));
+ IContext context = staticDeclarations.get(node);
+ if (context instanceof MethodContext) {
+ MethodContext methodContext = (MethodContext) context;
+ methodContext.setCurrentType(realType);
+ }
+ subGoals.add(new ExpressionTypeGoal(context, node));
}
} catch (Exception e) {
if (DLTKCore.DEBUG) {
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitMembers10.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitMembers10.pdtt
new file mode 100644
index 0000000..ec499d8
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitMembers10.pdtt
@@ -0,0 +1,24 @@
+--TEST--
+Test trait Members 8
+--PREFERENCES--
+org.eclipse.php.core/contentAssistShowStrictOptions=false
+--FILE--
+<?php
+trait AnotherA {
+ public function smallTalk() {
+ echo 'a';
+ }
+ public function bigTalk() {
+ echo 'A';
+ }
+}
+
+class Aliased_Talker {
+ use AnotherA {
+ AnotherA::| // Should get the methods smallTalk and bigTalk after the ::
+ }
+}
+?>
+--EXPECT--
+method(bigTalk)
+method(smallTalk) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitMembers9.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitMembers9.pdtt
new file mode 100644
index 0000000..7ce1ae1
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitMembers9.pdtt
@@ -0,0 +1,41 @@
+--TEST--
+Test trait Members 8
+--PREFERENCES--
+org.eclipse.php.core/contentAssistShowStrictOptions=false
+--FILE--
+<?php
+namespace Traits; // Second line that breaks it
+
+trait singleton {
+
+ private static $oInstance;
+
+ public static function getSingleton() {
+ if(!self::$oInstance instanceof self) {
+ self::$oInstance = new self;
+ }
+ return self::$oInstance;
+ }
+}
+namespace TestNamespace;
+
+require_once '386637.php';
+
+class UnNameSpacedClass {
+
+ /**
+ * @var \UnNameSpacedClass
+ * @return \UnNameSpacedClass
+ */
+ use \Traits\singleton; // First line that breaks it
+
+ public function testFunction() {
+ echo 'Test Function';
+ }
+}
+// Test 1: Not Working
+UnNameSpacedClass::getSingleton()->|
+?>
+--EXPECT--
+method(getSingleton)
+method(testFunction) \ No newline at end of file